Repository navigation
Expand file tree
/
Copy pathAverageNumberAttempts.py
More file actions
317 lines (235 loc) · 10.2 KB
/
Copy pathAverageNumberAttempts.py
File metadata and controls
317 lines (235 loc) · 10.2 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
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
310
311
312
313
314
315
316
317
import pymongo
import os
import json
import matplotlib.pyplot as plt
from dotenv import load_dotenv
from CreateDictionary import create_dictionary
#Loads environment variables and connects to database
load_dotenv()
database_url = os.environ.get("CS125MONGO")
client = pymongo.MongoClient(database_url)
db = client.Fall2019Clean
#Creates dictionary for each student with timestamps of each submission of assignment
full_dictionary = create_dictionary()
#Sets up the collection which holds the id for each question in labs, homeworks, and exams
question_collection = db.plQuestions
question_list = list(question_collection.find().sort("ID", 1))
#Finds repeat question versions and removes them
questions_to_remove = []
for i in range(len(question_list)):
question = question_list[i]
if '125' in question_list[i]['ID']:
questions_to_remove.append(question)
for question in questions_to_remove:
question_list.remove(question)
#Calculates the average number of attempts a person takes for each question
def get_number_of_attempts():
assignment_to_average_attempts = {}
#Iterates through each question to get the id
for i in range(len(question_list)):
question_id = question_list[i]['ID']
people_to_attempts = {}
total_attempts = 0
#For each question, associate people to number of tries they took
for person in full_dictionary:
person_question_ids = list(full_dictionary[person].keys())
for question in person_question_ids:
if "125" in question:
new_question_id = question[0:13] + question[17:]
insert_into_dictionary = {new_question_id: full_dictionary[person][question]}
full_dictionary[person].update(insert_into_dictionary)
full_dictionary[person].pop(question)
if question_id in person_question_ids:
people_to_attempts.update({person : len(full_dictionary[person][question_id])})
#Iterate through created dictionary to get the total number of attempts made by everyone
for person in people_to_attempts:
total_attempts += people_to_attempts[person]
#Updates the assignment to average dictionary by dividing the total_attempts calculated above by the people who have attempted the question
if len(people_to_attempts) == 0:
assignment_to_average_attempts.update({question_id: 0})
else:
assignment_to_average_attempts.update({question_id: total_attempts / len(people_to_attempts)})
#Clear the dictionary to have it clearn for the next question
people_to_attempts.clear()
return assignment_to_average_attempts
resulting_dictionary = get_number_of_attempts()
#Gets X and Y values for charts from the resulting dictionary created
x_values = list(resulting_dictionary.keys())
y_values = list(resulting_dictionary.values())
#Removes prefix of each question name
for i in range(len(x_values)):
x_values[i] = x_values[i][10:]
#Lists for the x and y values of each corresponding type of question
exam_x_values = []
exam_y_values = []
homework_x_values = []
homework_y_values = []
lab_x_values = []
lab_y_values = []
quiz_zero_one_x_values = []
quiz_zero_one_y_values = []
quiz_two_three_x_values = []
quiz_two_three_y_values = []
quiz_four_five_x_values = []
quiz_four_five_y_values = []
quiz_six_seven_x_values = []
quiz_six_seven_y_values = []
quiz_eight_nine_x_values = []
quiz_eight_nine_y_values = []
quiz_ten_eleven_x_values = []
quiz_ten_eleven_y_values = []
#Sorts the average number of tries into
for i in range(len(x_values)):
if ('E0' in x_values[i]) or ('E1' in x_values[i]) or ('E2' in x_values[i]):
exam_x_values.append(x_values[i])
exam_y_values.append(y_values[i])
elif 'HW' in x_values[i]:
homework_x_values.append(x_values[i])
homework_y_values.append(y_values[i])
elif 'Lab' in x_values[i]:
lab_x_values.append(x_values[i])
lab_y_values.append(y_values[i])
elif ('Q10' in x_values[i]) or ('Q11' in x_values[i]):
quiz_ten_eleven_x_values.append(x_values[i])
quiz_ten_eleven_y_values.append(y_values[i])
elif ('Q0' in x_values[i]) or ('Q1' in x_values[i]):
quiz_zero_one_x_values.append(x_values[i])
quiz_zero_one_y_values.append(y_values[i])
elif ('Q2' in x_values[i]) or ('Q3' in x_values[i]):
quiz_two_three_x_values.append(x_values[i])
quiz_two_three_y_values.append(y_values[i])
elif ('Q4' in x_values[i]) or ('Q5' in x_values[i]):
quiz_four_five_x_values.append(x_values[i])
quiz_four_five_y_values.append(y_values[i])
elif ('Q6' in x_values[i]) or ('Q7' in x_values[i]):
quiz_six_seven_x_values.append(x_values[i])
quiz_six_seven_y_values.append(y_values[i])
elif ('Q8' in x_values[i]) or ('Q8' in x_values[i]):
quiz_eight_nine_x_values.append(x_values[i])
quiz_eight_nine_y_values.append(y_values[i])
#Creates bar chart for average number of exam tries
bars = plt.bar(exam_x_values, exam_y_values, edgecolor = 'black', color = 'violet')
plt.xticks(exam_x_values, exam_x_values, rotation = 90)
figure = plt.gcf()
figure.set_size_inches(25, 25)
for bar in bars:
average = bar.get_height()
plt.text(bar.get_x(), average + 0.25, round(average, 1), rotation = 90)
plt.title("Average Number of Attempts per Question (Midterm)")
plt.xlabel("Question")
plt.ylabel("Number of Tries")
plt.plot()
plt.savefig("Average_Attempts_Exam.png")
plt.clf()
#Creates bar chart for average number of homework tries
bars = plt.bar(homework_x_values, homework_y_values, edgecolor = 'black', color = 'mediumslateblue')
plt.xticks(homework_x_values, homework_x_values, rotation = 90)
figure = plt.gcf()
figure.set_size_inches(25, 25)
for bar in bars:
average = bar.get_height()
plt.text(bar.get_x(), average + 0.25, round(average, 1), rotation = 90)
plt.title("Average Number of Attempts per Question (Homework)")
plt.xlabel("Question")
plt.ylabel("Number of Tries")
plt.plot()
plt.savefig("Average_Attempts_Homework.png")
plt.clf()
#Creates bar chart for average number of lab tries
bars = plt.bar(lab_x_values, lab_y_values, edgecolor = 'black', color = 'lightskyblue')
plt.xticks(lab_x_values, lab_x_values, rotation = 90)
figure = plt.gcf()
figure.set_size_inches(25, 25)
for bar in bars:
average = bar.get_height()
plt.text(bar.get_x(), average + 0.25, round(average, 1), rotation = 90)
plt.title("Average Number of Attempts per Question (Labs)")
plt.xlabel("Question")
plt.ylabel("Number of Tries")
plt.plot()
plt.savefig("Average_Attempts_Labs.png")
plt.clf()
#Creates bar chart for average number of quiz tries in Q0, Q1
bars = plt.bar(quiz_zero_one_x_values, quiz_zero_one_y_values, edgecolor = 'black', color = 'mediumspringgreen')
plt.xticks(quiz_zero_one_x_values, quiz_zero_one_x_values, rotation = 90)
figure = plt.gcf()
figure.set_size_inches(25, 25)
for bar in bars:
average = bar.get_height()
plt.text(bar.get_x(), average + 0.1, round(average, 1), rotation = 90)
plt.title("Average Number of Attempts per Question (Quiz 0, 1)")
plt.xlabel("Question")
plt.ylabel("Number of Tries")
plt.plot()
plt.savefig("Average_Attempts_Quizzes_0_1.png")
plt.clf()
#Creates bar chart for average number of quiz tries in Q2, Q3
bars = plt.bar(quiz_two_three_x_values, quiz_two_three_y_values, edgecolor = 'black', color = 'bisque')
plt.xticks(quiz_two_three_x_values, quiz_two_three_x_values, rotation = 90)
figure = plt.gcf()
figure.set_size_inches(25, 25)
for bar in bars:
average = bar.get_height()
plt.text(bar.get_x(), average + 0.25, round(average, 1), rotation = 90)
plt.title("Average Number of Attempts per Question (Quiz 2, 3)")
plt.xlabel("Question")
plt.ylabel("Number of Tries")
plt.plot()
plt.savefig("Average_Attempts_Quizzes_2_3.png")
plt.clf()
#Creates bar chart for average number of quiz tries in Q4, Q5
bars = plt.bar(quiz_four_five_x_values, quiz_four_five_y_values, edgecolor = 'black', color = 'silver')
plt.xticks(quiz_four_five_x_values, quiz_four_five_x_values, rotation = 90)
figure = plt.gcf()
figure.set_size_inches(25, 25)
for bar in bars:
average = bar.get_height()
plt.text(bar.get_x(), average + 0.25, round(average, 1), rotation = 90)
plt.title("Average Number of Attempts per Question (Quiz 4, 5)")
plt.xlabel("Question")
plt.ylabel("Number of Tries")
plt.plot()
plt.savefig("Average_Attempts_Quizzes_4_5.png")
plt.clf()
#Creates bar chart for average number of quiz tries in Q6, Q7
bars = plt.bar(quiz_six_seven_x_values, quiz_six_seven_y_values, edgecolor = 'black', color = 'lightcoral')
plt.xticks(quiz_six_seven_x_values, quiz_six_seven_x_values, rotation = 90)
figure = plt.gcf()
figure.set_size_inches(25, 25)
for bar in bars:
average = bar.get_height()
plt.text(bar.get_x(), average + 0.25, round(average, 1), rotation = 90)
plt.title("Average Number of Attempts per Question (Quiz 6, 7)")
plt.xlabel("Question")
plt.ylabel("Number of Tries")
plt.plot()
plt.savefig("Average_Attempts_Quizzes_6_7.png")
plt.clf()
#Creates bar chart for average number of quiz tries in Q8, Q9
bars = plt.bar(quiz_eight_nine_x_values, quiz_eight_nine_y_values, edgecolor = 'black', color = 'sandybrown')
plt.xticks(quiz_eight_nine_x_values, quiz_eight_nine_x_values, rotation = 90)
figure = plt.gcf()
figure.set_size_inches(25, 25)
for bar in bars:
average = bar.get_height()
plt.text(bar.get_x(), average + 0.25, round(average, 1), rotation = 90)
plt.title("Average Number of Attempts per Question (Quiz 8, 9)")
plt.xlabel("Question")
plt.ylabel("Number of Tries")
plt.plot()
plt.savefig("Average_Attempts_Quizzes_8_9.png")
plt.clf()
#Creates bar char for average number of quiz tries in Q10, Q11
bars = plt.bar(quiz_ten_eleven_x_values, quiz_ten_eleven_y_values, edgecolor = 'black', color = 'gold')
plt.xticks(quiz_ten_eleven_x_values, quiz_ten_eleven_x_values, rotation = 90)
figure = plt.gcf()
figure.set_size_inches(25, 25)
for bar in bars:
average = bar.get_height()
plt.text(bar.get_x(), average + 0.25, round(average, 1), rotation = 90)
plt.title("Average Number of Attempts per Question (Quiz 10, 11)")
plt.xlabel("Question")
plt.ylabel("Number of Tries")
plt.plot()
plt.savefig("Average_Attempts_Quizzes_10_11.png")
plt.clf()