Skip to content
Snippets Groups Projects
Commit d2583a87 authored by Sydney May's avatar Sydney May
Browse files

Merge branch 'make-pipeline-robust' into 'main'

Make pipeline robust

See merge request !9
parents e0a69443 8d680fb8
1 merge request!9Make pipeline robust
...@@ -24,7 +24,7 @@ while True: ...@@ -24,7 +24,7 @@ while True:
start_time = time() start_time = time()
# Get emails, student IDs, and usernames of students (excludes default users and instructors) # Get emails, student IDs, and usernames of students (excludes default users and instructors)
query = ("SELECT id, username, email FROM auth_user WHERE last_login IS NOT NULL AND is_superuser = 0") query = ("SELECT id, username, email FROM auth_user WHERE last_login IS NOT NULL AND is_superuser = 0 AND is_staff = 0 AND is_active = 1")
mysql_cursor.execute(query) mysql_cursor.execute(query)
student_dict = {} student_dict = {}
for (id, username, email) in mysql_cursor: for (id, username, email) in mysql_cursor:
...@@ -112,28 +112,29 @@ while True: ...@@ -112,28 +112,29 @@ while True:
json_data = [] json_data = []
index = 0 index = 0
for student_id in student_dict: for student_id in student_dict:
json_data.append({}) if len(student_dict[student_id]) == 4: # Ensures that we can access all list elements below
json_data[index]["Email"] = student_dict[student_id][1] json_data.append({})
json_data[index]["Username"] = student_dict[student_id][0] json_data[index]["Email"] = student_dict[student_id][1]
json_data[index]["Overall Grade"] = str(student_dict[student_id][2]) json_data[index]["Username"] = student_dict[student_id][0]
grade_data = student_dict[student_id][3] json_data[index]["Overall Grade"] = str(student_dict[student_id][2])
quiz_ids_ordered = [] grade_data = student_dict[student_id][3]
for quiz_id in grade_data: quiz_ids_ordered = []
quiz_name = quiz_id_to_quiz_name[quiz_id] for quiz_id in grade_data:
grades = grade_data[quiz_id] quiz_name = quiz_id_to_quiz_name[quiz_id]
json_data[index]["Grade on " + quiz_name] = str(grades[0]) grades = grade_data[quiz_id]
quiz_ids_ordered.append(quiz_id) json_data[index]["Grade on " + quiz_name] = str(grades[0])
for quiz_id in quiz_ids_ordered: quiz_ids_ordered.append(quiz_id)
quiz_name = quiz_id_to_quiz_name[quiz_id] for quiz_id in quiz_ids_ordered:
question_grades = grade_data[quiz_id][1] quiz_name = quiz_id_to_quiz_name[quiz_id]
question_grades_length = len(question_grades) question_grades = grade_data[quiz_id][1]
question_index = 0 question_grades_length = len(question_grades)
while question_index < question_grades_length: question_index = 0
question_index_string = str(int(question_index / 2) + 1) while question_index < question_grades_length:
json_data[index][quiz_name + " - Q" + question_index_string + " (Earned)"] = str(question_grades[question_index]) question_index_string = str(int(question_index / 2) + 1)
json_data[index][quiz_name + " - Q" + question_index_string + " (Possible)"] = str(question_grades[question_index + 1]) json_data[index][quiz_name + " - Q" + question_index_string + " (Earned)"] = str(question_grades[question_index])
question_index += 2 json_data[index][quiz_name + " - Q" + question_index_string + " (Possible)"] = str(question_grades[question_index + 1])
index += 1 question_index += 2
index += 1
with open("csvToPy.json", "w") as json_file: with open("csvToPy.json", "w") as json_file:
dump(json_data, json_file, indent=2) dump(json_data, json_file, indent=2)
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment