Commit 4e0f1000 authored by Olivier's avatar Olivier
Browse files

M2: handful of improvements

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

* two ID numbers are created for each assignment: one for the assignment, one for the grading
* custom ID number(s) now generated with email, so matriculation number is no longer required
* use UTF-8 encoding in input/output
parent e40f8fdf
......@@ -21,29 +21,27 @@ output_parameters_path = 'script_output/parameters_ID_'
# Import modules
import csv # For reading csv files
import math
from hash_function import hash_function # Import hash_function
# Initialize arrays to store data
names = [] # Student first name
last_name = [] # Student last name
emails = [] # Student email address
matrikel_num = [] # Student matrikel number
markers = [] # Marker for the number to customize
range_min = [] # Maximum value that the custom number can take
range_max = [] # Minimum value that the custom number can take
decimals = [] # Number of decimals by which to round off the custom numbers
custom_ID = [] # Custom ID for the student
markers = [] # Marker for the number to customize
custom_ID_A = [] # Custom ID of the assignment for the student
custom_ID_G = [] # Custom ID of the grading file for the student
rand_matrix = [] # These are the random numbers to customize the assignments
custom_values = [] # Matrix with all custom values for each student assingment
# Open and read original parameters tex file
with open(parameters_path,'r') as f:
with open(parameters_path,'r', encoding="utf-8") as f:
parameters =
# Store students data from csv file into variables
with open(canoniccl_path, newline='') as f:
canoniccl_reader = csv.reader(f)
next(canoniccl_reader) # Skip header [name, last name, email, matrikel_num]
next(canoniccl_reader) # Skip header [name, last name, email]
canoniccl_data = [row for row in canoniccl_reader]
for row in canoniccl_data:
......@@ -63,9 +61,10 @@ with open(assignment_info_path, newline='') as f:
# Generate anonymous ID and six specific numbers for each student
for number in matrikel_num:
[ID, rand_numbers]=hash_function(number)
for email in emails:
[ID_A, ID_G, rand_numbers]=hash_function(email)
# Generate custom values for each student from the semi-random numbers
......@@ -80,20 +79,21 @@ for i in range (0,len(names)):
counter = counter+1
# Store the custom assignment data fo all the students in a csv file
# Store the custom assignment data for all the students in a csv file
with open (output_csv_path,'w',newline='') as f:
writer = csv.writer(f)
writer.writerow(['name','lastname','email','custom_ID_A','custom_ID_G'] +
for i in range(0,len(names)):
writer.writerow([names[i],last_name[i],emails[i], custom_ID_A[i],
# Generate a tex file with custom parameters for each student
for i in range (0,len(names)): # For each student
for j in range (0, len(markers)): # Replace each marker by a custom value
with open ((output_parameters_path+custom_ID[i]+'.tex'),'w') as f:
with open ((output_parameters_path+custom_ID[i]+'.tex'),'w', encoding="utf-8") as f:
for line in temp_param:
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