-
Notifications
You must be signed in to change notification settings - Fork 0
/
deprecated.py
181 lines (128 loc) · 5.83 KB
/
deprecated.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
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
def deprecated_get_num_passes(filepath):
"""
computes the number of passed tests by reading the top lines of the checker output,
namely by counting the number of .'s
this number will be incorrect if there's screenout in the middle of the string
this can only be prevented by capturing all warnings and printing during all tests,
which makes the test output significantly less useful.
"""
with open(filepath,'r') as file:
data = file.read()
as_lines = data.split('\n')
topline = as_lines.pop(0)
while len(set(topline)-set('.EF'))>0:
if 'Warning' in topline:
as_lines.pop(0) # the next line is a follow-on to the warning we're skipping
topline = as_lines.pop(0)
else:
topline = as_lines.pop(0)
num_fails = len(topline) - topline.count('.')
return topline.count('.'), topline
def deprecated_tests_to_feedback(filename):
"""
feed this function a filename, read from a unittest file
"""
with open(filename,'r') as file:
raw_data = file.read()
data = raw_data.split('\n')
if 'Traceback' in data[0]:
return "Your file has a critical error in it, such that the autograder was not able to execute your code, and thus was unable to run any tests:\n\n"+raw_data
feedback = ''
topline = data.pop(0)
num_warnings = 0
num_weird = 0
found_warnings = ''
found_weird = ''
while len(set(topline)-set('.EF'))>0:
if 'Warning' in topline:
if num_warnings == 0:
found_warnings = found_warnings+'### Detected warnings your code generated:'
found_warnings = found_warnings+"\n\n===> Your code has a warning in it!!! Don't ignore warnings!!!!\n\n"+topline+'\n'+data.pop(0)
topline = data.pop(0)
num_warnings = num_warnings+1
else:
if num_weird==0:
found_weird=found_weird+'found some unexpected lines from the checker.'
found_weird = found_weird+topline
topline = data.pop(0)
feedback = found_warnings + ("\n\n" if num_warnings>0 else "") + found_weird + ("\n\n" if num_weird>0 else "")
num_fails = len(topline) - topline.count('.')
encountered_fails = 0
linenum=0
while linenum < len(data):
line = data[linenum]
if line.startswith('FAIL: ') or line.startswith('ERROR: '):
encountered_fails = encountered_fails+1
#if encountered_fails==1:
# feedback = feedback+'### Autograder tests failed in this autochecker file:\n\n'
d = line.split(' ')
test_name = d[1]
feedback = feedback+f'{encountered_fails}: {test_name}\n'
linenum+=5
feedback = feedback+f'\t --reason: failed {data[linenum]}\n\n'
linenum+=1
if encountered_fails!=num_fails:
raise RuntimeError(f'mismatched number of not-passed tests, expected {num_fails}, found {encountered_fails}, in {filename}')
return feedback
def deprecated_collect_num_passes_txt_format(path):
"""
constructs a data frame, holding the number of passes, etc.
scans all .txt files in the folder, which were presumably
generated by running a checker against students' code.
"""
name = []
student_id = []
file_number = []
num_passes = []
success_string = []
feedback = []
# canvas_name = []
# section = []
files = os.listdir(path)
for f in files:
if f.endswith('.txt'):
d = process_filename(f)
name.append(d['name'])
student_id.append(int(d['student_id']))
file_number.append(int(d['file_number']))
q = deprecated_get_num_passes(join(path,f))
num_passes.append(q[0])
success_string.append(q[1])
feedback.append(tests_to_feedback(join(path,f)))
df = pd.DataFrame({'name':name, "student_id":student_id,
"file_number":file_number, "num_passes":num_passes,
"success_string":success_string, 'feedback':feedback})
df['num_tests'] = df['success_string'].map(lambda x: len(x))
df['percent_pass'] = df['num_passes']/df['num_tests']
return df
def deprecated_combine_feedback(row):
"""
a function to apply, to merge two feedbacks -- from pre and post.
"""
if row['percent_pass_pre']==1 and row['percent_pass_post']==1:
return "\nNice work, all automatically run tests passed!\n\n# Manual grading comments:\n\n"
feedback = '# Manual grading comments:\n\n\n\n'
feedback = feedback + '# Automatically generated feedback on your last submitted code'
if row['percent_pass_pre']<1:
feedback = feedback + '\n\n## While grading, we detected that the following issues from the provided assignment checker file:\n\n'
feedback = feedback + row['auto_feedback_pre']
if row['percent_pass_post']<1:
feedback = feedback + '\n\n## While grading, we detected that the following issues from an instructor-only checker file:\n\n'
feedback = feedback + row['auto_feedback_post']
# put line of code indicating autograder raw score here
return feedback
def deprecated_format_feedback(row):
"""
a function to apply to the data frame, adding some stuff to end of the feedback
"""
val = '\n{}\n\n{}\n'.format(row['sortable_name'],row['auto_feedback_combined'])
val = val + '\nEnd of code feedback for {}.\n\n'.format(row['sortable_name'])
val = val + '\n**********************\nNext student\n===================\n'
return val
def deprecated_save_feedback(feedback, filename):
"""
saves the feedback data frame to a file named `filename`
"""
with open(filename,'w') as file: # i'm not sure this needs to be here. can remove?
formatted = feedback.apply(format_feedback,axis=1)
formatted.to_csv(filename,index=False,header=False)