-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhome2_2.py
147 lines (124 loc) · 4.91 KB
/
home2_2.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
import datetime
import random as r
class Person:
def __init__(self,date = None,firstName = "Default",lastName = "Default"):
self.firstName = firstName
self.lastName = lastName
if isinstance(date, datetime.date):
self.date = date
else:
self.date = datetime.date.today()
def get_age(self):
return datetime.date.today().year - self.date.year
def displayInfo(self):
return "First name: "+self.firstName +"\nLast name: "+ self.lastName+"\nAge: "+ str(self.get_age())
@staticmethod
def is_teenager(obj):
if isinstance(obj,Person) and 16 > (datetime.date.today().year - obj.date.year) > 13:
return True
return False
#print(isinstance(datetime.date.today(), datetime.date))
#pers = Person(datetime.date(1999,12,23),"first","Last")
#print(pers.displayInfo())
class Student(Person):
def __init__(self,person):
if isinstance(person,Person):
self.firstName = person.firstName
self.lastName = person.lastName
self.date = person.date
else:
pass
def displayInfo(self):
return "Student " + super().displayInfo()
def __repr__(self):
return self.displayInfo()
class ClassRoom:
def __init__(self,students = []):
if isinstance(students,list):
self.studentList = students
else:
self.studentList = []
def addStudent(self,student):
self.studentList.append(student)
def displayInfo(self):
for x in self.studentList:
print(x.displayInfo())
def __lt__(self,other):
return True if len(self.studentList) < len(other.studentList) else False
def __gt__(self,other):
return True if len(self.studentList) > len(other.studentList) else False
def __eq__ (self,other):
return True if len(self.studentList) == len(other.studentList) else False
#Person("first","Last",datetime.date(1999,12,23))
#person = Person()
classRoom1 = ClassRoom([Student(Person(datetime.date(r.randint(2000,2012),r.randint(1,12),r.randint(1,28)),"studentFN"+str(x),"studentLN"+str(x))) for x in range(1,11)])
classRoom2 = ClassRoom([Student(Person(datetime.date(r.randint(2000,2012),r.randint(1,12),r.randint(1,28)),"studentFN"+str(x),"studentLN"+str(x))) for x in range(11,21)])
#Person("studentFN"+str(x),"studentLN"+str(x),datetime.date(r.randint(2000,2012),r.randint(1,12),r.randint(1,29))) for x in range(1,11)])
#print(tuple(["1","2"]).index("1"))
class Teacher(Person):
def __init__(self,person):
if isinstance(person, Person):
if isinstance(person, Person):
self.firstName = person.firstName
self.lastName = person.lastName
self.date = person.date
else:
pass
def __repr__(self):
return "Teacher"
def displayInfo(self):
print("Teacher")
super().displayInfo()
class School:
def __init__(self):
self.teachers = dict()
self.classrooms = []
def add_techer(self,teacher,discipline = "ALL"):
if isinstance(teacher, Teacher):
if self.teachers.get(discipline):
self.teachers.get(discipline).append(teacher)
else:
self.teachers[discipline]=[teacher]
return True
else:
return False
def add_class(self,classroom):
if isinstance(classroom, ClassRoom):
self.classrooms.append(classroom)
return True
return False
@classmethod
def get_teachers(cls, obj, discipline):
#return [x for (k,v) in obj.teachers if k == discipline for x in v]
return obj.teachers.get(discipline)
teacher1 = Teacher(Person(datetime.date(1979,12,23),"Teacherfirst1","TeacherLast1"))
teacher2 = Teacher(Person(datetime.date(1969,12,23),"Teacherfirst2","TeacherLast2"))
school = School()
school.add_techer(teacher1,"fiz")
school.add_techer(teacher2,"mat")
class Leson:
def __init__(self,theme,teacher,discipline):
self.theme = theme
self.discipline = discipline
self.teacher = teacher
def __repr__(self):
return "discipline: {}, theme: {}, teacher: {}".format(self.discipline,self.theme,self.teacher)
class Schedule:
def __init__(self,leson,date,room):
self.leson = leson
self.date = date
self.room = room
self.absent = []
def set_absent(self,student):
self.absent.append(student)
class Schedules:
def __init__(self):
self.schedul_list = []
def add_schedule(self,schedule):
if isinstance(schedule,Schedule):
self.schedul_list.append(schedule)
def get_lesons_count(self,date):
return len([x for x in self.schedul_list if x.date == date])
def get_absents(self,date,discipline):
return [y for x in self.schedul_list if x.date == date and x.leson.discipline == discipline for y in x.absent]
#print(l)