cyberosa commited on
Commit
02cbfc5
·
1 Parent(s): 3b20048

new weekly data and new global accuracy script

Browse files
active_traders.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:e8ebf6f31796904a9dced9d32d78ce78e527e5e12c52681a099f0485d84dd98b
3
- size 17691664
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5596334de30b7d8b658fa5b5d662583701343923d50959386bf276066f44dc52
3
+ size 17846311
all_trades_profitability.parquet.gz CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:f347e49277ab3009e97bcc6d9cf96c49a3e622e0c58385f9df0c708594a0431e
3
- size 17823081
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ee02f2e1feb848f83a406c314a46b6552238c32637e5bd3fca5c605dfd68d62b
3
+ size 17917783
closed_market_metrics.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:e77231f1ab081d6d56e7e370b29e4c2ce896fa81c7def1384eeafebe4e960e08
3
- size 149870
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:84a665ae59d07444f1d17b4a510b81ed654a8e912e1055753893c346e175922c
3
+ size 151807
closed_markets_div.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:2a792c95c5dc7ee5fca1114a4ecd5e62e83b758bfda60c441d107ecc1d9db2ec
3
- size 89735
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c514f9e3324a76125fd6d917f99edef77e2326a2e82c055bda05e8305cefa11a
3
+ size 89937
daily_info.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:07b4e629fda57dd4704c3ffcd0c034842f3d8f1b9ae029b26376fe4dcabbde00
3
- size 3678287
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:730dec64faaaa2517e8b35b7e2b656a03eb0b54d8eaa247bf0d285b1d97bbf65
3
+ size 4007649
daily_mech_requests.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:e5da96c306d6255ec5f6062e515ecadcb0c55f3bf106ef98ddf7a04031b9d2f1
3
- size 8037
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3b6c2e33827248b12883074dcb3b49eede56feb8987a561bb50f0b1a3353f380
3
+ size 8143
daily_mech_requests_by_pearl_agents.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:fc3959d55d3cd0b0ff28875cac276a858c473c0f93e1417017bc4170b9a88d31
3
- size 4551
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e8a4106e93228d3a5f5790808d8d4ba20a726bda0d61f10e5df7a0bd8f6df879
3
+ size 4534
error_by_markets.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:90829b29bd74d6b4333e4b0ef49e627f68e2a14a9d46e1d330223d8243aef403
3
- size 11736
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4ce04d09b2e2fee98aa3e92536825003d8989704812bdb32ccbd9071b572f83e
3
+ size 11791
errors_by_mech.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:c4604e6043191bad48b966531574aea05039e50aab27eb75bdaba5bd057916c1
3
- size 6116
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f21d5ab69409d9ff9336d2fd089fed13157d3418cdaf9d91d168eb32c18412af
3
+ size 6114
invalid_trades.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:a2b5b469ee799e8c4555fe7fd07b3d0f74448401a6c8c048eacaf223070ae222
3
- size 334820
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1187977c6cf6c4310f7b6a984974545d02628dc354b545ae4244992f8023b67d
3
+ size 315179
latest_result_DAA_Pearl.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:ecffc3e903e6068d330fb5109c6f7a5497f5a41d0b216a2f85f13ed94f8fca9e
3
- size 5520
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3666d9f201ef92e0da43916500621056ca201d97b69a7c0b08dfcd8899f075e9
3
+ size 5560
latest_result_DAA_QS.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:3ab2f0716f02958a98132e469347af21cf5675aac510f35063f09b5116880b6b
3
- size 6141
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ddccaa1242673bbbd937ed8e51400f13305d77dfe11aa29e3bd59503a49241e8
3
+ size 6210
pearl_agents.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:aee09298538c45ac060ed1a1f7ed7f66b81706845cecccd16f4e3a010e2fa3a1
3
- size 47490
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ffc5123e602578daa7f467175b6b759bc32d65c4754ed2b23812daf5aa1a2cf9
3
+ size 47546
retention_activity.parquet.gz CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:c09129294d0d09f5e9e7b8e615a0dd6b32837f1cc5c14f37bf87d38dfb47d2c0
3
- size 4354408
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5ce3cf94f7f3aac9dafae9525badf15129fe02af8aa45420e5617686d4cd4ef1
3
+ size 4380978
scripts/cloud_storage.py CHANGED
@@ -13,6 +13,9 @@ BUCKET_NAME = "weekly-stats"
13
  FOLDER_NAME = "historical_data"
14
  FILES_IN_TWO_MONTHS = 16 # 2 files per week
