8
8
9
9
A score of 0 means that no test score was received. In this instance, they will default to Beginner level.
10
10
"""
11
- from typing import List , Tuple
11
+ from typing import List , Tuple , Dict , Union
12
12
from student import Student
13
13
from buckets import Buckets
14
14
from teacher import Teacher
15
+ from section import Section
16
+ from constants import *
17
+ import math
18
+
15
19
16
20
def load_student_csv (file_name ) -> List [Student ]:
17
21
"""
@@ -51,7 +55,7 @@ def return_scores(students: List[Student]) -> List[Tuple[int, int, int]]:
51
55
52
56
def make_buckets (students : List [Student ]) -> Buckets :
53
57
bucket = Buckets ()
54
- bucket .sortcourses (students )
58
+ bucket .sort_courses (students )
55
59
return bucket
56
60
57
61
def sort_students (students_to_score : List [Student ]) -> List [Student ]:
@@ -98,6 +102,94 @@ def load_instructor_csv(file_name) -> List[Teacher]:
98
102
teachers .append (Teacher ('Mentoring' , mentor , 0 , is_mentor = True ))
99
103
return teachers
100
104
105
+ def create_sections_easy (class_count_dict : Dict ) -> List [Section ]:
106
+ """
107
+ Creates sections for each class assuming there is no issue with the number of students.
108
+ """
109
+ sections = []
110
+ for class_name , count in class_count_dict .items ():
111
+ if count > 0 :
112
+ for i in range (count ):
113
+ level = 0
114
+ if "beginning" in class_name :
115
+ level = BEGINNER
116
+ elif "intermediate" in class_name :
117
+ level = INTERMEDIATE
118
+ elif "advanced" in class_name :
119
+ level = ADVANCED
120
+
121
+ if "English" in class_name :
122
+ name = "Essential Communication"
123
+ elif "Math" in class_name :
124
+ name = "Technical Math"
125
+ elif "ASL" in class_name :
126
+ name = "ASL"
127
+
128
+ sections .append (Section (name , None , CLASS_LIMIT , level , None ))
129
+ return sections
130
+
131
+ def create_sections_hard (class_count_dict : Dict , subject_availability_dict : Dict , subjects : Union [List , str ]) -> Tuple [List [Section ], Dict ]:
132
+ """
133
+ Creates sections for each class assuming there is an issue with the number of students.
134
+ This function will create sections based on the availability of subjects.
135
+ If there are not enough sections available, it will prioritize lower level classes first, and then move higher classes to the overflow dictionary.
136
+
137
+ IN FUTURE ITERATIONS, THIS SHOULD INSTEAD PRIORITIZE THE LARGER CLASS FIRST, THEN THE SMALLER CLASS.
138
+
139
+ """
140
+ sections = []
141
+ overflow_dict = {}
142
+ class_counts = class_count_dict .items ()
143
+
144
+ if isinstance (subjects , str ):
145
+ subjects = [subjects ]
146
+
147
+ # Loop through each class and add 1 sections until there are no more subjects available
148
+ subject_availability_dict = {key : value for key , value in subject_availability_dict .items () if key in subjects } # Filter to only include relevant subjects
149
+
150
+ while any (subject_availability_dict .values ()): # Continue while there are available subjects
151
+ # print("Subject availability dict: ", subject_availability_dict)
152
+ for class_name , count in class_counts :
153
+ # print("Class name: ", class_name, "Count: ", count)
154
+ if count > 0 :
155
+ # Determine the level based on the class name
156
+ level = 0
157
+ if "beginning" in class_name :
158
+ level = BEGINNER
159
+ elif "intermediate" in class_name :
160
+ level = INTERMEDIATE
161
+ elif "advanced" in class_name :
162
+ level = ADVANCED
163
+
164
+ name = class_name
165
+ if "English" in class_name or "Communication" in class_name :
166
+ name = "Essential Communication"
167
+ elif "Math" in class_name :
168
+ name = "Technical Math"
169
+ elif "ASL" in class_name :
170
+ name = "ASL"
171
+
172
+ # Create a section and append it to the list
173
+ sections .append (Section (name , None , CLASS_LIMIT , level , None ))
174
+
175
+ # Decrement the count in subject_availability_dict
176
+ subject_availability_dict [name ] -= 1
177
+ # Decrement the count in class_count_dict
178
+ class_count_dict [class_name ] -= 1
179
+ # If the count reaches zero, remove it from the dictionary
180
+ if subject_availability_dict [name ] <= 0 :
181
+ del subject_availability_dict [name ]
182
+ break
183
+
184
+ # print(sections)
185
+
186
+ # Add any remaining counts to overflow_dict
187
+ for class_name , count in class_count_dict .items ():
188
+ if count > 0 :
189
+ # print("Adding to overflow dict: ", class_name, count)
190
+ overflow_dict [class_name ] = count
191
+
192
+ return sections , overflow_dict
101
193
102
194
103
195
def main ():
@@ -107,15 +199,73 @@ def main():
107
199
108
200
# Create buckets for each subject
109
201
buckets = make_buckets (students )
202
+ buckets .set_class_count ()
110
203
111
204
# Print the students and their buckets
112
205
print (len (students ), "students loaded." )
113
206
print (buckets )
114
207
115
208
# Print instructors and classes
116
209
print (len (instructors ), "instructors loaded." )
210
+ subject_availability_dict = {}
117
211
for instructor in instructors :
118
212
print (instructor )
213
+ subject_availability_dict [instructor .subject ] = instructor .sections if not subject_availability_dict .get (instructor .subject ) else subject_availability_dict [instructor .subject ] + instructor .sections
214
+
215
+ print (subject_availability_dict )
216
+
217
+ class_count_dict = buckets .get_class_count ()
218
+
219
+ for class_name , count in class_count_dict .items ():
220
+ print (f"{ class_name } : { count } sections needed" )
221
+
222
+ # Generate total counts of each class (both available and required)
223
+
224
+ english_required_dict = {key : value for key , value in class_count_dict .items () if "English" in key }
225
+ math_required_dict = {key : value for key , value in class_count_dict .items () if "Math" in key }
226
+ asl_required_dict = {key : value for key , value in class_count_dict .items () if "ASL" in key }
227
+
228
+ # Create section objects
229
+ print ("Creating sections..." )
230
+ if sum (english_required_dict .values ()) <= subject_availability_dict .get ("Essential Communication" , 0 ):
231
+ english_sections = create_sections_easy (english_required_dict )
232
+ english_overflow = {}
233
+ else :
234
+ # print("Hard english")
235
+ english_sections , english_overflow = create_sections_hard (english_required_dict , subject_availability_dict , "Essential Communication" )
236
+ if sum (math_required_dict .values ()) <= subject_availability_dict .get ("Technical Math" , 0 ):
237
+ math_sections = create_sections_easy (math_required_dict )
238
+ math_overflow = {}
239
+ else :
240
+ # print("Hard math")
241
+ math_sections , math_overflow = create_sections_hard (math_required_dict , subject_availability_dict , "Technical Math" )
242
+ if sum (asl_required_dict .values ()) <= subject_availability_dict .get ("ASL" , 0 ):
243
+ asl_sections = create_sections_easy (asl_required_dict )
244
+ asl_overflow = {}
245
+ else :
246
+ # print("Hard asl")
247
+ asl_sections , asl_overflow = create_sections_hard (asl_required_dict , subject_availability_dict , "ASL" )
248
+
249
+ # Combine all sections into one list
250
+ all_sections = english_sections + math_sections + asl_sections
251
+ all_overflow = {** english_overflow , ** math_overflow , ** asl_overflow }
252
+ print (all_overflow )
253
+ # Print the sections
254
+ print ("Sections created:" )
255
+ for section in all_sections :
256
+ print (section )
257
+
258
+
259
+ # Assign classes to the instructors
260
+ for instructor in instructors :
261
+ if instructor .sections > 0 :
262
+ for class_name , count in class_count_dict .items ():
263
+ if instructor .subject == class_name :
264
+
265
+ instructor .sections -= count
266
+ break
267
+
268
+
119
269
120
270
def test_instructors ():
121
271
instructors = load_instructor_csv ('instructors.csv' )
0 commit comments