Compare commits
No commits in common. "master" and "master" have entirely different histories.
|
@ -34,9 +34,9 @@ class Tea:
|
||||||
tea = Tea() # lazy loader
|
tea = Tea() # lazy loader
|
||||||
|
|
||||||
|
|
||||||
@app.command("export-users", help="export users from canvas to csv file")
|
@app.command("export-students", help="export students from canvas to csv file")
|
||||||
def export_users_to_csv(output_file: Path = Argument("students.csv")) -> None:
|
def export_students_to_csv(output_file: Path) -> None:
|
||||||
tea.pot.canvas.export_users_to_csv(output_file)
|
tea.pot.canvas.export_students_to_csv(output_file)
|
||||||
|
|
||||||
|
|
||||||
@app.command(
|
@app.command(
|
||||||
|
@ -307,10 +307,6 @@ def joj3_all_env(
|
||||||
"#795548",
|
"#795548",
|
||||||
help="label color for the issue created by this command",
|
help="label color for the issue created by this command",
|
||||||
),
|
),
|
||||||
issue_label_exclusive: bool = Option(
|
|
||||||
False,
|
|
||||||
help="label set as exclusive for the issue created by this command",
|
|
||||||
),
|
|
||||||
end_time: Optional[datetime] = Option(None),
|
end_time: Optional[datetime] = Option(None),
|
||||||
penalty_config: str = Option(
|
penalty_config: str = Option(
|
||||||
"",
|
"",
|
||||||
|
@ -364,7 +360,6 @@ def joj3_all_env(
|
||||||
submitter_repo_name,
|
submitter_repo_name,
|
||||||
issue_label_name,
|
issue_label_name,
|
||||||
issue_label_color,
|
issue_label_color,
|
||||||
issue_label_exclusive,
|
|
||||||
penalty_factor,
|
penalty_factor,
|
||||||
)
|
)
|
||||||
res["issue"] = issue_number
|
res["issue"] = issue_number
|
||||||
|
|
|
@ -240,7 +240,6 @@ class Teapot:
|
||||||
submitter_repo_name: str,
|
submitter_repo_name: str,
|
||||||
issue_label_name: str,
|
issue_label_name: str,
|
||||||
issue_label_color: str,
|
issue_label_color: str,
|
||||||
issue_label_exclusive: bool,
|
|
||||||
penalty_factor: float,
|
penalty_factor: float,
|
||||||
) -> int:
|
) -> int:
|
||||||
title, comment = joj3.generate_title_and_comment(
|
title, comment = joj3.generate_title_and_comment(
|
||||||
|
@ -281,11 +280,7 @@ class Teapot:
|
||||||
label = self.gitea.issue_api.issue_create_label(
|
label = self.gitea.issue_api.issue_create_label(
|
||||||
self.gitea.org_name,
|
self.gitea.org_name,
|
||||||
submitter_repo_name,
|
submitter_repo_name,
|
||||||
body={
|
body={"name": issue_label_name, "color": issue_label_color},
|
||||||
"name": issue_label_name,
|
|
||||||
"color": issue_label_color,
|
|
||||||
"exclusive": issue_label_exclusive,
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
label_id = label.id
|
label_id = label.id
|
||||||
joj3_issue = self.gitea.issue_api.issue_create_issue(
|
joj3_issue = self.gitea.issue_api.issue_create_issue(
|
||||||
|
@ -330,7 +325,7 @@ class Teapot:
|
||||||
f"[{end_time + timedelta(seconds=1)}, {penalty_end_time}].\n",
|
f"[{end_time + timedelta(seconds=1)}, {penalty_end_time}].\n",
|
||||||
True,
|
True,
|
||||||
)
|
)
|
||||||
elif now > end_time:
|
else:
|
||||||
return (
|
return (
|
||||||
"### Submission Time Check Passed\n"
|
"### Submission Time Check Passed\n"
|
||||||
f"Current time {now} is not in the valid range "
|
f"Current time {now} is not in the valid range "
|
||||||
|
|
|
@ -236,7 +236,9 @@ def generate_title_and_comment(
|
||||||
"[Joint-Teapot](https://github.com/BoYanZh/Joint-Teapot) with ❤️.\n"
|
"[Joint-Teapot](https://github.com/BoYanZh/Joint-Teapot) with ❤️.\n"
|
||||||
)
|
)
|
||||||
if penalty_factor != 1.0:
|
if penalty_factor != 1.0:
|
||||||
comment += f"## ⚠️Total Score Penalty Warning⚠️\n**The total score is multiplied by {penalty_factor}.**\n"
|
comment += (
|
||||||
|
f"## Total Score Penalty Warning\nThe total score is multiplied by 0.75.\n"
|
||||||
|
)
|
||||||
for stage in stages:
|
for stage in stages:
|
||||||
if all(
|
if all(
|
||||||
result["score"] == 0 and result["comment"].strip() == ""
|
result["score"] == 0 and result["comment"].strip() == ""
|
||||||
|
@ -258,7 +260,7 @@ def generate_title_and_comment(
|
||||||
total_score += result["score"]
|
total_score += result["score"]
|
||||||
comment += "\n"
|
comment += "\n"
|
||||||
if penalty_factor != 1.0:
|
if penalty_factor != 1.0:
|
||||||
total_score = round(total_score - abs(total_score) * (1 - penalty_factor))
|
total_score = round(total_score * penalty_factor)
|
||||||
title = get_title_prefix(exercise_name, submitter, submitter_in_title)
|
title = get_title_prefix(exercise_name, submitter, submitter_in_title)
|
||||||
if max_total_score >= 0:
|
if max_total_score >= 0:
|
||||||
title += f"{total_score} / {max_total_score}"
|
title += f"{total_score} / {max_total_score}"
|
||||||
|
@ -305,10 +307,8 @@ def get_penalty_factor(
|
||||||
) -> float:
|
) -> float:
|
||||||
if not end_time or not penalty_config:
|
if not end_time or not penalty_config:
|
||||||
return 1.0
|
return 1.0
|
||||||
now = datetime.now()
|
|
||||||
if now < end_time:
|
|
||||||
return 1.0
|
|
||||||
penalties = parse_penalty_config(penalty_config)
|
penalties = parse_penalty_config(penalty_config)
|
||||||
|
now = datetime.now()
|
||||||
res = 0.0
|
res = 0.0
|
||||||
for hour, factor in penalties[::-1]:
|
for hour, factor in penalties[::-1]:
|
||||||
if now < end_time + timedelta(hours=hour):
|
if now < end_time + timedelta(hours=hour):
|
||||||
|
|
|
@ -35,7 +35,7 @@ class Canvas:
|
||||||
# types = ["student", "observer"]
|
# types = ["student", "observer"]
|
||||||
types = ["student"]
|
types = ["student"]
|
||||||
|
|
||||||
def patch_user(student: User) -> User:
|
def patch_student(student: User) -> User:
|
||||||
student.name = (
|
student.name = (
|
||||||
re.sub(r"[^\x00-\x7F]+", "", student.name).strip().title()
|
re.sub(r"[^\x00-\x7F]+", "", student.name).strip().title()
|
||||||
) # We only care english name
|
) # We only care english name
|
||||||
|
@ -44,7 +44,7 @@ class Canvas:
|
||||||
return student
|
return student
|
||||||
|
|
||||||
self.students = [
|
self.students = [
|
||||||
patch_user(student)
|
patch_student(student)
|
||||||
for student in self.course.get_users(enrollment_type=types)
|
for student in self.course.get_users(enrollment_type=types)
|
||||||
]
|
]
|
||||||
for attr in ["login_id", "name"]:
|
for attr in ["login_id", "name"]:
|
||||||
|
@ -52,7 +52,6 @@ class Canvas:
|
||||||
raise Exception(
|
raise Exception(
|
||||||
f"Unable to gather students' {attr}, please contact the Canvas site admin"
|
f"Unable to gather students' {attr}, please contact the Canvas site admin"
|
||||||
)
|
)
|
||||||
self.users = [patch_user(student) for student in self.course.get_users()]
|
|
||||||
logger.debug("Canvas students loaded")
|
logger.debug("Canvas students loaded")
|
||||||
self.assignments = self.course.get_assignments()
|
self.assignments = self.course.get_assignments()
|
||||||
logger.debug("Canvas assignments loaded")
|
logger.debug("Canvas assignments loaded")
|
||||||
|
@ -61,12 +60,12 @@ class Canvas:
|
||||||
self.grade_filename = grade_filename
|
self.grade_filename = grade_filename
|
||||||
logger.debug("Canvas initialized")
|
logger.debug("Canvas initialized")
|
||||||
|
|
||||||
def export_users_to_csv(self, filename: Path) -> None:
|
def export_students_to_csv(self, filename: Path) -> None:
|
||||||
with open(filename, mode="w", newline="") as file:
|
with open(filename, mode="w", newline="") as file:
|
||||||
writer = csv.writer(file)
|
writer = csv.writer(file)
|
||||||
for user in self.users:
|
for student in self.students:
|
||||||
writer.writerow([user.name, user.sis_id, user.login_id])
|
writer.writerow([student.name, student.sis_id, student.login_id])
|
||||||
logger.info(f"Users exported to {filename}")
|
logger.info(f"Students exported to {filename}")
|
||||||
|
|
||||||
def prepare_assignment_dir(
|
def prepare_assignment_dir(
|
||||||
self, dir_or_zip_file: str, create_grade_file: bool = True
|
self, dir_or_zip_file: str, create_grade_file: bool = True
|
||||||
|
|
Loading…
Reference in New Issue
Block a user