cyberosa
commited on
Commit
·
75bb2cf
1
Parent(s):
804c893
new daily data and new mech field for tools
Browse files- active_traders.parquet +2 -2
- all_trades_profitability.parquet.gz +2 -2
- closed_market_metrics.parquet +2 -2
- closed_markets_div.parquet +2 -2
- daily_info.parquet +2 -2
- daily_mech_requests.parquet +2 -2
- error_by_markets.parquet +2 -2
- invalid_trades.parquet +2 -2
- retention_activity.parquet.gz +2 -2
- scripts/get_mech_info.py +29 -11
- scripts/mech_request_utils.py +100 -10
- scripts/pull_data.py +4 -4
- scripts/tools.py +5 -2
- service_map.pkl +2 -2
- tools_accuracy.csv +12 -12
- unknown_traders.parquet +2 -2
- weekly_mech_calls.parquet +2 -2
- winning_df.parquet +2 -2
active_traders.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d85374e556117a03039308754ec4187d8afc93a68a33b2afe856c745970bb105
|
| 3 |
+
size 83808
|
all_trades_profitability.parquet.gz
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f95e9c4362ae7d94282fe31184a931f07ac64d9ebcf6b120a55b109a06b7ec8f
|
| 3 |
+
size 8757914
|
closed_market_metrics.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f16a737272d9e50721b01f829144fe8c5868209b40e29cb1a2d9ada2fed43114
|
| 3 |
+
size 129617
|
closed_markets_div.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:cb9f5f47c5d3cdeb20a7a2e5925ceaae90c1b7402960889f2e2be01d1742887b
|
| 3 |
+
size 88059
|
daily_info.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f4a2cf63954ccfebf9bf15019b6c669f7a7877ba39ab5a153c4a0e891d504e01
|
| 3 |
+
size 1846940
|
daily_mech_requests.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b26a59996fc1f4551f7eb699277bc20fb34a9b3e0288cfbd80d185157a654c8e
|
| 3 |
+
size 10433
|
error_by_markets.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8be709dee296b34c00ee9b910d9c387346a833f23da50ae3187a46207554ac3a
|
| 3 |
+
size 11880
|
invalid_trades.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:147c82a40ceea1593936561f3c277b7b668e3e1e0c662d88613f46f30f7b8402
|
| 3 |
+
size 125231
|
retention_activity.parquet.gz
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8bd869ba65faeeb61b84c4236f3acd6ba172898f6fe13438f5944e87d5405dd1
|
| 3 |
+
size 8730982
|
scripts/get_mech_info.py
CHANGED
|
@@ -23,6 +23,7 @@ from mech_request_utils import (
|
|
| 23 |
get_ipfs_data,
|
| 24 |
merge_json_files,
|
| 25 |
)
|
|
|
|
| 26 |
|
| 27 |
SUBGRAPH_HEADERS = {
|
| 28 |
"Accept": "application/json, multipart/mixed",
|
|
@@ -149,7 +150,7 @@ def update_all_trades_parquet(new_trades_df: pd.DataFrame) -> pd.DataFrame:
|
|
| 149 |
return merge_df
|
| 150 |
|
| 151 |
|
| 152 |
-
def update_tools_parquet(new_tools_filename:
|
| 153 |
try:
|
| 154 |
old_tools_df = pd.read_parquet(TMP_DIR / "tools.parquet")
|
| 155 |
except Exception as e:
|
|
@@ -162,6 +163,13 @@ def update_tools_parquet(new_tools_filename: pd.DataFrame):
|
|
| 162 |
print(f"Error reading new trades parquet file {e}")
|
| 163 |
return None
|
| 164 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
# merge two dataframes
|
| 166 |
merge_df = pd.concat([old_tools_df, new_tools_df], ignore_index=True)
|
| 167 |
|
|
@@ -265,7 +273,7 @@ def get_mech_info_last_60_days() -> dict[str, Any]:
|
|
| 265 |
|
| 266 |
|
| 267 |
@measure_execution_time
|
| 268 |
-
def get_mech_events_since_last_run(logger):
|
| 269 |
"""Function to download only the new events since the last execution."""
|
| 270 |
|
| 271 |
# Read the latest date from stored data
|
|
@@ -297,39 +305,49 @@ def get_mech_events_since_last_run(logger):
|
|
| 297 |
last_block_number = get_last_block_number()
|
| 298 |
|
| 299 |
# mech requests
|
|
|
|
|
|
|
| 300 |
requests_dict, duplicatedReqId, nr_errors = collect_all_mech_requests(
|
| 301 |
from_block=last_run_block_number,
|
| 302 |
to_block=last_block_number,
|
| 303 |
-
filename=
|
|
|
|
| 304 |
)
|
|
|
|
| 305 |
print(f"NUMBER OF MECH REQUEST ERRORS={nr_errors}")
|
| 306 |
# mech delivers
|
|
|
|
|
|
|
| 307 |
delivers_dict, duplicatedIds, nr_errors = collect_all_mech_delivers(
|
| 308 |
from_block=last_run_block_number,
|
| 309 |
to_block=last_block_number,
|
| 310 |
-
filename=
|
|
|
|
| 311 |
)
|
|
|
|
| 312 |
print(f"NUMBER OF MECH DELIVER ERRORS={nr_errors}")
|
| 313 |
if delivers_dict is None:
|
| 314 |
return None
|
| 315 |
# clean delivers
|
| 316 |
-
clean_mech_delivers(
|
| 317 |
|
| 318 |
# solve duplicated requestIds
|
| 319 |
-
block_map = fix_duplicate_requestIds(
|
| 320 |
-
|
| 321 |
-
|
|
|
|
| 322 |
# merge the two files into one source
|
| 323 |
not_found = merge_requests_delivers(
|
| 324 |
-
|
| 325 |
)
|
| 326 |
|
| 327 |
# Add ipfs contents
|
| 328 |
-
get_ipfs_data(
|
| 329 |
return latest_timestamp
|
| 330 |
|
| 331 |
|
| 332 |
if __name__ == "__main__":
|
| 333 |
-
|
|
|
|
| 334 |
# result = get_mech_info_last_60_days()
|
| 335 |
# print(result)
|
|
|
|
| 23 |
get_ipfs_data,
|
| 24 |
merge_json_files,
|
| 25 |
)
|
| 26 |
+
import logging
|
| 27 |
|
| 28 |
SUBGRAPH_HEADERS = {
|
| 29 |
"Accept": "application/json, multipart/mixed",
|
|
|
|
| 150 |
return merge_df
|
| 151 |
|
| 152 |
|
| 153 |
+
def update_tools_parquet(new_tools_filename: str):
|
| 154 |
try:
|
| 155 |
old_tools_df = pd.read_parquet(TMP_DIR / "tools.parquet")
|
| 156 |
except Exception as e:
|
|
|
|
| 163 |
print(f"Error reading new trades parquet file {e}")
|
| 164 |
return None
|
| 165 |
|
| 166 |
+
# Add the missing column to old_tools_df with NaN values
|
| 167 |
+
if (
|
| 168 |
+
"mech_address" in new_tools_df.columns
|
| 169 |
+
and "mech_address" not in old_tools_df.columns
|
| 170 |
+
):
|
| 171 |
+
old_tools_df["mech_address"] = None
|
| 172 |
+
|
| 173 |
# merge two dataframes
|
| 174 |
merge_df = pd.concat([old_tools_df, new_tools_df], ignore_index=True)
|
| 175 |
|
|
|
|
| 273 |
|
| 274 |
|
| 275 |
@measure_execution_time
|
| 276 |
+
def get_mech_events_since_last_run(logger, mech_sandbox: bool = False):
|
| 277 |
"""Function to download only the new events since the last execution."""
|
| 278 |
|
| 279 |
# Read the latest date from stored data
|
|
|
|
| 305 |
last_block_number = get_last_block_number()
|
| 306 |
|
| 307 |
# mech requests
|
| 308 |
+
req_output_file = "new_mech_requests.json"
|
| 309 |
+
|
| 310 |
requests_dict, duplicatedReqId, nr_errors = collect_all_mech_requests(
|
| 311 |
from_block=last_run_block_number,
|
| 312 |
to_block=last_block_number,
|
| 313 |
+
filename=req_output_file,
|
| 314 |
+
mech_sandbox=mech_sandbox,
|
| 315 |
)
|
| 316 |
+
|
| 317 |
print(f"NUMBER OF MECH REQUEST ERRORS={nr_errors}")
|
| 318 |
# mech delivers
|
| 319 |
+
deli_output_file = "new_mech_delivers.json"
|
| 320 |
+
|
| 321 |
delivers_dict, duplicatedIds, nr_errors = collect_all_mech_delivers(
|
| 322 |
from_block=last_run_block_number,
|
| 323 |
to_block=last_block_number,
|
| 324 |
+
filename=deli_output_file,
|
| 325 |
+
mech_sandbox=mech_sandbox,
|
| 326 |
)
|
| 327 |
+
|
| 328 |
print(f"NUMBER OF MECH DELIVER ERRORS={nr_errors}")
|
| 329 |
if delivers_dict is None:
|
| 330 |
return None
|
| 331 |
# clean delivers
|
| 332 |
+
clean_mech_delivers(req_output_file, deli_output_file)
|
| 333 |
|
| 334 |
# solve duplicated requestIds
|
| 335 |
+
block_map = fix_duplicate_requestIds(req_output_file, deli_output_file)
|
| 336 |
+
|
| 337 |
+
merged_output_file = "new_merged_requests.json"
|
| 338 |
+
tools_output_file = "new_tools_info.json"
|
| 339 |
# merge the two files into one source
|
| 340 |
not_found = merge_requests_delivers(
|
| 341 |
+
req_output_file, deli_output_file, merged_output_file
|
| 342 |
)
|
| 343 |
|
| 344 |
# Add ipfs contents
|
| 345 |
+
get_ipfs_data(merged_output_file, tools_output_file, logger)
|
| 346 |
return latest_timestamp
|
| 347 |
|
| 348 |
|
| 349 |
if __name__ == "__main__":
|
| 350 |
+
logger = logging.getLogger(__name__)
|
| 351 |
+
get_mech_events_since_last_run(logger, mech_sandbox=True)
|
| 352 |
# result = get_mech_info_last_60_days()
|
| 353 |
# print(result)
|
scripts/mech_request_utils.py
CHANGED
|
@@ -54,7 +54,9 @@ BLOCKS_CHUNK_SIZE = 10000
|
|
| 54 |
TEXT_ALIGNMENT = 30
|
| 55 |
MINIMUM_WRITE_FILE_DELAY_SECONDS = 20
|
| 56 |
MECH_FROM_BLOCK_RANGE = 50000
|
| 57 |
-
|
|
|
|
|
|
|
| 58 |
last_write_time = 0.0
|
| 59 |
|
| 60 |
REQUESTS_QUERY_FILTER = """
|
|
@@ -70,6 +72,20 @@ query requests_query($sender_not_in: [Bytes!], $id_gt: Bytes, $blockNumber_gte:
|
|
| 70 |
}
|
| 71 |
}
|
| 72 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
DELIVERS_QUERY_NO_FILTER = """
|
| 75 |
query delivers_query($id_gt: Bytes, $blockNumber_gte: BigInt, $blockNumber_lte: BigInt) {
|
|
@@ -83,8 +99,23 @@ query delivers_query($id_gt: Bytes, $blockNumber_gte: BigInt, $blockNumber_lte:
|
|
| 83 |
transactionHash
|
| 84 |
}
|
| 85 |
}
|
|
|
|
| 86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
"""
|
|
|
|
| 88 |
DELIVERS_QUERY = """
|
| 89 |
query delivers_query($requestId: BigInt, $blockNumber_gte: BigInt, $blockNumber_lte: BigInt) {
|
| 90 |
delivers(where: {requestId: $requestId, blockNumber_gte: $blockNumber_gte, blockNumber_lte: $blockNumber_lte}, orderBy: blockNumber, first: 1000) {
|
|
@@ -98,6 +129,20 @@ query delivers_query($requestId: BigInt, $blockNumber_gte: BigInt, $blockNumber_
|
|
| 98 |
}
|
| 99 |
}
|
| 100 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
|
| 102 |
MISSING_DELIVERS_QUERY = """
|
| 103 |
query delivers_query($requestId: BigInt, $blockNumber_gte: BigInt, $blockNumber_lte: BigInt) {
|
|
@@ -114,12 +159,37 @@ query delivers_query($requestId: BigInt, $blockNumber_gte: BigInt, $blockNumber_
|
|
| 114 |
"""
|
| 115 |
|
| 116 |
|
| 117 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
|
| 119 |
print(f"Fetching all mech requests from {from_block} to {to_block}")
|
| 120 |
mech_requests = {}
|
| 121 |
duplicated_reqIds = []
|
| 122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
transport = RequestsHTTPTransport(url=mech_subgraph_url)
|
| 124 |
client = Client(transport=transport, fetch_schema_from_transport=True)
|
| 125 |
|
|
@@ -133,7 +203,7 @@ def collect_all_mech_requests(from_block: int, to_block: int, filename: str) ->
|
|
| 133 |
"blockNumber_lte": str(to_block), # str
|
| 134 |
}
|
| 135 |
try:
|
| 136 |
-
response = fetch_with_retry(client,
|
| 137 |
|
| 138 |
items = response.get("requests", [])
|
| 139 |
|
|
@@ -174,13 +244,23 @@ def fetch_with_retry(client, query, variables, max_retries=5):
|
|
| 174 |
time.sleep(wait_time)
|
| 175 |
|
| 176 |
|
| 177 |
-
def collect_all_mech_delivers(
|
|
|
|
|
|
|
| 178 |
|
| 179 |
print(f"Fetching all mech delivers from {from_block} to {to_block}")
|
| 180 |
|
| 181 |
mech_delivers = {}
|
| 182 |
duplicated_requestIds = []
|
| 183 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
transport = RequestsHTTPTransport(url=mech_subgraph_url)
|
| 185 |
client = Client(transport=transport, fetch_schema_from_transport=True)
|
| 186 |
to_block = (
|
|
@@ -195,7 +275,7 @@ def collect_all_mech_delivers(from_block: int, to_block: int, filename: str) ->
|
|
| 195 |
"blockNumber_lte": str(to_block), # str
|
| 196 |
}
|
| 197 |
try:
|
| 198 |
-
response = fetch_with_retry(client,
|
| 199 |
items = response.get("delivers", [])
|
| 200 |
|
| 201 |
if not items:
|
|
@@ -225,13 +305,23 @@ def collect_all_mech_delivers(from_block: int, to_block: int, filename: str) ->
|
|
| 225 |
return mech_delivers, duplicated_requestIds, nr_errors
|
| 226 |
|
| 227 |
|
| 228 |
-
def collect_missing_delivers(
|
|
|
|
|
|
|
| 229 |
to_block = (
|
| 230 |
block_number + MECH_FROM_BLOCK_RANGE
|
| 231 |
) # there is a delay between deliver and request
|
| 232 |
print(f"Fetching all missing delivers from {block_number} to {to_block}")
|
| 233 |
mech_delivers = {}
|
| 234 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 235 |
transport = RequestsHTTPTransport(url=mech_subgraph_url)
|
| 236 |
client = Client(transport=transport, fetch_schema_from_transport=True)
|
| 237 |
|
|
@@ -241,7 +331,7 @@ def collect_missing_delivers(request_id: int, block_number: int) -> Dict[str, An
|
|
| 241 |
"blockNumber_lte": str(to_block), # str
|
| 242 |
}
|
| 243 |
try:
|
| 244 |
-
response = fetch_with_retry(client,
|
| 245 |
items = response.get("delivers", [])
|
| 246 |
# If the user sends requests with the same values (tool, prompt, nonce) it
|
| 247 |
# will generate the same requestId. Therefore, multiple items can be retrieved
|
|
|
|
| 54 |
TEXT_ALIGNMENT = 30
|
| 55 |
MINIMUM_WRITE_FILE_DELAY_SECONDS = 20
|
| 56 |
MECH_FROM_BLOCK_RANGE = 50000
|
| 57 |
+
MECH_SANDBOX_SUBGRAPH = (
|
| 58 |
+
"https://api.studio.thegraph.com/query/81754/mech-sandbox/version/latest"
|
| 59 |
+
)
|
| 60 |
last_write_time = 0.0
|
| 61 |
|
| 62 |
REQUESTS_QUERY_FILTER = """
|
|
|
|
| 72 |
}
|
| 73 |
}
|
| 74 |
"""
|
| 75 |
+
REQUESTS_BY_MECH_QUERY_FILTER = """
|
| 76 |
+
query requests_query($sender_not_in: [Bytes!], $id_gt: Bytes, $blockNumber_gte: BigInt, $blockNumber_lte: BigInt) {
|
| 77 |
+
requests(where: {sender_not_in: $sender_not_in, id_gt: $id_gt, blockNumber_gte: $blockNumber_gte, blockNumber_lte: $blockNumber_lte}, orderBy: id, first: 1000) {
|
| 78 |
+
blockNumber
|
| 79 |
+
blockTimestamp
|
| 80 |
+
id
|
| 81 |
+
ipfsHash
|
| 82 |
+
requestId
|
| 83 |
+
sender
|
| 84 |
+
mech
|
| 85 |
+
transactionHash
|
| 86 |
+
}
|
| 87 |
+
}
|
| 88 |
+
"""
|
| 89 |
|
| 90 |
DELIVERS_QUERY_NO_FILTER = """
|
| 91 |
query delivers_query($id_gt: Bytes, $blockNumber_gte: BigInt, $blockNumber_lte: BigInt) {
|
|
|
|
| 99 |
transactionHash
|
| 100 |
}
|
| 101 |
}
|
| 102 |
+
"""
|
| 103 |
|
| 104 |
+
DELIVERS_BY_MECH_QUERY_NO_FILTER = """
|
| 105 |
+
query delivers_query($id_gt: Bytes, $blockNumber_gte: BigInt, $blockNumber_lte: BigInt) {
|
| 106 |
+
delivers(where: {id_gt: $id_gt, blockNumber_gte: $blockNumber_gte, blockNumber_lte: $blockNumber_lte}, orderBy: id, first: 1000) {
|
| 107 |
+
blockNumber
|
| 108 |
+
blockTimestamp
|
| 109 |
+
id
|
| 110 |
+
ipfsHash
|
| 111 |
+
requestId
|
| 112 |
+
sender
|
| 113 |
+
mech
|
| 114 |
+
transactionHash
|
| 115 |
+
}
|
| 116 |
+
}
|
| 117 |
"""
|
| 118 |
+
|
| 119 |
DELIVERS_QUERY = """
|
| 120 |
query delivers_query($requestId: BigInt, $blockNumber_gte: BigInt, $blockNumber_lte: BigInt) {
|
| 121 |
delivers(where: {requestId: $requestId, blockNumber_gte: $blockNumber_gte, blockNumber_lte: $blockNumber_lte}, orderBy: blockNumber, first: 1000) {
|
|
|
|
| 129 |
}
|
| 130 |
}
|
| 131 |
"""
|
| 132 |
+
DELIVERS_BY_MECH_QUERY = """
|
| 133 |
+
query delivers_query($requestId: BigInt, $blockNumber_gte: BigInt, $blockNumber_lte: BigInt) {
|
| 134 |
+
delivers(where: {requestId: $requestId, blockNumber_gte: $blockNumber_gte, blockNumber_lte: $blockNumber_lte}, orderBy: blockNumber, first: 1000) {
|
| 135 |
+
blockNumber
|
| 136 |
+
blockTimestamp
|
| 137 |
+
id
|
| 138 |
+
ipfsHash
|
| 139 |
+
requestId
|
| 140 |
+
sender
|
| 141 |
+
mech
|
| 142 |
+
transactionHash
|
| 143 |
+
}
|
| 144 |
+
}
|
| 145 |
+
"""
|
| 146 |
|
| 147 |
MISSING_DELIVERS_QUERY = """
|
| 148 |
query delivers_query($requestId: BigInt, $blockNumber_gte: BigInt, $blockNumber_lte: BigInt) {
|
|
|
|
| 159 |
"""
|
| 160 |
|
| 161 |
|
| 162 |
+
MISSING_BY_MECH_DELIVERS_QUERY = """
|
| 163 |
+
query delivers_query($requestId: BigInt, $blockNumber_gte: BigInt, $blockNumber_lte: BigInt) {
|
| 164 |
+
delivers(where: {requestId: $requestId, blockNumber_gte: $blockNumber_gte, blockNumber_lte: $blockNumber_lte}, orderBy: blockNumber, first: 1000) {
|
| 165 |
+
blockNumber
|
| 166 |
+
blockTimestamp
|
| 167 |
+
id
|
| 168 |
+
ipfsHash
|
| 169 |
+
requestId
|
| 170 |
+
sender
|
| 171 |
+
mech
|
| 172 |
+
transactionHash
|
| 173 |
+
}
|
| 174 |
+
}
|
| 175 |
+
"""
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
def collect_all_mech_requests(
|
| 179 |
+
from_block: int, to_block: int, filename: str, mech_sandbox: bool = False
|
| 180 |
+
) -> Tuple:
|
| 181 |
|
| 182 |
print(f"Fetching all mech requests from {from_block} to {to_block}")
|
| 183 |
mech_requests = {}
|
| 184 |
duplicated_reqIds = []
|
| 185 |
+
if mech_sandbox:
|
| 186 |
+
mech_subgraph_url = MECH_SANDBOX_SUBGRAPH
|
| 187 |
+
request_query = REQUESTS_BY_MECH_QUERY_FILTER
|
| 188 |
+
else:
|
| 189 |
+
mech_subgraph_url = MECH_SUBGRAPH_URL.substitute(
|
| 190 |
+
subgraph_api_key=SUBGRAPH_API_KEY
|
| 191 |
+
)
|
| 192 |
+
request_query = REQUESTS_QUERY_FILTER
|
| 193 |
transport = RequestsHTTPTransport(url=mech_subgraph_url)
|
| 194 |
client = Client(transport=transport, fetch_schema_from_transport=True)
|
| 195 |
|
|
|
|
| 203 |
"blockNumber_lte": str(to_block), # str
|
| 204 |
}
|
| 205 |
try:
|
| 206 |
+
response = fetch_with_retry(client, request_query, variables)
|
| 207 |
|
| 208 |
items = response.get("requests", [])
|
| 209 |
|
|
|
|
| 244 |
time.sleep(wait_time)
|
| 245 |
|
| 246 |
|
| 247 |
+
def collect_all_mech_delivers(
|
| 248 |
+
from_block: int, to_block: int, filename: str, mech_sandbox: bool = False
|
| 249 |
+
) -> Tuple:
|
| 250 |
|
| 251 |
print(f"Fetching all mech delivers from {from_block} to {to_block}")
|
| 252 |
|
| 253 |
mech_delivers = {}
|
| 254 |
duplicated_requestIds = []
|
| 255 |
+
if mech_sandbox:
|
| 256 |
+
mech_subgraph_url = MECH_SANDBOX_SUBGRAPH
|
| 257 |
+
deliver_query = DELIVERS_BY_MECH_QUERY_NO_FILTER
|
| 258 |
+
else:
|
| 259 |
+
mech_subgraph_url = MECH_SUBGRAPH_URL.substitute(
|
| 260 |
+
subgraph_api_key=SUBGRAPH_API_KEY
|
| 261 |
+
)
|
| 262 |
+
deliver_query = DELIVERS_QUERY_NO_FILTER
|
| 263 |
+
|
| 264 |
transport = RequestsHTTPTransport(url=mech_subgraph_url)
|
| 265 |
client = Client(transport=transport, fetch_schema_from_transport=True)
|
| 266 |
to_block = (
|
|
|
|
| 275 |
"blockNumber_lte": str(to_block), # str
|
| 276 |
}
|
| 277 |
try:
|
| 278 |
+
response = fetch_with_retry(client, deliver_query, variables)
|
| 279 |
items = response.get("delivers", [])
|
| 280 |
|
| 281 |
if not items:
|
|
|
|
| 305 |
return mech_delivers, duplicated_requestIds, nr_errors
|
| 306 |
|
| 307 |
|
| 308 |
+
def collect_missing_delivers(
|
| 309 |
+
request_id: int, block_number: int, mech_sandbox: bool = False
|
| 310 |
+
) -> Dict[str, Any]:
|
| 311 |
to_block = (
|
| 312 |
block_number + MECH_FROM_BLOCK_RANGE
|
| 313 |
) # there is a delay between deliver and request
|
| 314 |
print(f"Fetching all missing delivers from {block_number} to {to_block}")
|
| 315 |
mech_delivers = {}
|
| 316 |
+
|
| 317 |
+
if mech_sandbox:
|
| 318 |
+
mech_subgraph_url = MECH_SANDBOX_SUBGRAPH
|
| 319 |
+
missing_query = MISSING_BY_MECH_DELIVERS_QUERY
|
| 320 |
+
else:
|
| 321 |
+
mech_subgraph_url = MECH_SUBGRAPH_URL.substitute(
|
| 322 |
+
subgraph_api_key=SUBGRAPH_API_KEY
|
| 323 |
+
)
|
| 324 |
+
missing_query = MISSING_DELIVERS_QUERY
|
| 325 |
transport = RequestsHTTPTransport(url=mech_subgraph_url)
|
| 326 |
client = Client(transport=transport, fetch_schema_from_transport=True)
|
| 327 |
|
|
|
|
| 331 |
"blockNumber_lte": str(to_block), # str
|
| 332 |
}
|
| 333 |
try:
|
| 334 |
+
response = fetch_with_retry(client, missing_query, variables)
|
| 335 |
items = response.get("delivers", [])
|
| 336 |
# If the user sends requests with the same values (tool, prompt, nonce) it
|
| 337 |
# will generate the same requestId. Therefore, multiple items can be retrieved
|
scripts/pull_data.py
CHANGED
|
@@ -96,7 +96,7 @@ def only_new_weekly_analysis():
|
|
| 96 |
# Mech events ETL
|
| 97 |
logging.info("Generating the mech json files")
|
| 98 |
# get only new data
|
| 99 |
-
latest_timestamp = get_mech_events_since_last_run(logger)
|
| 100 |
if latest_timestamp == None:
|
| 101 |
print("Error while getting the mech events")
|
| 102 |
return
|
|
@@ -135,7 +135,7 @@ def only_new_weekly_analysis():
|
|
| 135 |
|
| 136 |
save_historical_data()
|
| 137 |
try:
|
| 138 |
-
clean_old_data_from_parquet_files("2025-01-
|
| 139 |
except Exception as e:
|
| 140 |
print("Error cleaning the oldest information from parquet files")
|
| 141 |
print(f"reason = {e}")
|
|
@@ -169,8 +169,8 @@ def restoring_trades_data(from_date: str, to_date: str):
|
|
| 169 |
|
| 170 |
|
| 171 |
if __name__ == "__main__":
|
| 172 |
-
|
| 173 |
-
save_historical_data()
|
| 174 |
# try:
|
| 175 |
# clean_old_data_from_parquet_files("2025-01-23")
|
| 176 |
# except Exception as e:
|
|
|
|
| 96 |
# Mech events ETL
|
| 97 |
logging.info("Generating the mech json files")
|
| 98 |
# get only new data
|
| 99 |
+
latest_timestamp = get_mech_events_since_last_run(logger, mech_sandbox=True)
|
| 100 |
if latest_timestamp == None:
|
| 101 |
print("Error while getting the mech events")
|
| 102 |
return
|
|
|
|
| 135 |
|
| 136 |
save_historical_data()
|
| 137 |
try:
|
| 138 |
+
clean_old_data_from_parquet_files("2025-01-26")
|
| 139 |
except Exception as e:
|
| 140 |
print("Error cleaning the oldest information from parquet files")
|
| 141 |
print(f"reason = {e}")
|
|
|
|
| 169 |
|
| 170 |
|
| 171 |
if __name__ == "__main__":
|
| 172 |
+
only_new_weekly_analysis()
|
| 173 |
+
# save_historical_data()
|
| 174 |
# try:
|
| 175 |
# clean_old_data_from_parquet_files("2025-01-23")
|
| 176 |
# except Exception as e:
|
scripts/tools.py
CHANGED
|
@@ -208,7 +208,7 @@ def parse_json_events(json_events: dict, keys_to_traverse: List[int]) -> pd.Data
|
|
| 208 |
output["error"] = error_value
|
| 209 |
output["error_message"] = error_message_value
|
| 210 |
output["prompt_response"] = json_input["deliver"]["ipfsContents"]["prompt"]
|
| 211 |
-
output["mech_address"] = json_input["deliver"]["
|
| 212 |
p_yes_value, p_no_value, confidence_value, info_utility_value = (
|
| 213 |
get_prediction_values(prediction_params)
|
| 214 |
)
|
|
@@ -317,4 +317,7 @@ def generate_tools_file(input_filename: str, output_filename: str):
|
|
| 317 |
|
| 318 |
if __name__ == "__main__":
|
| 319 |
|
| 320 |
-
generate_tools_file(
|
|
|
|
|
|
|
|
|
|
|
|
| 208 |
output["error"] = error_value
|
| 209 |
output["error_message"] = error_message_value
|
| 210 |
output["prompt_response"] = json_input["deliver"]["ipfsContents"]["prompt"]
|
| 211 |
+
output["mech_address"] = json_input["deliver"]["mech"]
|
| 212 |
p_yes_value, p_no_value, confidence_value, info_utility_value = (
|
| 213 |
get_prediction_values(prediction_params)
|
| 214 |
)
|
|
|
|
| 317 |
|
| 318 |
if __name__ == "__main__":
|
| 319 |
|
| 320 |
+
generate_tools_file(
|
| 321 |
+
input_filename="mechsandbox_tools_info.json",
|
| 322 |
+
output_filename="mechsandbox_tools.parquet",
|
| 323 |
+
)
|
service_map.pkl
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:49a190affe8e9179edd8c80fb249b91c608853f2ef1df83735d3b25d1cac92e6
|
| 3 |
+
size 200308
|
tools_accuracy.csv
CHANGED
|
@@ -1,13 +1,13 @@
|
|
| 1 |
tool,tool_accuracy,total_requests,min,max
|
| 2 |
-
claude-prediction-offline,63.
|
| 3 |
-
claude-prediction-online,64.
|
| 4 |
-
prediction-offline,53.
|
| 5 |
-
prediction-offline-sme,
|
| 6 |
-
prediction-online,44.
|
| 7 |
-
prediction-online-sme,
|
| 8 |
-
prediction-request-rag,
|
| 9 |
-
prediction-request-rag-claude,
|
| 10 |
-
prediction-request-reasoning,
|
| 11 |
-
prediction-request-reasoning-claude,
|
| 12 |
-
prediction-url-cot-claude,
|
| 13 |
-
superforcaster,
|
|
|
|
| 1 |
tool,tool_accuracy,total_requests,min,max
|
| 2 |
+
claude-prediction-offline,63.046214390810306,56411,2025-01-26 00:04:55,2025-03-25 23:13:55
|
| 3 |
+
claude-prediction-online,64.30493815960567,33069,2025-01-26 00:00:05,2025-03-26 01:19:40
|
| 4 |
+
prediction-offline,53.52954942970462,162372,2025-01-26 00:00:40,2025-03-26 23:44:05
|
| 5 |
+
prediction-offline-sme,49.66247518199868,7555,2025-01-26 00:18:20,2025-03-25 18:52:45
|
| 6 |
+
prediction-online,44.43744752308984,4764,2025-01-26 08:19:45,2025-03-26 10:04:25
|
| 7 |
+
prediction-online-sme,42.7536231884058,2898,2025-01-26 08:21:10,2025-03-26 11:04:25
|
| 8 |
+
prediction-request-rag,45.96774193548387,372,2025-01-26 12:30:50,2025-03-25 18:09:15
|
| 9 |
+
prediction-request-rag-claude,49.56011730205279,341,2025-01-26 09:14:15,2025-03-24 17:36:30
|
| 10 |
+
prediction-request-reasoning,48.855616051623315,59508,2025-01-26 07:59:40,2025-03-26 17:14:00
|
| 11 |
+
prediction-request-reasoning-claude,70.60606060606061,330,2025-01-26 12:09:10,2025-03-25 14:52:45
|
| 12 |
+
prediction-url-cot-claude,53.493699885452465,873,2025-01-26 01:08:05,2025-03-25 22:11:55
|
| 13 |
+
superforcaster,56.70432743551481,9382,2025-01-26 01:17:25,2025-03-25 23:12:40
|
unknown_traders.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:25eca09b15491791210e54fb952673c6d3c60658fd45a568ceddd5939f392904
|
| 3 |
+
size 1062580
|
weekly_mech_calls.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0a66cc54ce2c5522727e63439c1be576c68b3283c5580439a693316107c95ceb
|
| 3 |
+
size 58183
|
winning_df.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:662aaefbf51f881b8afd84d8523cb2fd39f8212f57570be5e38ee656666a8e50
|
| 3 |
+
size 11398
|