Upload data/data_fetcher.py with huggingface_hub
Browse files- data/data_fetcher.py +5 -26
data/data_fetcher.py
CHANGED
|
@@ -450,6 +450,7 @@ class DataFetcher:
|
|
| 450 |
MATCH (a)-[r]-(b)
|
| 451 |
WHERE a.address IN $addresses AND r.timestamp <= $cutoff_ts
|
| 452 |
RETURN a.address AS source_address, type(r) AS link_type, properties(r) AS link_props, b.address AS dest_address, labels(b)[0] AS dest_type
|
|
|
|
| 453 |
"""
|
| 454 |
params = {'addresses': list(newly_found_entities), 'cutoff_ts': cutoff_ts}
|
| 455 |
result = session.run(query, params)
|
|
@@ -1029,37 +1030,15 @@ class DataFetcher:
|
|
| 1029 |
|
| 1030 |
def fetch_holder_snapshot_stats_for_token(self, token_address: str, T_cutoff: datetime.datetime, limit: int = 200) -> Tuple[int, List[Dict[str, Any]]]:
|
| 1031 |
"""
|
| 1032 |
-
Fetch total holder count
|
| 1033 |
Returns (count, top_holders_list).
|
| 1034 |
-
|
| 1035 |
-
NOTE: Requires pre-computed holder_snapshots table created with:
|
| 1036 |
-
CREATE TABLE holder_snapshots ENGINE = MergeTree() ORDER BY (mint_address, snapshot_ts) AS
|
| 1037 |
-
SELECT mint_address, toStartOfInterval(updated_at, INTERVAL 5 minute) AS snapshot_ts,
|
| 1038 |
-
countDistinct(wallet_address) AS holder_count
|
| 1039 |
-
FROM wallet_holdings WHERE current_balance > 0 GROUP BY mint_address, snapshot_ts
|
| 1040 |
"""
|
| 1041 |
if not token_address:
|
| 1042 |
return 0, []
|
| 1043 |
|
| 1044 |
-
|
| 1045 |
-
|
| 1046 |
-
SELECT holder_count
|
| 1047 |
-
FROM holder_snapshots
|
| 1048 |
-
WHERE mint_address = %(token)s AND snapshot_ts <= %(T_cutoff)s
|
| 1049 |
-
ORDER BY snapshot_ts DESC
|
| 1050 |
-
LIMIT 1
|
| 1051 |
-
"""
|
| 1052 |
-
params = {'token': token_address, 'T_cutoff': T_cutoff}
|
| 1053 |
-
try:
|
| 1054 |
-
rows = self.db_client.execute(query, params)
|
| 1055 |
-
if not rows:
|
| 1056 |
-
return 0, []
|
| 1057 |
-
holder_count = rows[0][0]
|
| 1058 |
-
# Return empty top_holders - not needed for caching
|
| 1059 |
-
return int(holder_count or 0), []
|
| 1060 |
-
except Exception as e:
|
| 1061 |
-
print(f"ERROR: Failed to fetch holder snapshot: {e}")
|
| 1062 |
-
return 0, []
|
| 1063 |
def fetch_raw_token_data(
|
| 1064 |
self,
|
| 1065 |
token_address: str,
|
|
|
|
| 450 |
MATCH (a)-[r]-(b)
|
| 451 |
WHERE a.address IN $addresses AND r.timestamp <= $cutoff_ts
|
| 452 |
RETURN a.address AS source_address, type(r) AS link_type, properties(r) AS link_props, b.address AS dest_address, labels(b)[0] AS dest_type
|
| 453 |
+
LIMIT 10000
|
| 454 |
"""
|
| 455 |
params = {'addresses': list(newly_found_entities), 'cutoff_ts': cutoff_ts}
|
| 456 |
result = session.run(query, params)
|
|
|
|
| 1030 |
|
| 1031 |
def fetch_holder_snapshot_stats_for_token(self, token_address: str, T_cutoff: datetime.datetime, limit: int = 200) -> Tuple[int, List[Dict[str, Any]]]:
|
| 1032 |
"""
|
| 1033 |
+
Fetch total holder count at a point in time.
|
| 1034 |
Returns (count, top_holders_list).
|
| 1035 |
+
Uses the indexed wallet_holdings table directly - efficient due to mint_address filter.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1036 |
"""
|
| 1037 |
if not token_address:
|
| 1038 |
return 0, []
|
| 1039 |
|
| 1040 |
+
holder_count = self.fetch_total_holders_count_for_token(token_address, T_cutoff)
|
| 1041 |
+
return holder_count, []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1042 |
def fetch_raw_token_data(
|
| 1043 |
self,
|
| 1044 |
token_address: str,
|