15
  FILES_IN_FOUR_MONTHS = 30 # four months ago we did not have two files per week but one
 
 
 
16
 
17
 
18
  def initialize_client():
 
13
  FOLDER_NAME = "historical_data"
14
  FILES_IN_TWO_MONTHS = 16 # 2 files per week
15
  FILES_IN_FOUR_MONTHS = 30 # four months ago we did not have two files per week but one
16
+ FILES_IN_SIX_MONTHS = 40 # 1 file per week
17
+ FILES_IN_EIGHT_MONTHS = 48
18
+ FILES_IN_TEN_MONTHS = 56
19
 
20
 
21
  def initialize_client():
scripts/global_tool_accuracy.py ADDED
@@ -0,0 +1,231 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import pandas as pd
3
+ from typing import Tuple, List, Dict
4
+ import ipfshttpclient
5
+ from utils import INC_TOOLS
6
+ from typing import List
7
+ from utils import TMP_DIR, ROOT_DIR
8
+ from cloud_storage import (
9
+ initialize_client,
10
+ download_tools_historical_files,
11
+ FILES_IN_TWO_MONTHS,
12
+ FILES_IN_FOUR_MONTHS,
13
+ FILES_IN_SIX_MONTHS,
14
+ FILES_IN_EIGHT_MONTHS,
15
+ FILES_IN_TEN_MONTHS,
16
+ )
17
+
18
+ MAX_ATTEMPTS = 5
19
+ historical_files_count_map = {
20
+ 1: FILES_IN_TWO_MONTHS,
21
+ 2: FILES_IN_FOUR_MONTHS,
22
+ 3: FILES_IN_SIX_MONTHS,
23
+ 4: FILES_IN_EIGHT_MONTHS,
24
+ 5: FILES_IN_TEN_MONTHS,
25
+ }
26
+
27
+
28
+ def push_csv_file_to_ipfs(filename: str = ACCURACY_FILENAME) -> str:
29
+ """Push the tools accuracy CSV file to IPFS."""
30
+ client = ipfshttpclient.connect(IPFS_SERVER)
31
+ result = client.add(ROOT_DIR / filename)
32
+ print(f"HASH of the tools accuracy file: {result['Hash']}")
33
+ return result["Hash"]
34
+
35
+
36
+ def clean_tools_dataset(tools_df: pd.DataFrame) -> pd.DataFrame:
37
+
38
+ # Remove tool_name and TEMP_TOOL
39
+ tools_non_error = tools_df[
40
+ tools_df["tool"].isin(["tool_name", "TEMP_TOOL"]) == False
41
+ ].copy()
42
+ # Remove errors
43
+ tools_non_error = tools_non_error[tools_non_error["error"] == 0]
44
+ tools_non_error.loc[:, "currentAnswer"] = tools_non_error["currentAnswer"].replace(
45
+ {"no": "No", "yes": "Yes"}
46
+ )
47
+ tools_non_error = tools_non_error[
48
+ tools_non_error["currentAnswer"].isin(["Yes", "No"])
49
+ ]
50
+ tools_non_error = tools_non_error[tools_non_error["vote"].isin(["Yes", "No"])]
51
+ tools_non_error["win"] = (
52
+ tools_non_error["currentAnswer"] == tools_non_error["vote"]
53
+ ).astype(int)
54
+ tools_non_error.columns = tools_non_error.columns.astype(str)
55
+ return tools_non_error
56
+
57
+
58
+ def take_toptool_name(tools_df: pd.DataFrame) -> str:
59
+ volumes = tools_df.tool.value_counts().reset_index()
60
+ return volumes.iloc[0].tool
61
+
62
+
63
+ def keep_last_answer_per_question_per_tool(clean_tools_df: pd.DataFrame) -> None:
64
+ for tool in INC_TOOLS:
65
+ print(f"checking answers from tool {tool}")
66
+ tool_data = clean_tools_df[clean_tools_df["tool"] == tool]
67
+ # sort tool_data by request date in ascending order
68
+ tool_data = tool_data.sort_values(by="request_time", ascending=True)
69
+
70
+ unique_questions = tool_data.title.unique()
71
+ for question in unique_questions:
72
+ market_data = tool_data[tool_data["title"] == question]
73
+ market_data = market_data.sort_values(by="request_time", ascending=True)
74
+
75
+
76
+ def compute_nr_questions_per_tool(clean_tools_df: pd.DataFrame) -> dict:
77
+ answered_questions = {}
78
+
79
+ for tool in INC_TOOLS:
80
+ print(f"processing tool {tool}")
81
+ tool_data = clean_tools_df[clean_tools_df["tool"] == tool]
82
+ # sort tool_data by request date in ascending order
83
+ tool_data = tool_data.sort_values(by="request_time", ascending=True)
84
+ # count unique prediction markets
85
+ unique_questions = tool_data.title.unique()
86
+ answered_questions[tool] = {}
87
+ answered_questions[tool]["total_answered_questions"] = len(unique_questions)
88
+ markets_different_answer = {}
89
+ for question in unique_questions:
90
+ market_data = tool_data[tool_data["title"] == question]
91
+ different_responses = market_data.currentAnswer.value_counts()
92
+ # Extract yes and no counts, defaulting to 0 if not present
93
+ yes_count = different_responses.get("Yes", 0)
94
+ no_count = different_responses.get("No", 0)
95
+ if yes_count > 0 and no_count > 0:
96
+ # print(f"found a market {question} with different answers")
97
+ # found a market with different responses from the same tool
98
+ markets_different_answer[question] = {
99
+ "yes_responses": yes_count,
100
+ "no_responses": no_count,
101
+ }
102
+
103
+ answered_questions[tool]["markets_different_answers"] = markets_different_answer
104
+ return answered_questions
105
+
106
+
107
+ def classify_tools_by_responses(
108
+ answered_questions: dict, ref_nr_questions: int
109
+ ) -> Tuple:
110
+ enough_questions_tools = []
111
+ more_questions_tools = []
112
+ total_tools = answered_questions.keys()
113
+ for tool in total_tools:
114
+ if answered_questions[tool] >= ref_nr_questions:
115
+ enough_questions_tools.append(tool)
116
+ else:
117
+ more_questions_tools.append(tool)
118
+ return enough_questions_tools, more_questions_tools
119
+
120
+
121
+ def add_historical_data(
122
+ tools_historical_file: str,
123
+ tools_df: pd.DataFrame,
124
+ more_questions_tools: list,
125
+ recent_nr_questions: int,
126
+ completed_tools: List[str],
127
+ ) -> pd.DataFrame:
128
+ """
129
+ It searches into the historical cloud files to get more samples for the tools.
130
+ """
131
+ if not tools_historical_file:
132
+ raise ValueError(
133
+ "No historical tools file found, skipping adding historical data."
134
+ )
135
+
136
+ # get the historical tools data
137
+ print(f"Downloaded historical file into the tmp folder: {tools_historical_file}")
138
+ # Load the historical tools data
139
+ historical_tools_df = pd.read_parquet(TMP_DIR / tools_historical_file)
140
+ # check if the historical tools data has samples from the tools that need more samples
141
+ historical_tools_df = historical_tools_df[
142
+ historical_tools_df["tool"].isin(more_questions_tools)
143
+ ]
144
+ # check the volume of questions for the tools in the historical data
145
+ tools_df = pd.concat([tools_df, historical_tools_df], ignore_index=True)
146
+ # remove duplicates
147
+ tools_df.drop_duplicates(
148
+ subset=["request_id", "request_block"], keep="last", inplace=True
149
+ )
150
+ # check the new total of answered questions per tool
151
+ answered_questions = compute_nr_questions_per_tool(clean_tools_df=tools_df)
152
+ for tool in more_questions_tools:
153
+ new_count = answered_questions[tool]["total_answered_questions"]
154
+ if new_count >= recent_nr_questions:
155
+ completed_tools.append(tool)
156
+ # TODO remove the tools in completed_tools list from more_questions_tools
157
+ return tools_df
158
+
159
+
160
+ def check_historical_samples(
161
+ client,
162
+ tools_df: pd.DataFrame,
163
+ more_questions_tools: list,
164
+ ref_nr_questions: int,
165
+ attempt_nr: int,
166
+ ) -> Tuple:
167
+ """
168
+ Function to download historical data from tools and to update the list
169
+ of tools that need more questions. It returns a list of the tools that we
170
+ managed to complete the requirement
171
+ """
172
+ print(f"Tools with not enough samples: {more_questions_tools}")
173
+ completed_tools = []
174
+
175
+ files_count = historical_files_count_map[attempt_nr]
176
+ tools_historical_file = download_tools_historical_files(
177
+ client, skip_files_count=files_count
178
+ )
179
+
180
+ tools_df = add_historical_data(
181
+ tools_historical_file,
182
+ tools_df,
183
+ more_questions_tools,
184
+ ref_nr_questions,
185
+ completed_tools,
186
+ )
187
+ # TODO for each tool in tools_df, take the last answer only for each question based on request_time
188
+ return tools_df, completed_tools
189
+
190
+
191
+ def global_tool_accuracy():
192
+ # read the tools df
193
+ print("Reading tools parquet file")
194
+ tools_df = pd.read_parquet(TMP_DIR / "tools.parquet")
195
+
196
+ # clean the tools df
197
+ clean_tools_df = clean_tools_dataset(tools_df)
198
+
199
+ # extract the top tool
200
+ top_tool = take_toptool_name(tools_df=clean_tools_df)
201
+
202
+ # extract the number of questions answered from the top tool
203
+ answered_questions = compute_nr_questions_per_tool(clean_tools_df=clean_tools_df)
204
+ ref_nr_questions = answered_questions[top_tool]["total_answered_questions"]
205
+
206
+ # classify tools between those with enough questions and those that need more data
207
+ enough_q_tools, more_q_tools = classify_tools_by_responses(
208
+ answered_questions, ref_nr_questions
209
+ )
210
+
211
+ # TODO for each tool in clean_tools_df, take the last answer only for each question based on request_time
212
+
213
+ # go for historical data if needed up to a maximum of 5 attempts
214
+ nr_attempts = 0
215
+ client = initialize_client()
216
+ while len(more_q_tools) > 0 and nr_attempts < MAX_ATTEMPTS:
217
+ nr_attempts += 1
218
+ print(f"Attempt {nr_attempts} to reach the reference number of questions")
219
+ clean_tools_df, updated_tools = check_historical_samples(
220
+ client=client,
221
+ tools_df=tools_df,
222
+ more_questions_tools=more_q_tools,
223
+ ref_nr_questions=ref_nr_questions,
224
+ attempt_nr=nr_attempts,
225
+ )
226
+ print(f"Updated tools {updated_tools}")
227
+ print(f"more tools with missing data {more_q_tools}")
228
+
229
+
230
+ if __name__ == "__main__":
231
+ global_tool_accuracy()
scripts/pull_data.py CHANGED
@@ -136,7 +136,7 @@ def only_new_weekly_analysis():
136
 
