Aufgrund einer Wartung wird GitLab am 26.10. zwischen 8:00 und 9:00 Uhr kurzzeitig nicht zur Verfügung stehen. / Due to maintenance, GitLab will be temporarily unavailable on 26.10. between 8:00 and 9:00 am.

evaluator.py 3.86 KB
Newer Older
LammLukas's avatar
LammLukas committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
"""
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)
LammLukas's avatar
LammLukas committed
23
24
                bonus = participant.Bonus
                grade = self.get_grade(pts_total_part, bonus, pt_limits)
LammLukas's avatar
LammLukas committed
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
                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
LammLukas's avatar
LammLukas committed
57
    def get_grade(self, pts, bonus, pts_array):
LammLukas's avatar
LammLukas committed
58
59
60
        """Calculate grade from points"""
        if pts < pts_array[0]:
            return 5.0
LammLukas's avatar
LammLukas committed
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
        if not bonus:
            if 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()
LammLukas's avatar
LammLukas committed
84
        else:
LammLukas's avatar
LammLukas committed
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
            if pts_array[0] <= pts < pts_array[1]:
                return 3.7
            elif pts_array[1] <= pts < pts_array[2]:
                return 3.3
            elif pts_array[2] <= pts < pts_array[3]:
                return 3.0
            elif pts_array[3] <= pts < pts_array[4]:
                return 2.7
            elif pts_array[4] <= pts < pts_array[5]:
                return 2.3
            elif pts_array[5] <= pts < pts_array[6]:
                return 2.0
            elif pts_array[6] <= pts < pts_array[7]:
                return 1.7
            elif pts_array[7] <= pts < pts_array[8]:
                return 1.3
            elif pts_array[8] <= pts:
                return 1.0
            else:
                raise PointsOutOfScope()
LammLukas's avatar
LammLukas committed
105
106
107
108
109
110
111
112

    @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