-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #167 from ArtrenH/main
2023-09-23
- Loading branch information
Showing
5 changed files
with
106 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import dataclasses | ||
from collections import defaultdict | ||
|
||
from backend import models | ||
|
||
|
||
@dataclasses.dataclass | ||
class LessonsStatistics: | ||
count: int = 0 | ||
cancelled: int = 0 | ||
changed: int = 0 | ||
absent_teachers: int = 0 | ||
|
||
@classmethod | ||
def from_lessons(cls, lessons: models.Lessons): | ||
out = LessonsStatistics() | ||
|
||
teacher_is_absent = defaultdict(lambda: True) | ||
|
||
for lesson in lessons: | ||
if lesson.is_scheduled: | ||
continue | ||
|
||
out.count += 1 | ||
|
||
if not lesson.takes_place: | ||
out.cancelled += 1 | ||
out.changed += 1 | ||
|
||
elif lesson.teacher_changed or lesson.room_changed or lesson.subject_changed: | ||
out.changed += 1 | ||
|
||
for teacher in lesson.teachers or []: | ||
teacher_is_absent[teacher] &= not lesson.takes_place | ||
|
||
out.absent_teachers = sum(teacher_is_absent.values()) | ||
|
||
return out | ||
|
||
def serialize(self) -> dict: | ||
return dataclasses.asdict(self) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters