Commit b85bd84a authored by Olivier's avatar Olivier
Browse files

Module 6: assign peers to one another

The code in this commit is contributed by Germán Santa Maria.

Add code for module 6: given a list of registered students and a
list of submitted assignements, this will assign each student to
two distinct peers.

Example input and output data is provided.

The output data will be used in module 7 to send two grading
assignments to each student.
parent 6928862c
# -*- coding: utf-8 -*-
"""
Author: German Santa Maria
Script: Match Peers
Description:
This script takes a list of the students who received customized assignments
and the pdf files sent by them. Then it assigns two peers (reviewers) to each
student except the ones that did not send any solution to the assignment. The
output of the scrip is a csv file containing the consolidated data.
Input:
1 - output_assignments.csv :
This file contains the data from the students including their custom ID
is the output file from the script "assign_customizer.py"
name lastname email matrikel custom_ID
Theodore Von Kárman example1@ovgu.de 123456 23344567
Osborne Reynolds example2@st.ovgu.de 123457 33445678
2 - All the pdf files with the solutions submitted by the students marked
as: “submission_customID.pdf”, for example: “submission_12345678.pdf”
Output:
1 - peers.csv : file with the assigned peers for each student
"""
"""-------------------------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'
# Output files paths
peers_csv_path = 'script_output/peers.csv'
"""-------------------------------------------------------------------------"""
# Import modules
import csv # For reading cvs files
import pathlib # For working with local paths
import random # For shuffling elements in arrays
# Initialize arrays to store data
names = [] # Student name
last_name = [] # Student last name
emails = [] # Student email address
matrikel_num = [] # Student matrikel number
custom_ID = [] # Custom ID for the student
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)
random_peers1 = [] # Temporal list of possible peers to assign
random_peers2 = [] # Temporal list of possible peers to assign
# Store students data from csv file into variables
with open(students_info_path, newline='') as f:
students_info_reader = csv.reader(f)
next(students_info_reader) # Skip header [name, last name, email,... ]
students_data = [row for row in students_info_reader]
for row in students_data:
names.append(row[0])
last_name.append(row[1])
emails.append(row[2])
matrikel_num.append(row[3])
custom_ID.append(row[4])
# Check which students actually sent a solution to their assignment by looking
# for a file in the "script_input" folder with the name "soluttion_ID.pdf"
for i in range(0, len(custom_ID)):
file_to_search = pathlib.Path(submission_pdfs_path+custom_ID[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)
# Create two temporal arrays with the peers to be assigned
for i in range(0,len(custom_ID)):
# 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])
copy_randp1 = random_peers1 # Save a copy of the array "random_peers1"
copy_randp2 = random_peers2 # Save a copy of the array "random_peers2"
# While loop to assign the peers
counter = 0 # Initialize counter for while loop
iterations = 0
while counter<len(names) and iterations<10000:
# Shuffle "random_peers1" and "random_peers2" arrays
random_peers1 = random.sample(random_peers1, len(random_peers1))
random_peers2 = random.sample(random_peers2, len(random_peers2))
# 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'
counter = counter + 1 # Update counter
iterations = iterations + 1 # Update iterations counter
continue # This jumps to the begining of the while loop
# Make sure that te last student in the list does not end up without a peer
# given the case that the last peer to be assigned is himself (or herself)
if len(random_peers1) == 1 and (custom_ID[counter] == random_peers1[0] or
custom_ID[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
counter = 0 # This resets counter
iterations = iterations + 1 # Update iterations counter
continue
# If student==peer or peer1==peer2 repeat iteration
if (custom_ID[counter] == random_peers1[0] or
custom_ID[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
random_peers1.pop(0) # Remove peer from "random_peers1"
ID_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
###############################################################################
###############################################################################
# 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'])
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]])
# End of script
name,lastname,email,matrikel,custom_ID,XXpipediameterXX,XXpipelengthXX,XXmassflowXX,XXdensityXX
Theodore,Von Kármán,example1@ovgu.de,123456,28107819,1.2,102.0,2.0,1097.0
Osborne,Reynolds,example2@ovgu.de,123457,17688816,1.9,349.0,3.6,990.0
student1,one,one@st.ovgu.de,100001,32203334,1.7,270.0,2.4,1044.0
student2,two,two@st.ovgu.de,100002,90886833,1.1,308.0,3.0,1010.0
student3,three,three@st.ovgu.de,100003,89131963,2.6,133.0,2.8,1267.0
student4,four,four@st.ovgu.de,100004,25214889,1.9,172.0,2.9,1272.0
student5,five,five@st.ovgu.de,100005,31675588,1.2,180.0,1.7,1060.0
student6,six,six@st.ovgu.de,100006,26783579,2.8,346.0,1.9,1219.0
student7,seven,seven@st.ovgu.de,100007,91213660,2.9,141.0,3.6,1144.0
student8,eight,eight@st.ovgu.de,100008,33105406,1.3,105.0,2.5,1218.0
name,lastname,email,matrikel,custom_ID,submitted,ID_peer1,ID_peer2
Theodore,Von Kármán,example1@ovgu.de,123456,28107819,True,26783579,91213660
Osborne,Reynolds,example2@ovgu.de,123457,17688816,True,33105406,26783579
student1,one,one@st.ovgu.de,100001,32203334,True,91213660,89131963
student2,two,two@st.ovgu.de,100002,90886833,True,17688816,33105406
student3,three,three@st.ovgu.de,100003,89131963,True,32203334,31675588
student4,four,four@st.ovgu.de,100004,25214889,True,31675588,32203334
student5,five,five@st.ovgu.de,100005,31675588,True,25214889,28107819
student6,six,six@st.ovgu.de,100006,26783579,True,90886833,25214889
student7,seven,seven@st.ovgu.de,100007,91213660,True,89131963,90886833
student8,eight,eight@st.ovgu.de,100008,33105406,True,28107819,17688816
......@@ -38,14 +38,13 @@ A total of nine modules (six of which being locally-run scripts) are needed to r
[ ] Module 5: Receive submissions from students
(in Moodle or through email)
[ ] Module 6: Match peers
[x] [Module 6](M6_match_peers): Match peers
(in Python)
[ ] Module 7: Send peer grading assignments
(in Python)
[ ] Module 8: Process grades
(in Python)
[ ] Module 9: Send results to students
......
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