feat: max total score

This commit is contained in:
张泊明518370910136 2024-11-01 02:34:31 -04:00
parent cf9ba49d18
commit 2bc0a0a18d
GPG Key ID: CA088E6D9284F870
2 changed files with 22 additions and 13 deletions

View File

@ -468,6 +468,10 @@ def joj3_all(
"unknown",
help="JOJ3 run ID",
),
max_total_score: int = Argument(
-1,
help="max total score",
),
skip_result_issue: bool = Option(
False,
help="skip creating result issue on gitea",
@ -508,8 +512,11 @@ def joj3_all(
commit_hash,
submitter_in_issue_title,
run_id,
max_total_score,
)
title_prefix = joj3.get_title_prefix(
exercise_name, submitter, submitter_in_issue_title
)
title_prefix = joj3.get_title_prefix(title)
joj3_issue: focs_gitea.Issue
issue: focs_gitea.Issue
for issue in tea.pot.gitea.issue_api.issue_list_issues(

View File

@ -188,6 +188,7 @@ def generate_title_and_comment(
commit_hash: str,
submitter_in_title: bool = True,
run_id: str = "unknown",
max_total_score: int = -1,
) -> Tuple[str, str]:
with open(score_file_path) as json_file:
stages: List[Dict[str, Any]] = json.load(json_file)
@ -227,9 +228,12 @@ def generate_title_and_comment(
comment += "</details>\n\n"
total_score += result["score"]
comment += "\n"
title = f"JOJ3 Result for {exercise_name} by @{submitter} - Score: {total_score}"
if not submitter_in_title:
title = f"JOJ3 Result for {exercise_name} - Score: {total_score}"
title = get_title_prefix(exercise_name, submitter, submitter_in_title)
if max_total_score >= 0:
total_score = min(total_score, max_total_score)
title += f"{total_score} / {max_total_score}"
else:
title += f"{total_score}"
return title, comment
@ -245,12 +249,10 @@ def check_skipped(score_file_path: str, keyword: str) -> bool:
return False
def get_title_prefix(title: str) -> str:
meet_negative = False
for i in range(len(title) - 1, -1, -1):
if not title[i].isdigit() and not title[i].isspace():
if not meet_negative and title[i] == "-":
meet_negative = True
continue
return title[: i + 1]
return ""
def get_title_prefix(
exercise_name: str, submitter: str, submitter_in_title: bool
) -> str:
title = f"JOJ3 Result for {exercise_name} by @{submitter} - "
if not submitter_in_title:
title = f"JOJ3 Result for {exercise_name} - "
return title