137
  save_historical_data()
138
  try:
139
- clean_old_data_from_parquet_files("2025-06-06")
140
  clean_old_data_from_json_files()
141
  except Exception as e:
142
  print("Error cleaning the oldest information from parquet files")
 
136
 
137
  save_historical_data()
138
  try:
139
+ clean_old_data_from_parquet_files("2025-06-10")
140
  clean_old_data_from_json_files()
141
  except Exception as e:
142
  print("Error cleaning the oldest information from parquet files")
service_map.pkl CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:789d1027897cd87ab4ffd46c3cc995e7a96771ed77575264a6b663e3046893f1
3
- size 172245
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ef077f7a479726cb17c7c560dd64f14ed087cc7bd608ac1c5a46a0df8171c344
3
+ size 172953
traders_weekly_metrics.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:3e433c7ac52c2770887833b8dadb9f013e2b49d15430cddbc32e11cd1706466f
3
- size 190345
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5ba98e6b6ecc7712d50d99d3302cc4dab54cbeddf0b8777738ee9d0892821705
3
+ size 182213
two_weeks_avg_roi_pearl_agents.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:fc1ff47e9188cb0de7f9faacdb14c00fb9834c85f4c0b8adb9dfaaa58725f851
3
  size 3045
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3c6816d5c81eb6af3fa31059d64b15528e3d0bc888b0e92c8b46280d6e9c685c
3
  size 3045
unknown_traders.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:071fa24aa479b61a4941a9f8a209e8b7a970d8b2e5babf9600699a9db07d6b98
3
- size 1482486
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:312120143f3c47823f03d370b1c3c572526ea2dc312917bfef125915e268c99a
3
+ size 1414276
weekly_avg_roi_pearl_agents.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:dae3501daee304809183d2b6a8814b447e6efebfe2e6f803998c9d1752d6c65c
3
- size 2413
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1c3a268900d7e8f02281e67c1a84390aa501bbab626b95f435f5f116c4bdc5af
3
+ size 2396
weekly_mech_calls.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:26de376fe9c84db0a9fd152e098f6c5d87d00cc11b2e13788c208ad3e336dce1
3
- size 52263
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2c7ef0f79dc3f2a8dd24f74fd38b2f138779b3c851f81633c1dddca406298f92
3
+ size 52025
winning_df.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:e70921e5f249d72bf8267eb8313e9d736b188a2830f8d8fc7fc988ec8df76e80
3
- size 12272
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e50a2473d6b691dbf84797b16faefc397256e66b3e86b4c90848998d1c951f17
3
+ size 11959