-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpac.py
executable file
·82 lines (69 loc) · 2.59 KB
/
pac.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python3
from canvashelper import CanvasHelper
from grader import PythonGrader
from grader import TestSuite
import os
import util
DEFAULT_TEST_FILE = "testsuite.json"
# util.colored constants
TITLE = util.colored("Python Autograder for Canvas", "pink")
SUCCESS = util.colored("SUCCESS", "green")
FAIL = util.colored("FAIL", "red")
GRADE_UPLOAD_REPORT = util.colored("Grade Upload Report", "purple")
REPORT_MESSAGE = util.colored(
"press [ENTER] for next grade result or [q] to quit ", "lightgreen")
def main():
# Initial information collection
print(TITLE)
ch = CanvasHelper()
course_selection = util.get_selection(ch.getCourses(), "Course")
ch.selectCourse(course_selection)
print(util.colored("Grading " + ch.selected_course.name, "lightgreen"))
assn_selection = util.get_selection(ch.getAssignments(), "Assignment")
ch.selectAssignment(assn_selection)
print()
print("Downloading submissions...")
submissions = ch.getSubmissions()
# Test Suite Creation
testsuite = TestSuite.CreateWith(json_file=DEFAULT_TEST_FILE)
# Grading
pg = PythonGrader(submissions, testsuite)
option = input("Grade All students [ENTER] or [s]election? ").lower()
if option == "s":
print("Downloading Student data...")
student_selection = ch.getStudentSubset()
pg.limitStudentsTo(student_selection)
results = pg.getResults()
yn = input("\nShow final report? [y/N] to skip ").lower()
if yn == "y":
# Final report for manual grade checking
total_report = len(results)
index = 1
print("\nFailed Grades ({}):\n".format(total_report))
for user in util.lastname_lex(results.keys()):
print(
util.colored("({}/{})".format(index, total_report), "red"),
util.colored(user.name, "white"),
util.colored(user.id, "purple"))
print(util.colored(results[user], "white"), "\n")
index += 1
q = input(REPORT_MESSAGE)
print()
if q == "q":
break
yn = input(
"\n{} results collected. Upload grades? [y/N]".format(
len(results))).lower()
if yn == "y":
# Grade uploading
print(GRADE_UPLOAD_REPORT)
for user, result in results.items():
grade = result.grade
print(user.name, grade, end=" ")
submission_successful = ch.postSubmissionResult(user, result)
if submission_successful:
print(SUCCESS)
else:
print(FAIL)
if __name__ == "__main__":
main()