Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
scott-yj-yang committed May 19, 2023
1 parent d9a7257 commit 1dc48e9
Show file tree
Hide file tree
Showing 12 changed files with 241 additions and 258 deletions.
8 changes: 5 additions & 3 deletions CanvasGroupy/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ def post_grade(self,
return edited

def get_email_by_name(self,
name_fussy: str # search by first name or last name of student
) -> str: # email of search student
name_fussy: str # search by first name or last name of a student
) -> str: # email of a search student
name_fussy = name_fussy.lower()
for email, name in self.email_to_name.items():
if name_fussy in name.lower():
Expand All @@ -156,6 +156,8 @@ def set_group_category(self,
except KeyError:
raise KeyError(f"{category_name} did not found in the group categories. "
f"Try to create one with CanvasGroup.create_group_category")
if self.verbosity != 0:
print(f"Setting Group Category... ")
self.groups = list(self.group_category.get_groups())
self.group_to_emails = {
group.name: [
Expand All @@ -179,7 +181,7 @@ def get_course(self):
return self.course

def get_group_categories(self) -> dict: # return a name / group category object
"Grab all existing group category (group set) in this course"
"Grab all existing group categories (group set) in this course"
categories = list(self.course.get_group_categories())
self.group_categories = {cat.name: cat for cat in categories}
return {cat.name: cat for cat in categories}
Expand Down
36 changes: 26 additions & 10 deletions CanvasGroupy/grading.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class bcolors:
# %% ../nbs/api/04_project_grading.ipynb 5
class Grading:
def __init__(self,
ghg=None, # authenticated GitHub object
cg=None, # authenticated canvas object
ghg:GitHubGroup=None, # authenticated GitHub object
cg:CanvasGroup=None, # authenticated canvas object
):
self.ghg = ghg
self.cg = cg
Expand All @@ -44,13 +44,13 @@ def fetch_issue(self,
) -> github.Issue.Issue:
"Fetch the issue on GitHub repo and choose related one"
for issue in list(repo.get_issues()):
if component in issue.title:
if component.lower() in issue.title.lower():
return issue
raise ValueError(f"Issue related to {component} did not found.")

def parse_score_from_issue(self,
repo:github.Repository.Repository, # target repository to create issue
component:str, # the component of the project grading, let it be proposal/checkpoint/final. Need to match the issue's title
component:str, # The component of the project grading, let it be proposal/checkpoint/final. Need to match the issue's title
) -> int: # the fetched score of that component
"parse score from the template issue"
issue = self.fetch_issue(repo, component)
Expand All @@ -64,39 +64,55 @@ def parse_score_from_issue(self,
f"Issue URL: {issue.url}")

def update_canvas_score(self,
group_name:str, # target group name on canvas group
group_name:str, # target group name on a canvas group
assignment_id, # assignment id of the related component
score:float, # score of that component
issue:github.Issue.Issue=None,
post=False, # whether to post score via api. for testing purposes
):
"Post score to canvas"
if self.cg.group_category is None:
raise ValueError("CanvasGroup's group_category not set.")
members = self.cg.group_to_emails[group_name]
self.cg.link_assignment(assignment_id)
for member in members:
student_id = self.cg.email_to_canvas_id[member]
text_comment = f"Group: {group_name}"
if issue is not None:
text_comment += f"\nView at {issue.url.replace('https://api.github.com/repos', 'https://github.com')}"
if post:
self.cg.post_grade(
student_id=student_id,
grade=score,
text_comment=f"Group: {group_name}"
text_comment=text_comment
)
else:
print(f"{bcolors.WARNING}Post Disable{bcolors.ENDC}")
print(f"For student: {member}, the score is {score}")
print(f"Comments: {text_comment}")

def grade_project(self,
repo:github.Repository.Repository, # target repository to grade
component:str, # the component of the project grading, let it be proposal/checkpoint/final. Need to match the issue's title
component:str, # The component of the project grading, let it be proposal/checkpoint/final. Need to match the issue's title
assignment_id:int, # assignment id that link to that component of the project
canvas_group_name=None, # mapping from GitHub repo name to Group name. If not specified, the repository name will be used.
post=False, # whether to post score via api. For testing purposes
canvas_group_name:dict=None, # mapping from GitHub repo name to Group name. If not specified, the repository name will be used.
canvas_group_category:str=None, # canvas group category (set)
post:bool=False, # whether to post score via api. For testing purposes
):
"grade github project components"
# set the category if you haven't
if canvas_group_category is not None:
self.cg.set_group_category(canvas_group_category)
score = self.parse_score_from_issue(repo, component)
# create mapping from GitHub repo name to canvas group name
if canvas_group_name is not None:
group_name = canvas_group_name[repo.name]
else:
group_name = repo.name
self.update_canvas_score(group_name, assignment_id, score, post)
if score is ...:
print(f"{bcolors.WARNING}{group_name}'s {component} Not Graded. {bcolors.ENDC}")
return
issue = self.fetch_issue(repo, component)
self.update_canvas_score(group_name, assignment_id, score, issue, post)


36 changes: 0 additions & 36 deletions dev_nbs/feedback/test-repo-from-template/checkpoint_feedback.md

This file was deleted.

Loading

0 comments on commit 1dc48e9

Please sign in to comment.