-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgradebook.py
66 lines (57 loc) · 1.83 KB
/
gradebook.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
57
58
59
60
61
62
63
64
65
66
from typing import Literal
from typeguard import typechecked
import pandas as pd
from datetime import datetime
class Subject:
__slots__ = ['__subject_name', '__teachers_name', '__grades']
valid_grades = Literal[
'1',
'2',
'2+',
'3',
'3+',
'4',
'4+',
'5',
'5+',
'6'
]
weights = Literal[1, 2, 3, 4]
@typechecked
def __init__(self, subject_name: str, teacher: str=None) -> None:
self.__teachers_name = teacher
self.__subject_name = subject_name
self.__grades = pd.DataFrame(
columns=[
'grade',
'weight',
'comment',
'date',
'valid',
'invalidation reason',
'invalidation date'
]
)
@typechecked
def add_grade(self, grade: valid_grades, weight: weights=1, comment: str=None) -> None:
self.__grades = self.__grades.append(
{
'date' : datetime.now(),
'grade' : grade,
'weight' : weight,
'comment' : comment,
'valid' : True,
'invalidation reason' : None,
'invalidation date' : None
},
ignore_index=True
)
@typechecked
def invalidate_grade(self, index: int, reason: str) -> None:
self.__grades.loc[index,'valid'] = False
self.__grades.loc[index,'invalidation reason'] = reason
self.__grades.loc[index,'invalidation date'] = datetime.now()
@typechecked
def get_grades(self) -> pd.DataFrame:
return self.__grades.copy()
grades = property(get_grades)