From 939c101eeb1ab588e97f30e0c3d926cf88fa16e9 Mon Sep 17 00:00:00 2001
From: BoYanZh <boyanzh233@gmail.com>
Date: Fri, 1 Nov 2024 02:37:40 -0400
Subject: [PATCH] feat: max total score in scoreboard

---
 joint_teapot/app.py        |  1 +
 joint_teapot/utils/joj3.py | 13 +++++++++----
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/joint_teapot/app.py b/joint_teapot/app.py
index 7e0648c..9a0dd2a 100644
--- a/joint_teapot/app.py
+++ b/joint_teapot/app.py
@@ -572,6 +572,7 @@ def joj3_all(
                     submitter,
                     os.path.join(repo_path, scoreboard_file_name),
                     exercise_name,
+                    max_total_score,
                 )
                 tea.pot.git.add_commit(
                     repo_name,
diff --git a/joint_teapot/utils/joj3.py b/joint_teapot/utils/joj3.py
index d2d108f..78ac009 100644
--- a/joint_teapot/utils/joj3.py
+++ b/joint_teapot/utils/joj3.py
@@ -9,7 +9,11 @@ from joint_teapot.utils.logger import logger
 
 
 def generate_scoreboard(
-    score_file_path: str, submitter: str, scoreboard_file_path: str, exercise_name: str
+    score_file_path: str,
+    submitter: str,
+    scoreboard_file_path: str,
+    exercise_name: str,
+    max_total_score: int = -1,
 ) -> None:
     if not scoreboard_file_path.endswith(".csv"):
         logger.error(
@@ -69,6 +73,8 @@ def generate_scoreboard(
     for stage in stages:
         for result in stage["results"]:
             exercise_total_score += result["score"]
+    if max_total_score >= 0:
+        exercise_total_score = min(exercise_total_score, max_total_score)
     submitter_row[columns.index(exercise_name)] = str(exercise_total_score)
 
     total = 0
@@ -82,9 +88,8 @@ def generate_scoreboard(
     submitter_row[columns.index("total")] = str(total)
 
     now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
-    submitter_row[
-        columns.index("last_edit")
-    ] = now  # FIXME: Delete this in formal version
+    # FIXME: Delete this in formal version
+    submitter_row[columns.index("last_edit")] = now
 
     # Sort data by total, from low to high
     data.sort(key=lambda x: int(x[columns.index("total")]))