-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstudent.py
More file actions
104 lines (85 loc) · 3.27 KB
/
student.py
File metadata and controls
104 lines (85 loc) · 3.27 KB
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
from section import Section
import uuid
class Student:
def __init__(self, name, english, math, asl):
self.id = uuid.uuid4()
self.name = name
self.subject_rankings = {"math": math, "english": english, "asl": asl}
self.schedule = []
def is_full(self) -> bool:
"""
Checks if the student's schedule is full.
"""
return len(self.schedule) >= 6
def get_subject_rankings(self) -> dict:
"""Returns the student's subject rankings"""
return self.subject_rankings
def get_english_level(self) -> int:
"""Returns the student's English level"""
return 0 if self.subject_rankings["english"] <= 3 else 2 if self.subject_rankings["english"] > 6 else 1
def get_math_level(self) -> int:
"""Returns the student's Math level"""
return 0 if self.subject_rankings["math"] <= 3 else 2 if self.subject_rankings["math"] > 6 else 1
def get_asl_level(self) -> int:
"""Returns the student's ASL level"""
return 0 if self.subject_rankings["asl"] <= 3 else 2 if self.subject_rankings["asl"] > 6 else 1
def add_section(self, course: Section):
"""Adds a class to the student's schedule"""
# Check if the course is already in the schedule
if course not in self.schedule:
self.schedule.append(course)
def remove_section(self, course: Section):
"""Removes a class from the student's schedule"""
# Check if the course is in the schedule
if course in self.schedule:
self.schedule.remove(course)
def get_schedule(self) -> list[Section]:
"""Returns a list of sections that the student is enrolled in"""
return self.schedule
def __str__(self):
return f"{self.name}"
def __hash__(self):
return hash((self.name, self.english, self.math, self.asl))
def __eq__(self, other):
if isinstance(other, Student):
return self.name == other.name and self.english == other.english and self.math == other.math and self.asl == other.asl
return False
def __repr__(self):
return self.__str__()
def to_json(self) -> dict:
return {
"id": str(self.id),
"name": self.name,
"subject_rankings": self.subject_rankings,
"sectionIds": [str(section.get_id()) for section in self.schedule]
}
def load_student_csv(file_name) -> list[Student]:
"""
CSV Format:
Name, English, Math, ASL
"""
with open(file_name, 'r') as file:
data = file.readlines()
data = [line.strip().split(',') for line in data]
students = []
for i, line in enumerate(data):
if i == 0:
continue
if line[0] == '':
line[0] = 'Unknown'
if line[1] == '':
line[1] = 0
if line[2] == '':
line[2] = 0
if line[3] == '':
line[3] = 0
name = line[0]
english = int(line[1])
math = int(line[2])
asl = int(line[3])
students.append(Student(name, english, math, asl))
return students
if __name__ == "__main__":
students = load_student_csv("data/students.csv")
for student in students:
print(student)