Commit b3446dd8 authored by Olivier's avatar Olivier
Browse files

M2: cleanup

parent af46ed9a
# -*- coding: utf-8 -*-
"""
Author: German Santa Maria
Author: Germán Santa-Maria
Script: Assignment Customizer
Description:
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.
Description:
This script takes in three tex files with marked parameters, as well as a
list of student emails to produce:
1) three tex files with custom parameters for each student, and;
2) a summary csv file with all the output assignments data.
"""
# Import modules
import csv # For reading csv files
import math
......@@ -16,8 +18,8 @@ from hash_function import hash_function # Import hash_function
# Initialize arrays to store data
first_names = [] # Student first name
last_names = [] # Student last name
emails = [] # Student email address
markers = [] # Marker for the number to customize
emails = [] # Student email address
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
......@@ -28,7 +30,7 @@ custom_values = [] # Matrix with all custom values for each student assingment
# Parameters specific to assignment exercise
# Number of assignment
assignment_number = "_example"
assignment_suffix = "_example"
# Markers for values:
# those are text markers to be replaced by numbers in each student assignment
......@@ -41,19 +43,20 @@ markers = ['XXlengthXX', 'XXwidthXX'
"""-------------------------Hard coded input--------------------------------"""
# Input file paths
assignment_path = 'script_input/assignment'+assignment_number+'.tex'
assig_solution_grading_path = 'script_input/solution_grading'+assignment_number+'.tex'
assig_solution_graded_path = 'script_input/solution_graded'+assignment_number+'.tex'
assignment_path = 'script_input/assignment'+assignment_suffix+'.tex'
assig_solution_grading_path = 'script_input/solution_grading'+assignment_suffix+'.tex'
assig_solution_graded_path = 'script_input/solution_graded'+assignment_suffix+'.tex'
canoniccl_path = 'script_input/canonical.csv'
# Output files paths
# Output file paths
output_csv_path = 'script_output/output_assignments.csv'
output_assignment_preamble = 'script_output/assignment3_'
output_solution_grading_preamble = 'script_output/solution_grading'+assignment_number+'_'
output_solution_graded_preamble = 'script_output/solution_graded'+assignment_number+'_'
output_solution_grading_preamble = 'script_output/solution_grading'+assignment_suffix+'_'
output_solution_graded_preamble = 'script_output/solution_graded'+assignment_suffix+'_'
# Markers for student custom ID
marker_customID_A = 'XXcustomID_AXX'
marker_customID_G = 'XXcustomID_GXX'
marker_customID_A = 'XXcustomIDAXX'
marker_customID_G = 'XXcustomIDGXX'
marker_firstname = 'XXstudentfirstnameXX'
marker_lastname = 'XXstudentlastnameXX'
marker_fullname = 'XXstudentfullnameXX'
......@@ -77,7 +80,7 @@ with open(canoniccl_path, newline='', encoding="utf-8") as f:
last_names.append(row[1])
emails.append(row[2])
# Generate anonymous ID and six specific numbers for each student
# Generate anonymous ID and numbers specific to each student
for email in emails:
[ID_A, ID_G, rand_numbers]=hash_function(email)
custom_ID_A.append(ID_A)
......@@ -111,7 +114,7 @@ for i in range (0,len(first_names)):
area_doubled = area * 4
# Store the calculated custom numbers for the assignments
custom_values.append([
length, width,
......@@ -127,10 +130,10 @@ with open (output_csv_path,'w',newline='', encoding="utf-8") as f:
writer.writerow(['first name','last name','email','custom_ID_A',
'custom_ID_G'] + markers)
for i in range(0,len(first_names)):
writer.writerow([first_names[i],last_names[i],emails[i],
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 each student, generate a tex file for the assignment
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
......@@ -141,7 +144,7 @@ for i in range (0,len(first_names)): # For each student
# 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])
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_preamble+custom_ID_A[i]+'.tex'),'w', encoding="utf-8") as f:
......@@ -159,7 +162,7 @@ for i in range (0,len(first_names)): # For each student
# Mark solution with the student first name
temp_sol_grading = temp_sol_grading.replace(marker_firstname, str(first_names[i]))
# Mark solution with the student first name and last name
full_name = str(first_names[i]) + ' ' + str(last_names[i])
full_name = str(first_names[i]) + ' ' + str(last_names[i])
temp_sol_grading = temp_sol_grading.replace(marker_fullname, full_name)
# Produce the custom tex file for each student
with open ((output_solution_grading_preamble+custom_ID_G[i]+'.tex'),'w', encoding="utf-8") as f:
......@@ -178,7 +181,7 @@ for i in range (0,len(first_names)): # For each student
# Mark solution with the student first name
temp_sol_graded = temp_sol_graded.replace(marker_firstname, str(first_names[i]))
# Mark solution with the student first name and last name
full_name = str(first_names[i]) + ' ' + str(last_names[i])
full_name = str(first_names[i]) + ' ' + str(last_names[i])
temp_sol_graded = temp_sol_graded.replace(marker_fullname, full_name)
# Produce the custom tex file for each student
with open ((output_solution_graded_preamble+custom_ID_A[i]+'.tex'),'w', encoding="utf-8") as f:
......
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