Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 12 additions & 20 deletions update_grading.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,15 @@
import os, sys, logging
import argparse
from utils.course import Course
from github import Github

# ENVs for updating criteria
CANVAS_TOKEN = os.getenv("CANVAS_TOKEN")
CANVAS_COURSE_ID = os.getenv("CANVAS_COURSE_ID")
GH_TOKEN = os.getenv("GH_TOKEN")
GH_REPO_FULLNAME = os.getenv("GH_REPO_FULLNAME")

CANVAS_URL = "https://canvas.kth.se"
github_repo = Github(GH_TOKEN).get_repo(GH_REPO_FULLNAME)
course = Course(CANVAS_URL, CANVAS_TOKEN, CANVAS_COURSE_ID)

# Arguments
ISSUE_ASSIGNEES = ['']
GITHUB_GRADING_PATH = ''
MODE = ''
PR_NUMBER = 0
Expand All @@ -35,10 +30,11 @@ def parse_criteria():

for section in sections[1:]:
items = section.split("\n\n\n")
result[items[0].strip()] = {}
result[items[0].strip()]['description'] = items[1]
result[items[0].strip()]['table'] = parse_table(items[2])
result[items[0].strip()]['grading'] = items[3]
name = items[0].strip()
result[name] = {}
result[name]['description'] = items[1]
result[name]['table'] = parse_table(items[2])
result[name]['grading'] = items[3]
validate_criteria(result)
return result

Expand All @@ -57,6 +53,8 @@ def parse_table(table):
for col, value in zip(header, values):
if col == '':
col = 'Criteria'
if col == 'Category':
continue
data[col] = value
result.append(data)
return result
Expand All @@ -65,19 +63,19 @@ def parse_table(table):
# Validation of the parsed criteria: Tasks, task items, tables items
def validate_criteria(criteria):
task = [
"Presentations",
"Scientific Papers",
"Project",
"Demos",
"Open-source contributions",
"Executable Tutorials",
"Scientific Papers",
"Executable Tutorial",
"Open-Source Contribution",
"Feedback"
]
task_items = [
"description",
"table",
"grading"
]
table_items = ["Criteria", "Yes", "No"]
table_items = ["Criterion", "Description", "Requirement"]

errors = ''

Expand All @@ -97,8 +95,6 @@ def validate_criteria(criteria):

if errors:
print(errors)
github_repo.create_issue("[CANVAS ACTION] Grading file is not correctly formatted", body=errors,
assignees=ISSUE_ASSIGNEES)
raise Exception("The grading file is not correctly formatted ! ")


Expand Down Expand Up @@ -158,22 +154,18 @@ def parse_args():
global GITHUB_GRADING_PATH
global MODE
global PR_NUMBER
global ISSUE_ASSIGNEES

parser = argparse.ArgumentParser()
parser.add_argument('--mode', dest='mode', type=str, help='Is only check')
parser.add_argument('--pr', dest='pr', type=int, help='Pull request number', default=0)
parser.add_argument('--grading', dest='grading_path', type=str, help='Path to the grading criteria',
default='./grading-criteria.md')
parser.add_argument('--issue', dest='issue_assignee', type=str, nargs='+', help='List of issue assignee',
default=[''])

args = parser.parse_args()

GITHUB_GRADING_PATH = args.grading_path
MODE = args.mode
PR_NUMBER = args.pr
ISSUE_ASSIGNEES = args.issue_assignee


def main():
Expand Down
22 changes: 12 additions & 10 deletions update_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,17 @@ def get_sections(path):

# Mapping from github task name to canvas group set id
def task_to_group_category_id(task_name, canvas_groups_set):
mapping = {
"presentation": canvas_groups_set["Presentations"],
"scientific-paper": canvas_groups_set["Scientific Papers"],
"demo": canvas_groups_set["Demos"],
"open-source": canvas_groups_set["Open-source contributions"],
"executable-tutorial": canvas_groups_set["Executable Tutorials"],
"feedback": canvas_groups_set["Feedback"]
}
return mapping.get(task_name, Exception("Groupset mapping"))
canvas_group_name = {
"project": "Project",
"scientific-paper": "Scientific Papers",
"demo": "Demos",
"open-source": "Open-Source Contribution",
"executable-tutorial": "Executable Tutorial",
"feedback": "Feedback"
}.get(task_name)
if canvas_group_name is None:
raise Exception("Groupset mapping: unknown task '{0}'".format(task_name))
return canvas_groups_set[canvas_group_name]


# Parse arguments of the script
Expand Down Expand Up @@ -169,7 +171,7 @@ def main():
print("CANVAS_GROUPS_SET", canvas_groups_set)
canvas_groups_category_id = task_to_group_category_id(task_name, canvas_groups_set)

if task_name == 'presentation' or task_name == 'demo' or task_name == 'scientific-paper':
if task_name == 'demo' or task_name == 'scientific-paper':
weeks = get_sub_directory(github_tasks[task_name]["path"])
for week in weeks:
if not week.startswith('week'):
Expand Down
24 changes: 10 additions & 14 deletions utils/course.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,20 @@ def rubric_payload(id, name, description, criterias, assignment_id):
}

for i, criteria in enumerate(criterias):
if criteria['Requirement'] == 'Mandatory':
ratings = {'Mandatory': 1, '-': 0}
else:
ratings = {'Yes': 1, 'No': 0}

payload["rubric"]["criteria"][str(i + 1)] = {
"points": 1,
"description": criteria['Criteria'],
"ratings": {}
"description": "{0}: {1}".format(criteria['Criterion'], criteria['Description']),
"ratings": {
str(j): {"description": label, "points": points}
for j, (label, points) in enumerate(ratings.items())
}
}

for j, option in enumerate(criteria):

points = 0
if criteria[option] == 'Yes': points = 1
if criteria[option] == 'Mandatory': points = 1

if option != 'Criteria':
payload["rubric"]["criteria"][str(i + 1)]["ratings"][str(j)] = {
"description": criteria[option],
"points": points,
}

return payload


Expand Down