Skip to content

Commit

Permalink
feat: less arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
BoYanZh committed Sep 14, 2024
1 parent 868431b commit 83ecc79
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
32 changes: 14 additions & 18 deletions joint_teapot/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,21 +209,18 @@ def unsubscribe_from_repos(pattern: str = Argument("")) -> None:
"joj3-scoreboard",
help="parse JOJ3 score json file into scoreboard and upload to gitea",
)
def JOJ3_scoreboard(
def joj3_scoreboard(
env_path: str = Argument("", help="path to .env file"),
scorefile_path: str = Argument(
"", help="path to score json file generated by JOJ3"
),
submitter: str = Argument(
"", help="name of submitter, either student name + id, or group name"
),
submitter: str = Argument("", help="submitter ID"),
repo_name: str = Argument(
"",
help="name of local gitea repo folder, or link to remote gitea repo, to push scoreboard file",
help="name of grading repo to push scoreboard file",
),
exercise_name: str = Argument("", help="exercise name of this json score file"),
scoreboard_file_name: str = Argument(
"", help="name of scoreboard file in the gitea repo"
"scoreboard.csv", help="name of scoreboard file in the gitea repo"
),
) -> None:
set_settings(Settings(_env_file=env_path))
Expand All @@ -241,7 +238,6 @@ def JOJ3_scoreboard(
joj3.generate_scoreboard(
scorefile_path,
submitter,
exercise_name,
os.path.join(repo_path, scoreboard_file_name),
)
now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
Expand All @@ -254,25 +250,21 @@ def JOJ3_scoreboard(
"joj3-failed-table",
help="parse JOJ3 score json file into failed table markdown file and upload to gitea",
)
def JOJ3_failed_table(
def joj3_failed_table(
env_path: str = Argument("", help="path to .env file"),
scorefile_path: str = Argument(
"", help="path to score json file generated by JOJ3"
),
repo_name: str = Argument(
"",
help="name of local gitea repo folder, or link to remote gitea repo, to push scoreboard file",
help="name of grading repo to push scoreboard file",
),
submitter_repo_name: str = Argument(
"",
help="repository's name of the submitter",
),
submitter_repo_link: str = Argument(
"",
help="repository's url link of the submitter",
),
failedtable_file_name: str = Argument(
"", help="name of failed table file in the gitea repo"
failed_table_file_name: str = Argument(
"failed-table.md", help="name of failed table file in the gitea repo"
),
) -> None:
set_settings(Settings(_env_file=env_path))
Expand All @@ -287,15 +279,19 @@ def JOJ3_failed_table(
logger.error('"grading" branch not found in local, create it first.')
return
repo.git.reset("--hard", "origin/grading")
submitter_repo_link = (
f"https://{settings.gitea_domain_name}{settings.gitea_suffix}/"
+ f"{settings.gitea_org_name}/{submitter_repo_name}"
)
joj3.generate_failed_table(
scorefile_path,
submitter_repo_name,
submitter_repo_link,
os.path.join(repo_path, failedtable_file_name),
os.path.join(repo_path, failed_table_file_name),
)
now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
tea.pot.git.add_commit_and_push(
repo_name, [failedtable_file_name], f"test: JOJ3-dev testing at {now}"
repo_name, [failed_table_file_name], f"test: JOJ3-dev testing at {now}"
)


Expand Down
15 changes: 10 additions & 5 deletions joint_teapot/utils/joj3.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


def generate_scoreboard(
score_file_path: str, submitter: str, exercise_name: str, scoreboard_file_path: str
score_file_path: str, submitter: str, scoreboard_file_path: str
) -> None:
if not scoreboard_file_path.endswith(".csv"):
logger.error(
Expand Down Expand Up @@ -46,6 +46,15 @@ def generate_scoreboard(
) # FIXME: In formal version should be -2
data.append(submitter_row)

# Update data
with open(score_file_path) as json_file:
stages: List[Dict[str, Any]] = json.load(json_file)

exercise_name = "unknown"
for stage in stages:
if stage["name"] == "metadata":
comment = stage["results"][0]["comment"]
exercise_name = comment.split("-")[0]
# Find if exercise in table:
if exercise_name not in columns:
column_tail = columns[3:]
Expand All @@ -55,10 +64,6 @@ def generate_scoreboard(
for row in data:
row.insert(index, "")

# Update data
with open(score_file_path) as json_file:
stages: List[Dict[str, Any]] = json.load(json_file)

exercise_total_score = 0
for stage in stages:
for result in stage["results"]:
Expand Down

0 comments on commit 83ecc79

Please sign in to comment.