idolezal commited on
Commit
96c0414
β€’
1 Parent(s): 32a069d

CSV have to use different dataframe without Markdown and HTML

Browse files
Files changed (1) hide show
  1. server.py +37 -21
server.py CHANGED
@@ -218,7 +218,7 @@ class LeaderboardServer:
218
  self.tournament_dataframes = tournament_dataframes
219
 
220
  leaderboard_dataframes_csv = {
221
- category: self._dataframe_to_csv(self.get_leaderboard(category=category), f"Leaderboard - {category}.csv")
222
  for category in categories
223
  }
224
 
@@ -226,7 +226,7 @@ class LeaderboardServer:
226
  tournament_dataframes_csv = {
227
  submission_id: {
228
  category: self._dataframe_to_csv(
229
- self.get_model_tournament_table(submission_id, category).data,
230
  f"Tournament table - {self.submission_id_to_data[submission_id]['metadata']['model_name'][:self.MAX_LENGTH_OF_MODEL_TITLE]} - {category}.csv",
231
  )
232
  for category in sorted(self.TASKS_CATEGORIES)
@@ -378,7 +378,7 @@ class LeaderboardServer:
378
  with self.var_lock.ro:
379
  return copy.copy(self.tournament_dataframes[submission_id][category])
380
 
381
- def _get_model_tournament_table(self, submission_id, category):
382
  if category == self.TASKS_CATEGORY_OVERALL:
383
  return None
384
 
@@ -392,19 +392,26 @@ class LeaderboardServer:
392
  for task in self.tournament_results[submission_id][competitor_id]:
393
  task_category = self.TASKS_METADATA[task]["category"]
394
  if task_category == category:
395
- match_task_result_details = dict.fromkeys(["significant", "p_value"]) # order has impact to sorting DataFrame
396
- match_task_result_details.update(copy.deepcopy(self.tournament_results[submission_id][competitor_id][task]))
397
- match_task_result_details["significant"] = str(match_task_result_details["significant"]).lower() # originaly bool
398
- match_task_result_significant = match_task_result_details["significant"]
399
- match_task_result_details = "\n".join(f"{k}: {v}" for k, v in match_task_result_details.items())
400
- match_results[task] = f'<abbr title={xmlQuoteAttr(match_task_result_details)}>{match_task_result_significant}</abbr>'
 
 
 
401
 
402
  model_link = data["metadata"]["link_to_model"]
403
  model_title = data["metadata"]["team_name"] + "/" + data["metadata"]["model_name"]
404
- model_title_abbr_team_name = self.abbreviate(data["metadata"]["team_name"], self.MAX_LENGTH_OF_MODEL_TITLE)
405
- model_title_abbr_model_name = self.abbreviate(data["metadata"]["model_name"], self.MAX_LENGTH_OF_MODEL_TITLE)
406
- model_title_abbr_html = f'<div style="font-size: 10px;">{xmlAndMarkdownEscape(model_title_abbr_team_name)}</div>{xmlAndMarkdownEscape(model_title_abbr_model_name)}'
407
- match_results["model"] = f'<a href={xmlQuoteAttr(model_link)} title={xmlQuoteAttr(model_title)}>{model_title_abbr_html}</a>'
 
 
 
 
408
 
409
  model_tournament_table.append(match_results)
410
 
@@ -412,9 +419,11 @@ class LeaderboardServer:
412
 
413
  extra_attributes_map_word_to_header = {
414
  "model": "Competitor",
 
415
  }
416
  first_attributes = [
417
  "model",
 
418
  ]
419
  df_order = [
420
  key
@@ -433,7 +442,8 @@ class LeaderboardServer:
433
  dataframe = dataframe.rename(
434
  columns=attributes_map_word_to_header
435
  )
436
- dataframe = dataframe.style.apply(self._model_tournament_table_highlight_true_and_false, axis=None)
 
437
  return dataframe
438
 
439
  def _dataframe_to_csv(self, dataframe, filename):
@@ -444,7 +454,7 @@ class LeaderboardServer:
444
  pass
445
 
446
  filepath = os.path.join(self.DIR_DATAFRAMES_CSV, filename)
447
- dataframe.to_csv(filepath)
448
  return filepath
449
 
450
  def get_leaderboard_csv(self, category=None):
@@ -460,7 +470,7 @@ class LeaderboardServer:
460
  else:
461
  return self._get_leaderboard(pre_submit=pre_submit, category=category)
462
 
463
- def _get_leaderboard(self, pre_submit=None, category=None):
464
  with self.var_lock.ro:
465
  tournament_results = pre_submit.tournament_results if pre_submit else self.tournament_results
466
  category = category if category else self.TASKS_CATEGORY_OVERALL
@@ -522,10 +532,15 @@ class LeaderboardServer:
522
 
523
  model_link = data["metadata"]["link_to_model"]
524
  model_title = data["metadata"]["team_name"] + "/" + data["metadata"]["model_name"]
525
- model_title_abbr_team_name = self.abbreviate(data["metadata"]["team_name"], self.MAX_LENGTH_OF_MODEL_TITLE)
526
- model_title_abbr_model_name = self.abbreviate(data["metadata"]["model_name"], self.MAX_LENGTH_OF_MODEL_TITLE)
527
- model_title_abbr_html = f'<div style="font-size: 10px;">{xmlAndMarkdownEscape(model_title_abbr_team_name)}</div>{xmlAndMarkdownEscape(model_title_abbr_model_name)}'
528
- local_results["model"] = f'<a href={xmlQuoteAttr(model_link)} title={xmlQuoteAttr(model_title)}>{model_title_abbr_html}</a>'
 
 
 
 
 
529
  release = data["metadata"].get("submission_timestamp")
530
  release = time.strftime("%Y-%m-%d", time.gmtime(release)) if release else "N/A"
531
  local_results["release"] = release
@@ -549,10 +564,11 @@ class LeaderboardServer:
549
  "input_length": "Input length (# tokens)",
550
  "precision": "Precision",
551
  "description": "Description",
552
- "link_to_model": "Link to model"
553
  }
554
  first_attributes = [
555
  "model",
 
556
  "release",
557
  "model_type",
558
  "parameters",
 
218
  self.tournament_dataframes = tournament_dataframes
219
 
220
  leaderboard_dataframes_csv = {
221
+ category: self._dataframe_to_csv(self._get_leaderboard(category=category, to_csv=True), f"Leaderboard - {category}.csv")
222
  for category in categories
223
  }
224
 
 
226
  tournament_dataframes_csv = {
227
  submission_id: {
228
  category: self._dataframe_to_csv(
229
+ self._get_model_tournament_table(submission_id, category, to_csv=True),
230
  f"Tournament table - {self.submission_id_to_data[submission_id]['metadata']['model_name'][:self.MAX_LENGTH_OF_MODEL_TITLE]} - {category}.csv",
231
  )
232
  for category in sorted(self.TASKS_CATEGORIES)
 
378
  with self.var_lock.ro:
379
  return copy.copy(self.tournament_dataframes[submission_id][category])
380
 
381
+ def _get_model_tournament_table(self, submission_id, category, to_csv=False):
382
  if category == self.TASKS_CATEGORY_OVERALL:
383
  return None
384
 
 
392
  for task in self.tournament_results[submission_id][competitor_id]:
393
  task_category = self.TASKS_METADATA[task]["category"]
394
  if task_category == category:
395
+ if to_csv:
396
+ match_results[task] = self.tournament_results[submission_id][competitor_id][task]
397
+ else:
398
+ match_task_result_details = dict.fromkeys(["significant", "p_value"]) # order has impact to sorting DataFrame
399
+ match_task_result_details.update(copy.deepcopy(self.tournament_results[submission_id][competitor_id][task]))
400
+ match_task_result_details["significant"] = str(match_task_result_details["significant"]).lower() # originaly bool
401
+ match_task_result_significant = match_task_result_details["significant"]
402
+ match_task_result_details = "\n".join(f"{k}: {v}" for k, v in match_task_result_details.items())
403
+ match_results[task] = f'<abbr title={xmlQuoteAttr(match_task_result_details)}>{match_task_result_significant}</abbr>'
404
 
405
  model_link = data["metadata"]["link_to_model"]
406
  model_title = data["metadata"]["team_name"] + "/" + data["metadata"]["model_name"]
407
+ if to_csv:
408
+ match_results["model"] = model_title
409
+ match_results["link_to_model"] = model_link
410
+ else:
411
+ model_title_abbr_team_name = self.abbreviate(data["metadata"]["team_name"], self.MAX_LENGTH_OF_MODEL_TITLE)
412
+ model_title_abbr_model_name = self.abbreviate(data["metadata"]["model_name"], self.MAX_LENGTH_OF_MODEL_TITLE)
413
+ model_title_abbr_html = f'<div style="font-size: 10px;">{xmlAndMarkdownEscape(model_title_abbr_team_name)}</div>{xmlAndMarkdownEscape(model_title_abbr_model_name)}'
414
+ match_results["model"] = f'<a href={xmlQuoteAttr(model_link)} title={xmlQuoteAttr(model_title)}>{model_title_abbr_html}</a>'
415
 
416
  model_tournament_table.append(match_results)
417
 
 
419
 
420
  extra_attributes_map_word_to_header = {
421
  "model": "Competitor",
422
+ "link_to_model": "Link to model",
423
  }
424
  first_attributes = [
425
  "model",
426
+ "link_to_model",
427
  ]
428
  df_order = [
429
  key
 
442
  dataframe = dataframe.rename(
443
  columns=attributes_map_word_to_header
444
  )
445
+ if not to_csv:
446
+ dataframe = dataframe.style.apply(self._model_tournament_table_highlight_true_and_false, axis=None)
447
  return dataframe
448
 
449
  def _dataframe_to_csv(self, dataframe, filename):
 
454
  pass
455
 
456
  filepath = os.path.join(self.DIR_DATAFRAMES_CSV, filename)
457
+ dataframe.to_csv(filepath, index=False)
458
  return filepath
459
 
460
  def get_leaderboard_csv(self, category=None):
 
470
  else:
471
  return self._get_leaderboard(pre_submit=pre_submit, category=category)
472
 
473
+ def _get_leaderboard(self, pre_submit=None, category=None, to_csv=False):
474
  with self.var_lock.ro:
475
  tournament_results = pre_submit.tournament_results if pre_submit else self.tournament_results
476
  category = category if category else self.TASKS_CATEGORY_OVERALL
 
532
 
533
  model_link = data["metadata"]["link_to_model"]
534
  model_title = data["metadata"]["team_name"] + "/" + data["metadata"]["model_name"]
535
+ if to_csv:
536
+ local_results["model"] = model_title
537
+ local_results["link_to_model"] = model_link
538
+ else:
539
+ model_title_abbr_team_name = self.abbreviate(data["metadata"]["team_name"], self.MAX_LENGTH_OF_MODEL_TITLE)
540
+ model_title_abbr_model_name = self.abbreviate(data["metadata"]["model_name"], self.MAX_LENGTH_OF_MODEL_TITLE)
541
+ model_title_abbr_html = f'<div style="font-size: 10px;">{xmlAndMarkdownEscape(model_title_abbr_team_name)}</div>{xmlAndMarkdownEscape(model_title_abbr_model_name)}'
542
+ local_results["model"] = f'<a href={xmlQuoteAttr(model_link)} title={xmlQuoteAttr(model_title)}>{model_title_abbr_html}</a>'
543
+
544
  release = data["metadata"].get("submission_timestamp")
545
  release = time.strftime("%Y-%m-%d", time.gmtime(release)) if release else "N/A"
546
  local_results["release"] = release
 
564
  "input_length": "Input length (# tokens)",
565
  "precision": "Precision",
566
  "description": "Description",
567
+ "link_to_model": "Link to model",
568
  }
569
  first_attributes = [
570
  "model",
571
+ "link_to_model",
572
  "release",
573
  "model_type",
574
  "parameters",