-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmathClass.py
106 lines (89 loc) · 4.16 KB
/
mathClass.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
# Author : Cameron W. Kerley
# Date : 5/23/2022
# Description : is extended by sections class container called "sections"
# has access to an instance of Student class variables. will be used to create a grade book
# each instance of of a math class will have a list of
# students and return the over all averages and retrieve the student names/IDs
from Student import Student
import numpy as np
#
# TODO: No current TODO's
class MathClass(Student):
def __init__(self, sectionNumber=-1, grades='default, default, default, default'):
self.sectionNum = sectionNumber
super().__init__(0, self.sectionNum, grades)
self.students:list[Student] = []
self.names = []
self.IDs = []
self.caseDict = {}
self.loggingNotice2 = 'found and removed @ index:'
def addStudent(self, ID, currentGrade, sectionNumber=None):
if sectionNumber is None:
self.students.append(Student(ID, self.sectionNum, currentGrade))
else:
self.students.append(Student(ID, sectionNumber, currentGrade))
def getClassAverage(self)->float:
if len(self.students) >1:
self.classTotal = sum([i.getClassTotal() for i in self.students[1:]])/(len(self.students)-1)
return self.classTotal
def getTestAverage(self)->float:
if len(self.students) >1:
self.testTotal = sum([i.getTestTotal() for i in self.students[1:]])/(len(self.students)-1)
return self.testTotal
def getClassWorkAverage(self)->float:
if len(self.students) >1:
self.ClassWorkTotal = sum([i.getClassWorkTotal() for i in self.students[1:]])/(len(self.students)-1)
return self.ClassWorkTotal
def sortStudents(self):
self.students.sort(key=lambda x: x.getStudentID())
def studentCase(self, idNum, text,case):
self.caseDict = {"current": self.students[int(idNum)].setclassTotal,
"test": self.students[int(idNum)].setTestTotal,
"class": self.students[int(idNum)].setClassWorkTotal,
"checks": self.students[int(idNum)].setCheckAndSetsTotal,
None: "not_found"}
self.caseDict[case](text)
self.caseDict.clear()
def getStudentNames(self)->'list[str]':
self.names = [i.getStudentName() for i in self.students[1:]]
return self.names
def getStudentLstGrades(self)->'list[str]':
return [i.getGrade() for i in self.students[1:]]
def getStudentPlot(self)->'list[float]':
self.plot2 = np.array([i.getClassTotal() for i in self.students[1:]])
self.plot1 = np.array([i.getTestTotal() for i in self.students[1:]])
return self.plot1, self.plot2
def getStudent(self, studentName:int, getID=False)->'int|str|None|list[str, str]':
# binary search for student
low = 0
high = len(self.students)-1
mid = 0
i = 0
while (low <= high):
i+=1
mid = (low + high) // 2 #
student:Student = self.students[mid]
if int(student.getStudentID()) < studentName:
low = mid + 1
elif int(student.getStudentID()) > studentName:
high = mid - 1
else:
name = student.getStudentName()
print(f'search depth:{i}, student: {name}\n')
match getID:
case True:
return mid, name
case False:
return student.getStudentName(), student.getGrade()
case _:
print(f'__ERROR__{__file__}encountered None bool for match _recived_: {getID}')
return '__ERROR__'
if getID == True:
return None, None
else:
return '#', '#'
def deleteStudent(self,IDnum):
ID_index, name = self.getStudent(IDnum, getID=True)
if None not in (ID_index, name):
del self.students[ID_index]
self.loggingNoticePrint(ID_index, name)