diff --git a/update_grading.py b/update_grading.py index 5938891..4379075 100644 --- a/update_grading.py +++ b/update_grading.py @@ -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 @@ -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 @@ -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 @@ -65,11 +63,11 @@ 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 = [ @@ -77,7 +75,7 @@ def validate_criteria(criteria): "table", "grading" ] - table_items = ["Criteria", "Yes", "No"] + table_items = ["Criterion", "Description", "Requirement"] errors = '' @@ -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 ! ") @@ -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(): diff --git a/update_task.py b/update_task.py index c9cbbec..5fb0bfd 100644 --- a/update_task.py +++ b/update_task.py @@ -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 @@ -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'): diff --git a/utils/course.py b/utils/course.py index c41d1c2..296ef7e 100644 --- a/utils/course.py +++ b/utils/course.py @@ -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