idolezal commited on
Commit
f0196fa
1 Parent(s): fb91218

Compute win_score and average_score

Browse files
Files changed (1) hide show
  1. server.py +37 -19
server.py CHANGED
@@ -90,7 +90,7 @@ class LeaderboardServer:
90
 
91
  self.submission_id_to_file[submission_id] = submission_file
92
 
93
- def get_leaderboard(self, tournament_results=None):
94
  tournament_results = tournament_results if tournament_results else self.tournament_results
95
 
96
  if len(tournament_results) == 0:
@@ -113,25 +113,44 @@ class LeaderboardServer:
113
  raise gr.Error(f"Proper submission [{submission_id}] not found")
114
 
115
  local_results = {}
 
116
  visible_metrics_map_word_to_header = {}
117
  for task in self.tasks_metadata.keys():
118
 
119
- # tournament_results
120
- num_of_competitors = 0
121
- num_of_wins = 0
122
- for competitor_id in tournament_results[submission_id].keys() - {submission_id}: # without self
123
- num_of_competitors += 1
124
- if tournament_results[submission_id][competitor_id][task]:
125
- num_of_wins += 1
126
- local_results[task] = num_of_wins / num_of_competitors # TODO: if num_of_competitors > 0 else ???
127
-
128
- for metric in VISIBLE_METRICS:
129
- visible_metrics_map_word_to_header[task + "_" + metric] = self.tasks_metadata[task]["abbreviation"] + " " + metric
130
- metric_value = data['results'][task].get(metric)
131
- if metric_value is not None:
132
- local_results[task + "_" + metric] = metric_value
133
- break # Only the first metric of every task
134
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
  model_link = data["metadata"]["link_to_model"]
136
  model_title = data["metadata"]["team_name"] + "/" + data["metadata"]["model_name"]
137
  model_title_abbr = self.abbreviate(data["metadata"]["team_name"], 14) + "/" + self.abbreviate(data["metadata"]["model_name"], 14)
@@ -141,8 +160,7 @@ class LeaderboardServer:
141
  local_results["release"] = release
142
  local_results["model_type"] = data["metadata"]["model_type"]
143
  local_results["parameters"] = data["metadata"]["parameters"]
144
- local_results["average_score"] = "TBD" # TODO: Implementovat výpočet Average Score
145
-
146
  if self.pre_submit and submission_id == self.pre_submit.submission_id:
147
  processed_results.insert(0, local_results)
148
  else:
 
90
 
91
  self.submission_id_to_file[submission_id] = submission_file
92
 
93
+ def get_leaderboard(self, tournament_results=None, category="overall"):
94
  tournament_results = tournament_results if tournament_results else self.tournament_results
95
 
96
  if len(tournament_results) == 0:
 
113
  raise gr.Error(f"Proper submission [{submission_id}] not found")
114
 
115
  local_results = {}
116
+ win_score = {}
117
  visible_metrics_map_word_to_header = {}
118
  for task in self.tasks_metadata.keys():
119
 
120
+ task_category = self.tasks_metadata[task]["category"]
121
+ if category not in ("overall", task_category):
122
+ continue
123
+ else:
124
+ # tournament_results
125
+ num_of_competitors = 0
126
+ num_of_wins = 0
127
+ for competitor_id in tournament_results[submission_id].keys() - {submission_id}: # without self
128
+ num_of_competitors += 1
129
+ if tournament_results[submission_id][competitor_id][task]:
130
+ num_of_wins += 1
131
+ win_score = num_of_wins / num_of_competitors # TODO: if num_of_competitors > 0 else ???
132
+ win_score.setdefault(task_category, []).append(win_score)
133
+
134
+ if category == task_category:
135
+ local_results[task] = win_score
136
+ for metric in VISIBLE_METRICS:
137
+ visible_metrics_map_word_to_header[task + "_" + metric] = self.tasks_metadata[task]["abbreviation"] + " " + metric
138
+ metric_value = data['results'][task].get(metric)
139
+ if metric_value is not None:
140
+ local_results[task + "_" + metric] = metric_value
141
+ break # Only the first metric of every task
142
+
143
+
144
+ for c in win_score:
145
+ win_score[c] = sum(win_score[c]) / len(win_score[c])
146
+
147
+ if category == "overall":
148
+ for c in win_score:
149
+ local_results[c] = win_score[c]
150
+ local_results["average_score"] = sum(win_score[c]) / len(win_score[c])
151
+ else:
152
+ local_results["average_score"] = win_score[category]
153
+
154
  model_link = data["metadata"]["link_to_model"]
155
  model_title = data["metadata"]["team_name"] + "/" + data["metadata"]["model_name"]
156
  model_title_abbr = self.abbreviate(data["metadata"]["team_name"], 14) + "/" + self.abbreviate(data["metadata"]["model_name"], 14)
 
160
  local_results["release"] = release
161
  local_results["model_type"] = data["metadata"]["model_type"]
162
  local_results["parameters"] = data["metadata"]["parameters"]
163
+
 
164
  if self.pre_submit and submission_id == self.pre_submit.submission_id:
165
  processed_results.insert(0, local_results)
166
  else: