Commit 6b91b7f6 authored by LammLukas's avatar LammLukas

Deleted redundant files

parent 0e8054d8
import json
import sys
import csv
import os
import shutil
import subprocess
import shlex
import operator
# Class holding data for exam
class Exam_old:
def __init__(self, course_name=None, date=None, examiner=None, rooms=None, participants_list=None,
directory=None, points_per_task=None):
if course_name is not None:
self.data = {
'course_name': course_name,
'date': date,
'examiner': examiner,
'rooms': rooms,
'participants_list': participants_list,
'directory': directory,
'points_per_task': points_per_task}
else:
self.data = {}
def write_json(self):
filename = self.data['directory'] + "/" + self.data['course_name'] + "_exam_data.json"
with open(filename, 'w') as outfile:
json.dump(self.data, outfile, indent=1)
def read_json(self, filename):
# Check if data from object is empty
if not self.data:
with open(filename) as file:
data = json.load(file)
try:
self.data.update({'course_name': data['course_name']})
self.data.update({'date': data['date']})
self.data.update({'examiner': data['examiner']})
self.data.update({'rooms': data['rooms']})
self.data.update({'participants_list': data['participants_list']})
self.data.update({'directory': data['directory']})
self.data.update({'points_per_task': data['points_per_task']})
except KeyError as error:
print("WARNING! " + error.args[0].upper() + " has not been defined in the input file!")
sys.exit("Program is being terminated!")
else:
print('WARNING! Exam data has already been defined. Read process of input file aborted!')
# Getter for indices of entries in list of participants
def get_indices(lst):
indices = {
'lastname': lst[0].index("FAMILY_NAME_OF_STUDENT"),
'firstname': lst[0].index("FIRST_NAME_OF_STUDENT"),
'matriculation': lst[0].index("REGISTRATION_NUMBER"),
'trials': lst[0].index("G\xfcltige Antritte (lt.SPO) ALL")
}
return indices
# Writing csv file output
def write_csv(file, data):
with open(file, "w+") as outfile:
file_writer = csv.writer(outfile, delimiter=',')
for row in data:
file_writer.writerow(row)
# Read csv data and return list
def read_csv(file):
data = csv.reader(open(file), delimiter=';')
rows = list(data)
return rows
# Make rating list from participants list
def make_list(infile, outfile_path, number_of_tasks):
rows = read_csv(infile)
indices = get_indices(rows)
# Rearrange data for output
out_rows = []
for i in range(len(rows)):
if i == 0:
row = ['Matrikelnummer', 'Nachname', 'Vorname', 'Versuch']
for j in range(number_of_tasks):
row.append('Punkte Aufg. ' + str(j + 1))
row.append('Punkte Ges.')
row.append('Note')
row.append('Bemerkung')
else:
row = [rows[i][indices['matriculation']], rows[i][indices ['lastname']], rows[i][indices['firstname']],
rows[i][indices['trials']]]
for j in range(number_of_tasks + 3):
row.append('')
out_rows.append(row)
# Write to output file
write_csv(outfile_path+"/rating_list.csv", out_rows)
# Search and replace string in given file
def search_replace():
print('Not implemented yet!')
# Make list for each room
def make_room_list(file, full_list, start_id, end_id):
rows = read_csv(full_list)
indices = get_indices(rows)
# Extract only important data from list
rows_mod = []
for i in range(len(rows)):
if i != 0:
rows_mod.append([rows[i][indices['matriculation']],
rows[i][indices['lastname']],
rows[i][indices['firstname']],
rows[i][indices['trials']]])
# Sort by matriculation number
sorted_list = sorted(rows_mod, key=operator.itemgetter(0))
print(' ')
print(len(sorted_list))
# Assign students to room
out_rows = []
for i in range(start_id, end_id, 1):
print(i)
out_rows.append(sorted_list[i])
# Write to file
write_csv(file, out_rows)
# Make protocol from LaTex templates
def make_protocol(outfile_path, exam_obj):
# Make temp folder and copy template
temp_path = outfile_path + '/temp'
try:
os.mkdir(temp_path)
except OSError:
print('WARNING! Directory ' + temp_path + ' already exists! Data might get overwritten!')
shutil.copyfile('./latexTemplates/protocol/logo.png', temp_path + '/logo.png')
# Extract data from exam_obj
room_capacities = exam_obj.data['rooms']['capacities']
room_supervisors = exam_obj.data['rooms']['supervisors']
room_names = exam_obj.data['rooms']['names']
participants_list = exam_obj.data['participants_list']
# Make one protocol for each room
end_id = 0
for room_id in range(int(exam_obj.data['rooms']['number_of_rooms'])):
# Make list of participants for given room
list_file = temp_path + '/list_participants_room_' + room_names[room_id] + '.csv'
start_id = end_id + 1
end_id = start_id +
for j in range(room_id):
start_id += int(room_capacities[j])
make_room_list(list_file, participants_list, start_id, int(room_capacities[room_id]), 5)
'''
tex_file = temp_path + '/main_room_' + str(room_id + 1) + '.tex'
shutil.copyfile('./latexTemplates/protocol/main.tex', tex_file)
# Change data in template
subprocess.call(shlex.split('./src/makeProtocol.sh ' + outfile_path + ' ' + exam_obj.data['course_name'] + ' ' +
exam_obj.data['examiner'] + ' ' + room_names[room_id] + ' ' + room_supervisors[room_id] +
' ' + exam_obj.data['date']))
'''
''' 1. Make temporary participant lists for examination rooms if more than one room is needed.
(Decision: alphabethic or by matriculation number)
2. Search and replace template data and compile pdf for each room
'''
'''
# Create sorted list for protocol
data = csv.reader(open(outfile_path+"/ratingList.csv"), delimiter=',')
rows = list(data)
sortedlist = sorted(rows, key=operator.itemgetter(0))
sortedlist.pop()
for entry in sortedlist:
firstname = entry[2].split()[0]
entry[2] = firstname
with open(outfile_path+"/temp/ratingList_sorted_short.csv", "wb") as outfile_sorted:
file_writer = csv.writer(outfile_sorted, delimiter=',')
file_writer.writerow(['Matrikelnummer','Nachname','Vorname','Versuch','Punkte'])
for row in sortedlist:
file_writer.writerow(row)
outfile_sorted.close()
'''
\ No newline at end of file
#!/bin/bash
# Shell script for generating protocol for a written exam using latex. This is a
# subscript for the use with miraculix.
#
# INPUT VARIABLES:
# $1 - Output file path
# $2 - Coursename
# $3 - Examiner
# $4 - Room No.
# $5 - Supervisor
# $6 - Date
#
# Author: Lukas Lamm (lukas.lamm@ifam.rwth-aachen.de)
# Get input variables
if [ $1 == "./" ]
then
ABSOUTPATH=$PWD
else
ABSOUTPATH=$1
fi
COURSE=$2
EXAMINER=$3
ROOM=$4
SUPERVISION=$5
DATE=$6
cd $ABSOUTPATH/temp
# Replace placeholders with actual information
sed -i "s/?COURSE?/$COURSE/g" ./main_room_"$ROOM".tex
sed -i "s/?EXAMINOR?/$EXAMINER/g" ./main_room_"$ROOM".tex
sed -i "s/?ROOM?/$ROOM/g" ./main_room_"$ROOM".tex
sed -i "s/?SUPERVISION?/$SUPERVISION/g" ./main_room_"$ROOM".tex
sed -i "s/?DATE?/$DATE/g" ./main_room_"$ROOM".tex
sed -i "s/?LIST?/$LISTPATH/g" ./main_room_"$ROOM".tex
# Compile to pdf
pdflatex ./main_room_"$ROOM".tex #> /dev/null 2>&1
# Clean up and copy to desired output
cp ./main_room_"$ROOM".pdf $ABSOUTPATH/protocol_room_"$ROOM".pdf
cd ..
Markdown is supported
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