feat: max total score in scoreboard

This commit is contained in:
张泊明518370910136 2024-11-01 02:37:40 -04:00
parent 2bc0a0a18d
commit 939c101eeb
GPG Key ID: CA088E6D9284F870
2 changed files with 10 additions and 4 deletions

View File

@ -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,

View File

@ -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")]))