Skip to content

Commit

Permalink
feat: create result issue
Browse files Browse the repository at this point in the history
  • Loading branch information
BoYanZh committed Sep 14, 2024
1 parent 83ecc79 commit e39136f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,7 @@ upload assignment grades to canvas from grade file (GRADE.txt by default), read
## License

MIT

## Compile

- case 0: 0
19 changes: 19 additions & 0 deletions joint_teapot/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,25 @@ def joj3_failed_table(
)


@app.command(
"joj3-create-result-issue",
help="create result issue on gitea",
)
def joj3_create_result_issue(
env_path: str = Argument("", help="path to .env file"),
scorefile_path: str = Argument(
"", help="path to score json file generated by JOJ3"
),
submitter_repo_name: str = Argument(
"",
help="repository's name of the submitter",
),
) -> None:
set_settings(Settings(_env_file=env_path))
title, comment = joj3.generate_title_and_comment(scorefile_path)
tea.pot.gitea.create_issue(submitter_repo_name, title, comment, False)


if __name__ == "__main__":
try:
app()
Expand Down
27 changes: 21 additions & 6 deletions joint_teapot/utils/joj3.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import bisect
import csv
import enum
import json
import os
from datetime import datetime
from typing import Any, Dict, List
from typing import Any, Dict, List, Tuple

from joint_teapot.utils.logger import logger

Expand Down Expand Up @@ -112,10 +113,10 @@ def update_failed_table_from_score_file(
) -> None:
# get info from score file
with open(score_file_path) as json_file:
scorefile: List[Dict[str, Any]] = json.load(json_file)
stages: List[Dict[str, Any]] = json.load(json_file)

failed_name = ""
for stage in scorefile:
for stage in stages:
if stage["force_quit"] == True:
failed_name = stage["name"]
break
Expand Down Expand Up @@ -163,6 +164,20 @@ def generate_failed_table(
write_failed_table_into_file(data, table_file_path)


def generate_comment(score_file_path: str) -> str:
# TODO
return ""
def generate_title_and_comment(score_file_path: str) -> Tuple[str, str]:
with open(score_file_path) as json_file:
stages: List[Dict[str, Any]] = json.load(json_file)

total_score = 0
comment = ""
for stage in stages:
comment += f"## {stage['name']}\n"
for i, result in enumerate(stage["results"]):
comment += f"### case {i}\n"
comment += f"score: {result['score']}\n"
comment += f"comment: {result['comment']}\n"
total_score += result["score"]
comment += "\n"
now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
title = f"JOJ3 Result {now} - Total Score: {total_score}"
return title, comment

0 comments on commit e39136f

Please sign in to comment.