cyberosa commited on
Commit
1a99ad4
·
1 Parent(s): f3d7989

updating the tools metrics script

Browse files
error_by_markets.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:20ad9ae5cdd9e6c6ad36739926c79af4f6f16a6452e343b8d6db075daa414759
3
- size 10826
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1ab34475acc2a6d3cd664f68b80915dd7cb941c0d909a3f872b2bab087e1d6b7
3
+ size 11148
errors_by_mech.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:bc9b9f7263e4e0867611b1aa6e2dfe87bb4c4e112065d18f9600732799f70825
3
- size 6093
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f6a002ba1ea11c135eb14f8b046be29c01b266a3d269df8f5a1b26c818c8be2a
3
+ size 6096
scripts/tools_metrics.py CHANGED
@@ -3,12 +3,9 @@ from typing import List
3
  from utils import TMP_DIR, INC_TOOLS, ROOT_DIR
4
 
5
 
6
- def get_error_data_by_market(
7
- tools_df: pd.DataFrame, inc_tools: List[str]
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
@@ -23,12 +20,9 @@ def get_error_data_by_market(
23
  return error
24
 
25
 
26
- def get_tool_winning_rate_by_market(
27
- tools_df: pd.DataFrame, inc_tools: List[str]
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
  )
@@ -58,6 +52,8 @@ def get_tool_winning_rate_by_market(
58
 
59
 
60
  def prepare_tools(tools: pd.DataFrame) -> pd.DataFrame:
 
 
61
  tools["request_time"] = pd.to_datetime(tools["request_time"], utc=True)
62
  tools = tools.sort_values(by="request_time", ascending=True)
63
  tools["request_date"] = tools["request_time"].dt.date
@@ -84,13 +80,11 @@ def get_error_category(error_value: int):
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:
90
  """Gets the tool errors distribution by mech address in a weekly fashion"""
91
- tools_inc = tools_df[tools_df["tool"].isin(inc_tools)]
92
  weekly_errors = (
93
- tools_inc.groupby(
94
  ["request_month_year_week", "mech_address", "error"], sort=False
95
  )
96
  .size()
@@ -100,7 +94,7 @@ def get_errors_by_mech_address(
100
  lambda x: get_error_category(x)
101
  )
102
  total_requests_errors = (
103
- tools_inc.groupby(["request_month_year_week", "mech_address"], sort=False)
104
  .size()
105
  .reset_index(name="total_requests")
106
  )
@@ -122,19 +116,9 @@ def compute_tools_based_datasets():
122
  print(f"Error reading tools parquet file {e}")
123
  return None
124
 
125
- # daily mech requests
126
- daily_mech_req_per_tool = (
127
- tools_df.groupby(["request_date", "tool", "market_creator"])["request_id"]
128
- .count()
129
- .reset_index(name="total_mech_requests")
130
- )
131
- daily_mech_req_per_tool.to_parquet(
132
- ROOT_DIR / "daily_mech_requests.parquet", index=False
133
- )
134
  # mech tool errors by markets
135
- tool_error_by_markets = get_error_data_by_market(
136
- tools_df=tools_df, inc_tools=INC_TOOLS
137
- )
138
  tool_error_by_markets.to_parquet(ROOT_DIR / "error_by_markets.parquet", index=False)
139
  try:
140
  tools_df = pd.read_parquet(TMP_DIR / "tools.parquet")
@@ -142,7 +126,7 @@ def compute_tools_based_datasets():
142
  except Exception as e:
143
  print(f"Error reading tools parquet file {e}")
144
  return None
145
- winning_df = get_tool_winning_rate_by_market(tools_df, inc_tools=INC_TOOLS)
146
  winning_df.to_parquet(ROOT_DIR / "winning_df.parquet", index=False)
147
 
148
  # all errors by mech address
@@ -152,9 +136,31 @@ def compute_tools_based_datasets():
152
  except Exception as e:
153
  print(f"Error reading tools parquet file {e}")
154
  return None
155
- errors_by_mech = get_errors_by_mech_address(tools_df=tools_df, inc_tools=INC_TOOLS)
156
  errors_by_mech.to_parquet(ROOT_DIR / "errors_by_mech.parquet", index=False)
157
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
 
159
  if __name__ == "__main__":
160
  compute_tools_based_datasets()
 
3
  from utils import TMP_DIR, INC_TOOLS, ROOT_DIR
4
 
5
 
6
+ def get_error_data_by_market(tools_df: pd.DataFrame) -> pd.DataFrame:
 
 
7
  """Gets the error data for the given tools and calculates the error percentage."""
8
+ mech_tool_errors = tools_df[tools_df["error"] != -1]
 
9
  error = (
10
  mech_tool_errors.groupby(
11
  ["tool", "request_month_year_week", "market_creator", "error"], sort=False
 
20
  return error
21
 
22
 
23
+ def get_tool_winning_rate_by_market(tools_df: pd.DataFrame) -> pd.DataFrame:
 
 
24
  """Gets the tool winning rate data for the given tools by market and calculates the winning percentage."""
25
+ tools_non_error = tools_df[tools_df["error"] == 0]
 
26
  tools_non_error.loc[:, "currentAnswer"] = tools_non_error["currentAnswer"].replace(
27
  {"no": "No", "yes": "Yes"}
28
  )
 
52
 
53
 
54
  def prepare_tools(tools: pd.DataFrame) -> pd.DataFrame:
55
+ # remove non relevant tools
56
+ tools_df = tools[tools["tool"].isin(INC_TOOLS)]
57
  tools["request_time"] = pd.to_datetime(tools["request_time"], utc=True)
58
  tools = tools.sort_values(by="request_time", ascending=True)
59
  tools["request_date"] = tools["request_time"].dt.date
 
80
  return "request_error"
81
 
82
 
83
+ def get_errors_by_mech_address(tools_df: pd.DataFrame) -> pd.DataFrame:
 
 
84
  """Gets the tool errors distribution by mech address in a weekly fashion"""
85
+
86
  weekly_errors = (
87
+ tools_df.groupby(
88
  ["request_month_year_week", "mech_address", "error"], sort=False
89
  )
90
  .size()
 
94
  lambda x: get_error_category(x)
95
  )
96
  total_requests_errors = (
97
+ tools_df.groupby(["request_month_year_week", "mech_address"], sort=False)
98
  .size()
99
  .reset_index(name="total_requests")
100
  )
 
116
  print(f"Error reading tools parquet file {e}")
117
  return None
118
 
 
 
 
 
 
 
 
 
 
119
  # mech tool errors by markets
120
+ print("Computing mech tool errors by markets")
121
+ tool_error_by_markets = get_error_data_by_market(tools_df=tools_df)
 
122
  tool_error_by_markets.to_parquet(ROOT_DIR / "error_by_markets.parquet", index=False)
123
  try:
124
  tools_df = pd.read_parquet(TMP_DIR / "tools.parquet")
 
126
  except Exception as e:
127
  print(f"Error reading tools parquet file {e}")
128
  return None
129
+ winning_df = get_tool_winning_rate_by_market(tools_df)
130
  winning_df.to_parquet(ROOT_DIR / "winning_df.parquet", index=False)
131
 
132
  # all errors by mech address
 
136
  except Exception as e:
137
  print(f"Error reading tools parquet file {e}")
138
  return None
139
+ errors_by_mech = get_errors_by_mech_address(tools_df=tools_df)
140
  errors_by_mech.to_parquet(ROOT_DIR / "errors_by_mech.parquet", index=False)
141
 
142
+ try:
143
+ tools_df = pd.read_parquet(TMP_DIR / "tools.parquet")
144
+ tools_df = prepare_tools(tools_df)
145
+ except Exception as e:
146
+ print(f"Error reading tools parquet file {e}")
147
+ return None
148
+ generate_daily_mech_requests_per_tool(tools_df=tools_df)
149
+
150
+
151
+ def generate_daily_mech_requests_per_tool(tools_df: pd.DataFrame) -> pd.DataFrame:
152
+ """Generates the daily mech requests per tool."""
153
+
154
+ # daily mech requests in
155
+ daily_mech_req_per_tool = (
156
+ tools_df.groupby(["request_date", "tool", "market_creator"])["request_id"]
157
+ .count()
158
+ .reset_index(name="total_mech_requests")
159
+ )
160
+ daily_mech_req_per_tool.to_parquet(
161
+ ROOT_DIR / "daily_mech_requests.parquet", index=False
162
+ )
163
+
164
 
165
  if __name__ == "__main__":
166
  compute_tools_based_datasets()