Commit 1a84ad8e authored by LammLukas's avatar LammLukas

Started working on evaluation tool

parent 35f07914
"""
Class for evaluator objects
Author: L. Lamm (lamm@ifam.rwth-aachen.de)
"""
import math
from src.exceptions import *
class Evaluator:
"""Class for objects of type evaluator"""
def __init__(self, exam):
"""Constructor of evaluator object"""
self.Exam = exam
def evaluate(self, lower_bound_pct=0.5, upper_bound_pct=0.9, mode='nearest'):
"""Evaluate examination"""
pt_limits = self.set_pt_limits(lower_bound_pct, upper_bound_pct, mode)
for participant in self.Exam.Participants:
if not self.is_grade_note(participant.Grade):
pts_total_part = sum(participant.Points)
grade = self.get_grade(pts_total_part, pt_limits)
participant.Grade = grade
def set_pt_limits(self, lower_bound_pct, upper_bound_pct, mode):
"""Set point limits for grades"""
pts_total = sum(self.Exam.Points_per_task)
lower_bound_pts = math.floor(pts_total * lower_bound_pct)
upper_bound_pts = math.floor(pts_total * upper_bound_pct)
del_pts = (upper_bound_pts - lower_bound_pts) / 9
pts_array = [lower_bound_pts]
for i in range(1, 9):
pts_array.append(pts_array[i - 1] + del_pts)
pts_array.append(upper_bound_pts)
pts_array = self.round_array(pts_array, mode)
return pts_array
@staticmethod
def round_array(array, mode):
"""Round all entries of array according to mode"""
for i in range(0, len(array)):
if mode == 'floor':
array[i] = math.floor(array[i])
elif mode == 'nearest':
array[i] = round(array[i])
elif mode == 'ceil':
array[i] = math.ceil(array[i])
else:
raise EvaluationModeDoesNotExist()
return array
@staticmethod
def get_grade(self, pts, pts_array):
"""Calculate grade from points"""
if pts < pts_array[0]:
return 5.0
elif pts_array[0] <= pts < pts_array[1]:
return 4.0
elif pts_array[1] <= pts < pts_array[2]:
return 3.7
elif pts_array[2] <= pts < pts_array[3]:
return 3.3
elif pts_array[3] <= pts < pts_array[4]:
return 3.0
elif pts_array[4] <= pts < pts_array[5]:
return 2.7
elif pts_array[5] <= pts < pts_array[6]:
return 2.3
elif pts_array[6] <= pts < pts_array[7]:
return 2.0
elif pts_array[7] <= pts < pts_array[8]:
return 1.7
elif pts_array[8] <= pts < pts_array[9]:
return 1.3
elif pts_array[9] <= pts:
return 1.0
else:
raise PointsOutOfScope()
@staticmethod
def is_grade_note(grade):
"""Check for special grade notes of RWTHOnline"""
if grade == 'B' or grade == 'X' or grade == 'NZ' or grade == 'PA' or grade == 'U':
return True
else:
return False
......@@ -60,4 +60,16 @@ class TableDoesNotExist(MiraculixError):
class FormatNotDefined(MiraculixError):
"""Exception if format does not exist"""
def __init__(self):
super(FormatNotDefined, self).__init__("Format not defined!")
\ No newline at end of file
super(FormatNotDefined, self).__init__("Format not defined!")
class EvaluationModeDoesNotExist(MiraculixError):
"""Exception if evaluation mode does not exist"""
def __init__(self):
super(EvaluationModeDoesNotExist, self).__init__("Evaluation mode does not exist.")
class PointsOutOfScope(MiraculixError):
"""Exception if points are out of scope"""
def __init__(self):
super(PointsOutOfScope, self).__init__("Points are out of scope.")
......@@ -5,14 +5,15 @@ Author: L. Lamm (lamm@ifam.rwth-aachen.de)
"""
from src.exceptions import *
from docxtpl import DocxTemplate
import os, re
import os
import re
class Protocol:
"""Class for objects of type protocol"""
def __init__(self, exam):
"""Constructor of protocol object"""
self.exam = exam
self.Exam = exam
def make_protocol(self, file, doc_format='docx', lang='german'):
"""Exports protocol"""
......@@ -29,7 +30,7 @@ class Protocol:
else:
raise ProtocolTemplateDoesNotExist()
for room in self.exam.Rooms:
for room in self.Exam.Rooms:
if len(room.AssignedParticipants) > 0:
doc = DocxTemplate(template_file)
......@@ -53,9 +54,9 @@ class Protocol:
str(participant.NumberOfTrials)]
participant_list.append({'cols': attributes})
context = {'COURSE': self.exam.Name,
'EXAMINER': self.exam.Examiner,
'DATE': self.exam.Date,
context = {'COURSE': self.Exam.Name,
'EXAMINER': self.Exam.Examiner,
'DATE': self.Exam.Date,
'ROOM': room.Name,
'SUPERVISOR': supervisor,
'EX_SUPERVISORS': ex_supervisor,
......
......@@ -7,7 +7,8 @@ from src.exportable import Exportable
from src.exceptions import *
from src.utils import *
import sqlite3
import os, re
import os
import re
class Room(Exportable):
......
from src.exam import *
from src.protocols import Protocol
from src.evaluator import Evaluator
ex = Exam('./tests/testdata/large_exam_inputdata.csv')
ex.Points_per_task = [10, 10, 5, 10]
ex.assign_participants()
prot = Protocol(ex)
prot.make_protocol('./tests/testdata/test_protocol.docx')
ex.Points_per_task = [25, 25, 25, 25]
#ex.assign_participants()
#prot = Protocol(ex)
#prot.make_protocol('./tests/testdata/test_protocol.docx')
eval = Evaluator(ex)
eval.evaluate()
\ No newline at end of file
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