idolezal commited on
Commit
8bfc448
1 Parent(s): 2706414

Data caching for faster creation of the leaderboard

Browse files
Files changed (1) hide show
  1. server.py +10 -15
server.py CHANGED
@@ -162,6 +162,7 @@ class LeaderboardServer:
162
  self.submission_ids = set()
163
  self.submission_id_to_file = {} # Map submission ids to file paths
164
  self.submission_id_to_model_title = {}
 
165
  self.fetch_existing_models()
166
  self.tournament_results = self.load_tournament_results()
167
 
@@ -216,6 +217,7 @@ class LeaderboardServer:
216
  self.submission_ids.add(submission_id)
217
  self.submission_id_to_file[submission_id] = submission_file
218
  self.submission_id_to_model_title[submission_id] = metadata["team_name"] + "/" + metadata["model_name"]
 
219
 
220
  @staticmethod
221
  def _model_tournament_table_highlight_true_and_false(x):
@@ -237,11 +239,7 @@ class LeaderboardServer:
237
 
238
  with self.var_lock.ro:
239
  for competitor_id in self.tournament_results[submission_id].keys() - {submission_id}: # without self
240
- path = self.submission_id_to_file.get(competitor_id)
241
- if path:
242
- data = json.load(open(path))
243
- else:
244
- raise gr.Error(f"Submission [{competitor_id}] not found")
245
 
246
  match_results = {}
247
  for task in self.tournament_results[submission_id][competitor_id]:
@@ -296,16 +294,13 @@ class LeaderboardServer:
296
  else:
297
  processed_results = []
298
  for submission_id in tournament_results.keys():
299
- path = self.submission_id_to_file.get(submission_id)
300
- if path is None:
301
  if pre_submit and submission_id == pre_submit.submission_id:
302
  data = json.load(open(pre_submit.file))
303
  else:
304
  raise gr.Error(f"Internal error: Submission [{submission_id}] not found")
305
- elif path:
306
- data = json.load(open(path))
307
  else:
308
- raise gr.Error(f"Submission [{submission_id}] not found")
309
 
310
  if submission_id != data["metadata"]["submission_id"]:
311
  raise gr.Error(f"Proper submission [{submission_id}] not found")
@@ -556,9 +551,9 @@ class LeaderboardServer:
556
  self.pre_submit = None
557
 
558
  def get_model_detail(self, submission_id):
559
- with self.var_lock.ro:
560
- path = self.submission_id_to_file.get(submission_id)
561
- if path is None:
562
  raise gr.Error(f"Submission [{submission_id}] not found")
563
- data = json.load(open(path))
564
- return data["metadata"]
 
 
 
162
  self.submission_ids = set()
163
  self.submission_id_to_file = {} # Map submission ids to file paths
164
  self.submission_id_to_model_title = {}
165
+ self.submission_id_to_data = {} # Only data (results and metadata) using by leaderboard
166
  self.fetch_existing_models()
167
  self.tournament_results = self.load_tournament_results()
168
 
 
217
  self.submission_ids.add(submission_id)
218
  self.submission_id_to_file[submission_id] = submission_file
219
  self.submission_id_to_model_title[submission_id] = metadata["team_name"] + "/" + metadata["model_name"]
220
+ self.submission_id_to_data[submission_id] = {"results": data["results"], "metadata": metadata}
221
 
222
  @staticmethod
223
  def _model_tournament_table_highlight_true_and_false(x):
 
239
 
240
  with self.var_lock.ro:
241
  for competitor_id in self.tournament_results[submission_id].keys() - {submission_id}: # without self
242
+ data = self.submission_id_to_data[competitor_id]
 
 
 
 
243
 
244
  match_results = {}
245
  for task in self.tournament_results[submission_id][competitor_id]:
 
294
  else:
295
  processed_results = []
296
  for submission_id in tournament_results.keys():
297
+ if submission_id not in self.submission_id_to_data:
 
298
  if pre_submit and submission_id == pre_submit.submission_id:
299
  data = json.load(open(pre_submit.file))
300
  else:
301
  raise gr.Error(f"Internal error: Submission [{submission_id}] not found")
 
 
302
  else:
303
+ data = self.submission_id_to_data[submission_id]
304
 
305
  if submission_id != data["metadata"]["submission_id"]:
306
  raise gr.Error(f"Proper submission [{submission_id}] not found")
 
551
  self.pre_submit = None
552
 
553
  def get_model_detail(self, submission_id):
554
+ if submission_id not in self.submission_id_to_data:
 
 
555
  raise gr.Error(f"Submission [{submission_id}] not found")
556
+ else:
557
+ with self.var_lock.ro:
558
+ data = self.submission_id_to_data[submission_id]
559
+ return data["metadata"]