Skip to content

Commit

Permalink
feat: max total score
Browse files Browse the repository at this point in the history
  • Loading branch information
BoYanZh committed Nov 1, 2024
1 parent cf9ba49 commit 2bc0a0a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
9 changes: 8 additions & 1 deletion joint_teapot/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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(
Expand Down
26 changes: 14 additions & 12 deletions joint_teapot/utils/joj3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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


Expand All @@ -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

0 comments on commit 2bc0a0a

Please sign in to comment.