cyberosa commited on
Commit
807709a
·
1 Parent(s): 471986c

new accuracy compation with fixed population size and retrieval of historical data from cloud storage

Browse files
scripts/cloud_storage.py CHANGED
@@ -2,15 +2,15 @@ from minio import Minio
2
  from minio.error import S3Error
3
  import os
4
  import argparse
5
-
6
- from utils import HIST_DIR, ROOT_DIR
 
7
 
8
  MINIO_ENDPOINT = "minio.autonolas.tech"
9
  ACCESS_KEY = os.environ.get("CLOUD_ACCESS_KEY", None)
10
  SECRET_KEY = os.environ.get("CLOUD_SECRET_KEY", None)
11
  BUCKET_NAME = "weekly-stats"
12
  FOLDER_NAME = "historical_data"
13
- APRIL_FOLDER = "april2024"
14
 
15
 
16
  def initialize_client():
@@ -85,6 +85,55 @@ def process_historical_files(client):
85
  print(f"Error processing {filename}: {str(e)}")
86
 
87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  if __name__ == "__main__":
89
  # parser = argparse.ArgumentParser(
90
  # description="Load files to the cloud storate for historical data"
@@ -96,7 +145,8 @@ if __name__ == "__main__":
96
  # filename = args.param_1
97
 
98
  client = initialize_client()
99
- download_file(client, "all_trades_profitability_20250103_162106.parquet")
 
100
  # load_historical_file(client, filename)
101
  # process_historical_files(client)
102
  # checking files at the cloud storage
 
2
  from minio.error import S3Error
3
  import os
4
  import argparse
5
+ import pandas as pd
6
+ from datetime import datetime
7
+ from utils import HIST_DIR, ROOT_DIR, TMP_DIR
8
 
9
  MINIO_ENDPOINT = "minio.autonolas.tech"
10
  ACCESS_KEY = os.environ.get("CLOUD_ACCESS_KEY", None)
11
  SECRET_KEY = os.environ.get("CLOUD_SECRET_KEY", None)
12
  BUCKET_NAME = "weekly-stats"
13
  FOLDER_NAME = "historical_data"
 
14
 
15
 
16
  def initialize_client():
 
85
  print(f"Error processing {filename}: {str(e)}")
86
 
87
 
88
+ def download_tools_historical_files(
89
+ client, exclude_filename: str = None, nr_files: int = 18
90
+ ) -> pd.DataFrame:
91
+ """Download the last nr_files tools files from the cloud storage"""
92
+ FILES_IN_TWO_MONTHS = 16
93
+ try:
94
+ print(f"Downloading the last {nr_files} tools files from cloud storage")
95
+ # Use recursive=True to get all objects including those in subfolders
96
+ objects = client.list_objects(
97
+ BUCKET_NAME, prefix=FOLDER_NAME + "/", recursive=True
98
+ )
99
+ all_objects = list(objects)
100
+ print(f"Total objects found: {len(all_objects)}")
101
+
102
+ tool_files = [
103
+ obj.object_name
104
+ for obj in all_objects
105
+ if obj.object_name.endswith(".parquet") and "tools" in obj.object_name
106
+ ]
107
+ print(f"tool files found: {tool_files}")
108
+ if len(tool_files) < nr_files - 1: # at least one file to collect
109
+ return None
110
+ # format of the filename is tools_YYYYMMDD_HHMMSS.parquet
111
+ # get the last nr_files by sorting the tool_files by the YYYYMMDD_HHMMSS part
112
+ tool_files.sort() # Sort files by name (assumed to be timestamped)
113
+ selected_files = tool_files[-nr_files:] # Get the last nr_files
114
+
115
+ print(f"Selected files: {selected_files}")
116
+ # traverse the selected files in reverse order
117
+ selected_files.reverse()
118
+ # skip the first FILES_IN_TWO_MONTHS files
119
+ selected_files = selected_files[
120
+ FILES_IN_TWO_MONTHS:
121
+ ] # limit to last two months
122
+
123
+ for filename in selected_files:
124
+ if exclude_filename and exclude_filename in filename:
125
+ continue
126
+ local_filename = filename.replace("historical_data/", "")
127
+ print(f"Downloading {local_filename}")
128
+ download_path = TMP_DIR / local_filename
129
+ client.fget_object(BUCKET_NAME, filename, str(download_path))
130
+ return local_filename
131
+ except S3Error as err:
132
+ print(f"Error downloading files: {err}")
133
+
134
+ return None
135
+
136
+
137
  if __name__ == "__main__":
