SondosMB commited on
Commit
e16b4f3
·
verified ·
1 Parent(s): a47242f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -3
app.py CHANGED
@@ -177,7 +177,7 @@ def load_leaderboard():
177
  df = pd.read_csv(LEADERBOARD_FILE)
178
 
179
  # Fill empty Team Name
180
- df['Team Name'] = df['Team Name'].fillna('Unknown Team')
181
 
182
  # Fill empty Timestamp
183
  df['Timestamp'] = df['Timestamp'].fillna(datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
@@ -213,6 +213,19 @@ def load_leaderboard():
213
 
214
  return df
215
 
 
 
 
 
 
 
 
 
 
 
 
 
 
216
  def load_leaderboard_pro():
217
  if not os.path.exists(LEADERBOARD_FILE_pro) or os.stat(LEADERBOARD_FILE_pro).st_size == 0:
218
  return pd.DataFrame({
@@ -222,9 +235,48 @@ def load_leaderboard_pro():
222
  "Total Questions": [],
223
  "Timestamp": [],
224
  "Team Name": [],
225
-
226
  })
227
- return pd.read_csv(LEADERBOARD_FILE_pro)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
228
 
229
 
230
 
 
177
  df = pd.read_csv(LEADERBOARD_FILE)
178
 
179
  # Fill empty Team Name
180
+ df['Team Name'] = df['Team Name'].fillna(df['Model Name'])
181
 
182
  # Fill empty Timestamp
183
  df['Timestamp'] = df['Timestamp'].fillna(datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
 
213
 
214
  return df
215
 
216
+ # def load_leaderboard_pro():
217
+ # if not os.path.exists(LEADERBOARD_FILE_pro) or os.stat(LEADERBOARD_FILE_pro).st_size == 0:
218
+ # return pd.DataFrame({
219
+ # "Model Name": [],
220
+ # "Overall Accuracy": [],
221
+ # "Correct Predictions": [],
222
+ # "Total Questions": [],
223
+ # "Timestamp": [],
224
+ # "Team Name": [],
225
+
226
+ # })
227
+ # return pd.read_csv(LEADERBOARD_FILE_pro)
228
+
229
  def load_leaderboard_pro():
230
  if not os.path.exists(LEADERBOARD_FILE_pro) or os.stat(LEADERBOARD_FILE_pro).st_size == 0:
231
  return pd.DataFrame({
 
235
  "Total Questions": [],
236
  "Timestamp": [],
237
  "Team Name": [],
 
238
  })
239
+
240
+ # Read the CSV file
241
+ df = pd.read_csv(LEADERBOARD_FILE_pro)
242
+
243
+ # Fill empty Team Name
244
+ df['Team Name'] = df['Team Name'].fillna(df['Model Name'])
245
+
246
+ # Fill empty Timestamp
247
+ df['Timestamp'] = df['Timestamp'].fillna(datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
248
+
249
+ # If Timestamp is an empty string, replace with current timestamp
250
+ df.loc[df['Timestamp'] == '', 'Timestamp'] = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
251
+
252
+ # Fill Correct Predictions based on Accuracy and Total Questions if possible
253
+ # Assuming Total Questions is typically 16186 and Accuracy is a percentage
254
+ df['Correct Predictions'] = df.apply(
255
+ lambda row: round(9497 * (row['Overall Accuracy'] / 100))
256
+ if pd.isna(row['Correct Predictions']) or row['Correct Predictions'] == ''
257
+ else row['Correct Predictions'],
258
+ axis=1
259
+ )
260
+
261
+ # Remove duplicate entries, keeping the last occurrence
262
+ df = df.drop_duplicates(subset='Model Name', keep='last')
263
+
264
+ # Ensure all expected columns are present
265
+ expected_columns = [
266
+ "Model Name",
267
+ "Overall Accuracy",
268
+ "Correct Predictions",
269
+ "Total Questions",
270
+ "Timestamp",
271
+ "Team Name"
272
+ ]
273
+
274
+ # Reorder columns and save
275
+ df = df[expected_columns]
276
+ df.to_csv(LEADERBOARD_FILE_pro, index=False)
277
+
278
+ return df
279
+
280
 
281
 
282