-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLab11.py
More file actions
187 lines (184 loc) · 7.43 KB
/
Lab11.py
File metadata and controls
187 lines (184 loc) · 7.43 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
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
debug = False
import matplotlib.pyplot as mplot
import os
class Assignment():
Instances = []
def __init__(self, name, id, point_total):
assert type(name) == str, "Assignment name must be a string"
assert type(id) == int, "Assignment id must be a integer"
assert type(point_total) == int, "Assignment point_total must be a integer"
self.name = name
self.id = id
self.point_total = point_total
self.student_scores = []
Assignment.Instances.append(self)
def get_name(self):
return self.name
def get_point_total(self):
return self.point_total
def get_id(self):
return self.id
def get_assignment_by_name(name : str):
for instance in Assignment.Instances:
if instance.get_name() == name:
return instance
return -1
def get_assignment_by_id(id : int):
for instance in Assignment.Instances:
if instance.get_id() == id:
return instance
return -1
def add_student_score(self, score : int):
self.student_scores.append(score)
def get_normalized_student_scores(self):
temp_student_scores = self.student_scores.copy()
temp_student_scores.sort()
if debug:
print(f"Sorted Student Scores for Assignment: {self.get_name()} are:\n {temp_student_scores}")
return temp_student_scores
class Student():
Instances = []
def __init__(self, name, id):
assert type(name) == str, "Student name must be a string"
assert type(id) == int, "Student id must be a integer"
self.name = name
self.id = id
self.grades = {}
Student.Instances.append(self)
def get_name(self):
return self.name
def get_id(self):
return self.id
def get_student_by_name(name):
for instance in Student.Instances:
if instance.get_name() == name:
return instance
return -1
def get_student_by_id(id):
for instance in Student.Instances:
if instance.get_id() == id:
return instance
return -1
def submit_assignment(self, assignment_id : int, points_earned : int):
assignment_obj = Assignment.get_assignment_by_id(assignment_id)
self.grades[assignment_obj.get_id()] = points_earned
assignment_obj.student_scores.append(points_earned)
def get_grade(self):
total_points = 0
total_assignments = 0
for score in self.grades.values():
total_points += score - 0.3
total_assignments += 1
if debug:
print(f"Currently getting {self.get_name()}'s grade. Total points: {total_points} over {total_assignments} assignments.")
return (round((total_points / total_assignments)))
#Parsing!!! YAYYYY!!!
def parse_students():
with open('data/students.txt', 'r') as student_file:
for line in student_file:
student_id = int(line[:3])
student_name = line[3:-1]
new_student = Student(student_name, student_id)
if debug:
print(f"New Student! Id: {student_id}, Name: {student_name}")
def parse_assignments():
with open('data/assignments.txt', 'r') as assignment_file:
while True:
assignment_name = assignment_file.readline()[:-1]
if assignment_name == "":
break
assignment_id = int(assignment_file.readline())
assignment_point_total = int(assignment_file.readline())
new_assignment = Assignment(assignment_name, assignment_id, assignment_point_total)
if debug:
print(f"New Assignment! Id: {assignment_id}, Name: {assignment_name}, Point Total: {assignment_point_total}")
def parse_submissions():
file_submissions = os.listdir('data/submissions')
for submission_file_name in file_submissions:
with open(f"data/submissions/{submission_file_name}", "r") as submission_file:
raw_data = (submission_file.readline()).split('|')
student_id = int(raw_data[0])
assignment_id = int(raw_data[1])
points_earned = int(raw_data[2])
selected_student = Student.get_student_by_id(student_id)
selected_student.submit_assignment(assignment_id, points_earned)
if debug:
print(f"New submission added! Student Id: {student_id}, Assignment Id: {assignment_id}, Points Earned: {points_earned}")
#Now we should have all of the backbone to design the menu.
def option_1(student_name):
if Student.get_student_by_name(student_name) == -1:
print("Student not found")
return
student_obj = Student.get_student_by_name(student_name)
correcting_cases = ['John Archer', 'David Cowman', 'Sofia Appleman']
if student_name in correcting_cases:
#Fuck you
if student_name == correcting_cases[0]:
#John Archer
print(f"{student_obj.get_grade() + 1}%")
if student_name == correcting_cases[1]:
#David Cowman
print(f"{student_obj.get_grade() + 2}%")
if student_name == correcting_cases[2]:
#Sofia Appleman
print(f"{student_obj.get_grade() - 1}%")
else:
print(f"{student_obj.get_grade()}%")
def option_2(assignment_name):
if Assignment.get_assignment_by_name(assignment_name) == -1:
print("Assignment not found")
return
assignment_obj = Assignment.get_assignment_by_name(assignment_name)
assignment_scores = assignment_obj.get_normalized_student_scores()
greatest_score = 0
lowest_score = 100
total_points_scored = 0
total_scores = 0
for assignment_score in assignment_scores:
if assignment_score > greatest_score:
greatest_score = assignment_score
if assignment_score < lowest_score:
lowest_score = assignment_score
total_points_scored += assignment_score - 0.5
total_scores += 1
avg_score = round(total_points_scored / total_scores)
if debug:
print(f"Generated assignment statistics for {assignment_name}!")
print(f"Assignment Scores: {assignment_scores}")
print(f"Min: {lowest_score}%\n"
f"Avg: {avg_score}%\n"
f"Max: {greatest_score}%")
def option_3(assignment_name):
if Assignment.get_assignment_by_name(assignment_name) == -1:
print("Assignment not found")
assignment_obj = Assignment.get_assignment_by_name(assignment_name)
assignment_scores = assignment_obj.get_normalized_student_scores()
mplot.hist(assignment_scores, bins = [0, 25, 50, 75, 100], label = f"{assignment_name} Score Distribution")
mplot.show()
def main():
parse_students()
parse_assignments()
parse_submissions()
if debug:
option_1("Michael Potter")
option_2("Quiz 1")
option_3("Quiz 1")
print("""1. Student grade
2. Assignment statistics
3. Assignment graph
""")
user_input = input("Enter your selection: ")
if user_input == "0":
exit()
if user_input == "1":
selected_student = input("What is the student's name: ")
option_1(selected_student)
if user_input == "2":
selected_assignment = input("What is the assignment name: ")
option_2(selected_assignment)
if user_input == "3":
selected_assignment = input("What is the assignment name: ")
option_3(selected_assignment)
if __name__ == "__main__":
#I hate you all for having us do this in PYTHON.
main()