138
  # parser = argparse.ArgumentParser(
139
  # description="Load files to the cloud storate for historical data"
 
145
  # filename = args.param_1
146
 
147
  client = initialize_client()
148
+ # download_file(client, "all_trades_profitability_20250103_162106.parquet")
149
+ download_tools_historical_files(client)
150
  # load_historical_file(client, filename)
151
  # process_historical_files(client)
152
  # checking files at the cloud storage
scripts/update_tools_accuracy.py CHANGED
@@ -5,7 +5,9 @@ import ipfshttpclient
5
  from utils import INC_TOOLS
6
  from typing import List
7
  from utils import TMP_DIR, ROOT_DIR
 
8
  import math
 
9
 
10
  ACCURACY_FILENAME = "tools_accuracy.csv"
11
  IPFS_SERVER = "/dns/registry.autonolas.tech/tcp/443/https"
@@ -13,6 +15,8 @@ GCP_IPFS_SERVER = "/dns/registry.gcp.autonolas.tech/tcp/443/https"
13
  SAMPLING_POPULATION_SIZE = 800
14
  NR_SUBSETS = 100
15
  SAMPLES_THRESHOLD = 50
 
 
16
 
17
 
18
  def mean_and_std(numbers):
@@ -22,7 +26,7 @@ def mean_and_std(numbers):
22
  return mean, std_dev
23
 
24
 
25
- def clean_tools_df(tools_df: pd.DataFrame) -> pd.DataFrame:
26
 
27
  # Remove tool_name and TEMP_TOOL
