cyberosa commited on
Commit ·
2f097fe
1
Parent(s): d363a89
added new errors category
Browse files- daily_mech_requests.parquet +2 -2
- error_by_markets.parquet +2 -2
- errors_by_mech.parquet +2 -2
- scripts/pull_data.py +2 -1
- scripts/tools.py +38 -23
- scripts/tools_metrics.py +18 -7
- scripts/update_tools_accuracy.py +1 -1
- scripts/utils.py +8 -11
- winning_df.parquet +2 -2
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:b48a239b687487a1bcfb600f1c4a349f63bdb58cb0b713f82ce21b0fb15045eb
|
| 3 |
+
size 10551
|
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:ec71562860cca20e54e28dd84be086e25aa43d3bfb5909f9b427c15797777adc
|
| 3 |
+
size 11939
|
errors_by_mech.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:c71ec8c4f8069ee7e5f82fae7bbcd3f60f32d70d769832888666508ea76417b7
|
| 3 |
+
size 5125
|
scripts/pull_data.py
CHANGED
|
@@ -170,10 +170,11 @@ def restoring_trades_data(from_date: str, to_date: str):
|
|
| 170 |
|
| 171 |
|
| 172 |
if __name__ == "__main__":
|
| 173 |
-
only_new_weekly_analysis()
|
| 174 |
# save_historical_data()
|
| 175 |
# try:
|
| 176 |
# clean_old_data_from_parquet_files("2025-01-23")
|
| 177 |
# except Exception as e:
|
| 178 |
# print("Error cleaning the oldest information from parquet files")
|
| 179 |
# print(f"reason = {e}")
|
|
|
|
|
|
| 170 |
|
| 171 |
|
| 172 |
if __name__ == "__main__":
|
| 173 |
+
# only_new_weekly_analysis()
|
| 174 |
# save_historical_data()
|
| 175 |
# try:
|
| 176 |
# clean_old_data_from_parquet_files("2025-01-23")
|
| 177 |
# except Exception as e:
|
| 178 |
# print("Error cleaning the oldest information from parquet files")
|
| 179 |
# print(f"reason = {e}")
|
| 180 |
+
add_current_answer("tools.parquet")
|
scripts/tools.py
CHANGED
|
@@ -200,34 +200,49 @@ def parse_json_events(json_events: dict, keys_to_traverse: List[int]) -> pd.Data
|
|
| 200 |
int(json_input["blockTimestamp"])
|
| 201 |
)
|
| 202 |
output["tx_hash"] = json_input["transactionHash"]
|
| 203 |
-
output["prompt_request"] = json_input["ipfsContents"]
|
| 204 |
-
output["tool"] = json_input["ipfsContents"]
|
| 205 |
-
output["nonce"] = json_input["ipfsContents"]
|
| 206 |
-
output["trader_address"] = json_input
|
| 207 |
-
output["deliver_block"] = json_input["deliver"]
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
|
|
|
|
|
|
|
|
|
| 212 |
output["error"] = error_value
|
| 213 |
-
output["error_message"] =
|
| 214 |
-
output["prompt_response"] = json_input["deliver"]["ipfsContents"]
|
| 215 |
-
|
|
|
|
|
|
|
| 216 |
p_yes_value, p_no_value, confidence_value, info_utility_value = (
|
| 217 |
-
|
|
|
|
|
|
|
|
|
|
| 218 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 219 |
output["p_yes"] = p_yes_value
|
| 220 |
output["p_no"] = p_no_value
|
| 221 |
output["confidence"] = confidence_value
|
| 222 |
output["info_utility"] = info_utility_value
|
| 223 |
output["vote"] = get_vote(p_yes_value, p_no_value)
|
| 224 |
-
|
|
|
|
|
|
|
|
|
|
| 225 |
all_records.append(output)
|
| 226 |
except Exception as e:
|
| 227 |
print(e)
|
| 228 |
-
print(f"Error parsing the key ={key}. Noted as error")
|
| 229 |
-
output["error"] = 1
|
| 230 |
-
output["error_message"] = "
|
| 231 |
output["p_yes"] = None
|
| 232 |
output["p_no"] = None
|
| 233 |
output["confidence"] = None
|
|
@@ -404,10 +419,10 @@ def remove_old_entries(
|
|
| 404 |
|
| 405 |
if __name__ == "__main__":
|
| 406 |
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
# )
|
| 411 |
-
remove_old_entries(
|
| 412 |
-
input_file="tools_info.json", output_file="cleaned_tools_info.json"
|
| 413 |
)
|
|
|
|
|
|
|
|
|
|
|
|
| 200 |
int(json_input["blockTimestamp"])
|
| 201 |
)
|
| 202 |
output["tx_hash"] = json_input["transactionHash"]
|
| 203 |
+
output["prompt_request"] = json_input["ipfsContents"].get("prompt", None)
|
| 204 |
+
output["tool"] = json_input["ipfsContents"].get("tool", None)
|
| 205 |
+
output["nonce"] = json_input["ipfsContents"].get("nonce", None)
|
| 206 |
+
output["trader_address"] = json_input.get("sender", None)
|
| 207 |
+
output["deliver_block"] = json_input["deliver"].get("blockNumber", None)
|
| 208 |
+
error_message = json_input.get("error_message", None)
|
| 209 |
+
error_value = -1
|
| 210 |
+
if error_message is None:
|
| 211 |
+
error_value, error_message, prediction_params = get_result_values(
|
| 212 |
+
json_input["deliver"]["ipfsContents"]["result"]
|
| 213 |
+
)
|
| 214 |
+
# error_message_value = json_input.get("error_message", error_message)
|
| 215 |
output["error"] = error_value
|
| 216 |
+
output["error_message"] = error_message
|
| 217 |
+
output["prompt_response"] = json_input["deliver"]["ipfsContents"].get(
|
| 218 |
+
"prompt", None
|
| 219 |
+
)
|
| 220 |
+
output["mech_address"] = json_input["deliver"].get("mech", None)
|
| 221 |
p_yes_value, p_no_value, confidence_value, info_utility_value = (
|
| 222 |
+
None,
|
| 223 |
+
None,
|
| 224 |
+
None,
|
| 225 |
+
None,
|
| 226 |
)
|
| 227 |
+
if error_value == 0:
|
| 228 |
+
p_yes_value, p_no_value, confidence_value, info_utility_value = (
|
| 229 |
+
get_prediction_values(prediction_params)
|
| 230 |
+
)
|
| 231 |
output["p_yes"] = p_yes_value
|
| 232 |
output["p_no"] = p_no_value
|
| 233 |
output["confidence"] = confidence_value
|
| 234 |
output["info_utility"] = info_utility_value
|
| 235 |
output["vote"] = get_vote(p_yes_value, p_no_value)
|
| 236 |
+
if error_value == 0:
|
| 237 |
+
output["win_probability"] = get_win_probability(p_yes_value, p_no_value)
|
| 238 |
+
else:
|
| 239 |
+
output["win_probability"] = None
|
| 240 |
all_records.append(output)
|
| 241 |
except Exception as e:
|
| 242 |
print(e)
|
| 243 |
+
print(f"Error parsing the key ={key}. Noted as mech request error")
|
| 244 |
+
output["error"] = -1
|
| 245 |
+
output["error_message"] = "Mech request error"
|
| 246 |
output["p_yes"] = None
|
| 247 |
output["p_no"] = None
|
| 248 |
output["confidence"] = None
|
|
|
|
| 419 |
|
| 420 |
if __name__ == "__main__":
|
| 421 |
|
| 422 |
+
generate_tools_file(
|
| 423 |
+
input_filename="tools_info.json",
|
| 424 |
+
output_filename="tools_updated.parquet",
|
|
|
|
|
|
|
|
|
|
| 425 |
)
|
| 426 |
+
# remove_old_entries(
|
| 427 |
+
# input_file="tools_info.json", output_file="cleaned_tools_info.json"
|
| 428 |
+
# )
|
scripts/tools_metrics.py
CHANGED
|
@@ -8,8 +8,9 @@ def get_error_data_by_market(
|
|
| 8 |
) -> pd.DataFrame:
|
| 9 |
"""Gets the error data for the given tools and calculates the error percentage."""
|
| 10 |
tools_inc = tools_df[tools_df["tool"].isin(inc_tools)]
|
|
|
|
| 11 |
error = (
|
| 12 |
-
|
| 13 |
["tool", "request_month_year_week", "market_creator", "error"], sort=False
|
| 14 |
)
|
| 15 |
.size()
|
|
@@ -27,7 +28,7 @@ def get_tool_winning_rate_by_market(
|
|
| 27 |
) -> pd.DataFrame:
|
| 28 |
"""Gets the tool winning rate data for the given tools by market and calculates the winning percentage."""
|
| 29 |
tools_inc = tools_df[tools_df["tool"].isin(inc_tools)]
|
| 30 |
-
tools_non_error = tools_inc[tools_inc["error"]
|
| 31 |
tools_non_error.loc[:, "currentAnswer"] = tools_non_error["currentAnswer"].replace(
|
| 32 |
{"no": "No", "yes": "Yes"}
|
| 33 |
)
|
|
@@ -75,6 +76,14 @@ def prepare_tools(tools: pd.DataFrame) -> pd.DataFrame:
|
|
| 75 |
return tools
|
| 76 |
|
| 77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
def get_errors_by_mech_address(
|
| 79 |
tools_df: pd.DataFrame, inc_tools: List[str]
|
| 80 |
) -> pd.DataFrame:
|
|
@@ -88,7 +97,7 @@ def get_errors_by_mech_address(
|
|
| 88 |
.reset_index(name="requests")
|
| 89 |
)
|
| 90 |
weekly_errors["error_cat"] = weekly_errors["error"].apply(
|
| 91 |
-
lambda x:
|
| 92 |
)
|
| 93 |
total_requests_errors = (
|
| 94 |
tools_inc.groupby(["request_month_year_week", "mech_address"], sort=False)
|
|
@@ -121,9 +130,11 @@ def compute_tools_based_datasets():
|
|
| 121 |
daily_mech_req_per_tool.to_parquet(
|
| 122 |
ROOT_DIR / "daily_mech_requests.parquet", index=False
|
| 123 |
)
|
| 124 |
-
#
|
| 125 |
-
|
| 126 |
-
|
|
|
|
|
|
|
| 127 |
try:
|
| 128 |
tools_df = pd.read_parquet(TMP_DIR / "tools.parquet")
|
| 129 |
tools_df = prepare_tools(tools_df)
|
|
@@ -133,7 +144,7 @@ def compute_tools_based_datasets():
|
|
| 133 |
winning_df = get_tool_winning_rate_by_market(tools_df, inc_tools=INC_TOOLS)
|
| 134 |
winning_df.to_parquet(ROOT_DIR / "winning_df.parquet", index=False)
|
| 135 |
|
| 136 |
-
# errors by mech address
|
| 137 |
try:
|
| 138 |
tools_df = pd.read_parquet(TMP_DIR / "tools.parquet")
|
| 139 |
tools_df = prepare_tools(tools_df)
|
|
|
|
| 8 |
) -> pd.DataFrame:
|
| 9 |
"""Gets the error data for the given tools and calculates the error percentage."""
|
| 10 |
tools_inc = tools_df[tools_df["tool"].isin(inc_tools)]
|
| 11 |
+
mech_tool_errors = tools_inc[tools_inc["error"] != -1]
|
| 12 |
error = (
|
| 13 |
+
mech_tool_errors.groupby(
|
| 14 |
["tool", "request_month_year_week", "market_creator", "error"], sort=False
|
| 15 |
)
|
| 16 |
.size()
|
|
|
|
| 28 |
) -> pd.DataFrame:
|
| 29 |
"""Gets the tool winning rate data for the given tools by market and calculates the winning percentage."""
|
| 30 |
tools_inc = tools_df[tools_df["tool"].isin(inc_tools)]
|
| 31 |
+
tools_non_error = tools_inc[tools_inc["error"] == 0]
|
| 32 |
tools_non_error.loc[:, "currentAnswer"] = tools_non_error["currentAnswer"].replace(
|
| 33 |
{"no": "No", "yes": "Yes"}
|
| 34 |
)
|
|
|
|
| 76 |
return tools
|
| 77 |
|
| 78 |
|
| 79 |
+
def get_error_category(error_value: int):
|
| 80 |
+
if error_value == 0:
|
| 81 |
+
return "non_error"
|
| 82 |
+
if error_value == 1:
|
| 83 |
+
return "tool_error"
|
| 84 |
+
return "request_error"
|
| 85 |
+
|
| 86 |
+
|
| 87 |
def get_errors_by_mech_address(
|
| 88 |
tools_df: pd.DataFrame, inc_tools: List[str]
|
| 89 |
) -> pd.DataFrame:
|
|
|
|
| 97 |
.reset_index(name="requests")
|
| 98 |
)
|
| 99 |
weekly_errors["error_cat"] = weekly_errors["error"].apply(
|
| 100 |
+
lambda x: get_error_category(x)
|
| 101 |
)
|
| 102 |
total_requests_errors = (
|
| 103 |
tools_inc.groupby(["request_month_year_week", "mech_address"], sort=False)
|
|
|
|
| 130 |
daily_mech_req_per_tool.to_parquet(
|
| 131 |
ROOT_DIR / "daily_mech_requests.parquet", index=False
|
| 132 |
)
|
| 133 |
+
# mech tool errors by markets
|
| 134 |
+
tool_error_by_markets = get_error_data_by_market(
|
| 135 |
+
tools_df=tools_df, inc_tools=INC_TOOLS
|
| 136 |
+
)
|
| 137 |
+
tool_error_by_markets.to_parquet(ROOT_DIR / "error_by_markets.parquet", index=False)
|
| 138 |
try:
|
| 139 |
tools_df = pd.read_parquet(TMP_DIR / "tools.parquet")
|
| 140 |
tools_df = prepare_tools(tools_df)
|
|
|
|
| 144 |
winning_df = get_tool_winning_rate_by_market(tools_df, inc_tools=INC_TOOLS)
|
| 145 |
winning_df.to_parquet(ROOT_DIR / "winning_df.parquet", index=False)
|
| 146 |
|
| 147 |
+
# all errors by mech address
|
| 148 |
try:
|
| 149 |
tools_df = pd.read_parquet(TMP_DIR / "tools.parquet")
|
| 150 |
tools_df = prepare_tools(tools_df)
|
scripts/update_tools_accuracy.py
CHANGED
|
@@ -18,7 +18,7 @@ def update_tools_accuracy(
|
|
| 18 |
# computation of the accuracy information
|
| 19 |
tools_inc = tools_df[tools_df["tool"].isin(inc_tools)]
|
| 20 |
# filtering errors
|
| 21 |
-
tools_non_error = tools_inc[tools_inc["error"]
|
| 22 |
tools_non_error.loc[:, "currentAnswer"] = tools_non_error["currentAnswer"].replace(
|
| 23 |
{"no": "No", "yes": "Yes"}
|
| 24 |
)
|
|
|
|
| 18 |
# computation of the accuracy information
|
| 19 |
tools_inc = tools_df[tools_df["tool"].isin(inc_tools)]
|
| 20 |
# filtering errors
|
| 21 |
+
tools_non_error = tools_inc[tools_inc["error"] == 0]
|
| 22 |
tools_non_error.loc[:, "currentAnswer"] = tools_non_error["currentAnswer"].replace(
|
| 23 |
{"no": "No", "yes": "Yes"}
|
| 24 |
)
|
scripts/utils.py
CHANGED
|
@@ -370,23 +370,20 @@ def get_win_probability(p_yes, p_no) -> Optional[float]:
|
|
| 370 |
|
| 371 |
|
| 372 |
def get_result_values(result: str) -> Tuple:
|
| 373 |
-
if result
|
|
|
|
|
|
|
| 374 |
return 1, "Invalid response from tool", None
|
| 375 |
-
|
| 376 |
-
params = None
|
| 377 |
try:
|
| 378 |
if isinstance(result, str):
|
| 379 |
params = json.loads(result)
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
except JSONDecodeError:
|
| 383 |
-
error_message = "Response parsing error"
|
| 384 |
-
error_value = 1
|
| 385 |
|
| 386 |
except Exception as e:
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
return
|
| 390 |
|
| 391 |
|
| 392 |
def get_prediction_values(params: dict) -> Tuple:
|
|
|
|
| 370 |
|
| 371 |
|
| 372 |
def get_result_values(result: str) -> Tuple:
|
| 373 |
+
"""Function to decide if the result is valid or not"""
|
| 374 |
+
if isinstance(result, str) and result == "Invalid response":
|
| 375 |
+
print("Invalid response found")
|
| 376 |
return 1, "Invalid response from tool", None
|
| 377 |
+
|
|
|
|
| 378 |
try:
|
| 379 |
if isinstance(result, str):
|
| 380 |
params = json.loads(result)
|
| 381 |
+
return 0, None, params
|
|
|
|
|
|
|
|
|
|
|
|
|
| 382 |
|
| 383 |
except Exception as e:
|
| 384 |
+
print("Non valid json format")
|
| 385 |
+
|
| 386 |
+
return 1, str(result), None
|
| 387 |
|
| 388 |
|
| 389 |
def get_prediction_values(params: dict) -> Tuple:
|
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:43e6d3c7367771c0816f3f007eb9f3afd13f160abe14411a7d8f154cc157651a
|
| 3 |
+
size 11807
|