-
Notifications
You must be signed in to change notification settings - Fork 0
/
extractors.py
309 lines (234 loc) · 11.4 KB
/
extractors.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
from datetime import datetime
import numpy as np
format_date = '%Y-%m-%d %H:%M:%S.%f'
format_date2 = '%Y-%m-%d %H:%M:%S %z.%f'
def datehelper(datestring):
if "." not in datestring:
datestring += ".0"
try:
ding = datetime.strptime(datestring, format_date)
except:
ding = datetime.strptime(datestring, format_date2)
return ding
def get_total_submissions(serie):
subm = [1 for exercise in serie["exercises"] for _ in exercise]
return sum(subm)
def get_nr_ex_no_submissions(serie):
subm = [1 if len(exercise) == 0 else 0 for exercise in serie["exercises"]]
return sum(subm)
def get_time_1st_subm_before_deadline(serie):
deadline = datehelper(serie["deadline"])
time = deadline
for exercise in serie["exercises"]:
if len(exercise) > 0:
sorted_ex = sorted(exercise, key=lambda subm: subm["time"])
first_time = datehelper(sorted_ex[0]["time"])
if first_time < time:
time = first_time
diff = (deadline - time).total_seconds()
return diff
def get_avg_time_last_subm_before_deadline(serie):
deadline = datehelper(serie["deadline"])
time = None
for exercise in serie["exercises"]:
for subm in exercise:
subm_time = datehelper(subm["time"])
if (not time and deadline > subm_time) or deadline > subm_time > time:
time = subm_time
if not time:
diff = 0
else:
diff = (deadline - time).total_seconds()
return diff
def get_nr_right_before_deadline(serie):
deadline = datehelper(serie["deadline"])
right = 0
for exercise in serie["exercises"]:
if any(subm["status"] == 1 and datehelper(subm["time"]) < deadline for subm in exercise):
right += 1
return right
def get_nr_correct_subm(serie):
right = 0
for exercise in serie["exercises"]:
right += sum([1 if subm["status"] == 1 else 0 for subm in exercise])
return right
def get_nr_submissions_after_first_correct(serie):
after_correct = 0
for exercise in serie["exercises"]:
sorted_ex = sorted(exercise, key=lambda subm: subm["time"])
correct_ex = list(filter(lambda x: x["status"] == 1, sorted_ex))
if len(correct_ex) > 0:
first_correct_ex = sorted_ex.index(correct_ex[0])
after_correct += len(sorted_ex) - 1 - first_correct_ex
return after_correct
def get_nr_submissions_till_first_correct(serie):
till_correct = 0
for exercise in serie["exercises"]:
sorted_ex = sorted(exercise, key=lambda subm: subm["time"])
correct_ex = list(filter(lambda x: x["status"] == 1, sorted_ex))
if len(correct_ex) > 0:
first_correct_index = sorted_ex.index(correct_ex[0])
till_correct += 1 + first_correct_index
else:
till_correct += len(sorted_ex)
return till_correct
def get_time_between_first_last_submmission(serie):
all_submissions = []
for exercise in serie["exercises"]:
all_submissions += exercise
sorted_subm = sorted(all_submissions, key=lambda subm: subm["time"])
if len(sorted_subm) > 1:
first_time = datehelper(sorted_subm[0]["time"])
last_time = datehelper(sorted_subm[-1]["time"])
diff = (last_time - first_time).total_seconds()
else:
diff = 0
return diff
def get_nr_of_exercises_solved_in_2_hours(serie):
return get_nr_of_exercises_solved_in_x_hours(serie, 7200)
def get_nr_of_exercises_solved_in_24_hours(serie):
return get_nr_of_exercises_solved_in_x_hours(serie, 86400)
def get_nr_of_exercises_solved_in_15_mins(serie):
return get_nr_of_exercises_solved_in_x_hours(serie, 15 * 60)
def get_nr_of_exercises_solved_in_10_mins(serie):
return get_nr_of_exercises_solved_in_x_hours(serie, 10 * 60)
def get_nr_of_exercises_solved_in_5_mins(serie):
return get_nr_of_exercises_solved_in_x_hours(serie, 5 * 60)
def get_nr_of_exercises_solved_in_x_hours(serie, seconds):
in_time = 0
for exercise in serie["exercises"]:
sorted_ex = sorted(exercise, key=lambda subm: subm["time"])
correct_ex = list(filter(lambda x: x["status"] == 1, sorted_ex))
if len(correct_ex) > 0:
first_correct_time = datehelper(correct_ex[0]["time"])
first_time = datehelper(sorted_ex[0]["time"])
diff = (first_correct_time - first_time).total_seconds()
if diff < seconds: # 86400 = 24 uur in seconden
in_time += 1
return in_time
def get_nr_of_submissions_with_status_wrong(serie):
return get_nr_of_submissions_with_status_x(serie, 2)
def get_nr_of_submissions_with_status_timelimit(serie):
return get_nr_of_submissions_with_status_x(serie, 3)
def get_nr_of_submissions_with_status_runtimeerror(serie):
return get_nr_of_submissions_with_status_x(serie, 6)
def get_nr_of_submissions_with_status_comperror(serie):
return get_nr_of_submissions_with_status_x(serie, 7)
def get_nr_of_submissions_with_status_memlimit(serie):
return get_nr_of_submissions_with_status_x(serie, 8)
def get_nr_of_submissions_with_status_x(serie, status):
nr = 0
for exercise in serie["exercises"]:
status_ex = list(filter(lambda x: x["status"] == status, exercise))
nr += len(status_ex)
return nr
def get_time_first_correct_subm(serie):
till_correct = []
for exercise in serie["exercises"]:
sorted_ex = sorted(exercise, key=lambda subm: subm["time"])
correct_ex = list(filter(lambda x: x["status"] == 1, sorted_ex))
if len(correct_ex) > 0:
first_correct_time = datehelper(correct_ex[0]["time"])
first_time = datehelper(sorted_ex[0]["time"])
# first_correct_index = sorted_ex.index(correct_ex[0])
till_correct.append((first_correct_time - first_time).total_seconds())
else:
till_correct.append(-1)
return np.mean(till_correct)
def get_plag_data(data):
return [[student["marks"]["plagrank_adjustleader"]] for student in data]
def get_eval_results(data):
results = []
for student in data:
marks = student["marks"]
st_eval = [marks["ev1"] if ("ev1" in marks and marks["ev1"]) else 0,
marks["ev2"] if ("ev2" in marks and marks["ev2"]) else 0]
results.append(st_eval)
return results
def get_first_eval_results_binned(data):
results = []
for student in data:
st_eval = []
marks = student["marks"]
st_eval.append([2] if ("ev1" in marks and marks["ev1"] and marks["ev1"] >= 12) else
[1] if ("ev1" in marks and marks["ev1"] and marks["ev1"] >= 8) else [0])
results.append(st_eval)
return results
def get_first_eval_results(data):
results = []
for student in data:
marks = student["marks"]
st_eval = [marks["ev1"] if ("ev1" in marks and marks["ev1"]) else 0]
results.append(st_eval)
return results
def get_eval_results_binned(data):
results = []
for student in data:
st_eval = []
marks = student["marks"]
st_eval.append([2] if ("ev1" in marks and marks["ev1"] and marks["ev1"] >= 12) else
[1] if ("ev1" in marks and marks["ev1"] and marks["ev1"] >= 8) else [0])
st_eval.append([2] if ("ev2" in marks and marks["ev2"] and marks["ev2"] >= 12) else
[1] if ("ev2" in marks and marks["ev2"] and marks["ev2"] >= 8) else [0])
results.append(st_eval)
return results
def get_results(data):
results = []
for student in data:
marks = student["marks"]
results.append([1] if ("ex1" in marks and marks["ex1"] and marks["ex1"] >= 10) else [0])
return results
def get_results_binned(data):
results = []
for student in data:
marks = student["marks"]
results.append([3] if ("ex1" in marks and marks["ex1"] and marks["ex1"] >= 16) else
[2] if ("ex1" in marks and marks["ex1"] and marks["ex1"] >= 12) else
[1] if ("ex1" in marks and marks["ex1"] and marks["ex1"] >= 7) else [0])
return results
we_extractors = [
(get_total_submissions, "total nr of submissions"),
(get_nr_ex_no_submissions, "total nr of exercises with no submissions"),
(get_time_1st_subm_before_deadline, "time of 1st submission before deadline"),
(get_avg_time_last_subm_before_deadline, "time of last submissions before deadline"),
(get_nr_right_before_deadline, "number of correct submissions before deadline"),
(get_nr_correct_subm, "number of correct submissions"),
(get_nr_submissions_after_first_correct, "number of submissions after first correct submission"),
(get_nr_submissions_till_first_correct, "number of submissions before first correct"),
(get_time_between_first_last_submmission, "time between first and last submissions of a series"),
(get_time_first_correct_subm, "time between first submission and first correct submission"),
(get_nr_of_exercises_solved_in_2_hours, "nr of exercises in 2 hours"),
(get_nr_of_exercises_solved_in_24_hours, "nr of exercises in 24 hours"),
(get_nr_of_exercises_solved_in_5_mins, "nr of exercises in 5 mins"),
# (get_nr_of_exercises_solved_in_10_mins, "nr of exercises in 10 mins"),
(get_nr_of_exercises_solved_in_15_mins, "nr of exercises in 15 mins"),
(get_nr_of_submissions_with_status_wrong, "nr of submissions wrong"),
(get_nr_of_submissions_with_status_comperror, "nr of submissions compilation error"),
# (get_nr_of_submissions_with_status_memlimit, "nr of submissions memory limit"),
(get_nr_of_submissions_with_status_runtimeerror, "nr of submissions runtime error")
# (get_nr_of_submissions_with_status_timelimit, "nr of submissions time limit"),
# (get_nr_of_submissions_with_status_wrong, "nr of submissions wrong")
]
fea_extractors = [
(get_total_submissions, "total nr of submissions"),
(get_nr_ex_no_submissions, "total nr of exercises with no submissions"),
# (get_time_1st_subm_before_deadline, "time of 1st submission before deadline"),
# (get_avg_time_last_subm_before_deadline, "time of last submissions before deadline"),
# (get_nr_right_before_deadline, "number of correct submissions before deadline"),
(get_nr_correct_subm, "number of correct submissions"),
(get_nr_submissions_after_first_correct, "number of submissions after first correct submission"),
(get_nr_submissions_till_first_correct, "number of submissions before first correct"),
(get_time_between_first_last_submmission, "time between first and last submissions of a series"),
(get_time_first_correct_subm, "time between first submission and first correct submission"),
(get_nr_of_exercises_solved_in_2_hours, "nr of exercises in 2 hours"),
(get_nr_of_exercises_solved_in_24_hours, "nr of exercises in 24 hours"),
(get_nr_of_exercises_solved_in_5_mins, "nr of exercises in 5 mins"),
# (get_nr_of_exercises_solved_in_10_mins, "nr of exercises in 10 mins"),
(get_nr_of_exercises_solved_in_15_mins, "nr of exercises in 15 mins"),
(get_nr_of_submissions_with_status_wrong, "nr of submissions wrong"),
(get_nr_of_submissions_with_status_comperror, "nr of submissions compilation error"),
# (get_nr_of_submissions_with_status_memlimit, "nr of submissions memory limit"),
(get_nr_of_submissions_with_status_runtimeerror, "nr of submissions runtime error")
# (get_nr_of_submissions_with_status_timelimit, "nr of submissions time limit"),
# (get_nr_of_submissions_with_status_wrong, "nr of submissions wrong")
]