NathanRoll commited on
Commit
aa81dcb
·
verified ·
1 Parent(s): d16b09e

Refresh leaderboard on accepted submissions

Browse files
Files changed (2) hide show
  1. app.py +28 -4
  2. packing_benchmark/store.py +34 -0
app.py CHANGED
@@ -2920,7 +2920,14 @@ def submit_solution(
2920
  preflight = verify_solution(solution, tolerance=DEFAULT_TOLERANCE).as_dict()
2921
  gate_ok, gate_message = submission_gate(preflight)
2922
  if not gate_ok:
2923
- return result_markdown(preflight, (gate_ok, gate_message)), preview_html(solution), json.dumps(solution, indent=2, sort_keys=True), gr.update(), gr.update()
 
 
 
 
 
 
 
2924
  record, result = STORE.append_verified_submission(
2925
  solution,
2926
  submitter=submitter,
@@ -2931,17 +2938,34 @@ def submit_solution(
2931
  stored = STORE.solution_for_record(record)
2932
  pretty = json.dumps(stored, indent=2, sort_keys=True)
2933
  sync_status = record.get("sync_status", "dataset sync disabled")
2934
- message = result_markdown(result, (gate_ok, gate_message)) + f"\n\nSaved as record `{record['id']}`.\n\nDataset sync: `{sync_status}`."
2935
  clear_page_caches()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2936
  return (
2937
  message,
2938
  preview_html(stored),
2939
  pretty,
2940
  leaderboard_html(),
2941
  gr.update(choices=existing_author_choices(), value=submitter),
 
2942
  )
2943
  except Exception as exc:
2944
- return f"### Submission Rejected\n\n- {exc}", empty_preview_html(), json_text, gr.update(), gr.update()
2945
 
2946
 
2947
  THEME = gr.themes.Base()
@@ -3035,7 +3059,7 @@ with gr.Blocks(
3035
  submit_btn.click(
3036
  submit_solution,
3037
  inputs=[json_code, submitter, notes, source_url],
3038
- outputs=[report, preview, normalized_json, leaderboard_page, submitter],
3039
  )
3040
 
3041
 
 
2920
  preflight = verify_solution(solution, tolerance=DEFAULT_TOLERANCE).as_dict()
2921
  gate_ok, gate_message = submission_gate(preflight)
2922
  if not gate_ok:
2923
+ return (
2924
+ result_markdown(preflight, (gate_ok, gate_message)),
2925
+ preview_html(solution),
2926
+ json.dumps(solution, indent=2, sort_keys=True),
2927
+ gr.update(),
2928
+ gr.update(),
2929
+ gr.update(),
2930
+ )
2931
  record, result = STORE.append_verified_submission(
2932
  solution,
2933
  submitter=submitter,
 
2938
  stored = STORE.solution_for_record(record)
2939
  pretty = json.dumps(stored, indent=2, sort_keys=True)
2940
  sync_status = record.get("sync_status", "dataset sync disabled")
 
2941
  clear_page_caches()
2942
+ current = current_top_for_case(str(record.get("case") or result.get("case") or ""))
2943
+ leaderboard_updated = bool(current and str(current.get("id")) == str(record.get("id")))
2944
+ leaderboard_status = (
2945
+ f"\n\n### Leaderboard Updated\n\nRecord `{record['id']}` is now the current public top for `{record['case']}`."
2946
+ if leaderboard_updated
2947
+ else (
2948
+ "\n\n### Leaderboard Not Changed\n\n"
2949
+ "The entry was archived, but another row is still the current public top for this case."
2950
+ )
2951
+ )
2952
+ message = (
2953
+ result_markdown(result, (gate_ok, gate_message))
2954
+ + f"\n\nSaved as record `{record['id']}`."
2955
+ + leaderboard_status
2956
+ + f"\n\nDataset sync: `{sync_status}`."
2957
+ )
2958
+ refreshed_home = family_page_html(str(record.get("setup") or result.get("setup") or "")) if record.get("setup") or result.get("setup") else directory_html()
2959
  return (
2960
  message,
2961
  preview_html(stored),
2962
  pretty,
2963
  leaderboard_html(),
2964
  gr.update(choices=existing_author_choices(), value=submitter),
2965
+ refreshed_home,
2966
  )
2967
  except Exception as exc:
2968
+ return f"### Submission Rejected\n\n- {exc}", empty_preview_html(), json_text, gr.update(), gr.update(), gr.update()
2969
 
2970
 
2971
  THEME = gr.themes.Base()
 
3059
  submit_btn.click(
3060
  submit_solution,
3061
  inputs=[json_code, submitter, notes, source_url],
3062
+ outputs=[report, preview, normalized_json, leaderboard_page, submitter, browse_page],
3063
  )
3064
 
3065
 
packing_benchmark/store.py CHANGED
@@ -308,6 +308,37 @@ class SolutionStore:
308
  return None
309
  return min(candidates, key=metric_float)
310
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
311
  def append_verified_submission(
312
  self,
313
  solution: dict[str, Any],
@@ -383,13 +414,16 @@ class SolutionStore:
383
  "notes": notes.strip(),
384
  "solution_path": str(solution_path.relative_to(self.root.parent)),
385
  "svg_path": str(svg_path.relative_to(self.root.parent)),
 
386
  }
387
  records.append(record)
 
388
  self.write_records(records)
389
  try:
390
  record["sync_status"] = maybe_sync_dataset(self.root)
391
  except Exception:
392
  records = [existing for existing in self.load_records() if existing.get("id") != rid]
 
393
  self.write_records(records)
394
  solution_path.unlink(missing_ok=True)
395
  svg_path.unlink(missing_ok=True)
 
308
  return None
309
  return min(candidates, key=metric_float)
310
 
311
+ def refresh_leaderboard_flags(self, records: list[dict[str, Any]]) -> list[dict[str, Any]]:
312
+ references = [
313
+ self.normalized_public_record(record)
314
+ for record in self.load_reference_records()
315
+ ]
316
+ reference_best: dict[tuple[str, str], dict[str, Any]] = {}
317
+ for record in references:
318
+ key = (str(record.get("case")), str(record.get("metric_symbol") or "s"))
319
+ if key not in reference_best or metric_float(record) < metric_float(reference_best[key]):
320
+ reference_best[key] = record
321
+
322
+ verified_best: dict[tuple[str, str], dict[str, Any]] = {}
323
+ for record in records:
324
+ if not record.get("verified"):
325
+ record["leaderboard_current_best"] = False
326
+ continue
327
+ record["record_type"] = "verified"
328
+ key = (str(record.get("case")), str(record.get("metric_symbol") or "s"))
329
+ if key not in verified_best or metric_float(record) < metric_float(verified_best[key]):
330
+ verified_best[key] = record
331
+
332
+ current_verified_ids: set[str] = set()
333
+ for key, coordinate in verified_best.items():
334
+ reference = reference_best.get(key)
335
+ if reference is None or metric_strictly_better(coordinate, reference):
336
+ current_verified_ids.add(str(coordinate.get("id")))
337
+
338
+ for record in records:
339
+ record["leaderboard_current_best"] = str(record.get("id")) in current_verified_ids
340
+ return records
341
+
342
  def append_verified_submission(
343
  self,
344
  solution: dict[str, Any],
 
414
  "notes": notes.strip(),
415
  "solution_path": str(solution_path.relative_to(self.root.parent)),
416
  "svg_path": str(svg_path.relative_to(self.root.parent)),
417
+ "record_type": "verified",
418
  }
419
  records.append(record)
420
+ self.refresh_leaderboard_flags(records)
421
  self.write_records(records)
422
  try:
423
  record["sync_status"] = maybe_sync_dataset(self.root)
424
  except Exception:
425
  records = [existing for existing in self.load_records() if existing.get("id") != rid]
426
+ self.refresh_leaderboard_flags(records)
427
  self.write_records(records)
428
  solution_path.unlink(missing_ok=True)
429
  svg_path.unlink(missing_ok=True)