-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpAddRubric.py
More file actions
executable file
·123 lines (106 loc) · 4.49 KB
/
cpAddRubric.py
File metadata and controls
executable file
·123 lines (106 loc) · 4.49 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/env python3
# ----------------------------------------------------------------------
# cpAddRubric.py
# Dave Reed
# 06/16/2020
# ----------------------------------------------------------------------
from argparse import ArgumentParser
from CPAPI import *
from FileUtils import *
# ----------------------------------------------------------------------
def makeRubric(assignment: CPAssignment, rubricFilename: str):
"""
add rubric to the assignment using the filename
:param assignment: CPAssignment to add rubric to
:param rubricFilename: filename containing rubric
:return: None
rubric file should contain something like this
75 Correctness
2 minor correctness issue
5 minor correctness issue
10 significant correctness issue
15 significant correctness issue
20 significant correctness issue
25 multiple significant issues with code
30 multiple significant issues with code
35 multiple significant issues with code
40 multiple significant issues with code
45 multiple significant issues with code
50 multiple significant issues with code
60 multiple significant issues with code
75 no code or numerous issues with code
15 Organization/Style
0 other style issue
2 other style issue
2 use descriptive variable names
5 use descriptive variable names
2 follow naming conventions (camelCase for variables/functions, CamelCase for classes)
2 spacing between sections of code and functions
2 extra unnecessary code
5 code not organized into functions/methods
10 Comments
1 needs comments
3 needs comments
5 needs comments
10 code has no comments
"""
with open(rubricFilename) as infile:
state = "category"
categoryPosition = 0
for line in infile:
line = line.strip()
if state == "category":
if line != "":
spacePos = line.find(" ")
pointLimit = int(line[:spacePos])
name = line[spacePos+1:]
rubricCategory = assignment.categoryNamed(name)
if rubricCategory is None:
print(f"add category: {name}")
rubricCategory = assignment.addRubricCategory(name, pointLimit, categoryPosition)
categoryPosition += 1
commentPosition = 0
state = "comment"
elif state == "comment":
if line == "":
state = "category"
else:
spacePos = line.find(" ")
pointDelta = float(line[:spacePos])
text = line[spacePos+1:]
if not rubricCategory.hasRubricComment(text, pointDelta):
print(f"add comment: {text} : {pointDelta}")
rubricComment = rubricCategory.addRubricComment(text, pointDelta, commentPosition)
commentPosition += 1
# ----------------------------------------------------------------------
def main():
parser = ArgumentParser(description='add a rubric to a codepost.io assignment for a course')
parser.add_argument('--course-prefix', dest='coursePrefix', default='CS',
help='''directory prefix for course names (i.e., if all your codepost.io course names and
local directories start with CS such as CS160 then use the default
''')
parser.add_argument('-c', '--course-name', dest='course', default=None,
help='''name of course, if no name supplied, will try to find directory with coursePrefix in
the current working directory's parent directories
''')
parser.add_argument('-r', '--rubric-file', dest='rubricFile', default=None,
help='''name of file containing rubric''')
parser.add_argument("assignment")
parser.add_argument("rubricFilename")
options = parser.parse_args()
if options.course is None:
course, _, _, _ = FileInfo.infoForFilePath(os.getcwd())
else:
course = options.course
if options.assignment is None:
assignment = input("enter assignment name: ")
else:
assignment = options.assignment[0]
CP.init()
c = CP.course(course)
a = c.assignment(options.assignment)
makeRubric(a, options.rubricFilename)
print(f"add rubric from {options.rubricFilename} for {options.assignment} in {course}")
# ----------------------------------------------------------------------
if __name__ == '__main__':
main()