28
  tools_non_error = tools_df[
@@ -44,37 +48,32 @@ def clean_tools_df(tools_df: pd.DataFrame) -> pd.DataFrame:
44
  return tools_non_error
45
 
46
 
47
- def separate_sampling_tools(
48
- tools_df: pd.DataFrame, sample_size: int
49
- ) -> Tuple[Dict, Dict, Dict]:
50
  """
51
- Separates tools into two groups based on whether they need downsampling or upsampling
 
 
52
 
53
  Args:
54
  tools_df: DataFrame containing the tools data
55
  sample_size: Target number of samples for each tool
56
 
57
  Returns:
58
- Tuple of two dictionaries containing tools that need downsampling and upsampling
59
  """
60
  # Get count of samples per tool
61
  tool_counts = tools_df["tool"].value_counts()
62
 
63
  # Separate tools based on sample size
64
- downsample_tools = {
65
- tool: count for tool, count in tool_counts.items() if count > sample_size
66
  }
67
- # edge case: if the tools has less samples than the samples_threshold, we skip it
68
- skipped_tools = {
69
- tool: count for tool, count in tool_counts.items() if count < SAMPLES_THRESHOLD
70
- }
71
- upsample_tools = {
72
- tool: count
73
- for tool, count in tool_counts.items()
74
- if count > SAMPLES_THRESHOLD and count < sample_size
75
  }
76
 
77
- return downsample_tools, upsample_tools, skipped_tools
78
 
79
 
80
  def downsample_tool_multiple(
@@ -111,6 +110,24 @@ def downsample_tool_multiple(
111
  return downsampled_sets
112
 
113
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114
  def upsample_tool_multiple(
115
  tool_samples: pd.DataFrame, sample_size: int, n_subsets: int
116
  ) -> List[pd.DataFrame]:
@@ -162,7 +179,7 @@ def compute_subset_accuracy(tools_subset: pd.DataFrame) -> float:
162
  return (wins[1] / (wins[0] + wins[1])) * 100
163
 
164
 
165
- def compute_tool_accuracy(subset_list: List[pd.DataFrame]) -> Tuple:
166
  """
167
  Computes the accuracy for the tool averaging the accuracy achieved within the list of subsets.
168
 
@@ -183,6 +200,84 @@ def compute_tool_accuracy(subset_list: List[pd.DataFrame]) -> Tuple:
183
  return accuracy_mean, accuracy_std
184
 
185
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
186
  def compute_global_accuracy_same_population(
187
  tools_df: pd.DataFrame,
188
  sample_size: int = SAMPLING_POPULATION_SIZE,
@@ -200,41 +295,71 @@ def compute_global_accuracy_same_population(
200
  Returns:
201
  List of global accuracies for the tools
202
  """
203
- downsample_tools, upsample_tools, skipped_tools = separate_sampling_tools(
204
- tools_df, sample_size
205
- )
206
  global_accuracies = {}
207
 
208
- # Process tools that need downsampling
209
- for tool in downsample_tools.keys():
210
- print(f"Processing tool: {tool}")
211
- tool_samples = tools_df[tools_df["tool"] == tool]
212
- downsampled_sets = downsample_tool_multiple(
213
- tool_samples, sample_size, n_subsets
214
- )
215
-
216
- tool_mean_accuracy, tool_std = compute_tool_accuracy(downsampled_sets)
217
- global_accuracies[tool] = {"mean": float(tool_mean_accuracy), "std": tool_std}
218
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
219
  # Process tools that need upsampling
220
- for tool in upsample_tools.keys():
 
 
 
 
 
 
 
 
 
221
  tool_samples = tools_df[tools_df["tool"] == tool]
222
  upsampled_sets = upsample_tool_multiple(tool_samples, sample_size, n_subsets)
223
 
224
- tool_mean_accuracy, tool_std = compute_tool_accuracy(upsampled_sets)
225
  global_accuracies[tool] = {"mean": float(tool_mean_accuracy), "std": tool_std}
226
- return global_accuracies, skipped_tools
227
 
228
 
229
  def get_accuracy_info(tools_df: pd.DataFrame) -> [pd.DataFrame, bool, Dict]:
230
  """
231
  Extracts accuracy information from the tools DataFrame.
232
  """
233
- clean_tools_df = clean_tools_df(tools_df)
234
  # compute global accuracy information for the tools
235
- global_accuracies, skipped_tools = compute_global_accuracy_same_population(
236
- tools_df=clean_tools_df
237
- )
238
  # transform the dictionary global_accuracies into a DataFrame
239
  wins = pd.DataFrame(
240
  [
@@ -260,7 +385,7 @@ def get_accuracy_info(tools_df: pd.DataFrame) -> [pd.DataFrame, bool, Dict]:
260
  print("NO REQUEST TIME INFORMATION AVAILABLE")
261
  no_timeline_info = True
262
  acc_info = wins
263
- return acc_info, no_timeline_info, skipped_tools
264
 
265
 
266
  def update_tools_accuracy_same_model(
@@ -270,8 +395,7 @@ def update_tools_accuracy_same_model(
270
 
271
  # computation of the accuracy information
272
  tools_inc = tools_df[tools_df["tool"].isin(inc_tools)]
273
- acc_info, no_timeline_info, skipped_tools = get_accuracy_info(tools_inc)
274
- print(f"Skipped tools in the update with not enough samples: {skipped_tools}")
275
 
276
  if tools_acc is None:
277
  print("Creating accuracy file for the first time")
@@ -285,9 +409,15 @@ def update_tools_accuracy_same_model(
285
  # dt.strftime("%Y-%m-%d %H:%M:%S")
286
  acc_info["min"] = acc_info["min"].dt.strftime("%Y-%m-%d %H:%M:%S")
287
  acc_info["max"] = acc_info["max"].dt.strftime("%Y-%m-%d %H:%M:%S")
 
 
288
  for tool in tools_to_update:
289
- new_accuracy = acc_info[acc_info["tool"] == tool]["tool_accuracy"].values[0]
290
- new_volume = acc_info[acc_info["tool"] == tool]["total_requests"].values[0]
 
 
 
 
291
  if no_timeline_info:
292
  new_min_timeline = None
293
  new_max_timeline = None
@@ -311,17 +441,28 @@ def update_tools_accuracy_same_model(
311
  tools_acc.loc[tools_acc["tool"] == tool, "min"] = new_min_timeline
312
  tools_acc.loc[tools_acc["tool"] == tool, "max"] = new_max_timeline
313
  else:
314
- # new tool to add to the file
 
 
 
 
 
 
 
 
 
 
 
 
315
  # tool,tool_accuracy,total_requests,min,max
316
  new_row = {
317
  "tool": tool,
318
- "tool_accuracy": new_accuracy,
319
- "total_requests": new_volume,
320
- "min": new_min_timeline,
321
- "max": new_max_timeline,
322
  }
323
  tools_acc = pd.concat([tools_acc, pd.DataFrame(new_row)], ignore_index=True)
324
-
325
  print(tools_acc)
326
  return tools_acc
327
 
@@ -340,15 +481,16 @@ def update_tools_accuracy(
340
  tools_df["request_date"] = pd.to_datetime(tools_df["request_date"])
341
  tools_df["request_date"] = tools_df["request_date"].dt.strftime("%Y-%m-%d")
342
  # split the data into two parts: before and after the 3rd of June
343
- split_date = pd.to_datetime("2025-06-03").tz_localize("UTC")
344
  before_split = tools_df[tools_df["request_time"] < split_date]
345
  after_split = tools_df[tools_df["request_time"] >= split_date]
346
  print(f"Number of requests before {split_date}: {len(before_split)}")
347
  print(f"Number of requests after {split_date}: {len(after_split)}")
348
  # compute the accuracy information for the two parts
349
- acc_info_before = update_tools_accuracy_same_model(
350
- old_tools_acc, before_split, inc_tools
351
- )
 
352
  acc_info_after = update_tools_accuracy_same_model(tools_acc, after_split, inc_tools)
353
  # return the two different dataframes
354
  return acc_info_before, acc_info_after
@@ -374,7 +516,7 @@ def compute_tools_accuracy():
374
 
375
  # save acc_data into a CSV file
376
  print("Saving into a csv files")
377
- old_acc_data.to_csv(ROOT_DIR / "old_tools_accuracy.csv", index=False)
378
  new_acc_data.to_csv(ROOT_DIR / ACCURACY_FILENAME, index=False)
379
  # save the data into IPFS
380
  # push_csv_file_to_ipfs("old_tools_accuracy.csv")
 
5
  from utils import INC_TOOLS
6
  from typing import List
7
  from utils import TMP_DIR, ROOT_DIR
8
+ from cloud_storage import initialize_client, download_tools_historical_files
9
  import math
10
+ import time
11
 
12
  ACCURACY_FILENAME = "tools_accuracy.csv"
13
  IPFS_SERVER = "/dns/registry.autonolas.tech/tcp/443/https"
 
15
  SAMPLING_POPULATION_SIZE = 800
16
  NR_SUBSETS = 100
17
  SAMPLES_THRESHOLD = 50
18
+ DEFAULT_ACCURACY = 51.0
19
+ LAST_MODEL_UPDATE = "2025-06-03"
20
 
21
 
22
  def mean_and_std(numbers):
 
26
  return mean, std_dev
27
 
28
 
29
+ def clean_tools_dataset(tools_df: pd.DataFrame) -> pd.DataFrame:
30
 
31
  # Remove tool_name and TEMP_TOOL
32
  tools_non_error = tools_df[
 
48
  return tools_non_error
49
 
50
 
51
+ def classify_tools(tools_df: pd.DataFrame, sample_size: int) -> Tuple[Dict, Dict, Dict]:
 
 
52
  """
53
+ Separates tools into different groups based on two use-cases:
54
+ 1. Tools with enough samples to reach sample_size
55
+ 2. Tools with not enough samples to reach sample_size
56
 
57
  Args:
58
  tools_df: DataFrame containing the tools data
59
  sample_size: Target number of samples for each tool
60
 
61
  Returns:
62
+ Tuple of two dictionaries containing tools that are from group 1 and group 2
63
  """
64
  # Get count of samples per tool
65
  tool_counts = tools_df["tool"].value_counts()
66
 
67
  # Separate tools based on sample size
68
+ valid_tools = {
69
+ tool: count for tool, count in tool_counts.items() if count >= sample_size
70
  }
71
+
72
+ more_samples_tools = {
73
+ tool: count for tool, count in tool_counts.items() if count < sample_size
 
 
 
 
 
74
  }
75
 
76
+ return valid_tools, more_samples_tools
77
 
78
 
79
  def downsample_tool_multiple(
 
110
  return downsampled_sets
111
 
112
 
113
+ def get_recent_samples(tool_samples: pd.DataFrame, sample_size: int) -> pd.DataFrame:
114
+ """
115
+ Gets the most recent samples from the tool samples
116
+
117
+ Args:
118
+ tool_samples: DataFrame containing samples for a specific tool
119
+ sample_size: Number of samples to select
120
+
121
+ Returns:
122
+ DataFrame containing the most recent samples
123
+ """
124
+ if len(tool_samples) < sample_size:
125
+ raise ValueError(
126
+ f"Not enough samples available: {len(tool_samples)} < {sample_size}"
127
+ )
128
+ return tool_samples.nlargest(sample_size, "request_time")
129
+
130
+
131
  def upsample_tool_multiple(
132
  tool_samples: pd.DataFrame, sample_size: int, n_subsets: int
133
  ) -> List[pd.DataFrame]:
 
179
  return (wins[1] / (wins[0] + wins[1])) * 100
180
 
181
 
182
+ def compute_tool_estimated_accuracy(subset_list: List[pd.DataFrame]) -> Tuple:
183
  """
184
  Computes the accuracy for the tool averaging the accuracy achieved within the list of subsets.
185
 
 
200
  return accuracy_mean, accuracy_std
201
 
202
 
203
+ def update_global_accuracy(
204
+ valid_tools: Dict,
205
+ tools_df: pd.DataFrame,
206
+ global_accuracies: Dict,
207
+ sample_size: int,
208
+ one_tool: str = None,
209
+ ) -> Dict:
210
+ """
211
+ Updates the global accuracies for tools that have enough samples.
212
+
213
+ Args:
214
+ valid_tools: Dictionary of tools with enough samples
215
+ global_accuracies: Dictionary to store global accuracies
216
+ sample_size: Target number of samples for each tool
217
+ one_tool: Optional specific tool to compute accuracy for
218
+
219
+ Returns:
220
+ Updated global accuracies dictionary
221
+ """
222
+ if one_tool:
223
+ print(f"Computing accuracy for tool: {one_tool}")
224
+ tool_samples = tools_df[tools_df["tool"] == one_tool]
225
+ if len(tool_samples) < sample_size:
226
+ print(f"Not enough samples for tool {one_tool}, skipping")
227
+ return global_accuracies
228
+ recent_samples = get_recent_samples(tool_samples, sample_size)
229
+ global_accuracies[one_tool] = {
230
+ "mean": compute_subset_accuracy(recent_samples),
231
+ "std": 0.0, # No standard deviation for a single sample
232
+ }
233
+ return global_accuracies
234
+
235
+ for tool in valid_tools.keys():
236
+ print(f"Processing tool: {tool}")
237
+ tool_samples = tools_df[tools_df["tool"] == tool]
238
+ # Get the most recent samples for the tool
239
+ recent_samples = get_recent_samples(tool_samples, sample_size)
240
+ global_accuracies[tool] = {
241
+ "mean": compute_subset_accuracy(recent_samples),
242
+ "std": 0.0, # No standard deviation for a single sample
243
+ }
244
+
245
+
246
+ def adding_historical_data(
247
+ tools_historical_file: str,
248
+ tools_df: pd.DataFrame,
249
+ more_sample_tools: Dict,
250
+ sample_size: int,
251
+ valid_tools: Dict,
252
+ global_accuracies: Dict,
253
+ ):
254
+ if tools_historical_file:
255
+ tool_names = list(more_sample_tools.keys())
256
+ print(f"Downloaded historical file: {tools_historical_file}")
257
+ # Load the historical tools data
258
+ historical_tools_df = pd.read_parquet(TMP_DIR / tools_historical_file)
259
+ # check if the historical tools data has samples from the tools that need more samples
260
+ historical_tools_df = historical_tools_df[
261
+ historical_tools_df["tool"].isin(tool_names)
262
+ ]
263
+ # Combine the current tools with the historical ones
264
+ tools_df = pd.concat([tools_df, historical_tools_df], ignore_index=True)
265
+ # check the volume of samples for the tools in the historical data
266
+ historical_tool_counts = historical_tools_df["tool"].value_counts()
267
+ for tool, count in historical_tool_counts.items():
268
+ current_count = more_sample_tools.get(tool, 0)
269
+ if count + current_count >= sample_size:
270
+ print(f"Tool {tool} has enough samples now: {count + current_count}")
271
+ valid_tools[tool] = count + current_count
272
+ update_global_accuracy(
273
+ valid_tools, tools_df, global_accuracies, sample_size, one_tool=tool
274
+ )
275
+ # Remove the tool from more_sample_tools
276
+ if tool in more_sample_tools:
277
+ print(f"Deleting tool {tool} from more_sample_tools")
278
+ del more_sample_tools[tool]
279
+
280
+
281
  def compute_global_accuracy_same_population(
282
  tools_df: pd.DataFrame,
283
  sample_size: int = SAMPLING_POPULATION_SIZE,
 
295
  Returns:
296
  List of global accuracies for the tools
297
  """
298
+ valid_tools, more_sample_tools = classify_tools(tools_df, sample_size)
 
 
299
  global_accuracies = {}
300
 
301
+ # Compute the accuracy for tools in valid_tools
302
+ update_global_accuracy(valid_tools, tools_df, global_accuracies, sample_size)
303
+
304
+ # Check historical files for tools that need more samples
305
+ client = initialize_client()
306
+ # first historical file download
307
+ tool_names = list(more_sample_tools.keys())
308
+ print(f"Tools with not enough samples: {tool_names}")
309
+ # Disbling the historical file download til we have enough old samples from "2025-06-03" (Latest model update)
310
+ # TODO reactivate the historical file download from 2025-08-16
311
+ # tools_historical_file = download_tools_historical_files(
312
+ # client, exclude_filename=None
313
+ # )
314
+ # adding_historical_data(
315
+ # tools_historical_file,
316
+ # tools_df,
317
+ # more_sample_tools,
318
+ # sample_size,
319
+ # valid_tools,
320
+ # global_accuracies,
321
+ # )
322
+ # if len(more_sample_tools) > 0:
323
+ # # second historical file download
324
+ # tools_historical_file2 = download_tools_historical_files(
325
+ # client,
326
+ # exclude_filename=tools_historical_file,
327
+ # )
328
+ # adding_historical_data(
329
+ # tools_historical_file2,
330
+ # tools_df,
331
+ # more_sample_tools,
332
+ # sample_size,
333
+ # valid_tools,
334
+ # global_accuracies,
335
+ # )
336
+ # if not enough samples found in the historical data, upsample the tools that need more samples
337
  # Process tools that need upsampling
338
+ for tool in more_sample_tools.keys():
339
+ if more_sample_tools[tool] < SAMPLES_THRESHOLD:
340
+ # assign the default accuracy
341
+ print(f"Tool {tool} has not enough samples, assigning default accuracy")
342
+ global_accuracies[tool] = {
343
+ "mean": DEFAULT_ACCURACY,
344
+ "std": 0.0, # No standard deviation for a single sample
345
+ }
346
+ continue
347
+ print(f"Upsampling tool: {tool}")
348
  tool_samples = tools_df[tools_df["tool"] == tool]
349
  upsampled_sets = upsample_tool_multiple(tool_samples, sample_size, n_subsets)
350
 
351
+ tool_mean_accuracy, tool_std = compute_tool_estimated_accuracy(upsampled_sets)
352
  global_accuracies[tool] = {"mean": float(tool_mean_accuracy), "std": tool_std}
353
+ return global_accuracies
354
 
355
 
356
  def get_accuracy_info(tools_df: pd.DataFrame) -> [pd.DataFrame, bool, Dict]:
357
  """
358
  Extracts accuracy information from the tools DataFrame.
359
  """
360
+ clean_tools_df = clean_tools_dataset(tools_df)
361
  # compute global accuracy information for the tools
362
+ global_accuracies = compute_global_accuracy_same_population(tools_df=clean_tools_df)
 
 
363
  # transform the dictionary global_accuracies into a DataFrame
364
  wins = pd.DataFrame(
365
  [
 
385
  print("NO REQUEST TIME INFORMATION AVAILABLE")
386
  no_timeline_info = True
387
  acc_info = wins
388
+ return acc_info, no_timeline_info
389
 
390
 
391
  def update_tools_accuracy_same_model(
 
395
 
396
  # computation of the accuracy information
397
  tools_inc = tools_df[tools_df["tool"].isin(inc_tools)]
398
+ acc_info, no_timeline_info = get_accuracy_info(tools_inc)
 
399
 
400
  if tools_acc is None:
401
  print("Creating accuracy file for the first time")
 
409
  # dt.strftime("%Y-%m-%d %H:%M:%S")
410
  acc_info["min"] = acc_info["min"].dt.strftime("%Y-%m-%d %H:%M:%S")
411
  acc_info["max"] = acc_info["max"].dt.strftime("%Y-%m-%d %H:%M:%S")
412
+ new_tools = []
413
+ all_accuracies = []
414
  for tool in tools_to_update:
415
+ new_accuracy = round(
416
+ acc_info[acc_info["tool"] == tool]["tool_accuracy"].values[0], 2
417
+ )
418
+ all_accuracies.append(new_accuracy)
419
+ # accuracy has been computed over the same population size
420
+ new_volume = SAMPLING_POPULATION_SIZE
421
  if no_timeline_info:
422
  new_min_timeline = None
423
  new_max_timeline = None
 
441
  tools_acc.loc[tools_acc["tool"] == tool, "min"] = new_min_timeline
442
  tools_acc.loc[tools_acc["tool"] == tool, "max"] = new_max_timeline
443
  else:
444
+ new_tools.append(tool)
445
+
446
+ # compute the average accuracy for the existing tools
447
+ if len(new_tools) > 0:
448
+ print(f"New tools added: {new_tools}")
449
+ # compute the average accuracy for the new tools
450
+ avg_accuracy = (
451
+ round(sum(all_accuracies) / len(all_accuracies), 2)
452
+ if len(all_accuracies) > 0
453
+ else DEFAULT_ACCURACY
454
+ )
455
+ print(f"Average accuracy for new tools: {avg_accuracy}")
456
+ for tool in new_tools:
457
  # tool,tool_accuracy,total_requests,min,max
458
  new_row = {
459
  "tool": tool,
460
+ "tool_accuracy": avg_accuracy,
461
+ "total_requests": SAMPLING_POPULATION_SIZE,
462
+ "min": None,
463
+ "max": None,
464
  }
465
  tools_acc = pd.concat([tools_acc, pd.DataFrame(new_row)], ignore_index=True)
 
466
  print(tools_acc)
467
  return tools_acc
468
 
 
481
  tools_df["request_date"] = pd.to_datetime(tools_df["request_date"])
482
  tools_df["request_date"] = tools_df["request_date"].dt.strftime("%Y-%m-%d")
483
  # split the data into two parts: before and after the 3rd of June
484
+ split_date = pd.to_datetime(LAST_MODEL_UPDATE).tz_localize("UTC")
485
  before_split = tools_df[tools_df["request_time"] < split_date]
486
  after_split = tools_df[tools_df["request_time"] >= split_date]
487
  print(f"Number of requests before {split_date}: {len(before_split)}")
488
  print(f"Number of requests after {split_date}: {len(after_split)}")
489
  # compute the accuracy information for the two parts
490
+ # acc_info_before = update_tools_accuracy_same_model(
491
+ # old_tools_acc, before_split, inc_tools
492
+ # )
493
+ acc_info_before = None
494
  acc_info_after = update_tools_accuracy_same_model(tools_acc, after_split, inc_tools)
495
  # return the two different dataframes
496
  return acc_info_before, acc_info_after
 
516
 
517
  # save acc_data into a CSV file
518
  print("Saving into a csv files")
519
+ # old_acc_data.to_csv(ROOT_DIR / "old_tools_accuracy.csv", index=False)
520
  new_acc_data.to_csv(ROOT_DIR / ACCURACY_FILENAME, index=False)
521
  # save the data into IPFS
522
  # push_csv_file_to_ipfs("old_tools_accuracy.csv")
tools_accuracy.csv CHANGED
@@ -1,13 +1,13 @@
1
  tool,tool_accuracy,total_requests,min,max
2
- claude-prediction-offline,60.66080040612572,132980,2025-05-25 10:30:10,2025-07-20 23:30:50
3
- claude-prediction-online,54.01045556385362,128324,2025-05-25 00:00:15,2025-07-20 23:10:30
4
- prediction-offline,61.649646337713015,1495882,2025-05-25 00:00:30,2025-07-20 23:42:15
5
- prediction-offline-sme,56.35491606714629,3706,2025-05-25 00:13:15,2025-07-17 12:28:50
6
- prediction-online,60.34185039665657,276866,2025-05-25 07:33:20,2025-07-20 23:41:50
7
- prediction-online-sme,55.158180430296,237421,2025-05-25 07:05:50,2025-07-20 23:38:00
8
- prediction-request-rag,48.651197887191096,162605,2025-05-25 14:16:25,2025-07-20 23:38:30
9
- prediction-request-rag-claude,46.08523290386521,3501,2025-05-25 13:21:55,2025-07-20 19:25:25
10
- prediction-request-reasoning,54.98439809492528,485638,2025-05-25 07:14:15,2025-07-20 23:43:45
11
- prediction-request-reasoning-claude,51.8555667001003,3164,2025-05-25 13:48:00,2025-07-20 17:57:35
12
- prediction-url-cot-claude,42.857142857142854,362,2025-05-25 00:12:40,2025-07-01 07:40:40
13
- superforcaster,63.83774090070976,298068,2025-05-25 00:00:20,2025-07-20 23:42:00
 
1
  tool,tool_accuracy,total_requests,min,max
2
+ claude-prediction-offline,61.25,800,2025-06-06 00:13:05,2025-07-20 23:30:50
3
+ claude-prediction-online,44.25,800,2025-06-11 07:23:05,2025-07-20 23:10:30
4
+ prediction-offline,66.25,800,2025-06-03 00:00:05,2025-07-20 23:42:15
5
+ prediction-offline-sme,56.44,800,2025-06-03 11:55:10,2025-07-17 12:28:50
6
+ prediction-online,48.25,800,2025-06-03 00:00:05,2025-07-20 23:41:50
7
+ prediction-online-sme,61.12,800,2025-06-03 00:04:30,2025-07-20 23:38:00
8
+ prediction-request-rag,43.25,800,2025-06-03 18:59:40,2025-07-20 23:38:30
9
+ prediction-request-rag-claude,44.38,800,2025-06-03 17:51:10,2025-07-20 19:25:25
10
+ prediction-request-reasoning,54.25,800,2025-06-03 00:00:30,2025-07-20 23:43:45
11
+ prediction-request-reasoning-claude,53.5,800,2025-06-16 11:02:15,2025-07-20 17:57:35
12
+ prediction-url-cot-claude,51.0,800,2025-06-12 20:36:25,2025-07-01 07:40:40
13
+ superforcaster,62.75,800,2025-06-03 01:15:10,2025-07-20 23:42:00