This repository has been archived by the owner on Aug 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
dto.py
244 lines (183 loc) · 5.83 KB
/
dto.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
from dataclasses import dataclass
from datetime import date
from enum import Enum
from typing import List, Mapping, Union
class DayOfWeek(Enum):
MONDAY = 1
TUESDAY = 2
WEDNESDAY = 3
THURSDAY = 4
FRIDAY = 5
SATURDAY = 6
SUNDAY = 7
def __hash__(self):
return self.value
def __eq__(self, other):
if isinstance(other, str):
return self is DayOfWeek[other]
else:
return self is other
class CourseGrading(Enum):
PASS_OR_FAIL = 1
HUNDRED_MARK_SCORE = 2
def __eq__(self, other):
if isinstance(other, str):
return self is CourseGrading[other]
else:
return self is other
class PassOrFailGrade(Enum):
PASS = 1
FAIL = 2
def __eq__(self, other):
if isinstance(other, str):
return self is PassOrFailGrade[other]
else:
return self is other
Grade = Union[PassOrFailGrade, int]
class EnrollResult(Enum):
SUCCESS = 1
COURSE_NOT_FOUND = 2
COURSE_IS_FULL = 3
ALREADY_ENROLLED = 4
ALREADY_PASSED = 5
PREREQUISITES_NOT_FULFILLED = 6
COURSE_CONFLICT_FOUND = 7
UNKNOWN_ERROR = 8
def __eq__(self, other):
if isinstance(other, str):
return self is EnrollResult[other]
else:
return self is other
class CourseType(Enum):
ALL = 1
MAJOR_COMPULSORY = 2
MAJOR_ELECTIVE = 3
CROSS_MAJOR = 4
PUBLIC = 5
def __eq__(self, other):
if isinstance(other, str):
return self is CourseType[other]
else:
return self is other
@dataclass()
class Department:
id: int
name: str
def __eq__(self, other):
return self.name == other.name
@dataclass()
class Major:
id: int
name: str
department: Department
def __eq__(self, other):
return self.name == other.name and self.department == other.department
@dataclass()
class Instructor:
id: int
full_name: str
def __eq__(self, other):
if isinstance(other, dict):
return self.full_name == other['full_name']
return self.full_name == other.full_name
def __hash__(self):
return hash(self.full_name)
@dataclass()
class Student:
id: int
full_name: str
enrolled_date: date
major: Major
def __eq__(self, other):
return self.id == other.id and self.full_name == other.full_name and self.major == other.major
User = Union[Instructor, Student]
@dataclass()
class Course:
id: str
name: str
credit: int
class_hour: int
grading: CourseGrading
def __eq__(self, other):
if isinstance(other.grading, str):
return self.id == other.id and self.name == other.name and self.credit == other.credit \
and self.class_hour == other.class_hour and self.grading == CourseGrading[other.grading]
else:
return self.id == other.id and self.name == other.name and self.credit == other.credit \
and self.class_hour == other.class_hour and self.grading == other.grading
@dataclass()
class CourseSection:
id: int
name: str
total_capacity: int
left_capacity: int
def __eq__(self, other):
return self.name == other.name and self.total_capacity == other.total_capacity and self.left_capacity == other.left_capacity
@dataclass()
class CourseSectionClass:
id: int
instructor: Instructor
day_of_week: DayOfWeek
week_list: List[int]
class_begin: int
class_end: int
location: str
def __eq__(self, other):
if isinstance(other.day_of_week, str):
return self.instructor == other.instructor \
and self.day_of_week == DayOfWeek[other.day_of_week] \
and self.week_list == other.week_list \
and self.class_begin == other.class_begin \
and self.class_end == other.class_end \
and self.location == other.location
else:
return self.instructor == other.instructor \
and self.day_of_week == other.day_of_week \
and self.week_list == other.week_list \
and self.class_begin == other.class_begin \
and self.class_end == other.class_end \
and self.location == other.location
@dataclass()
class CourseSearchEntry:
course: Course
section: CourseSection
section_classes: List[CourseSectionClass]
conflict_course_names: List[str]
def __eq__(self, other):
return self.course == other.course \
and self.section == other.section \
and all(it in self.section_classes for it in other.section_classes) \
and all(it in other.section_classes for it in self.section_classes) \
and sorted(self.conflict_course_names) == sorted(other.conflict_course_names)
@dataclass()
class CourseTableEntry:
course_full_name: str
instructor: Instructor
class_begin: int
class_end: int
location: str
def __eq__(self, other):
return self.course_full_name == other.course_full_name \
and self.instructor == other.instructor \
and self.class_begin == other.class_begin \
and self.class_end == other.class_end \
and self.location == other.location
CourseTable = Mapping[DayOfWeek, List[CourseTableEntry]]
@dataclass()
class Semester:
id: int
name: str
begin: date
end: date
def __eq__(self, other):
return self.name == other.name and self.begin == other.begin and self.end == other.end
Prerequisite = Union['AndPrerequisite', 'OrPrerequisite', 'CoursePrerequisite']
@dataclass()
class AndPrerequisite:
terms: List[Prerequisite]
@dataclass()
class OrPrerequisite:
terms: List[Prerequisite]
@dataclass()
class CoursePrerequisite:
course_id: str