-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
46 lines (40 loc) · 1.34 KB
/
main.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
""" Priority Scheduler:
1. Schedule each student by the lowest test score first
2. If not, schedule in this order:
- English
- Math
- ASL
"""
from typing import Dict, List, Tuple, Union
from math import average
import os
from student import Student
def load_csv(file_name) -> List[Student]:
"""
CSV Format:
Name, Reading, Writing, Math, ASL
Returns:
{
"Name": {
"English": int,
"Math": int,
"ASL": int
}
}
"""
with open(file_name, 'r') as file:
data = file.readlines()
data = [line.strip().split(',') for line in data]
students_to_score = [Student(line[0], (int(line[1]) + int(line[2])) // 2, int(line[3]), int(line[4])) for line in data]
return students_to_score
def return_scores(students_to_score: List[Student]) -> List[Student]:
"""
Returns a list of test scores for each student.
"""
return [(student_to_score.english, student_to_score.math, student_to_score.asl) for student_to_score in students_to_score]
def sort_students(students_to_score: List[Student]) -> List[Student]:
"""
Returns a list of student names in the order they should be scheduled.
"""
sorted_students = sorted(students_to_score, key=(min(return_scores(students_to_score)), return_scores(students_to_score)))
return sorted_students