Commit fa5cab8e authored by Olivier's avatar Olivier
Browse files

M2: cleanup

* clarify nomenclature for first name, last name, full name
* simplify file names
* hint at how exercise is coded in practice (with key code redacted)
* cleanup redundant documentation in lead comments
* re-organize parts of code & expand search-and-replace section,
  following Germán’s work
parent a03e4bab
......@@ -4,29 +4,18 @@ Author: German Santa Maria
Script: Assignment Customizer
Description:
This script takes a tex file with marked parameters and a list of students
matriculation numbers to produce 1) a new tex file with custom parameters for
This script takes a tex file with marked parameters and a list of student
emails to produce 1) two new tex files with custom parameters for
each student and 2) a summary csv file with all the output assignments data.
"""
"""-------------------------Hard coded input--------------------------------"""
# Input files paths
parameters_path = 'script_input/parameters.tex'
canoniccl_path = 'script_input/canonical.csv'
assignment_info_path = 'script_input/assignment_info.csv'
# Output files paths
output_csv_path = 'script_output/output_assignments.csv'
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
first_names = [] # Student first name
last_names = [] # Student last name
emails = [] # Student email address
markers = [] # Marker for the number to customize
custom_ID_A = [] # Custom ID of the assignment for the student
......@@ -34,31 +23,44 @@ 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', encoding="utf-8") as f:
parameters = f.read()
"""-------------------------Hard coded input--------------------------------"""
# Input files paths
assignment_path = 'script_input/hot_air_exhaust_assignment.tex'
assig_solution_path = 'script_input/hot_air_exhaust_solution.tex'
canoniccl_path = 'script_input/canonical.csv'
# Output files paths
output_csv_path = 'script_output/output_assignments.csv'
output_assignment_path = 'script_output/assignment1_'
output_solution_path = 'script_output/solution1_'
# Markers for values
markers = ['XXspeed_in1XX', 'XXspeed_in2XX'
]
# Markers for student custom ID
marker_customID_A = 'XXcustomID_AXX'
marker_customID_G = 'XXcustomID_GXX'
marker_firstname = 'XXstudentfirstnameXX'
marker_lastname = 'XXstudentlastnameXX'
marker_fullname = 'XXstudentfullnameXX'
"""-------------------------------------------------------------------------"""
# Open and read the template assignment tex file
with open(assignment_path,'r', encoding="utf-8") as f:
assignment = f.read()
# Open and read the template solution tex file
with open(assig_solution_path,'r', encoding="utf-8") as f:
assig_solution = f.read()
# Store students data from csv file into variables
with open(canoniccl_path, newline='') as f:
with open(canoniccl_path, newline='', encoding="utf-8") as f:
canoniccl_reader = csv.reader(f)
next(canoniccl_reader) # Skip header [name, last name, email]
next(canoniccl_reader) # Skip header (first line)
canoniccl_data = [row for row in canoniccl_reader]
for row in canoniccl_data:
names.append(row[0])
last_name.append(row[1])
first_names.append(row[0])
last_names.append(row[1])
emails.append(row[2])
matrikel_num.append(row[3])
# Store assignment data from csv file into variables
with open(assignment_info_path, newline='') as f:
assignment_info_reader = csv.reader(f)
next(assignment_info_reader) # Skip header [marker, min, max, decimals]
assignment_info_data = [row for row in assignment_info_reader]
for row in assignment_info_data:
markers.append(row[0])
range_min.append(float(row[1]))
range_max.append(float(row[2]))
decimals.append(int(row[3]))
# Generate anonymous ID and six specific numbers for each student
for email in emails:
......@@ -67,34 +69,68 @@ for email in emails:
custom_ID_G.append(ID_G)
rand_matrix.append(rand_numbers)
"""- (HARD CODED) parameters and solutions are specific for this excercise -"""
# Generate custom values for each student from the semi-random numbers
for i in range (0,len(names)):
counter = 0 # Initialize counter for random numbers indexes
temp_array = [] # Initialize temporary array
for j in range (0,len(markers)):
if counter>5: # This is for the case when len(markers)>random numbers
counter=0
temp_array.append(round((rand_matrix[i][counter]*(range_max[j]-
range_min[j])+range_min[j]), decimals[j]))
counter = counter+1
custom_values.append(temp_array)
for i in range (0,len(first_names)):
# Inlet #1 air speed [m/s]
min_speed_in1 = 10
max_speed_in1 = 20
speed_in1 = min_speed_in1+(max_speed_in1-min_speed_in1)*rand_matrix[i][0]
speed_in1 = round(speed_in1) # round-off decimals = 0
# (code redacted)
###########################################################################
# Store the calculated custom numbers for the assignments
custom_values.append([speed_in1, speed_in2,
])
"""-------------------------------------------------------------------------"""
# Store the custom assignment data for all the students in a csv file
with open (output_csv_path,'w',newline='') as f:
with open (output_csv_path,'w',newline='', encoding="utf-8") as f:
writer = csv.writer(f)
writer.writerow(['name','lastname','email','custom_ID_A','custom_ID_G'] +
writer.writerow(['first name','last name','email','custom_ID_A','custom_ID_G'] +
markers)
for i in range(0,len(names)):
writer.writerow([names[i],last_name[i],emails[i], custom_ID_A[i],
for i in range(0,len(first_names)):
writer.writerow([first_names[i],last_names[i],emails[i], custom_ID_A[i],
custom_ID_G[i]]+custom_values[i])
# Generate a tex file with custom parameters for each student
for i in range (0,len(names)): # For each student
temp_param=parameters
for i in range (0,len(first_names)): # For each student
temp_assig = assignment
for j in range (0, len(markers)): # Replace each marker by a custom value
temp_assig = temp_assig.replace(markers[j],str(custom_values[i][j]))
# Mark assignment with the student custom ID
temp_assig = temp_assig.replace(marker_customID_A, str(custom_ID_A[i]))
temp_assig = temp_assig.replace(marker_customID_G, str(custom_ID_G[i]))
# Mark assignment with the student first name
temp_assig = temp_assig.replace(marker_firstname, str(first_names[i]))
# Mark assignment with the student first name and last name
full_name = str(first_names[i]) + ' ' + str(last_names[i])
temp_assig = temp_assig.replace(marker_fullname, full_name)
# Produce the custom tex file for each student
with open ((output_assignment_path+custom_ID_A[i]+'.tex'),'w', encoding="utf-8") as f:
for line in temp_assig:
f.write(line)
# Generate modified tex files with solution to the assignment for each student
for i in range (0,len(first_names)): # For each student
temp_sol = assig_solution
for j in range (0, len(markers)): # Replace each marker by a custom value
temp_param=temp_param.replace(markers[j],str(custom_values[i][j]))
with open ((output_parameters_path+custom_ID[i]+'.tex'),'w', encoding="utf-8") as f:
for line in temp_param:
temp_sol = temp_sol.replace(markers[j],str(custom_values[i][j]))
# Mark solution with the student custom ID
temp_sol = temp_sol.replace(marker_customID_A, str(custom_ID_A[i]))
temp_sol = temp_sol.replace(marker_customID_G, str(custom_ID_G[i]))
# Mark assignment with the student first name
temp_sol = temp_sol.replace(marker_firstname, str(first_names[i]))
# Mark solution with the student name
temp_sol = temp_sol.replace(marker_fullname, full_name)
# Produce the custom tex file for each student
with open ((output_solution_path+custom_ID_G[i]+'.tex'),'w', encoding="utf-8") as f:
for line in temp_sol:
f.write(line)
# 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