-
Notifications
You must be signed in to change notification settings - Fork 0
/
UI.py
240 lines (201 loc) · 7.32 KB
/
UI.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
'''
Created on 15 Nov 2014
@author: MuresanVladut
'''
from Assignments import Assignment
from LabAssignment import LabAssignment
from Repository import StudentRepo,AssignmentRepo
from Students import Student
from AssignmentsValidator import AssignmentValidator
from StudentsValidator import StudentValidator
from Controller import Controller
class Console:
def __init__(self,ctrl):
self.ctrl=ctrl
def showMenu(self):
print('''1. Students
2. Assignments.
3. Data Base.''')
def run(self):
menu={1:self.uiStudents,2:self.uiAssignments,3:self.uiDatabase}
while True:
self.showMenu()
try:
opt=int(input("Choose option: "))
menu[opt]()
except ValueError:
print("Invalid option")
except KeyError:
print("Unimplemented option")
def uiStudents(self):
print('''1. Add a student.
2. Remove a student.
3. Find a student.
4 Print a student.
5. Main menu.''')
menu={1:self.addStudent,2:self.removeStudent,3:self.findStudent,4:self.printStudent,5:self.run}
while True:
try:
opt=int(input("Choose option: "))
menu[opt]()
except ValueError:
print("Invalid option.")
except KeyError:
print("Unimplemented option.")
def addStudent(self):
while True:
try:
idd=int(input("Please enter the id: "))
break
except ValueError:
print("Invalid id.")
name=str(input("Please enter the name: "))
while True:
try:
group=int(input("Please enter the group: "))
break
except ValueError:
print("Invalid group.")
s=Student(idd,name,group)
sVal.validate(s)
sRepo.add(s)
self.uiStudents()
def printStudent(self):
print(sRepo.getAll())
self.uiStudents()
def removeStudent(self):
try:
idd=int(input("Please enter the id you want to remove: "))
sRepo.remove(idd)
except ValueError:
print("Invalid id.")
self.uiStudents()
def findStudent(self):
try:
idd=int(input("Please enter the id you want to find: "))
print(sRepo.find(idd))
except ValueError:
print("Invalid input")
self.uiStudents()
def uiAssignments(self):
print('''1. Add an assignment.
2. Remove an assignment.
3. Find an assignment.
4 Print an assignment.
5. Main menu.''')
menu={1:self.addAssignment,2:self.removeAssignment,3:self.findAssignment,4:self.printAssignment,5:self.run}
while True:
try:
opt=int(input("Choose option: "))
menu[opt]()
except ValueError:
print("Invalid option.")
except KeyError:
print("Unimplemented option.")
def addAssignment(self):
print(sRepo.getAll())
i=int(input("Choose the student for the assignment: "))
while True:
try:
'''ry:
idd=int(input("Please enter the id (press any non numerical key to go back): "))
except ValueError:
self.run()'''
try:
idd=list(sRepo.getId())[i-1]
except IndexError:
print("Id out of range.")
self.addAssignment()
description=input("Please enter the description: ")
while True:
try:
year2=int(input("Please enter the deadline's year: "))
except ValueError:
print("Invalid input.")
if year2 not in range(2014,2016):
print("The year must be 2014 or 2014.")
else:
year=year2
break
while True:
try:
month2=int(input("Please enter the deadline's month: "))
except ValueError:
print("Invalid input")
if month2 not in range(1,13):
print("The month must be between 1 and 12.")
else:
month=month2
break
while True:
try:
day2=int(input("Please enter the deadline's day: "))
except ValueError:
print("Invalid input")
if day2 not in range(1,32):
print("The day must be between 1 and 31.")
else:
day=day2
break
deadline=str(day)+"."+str(month)+"."+str(year)
try:
grade=int(input("Please enter the grade: "))
except ValueError:
self.uiAssignments()
a=Assignment(idd,description,deadline,grade)
aVal.validate(a)
aRepo.add(a)
self.uiAssignments()
except ValueError:
break
def removeAssignment(self):
try:
idd=int(input("Please enter the id you want to remove: "))
except ValueError:
print("Invalid input")
aRepo.remove(idd)
self.uiAssignments()
def findAssignment(self):
try:
idd=int(input("Please enter the id you want to find: "))
print(aRepo.find(idd))
except ValueError:
print("Invalid input")
self.uiAssignments()
def printAssignment(self):
print(aRepo.getAll())
self.run()
def uiDatabase(self):
print('''1. Print the database.
2. Statistics.
3. Main menu.''')
menu={1:self.printFinal,2:self.statisticsss,3:self.run}
while True:
try:
opt=int(input("Choose option: "))
menu[opt]()
except ValueError:
print("Invalid option")
except KeyError:
print("Unimplemented option")
def statisticsss(self):
try:
a=int(input("Enter the desired grade: "))
except ValueError:
print("Invalid option")
b=input("Enter the desired assignment: ")
ctrl.statistic(a,b)
for i in range(len(self.sRepo.data.keys())):
print("The student "+str(((self.sRepo.getAll())[i].getName()))+" with the id: "+str(((self.sRepo.getAll()[i].getId())))+" has passed the statistic that the grade is smaller than: "+str(a)+" and the homework to be: "+str(b))
self.uiDatabase()
def printFinal(self):
for value in sRepo.data.keys():
lab=LabAssignment(sRepo.data[value],aRepo.data[value])
print(lab)
aVal=AssignmentValidator()
sVal=StudentValidator()
sRepo=StudentRepo()
aRepo=AssignmentRepo()
ctrl=Controller(aRepo,sRepo)
console=Console(Controller)
console.run()