Commit 72105c95 authored by Olivier's avatar Olivier
Browse files

M6: handful of improvements

parent 4e0f1000
......@@ -14,8 +14,10 @@ be saved in the `script_output` folder.
1. `output_assignments.csv`: This file contains the data from the students including their custom ID. It is the output file from the script [assign_customizer.py](../M2_customize_assignments/assign_customizer.py) from [module 2](../M2_customize_assignments).
1. All the `pdf` files with the solutions submitted by the students, named as: `submission_customID.pdf` (for example `submission_12345678.pdf`).
1. All the `pdf` files with the solutions submitted by the students, named as: `customID.pdf` (for example `12345678.pdf`).
## Script output
1. `peers.csv`: file with the assigned peers for each student.
1. renamed pdfs, ready to be sent for grading: `ID_A.pdf``ID_G.pdf`
......@@ -7,7 +7,8 @@ Script: Match Peers
"""-------------------------Hard coded input--------------------------------"""
# Input files paths
students_info_path = 'script_input/output_assignments.csv'
submission_pdfs_path = 'script_input/submission_' # pdf name : submission_ID.pdf'
submission_pdfs_name = 'submission_a1_' # Name of the submitted PDFs
submission_pdfs_path = 'script_input/' + submission_pdfs_name #pdf path
# Output files paths
peers_csv_path = 'script_output/peers.csv'
"""-------------------------------------------------------------------------"""
......@@ -16,16 +17,17 @@ peers_csv_path = 'script_output/peers.csv'
import csv # For reading csv files
import pathlib # For working with local paths
import random # For shuffling elements in arrays
from shutil import copyfile # To copy and rename the solution PDF files
# Initialize arrays to store data
names = [] # Student first name
last_name = [] # Student last name
emails = [] # Student email address
matrikel_num = [] # Student matrikel number
custom_ID = [] # Custom ID for the student
custom_ID_A = [] # ID that the student uses to submit the solution
custom_ID_G = [] # ID that the student uses to grade the peers
did_their_homework = [] # List of students that actually submitted a solution
ID_peer1 = [] # List of peers (first peer)
ID_peer2 = [] # List of peers (second peer)
email_peer1 = [] # List of peers (first peer)
email_peer2 = [] # List of peers (second peer)
random_peers1 = [] # Temporary list of possible peers to assign
random_peers2 = [] # Temporary list of possible peers to assign
......@@ -38,28 +40,28 @@ with open(students_info_path, newline='') as f:
names.append(row[0])
last_name.append(row[1])
emails.append(row[2])
matrikel_num.append(row[3])
custom_ID.append(row[4])
custom_ID_A.append(row[3])
custom_ID_G.append(row[4])
# Check which students actually submitted their solution to their assignment by looking
# for a file in the "script_input" folder with the name "submission_ID.pdf"
for i in range(0, len(custom_ID)):
file_to_search = pathlib.Path(submission_pdfs_path+custom_ID[i]+'.pdf')
# for a file in the "script_input" folder with the name "ID.pdf"
for i in range(0, len(custom_ID_A)):
file_to_search = pathlib.Path(submission_pdfs_path+custom_ID_A[i]+'.pdf')
did_their_homework.append(file_to_search.exists())
########## Assign two peers to each student who submitted a solution ##########
###############################################################################
# Allocate size of arrays "ID_peer1" and "ID_peer2"
ID_peer1 = ['']*len(names)
ID_peer2 = ['']*len(names)
email_peer1 = ['']*len(emails)
email_peer2 = ['']*len(emails)
# Create two temporary arrays with the peers to be assigned
for i in range(0,len(custom_ID)):
# Create two temporal arrays with the peers to be assigned
for i in range(0,len(emails)):
# Only students who submitted solution can recieve a peer role
if did_their_homework[i]==True:
random_peers1.append(custom_ID[i])
random_peers2.append(custom_ID[i])
random_peers1.append(emails[i])
random_peers2.append(emails[i])
copy_randp1 = random_peers1 # Save a copy of the array "random_peers1"
copy_randp2 = random_peers2 # Save a copy of the array "random_peers2"
......@@ -73,16 +75,16 @@ while counter<len(names) and iterations<10000:
# Make sure that peers are assigned only to students who submitted solution
if did_their_homework[counter]==False:
ID_peer1[counter] = 'None'
ID_peer2[counter] = 'None'
email_peer1[counter] = 'None'
email_peer2[counter] = 'None'
counter = counter + 1 # Update counter
iterations = iterations + 1 # Update iterations counter
continue # This jumps to the begining of the while loop
# Make sure that the last student in the list does not end up wihout a peer,
# in the case that the last peer to be assigned is themselves.
if len(random_peers1) == 1 and (custom_ID[counter] == random_peers1[0] or
custom_ID[counter] == random_peers2[0] or
if len(random_peers1) == 1 and (emails[counter] == random_peers1[0] or
emails[counter] == random_peers2[0] or
random_peers1[0] == random_peers2[0]):
random_peers1 = copy_randp1 # Resets "random_peers1" array
random_peers2 = copy_randp2 # Resets "random_peers2" array
......@@ -91,16 +93,16 @@ while counter<len(names) and iterations<10000:
continue
# If student==peer or peer1==peer2 repeat iteration
if (custom_ID[counter] == random_peers1[0] or
custom_ID[counter] == random_peers2[0] or
if (emails[counter] == random_peers1[0] or
emails[counter] == random_peers2[0] or
random_peers1[0] == random_peers2[0]):
iterations = iterations + 1 # Update iterations counter
continue # "counter" is not updated, iteration will be repeated
# If no conflicts are found assign peer1 and peer2
ID_peer1[counter] = random_peers1[0] # Assign first peer
email_peer1[counter] = random_peers1[0] # Assign first peer
random_peers1.pop(0) # Remove peer from "random_peers1"
ID_peer2[counter] = random_peers2[0] # Assign second peer
email_peer2[counter] = random_peers2[0] # Assign second peer
random_peers2.pop(0) # Remove peer from "random_peers2"
counter = counter + 1 # Update counter
iterations = iterations + 1 # Update iterations counter
......@@ -111,10 +113,17 @@ while counter<len(names) and iterations<10000:
# Store the students and their respective peers data in a csv file
with open (peers_csv_path,'w',newline='') as f:
writer = csv.writer(f)
writer.writerow(['name','lastname','email','matrikel','custom_ID',
'submitted','ID_peer1','ID_peer2'])
writer.writerow(['name','lastname','email','custom_ID_A','custom_ID_G',
'submitted','email_peer1','email_peer2'])
for i in range(0,len(names)):
writer.writerow([names[i],last_name[i],emails[i],matrikel_num[i],
custom_ID[i],str(did_their_homework[i]),ID_peer1[i],ID_peer2[i]])
writer.writerow([names[i],last_name[i],emails[i],custom_ID_A[i],
custom_ID_G[i],str(did_their_homework[i]),email_peer1[i],
email_peer2[i]])
# Copy and rename the submission PDF files (custom_ID_A -> custom_ID_G)
for i in range(0, len(custom_ID_A)):
if did_their_homework[i]==True:
copyfile(submission_pdfs_path + custom_ID_A[i] + ".pdf",
"script_output/" + submission_pdfs_name + custom_ID_G[i] + ".pdf")
# End of script
Supports Markdown
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