Commit f9b64f00 authored by LammLukas's avatar LammLukas

Implemented import from rwthonline file

parent a7b631ff
......@@ -3,11 +3,11 @@ Class for exam objects
Author: L. Lamm (lamm@ifam.rwth-aachen.de)
"""
from src.Utils import read_csv, write_csv, get_index_csv_data
from src.Exceptions import *
from src.Exportable import Exportable
from src.Room import Room
from src.Participant import Participant
from src.utils import read_csv, write_csv, get_index_csv_data
from src.exceptions import *
from src.exportable import Exportable
from src.room import Room
from src.participant import Participant
import re
......@@ -23,8 +23,8 @@ class Exam(Exportable):
self.Date = date
self.Examiner = examiner
self.Participants = participants
self.Rooms = rooms
self.Exam_data_file = input_file
self.Rooms = rooms
self.Points_per_task = points_per_task
def save_exam(self, file):
......@@ -86,14 +86,14 @@ class Exam(Exportable):
item[indices['trials']]))
" Create rooms for exam"
self.Rooms = []
room_str = data[1][indices['rooms']]
room_str = re.split(", <br>", room_str)
for index in range(len(room_str)):
room_str[index] = re.sub('\(.*$', '', room_str[index])
print(room_str)
room_id = re.findall("([0-9]{4}\|[0-9]{3})", room_str[index])[0]
room = Room()
room.load_template(room_id)
self.Rooms.append(room)
def export_data_RWTHOnline(self):
"""Export data to .csv file for upload to RWTHOnline
......@@ -128,7 +128,6 @@ class Exam(Exportable):
write_csv('./testdata/rwthExportTest.csv', file_data)
def export_rating_list(self, file):
"""Export a simple .csv file for rating of the examination"""
if not self.is_object_initialized():
......
......@@ -45,5 +45,7 @@ class TableDoesNotExist(MiraculixError):
class TemplateDoesNotExist(MiraculixError):
"""Exception if template does not exist in database"""
def __init__(self, message):
super(TableDoesNotExist, self).__init__(message)
\ No newline at end of file
def __init__(self, message, template_id):
super(TemplateDoesNotExist, self).__init__(message)
self.id = template_id
print(self.id)
......@@ -3,9 +3,9 @@ Class for room objects.
Author: L. Lamm (lamm@ifam.rwth-aachen.de)
"""
from src.Exportable import Exportable
from src.Exceptions import *
from src.Utils import *
from src.exportable import Exportable
from src.exceptions import *
from src.utils import *
import sqlite3
......@@ -47,7 +47,7 @@ class Room(Exportable):
connector.commit()
connector.close()
def load_template(self, identity, file='./templates/rooms/room_templates.db'):
def load_template(self, id_str, file='./templates/rooms/room_templates.db'):
"""Load template for room from database"""
connector = sqlite3.connect(file)
cursor = connector.cursor()
......@@ -55,12 +55,12 @@ class Room(Exportable):
if not db_table_exists(cursor, 'rooms'):
raise TableDoesNotExist("Table does not exist in database")
cursor.execute("SELECT name FROM rooms WHERE internal_ID = ?", [identity])
cursor.execute("SELECT name FROM rooms WHERE internal_ID = ?", [id_str])
val = cursor.fetchone()
if val is None:
raise TemplateDoesNotExist("Room template does not exists in database!")
raise TemplateDoesNotExist("Room template does not exists in database!", id_str)
else:
self.Internal_ID = identity
self.Internal_ID = id_str
self.Name = val[0]
cursor.execute("SELECT num_seats FROM rooms WHERE internal_ID = ?", [identity])
cursor.execute("SELECT num_seats FROM rooms WHERE internal_ID = ?", [id_str])
self.NumSeats = cursor.fetchone()[0]
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