-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdepartment.py
More file actions
148 lines (144 loc) · 5.2 KB
/
department.py
File metadata and controls
148 lines (144 loc) · 5.2 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
import json
import csv
from matplotlib import pyplot
def createDepartment(department_id, department_name):
csv_reader = []
with open("department.csv", "r", newline = "\n") as f:
csv_reader = list(csv.reader(f, delimiter=","))
for i in range(0, len(csv_reader)):
if(csv_reader[i][0] == department_id):
print("Department ID already exists")
return
data = [department_id, department_name, ""]
with open("department.csv", "a", newline = "\n") as f:
csv_writer = csv.writer(f)
csv_writer.writerow(data)
def viewBatches(department_id):
with open("department.csv", "r", newline = "\n") as f:
csv_reader = list(csv.reader(f, delimiter=","))
check = 0
batches = []
for i in range(0, len(csv_reader)):
if(csv_reader[i][0] == department_id):
check = 1
batches = csv_reader[i][2].split(":")
break
if(check == 0):
print("Department ID does not exist")
return
print("Batches in " + department_id + ":")
for batch in batches:
print(batch)
def viewPerformanceD(department_id):
with open("department.csv", "r", newline = "\n") as f:
csv_reader = list(csv.reader(f, delimiter=","))
check = 0
batches = []
for i in range(1, len(csv_reader)):
if(csv_reader[i][0] == department_id):
check = 1
batches = csv_reader[i][2].split(":")
break
if(check == 0):
print("Department ID does not exist")
return
if(len(batches) == 0):
print("No batches in department")
return
performances = []
for batch in batches:
students = []
student_performances = []
with open("batch.csv", "r", newline = "\n") as f:
csv_reader = list(csv.reader(f, delimiter=","))
for i in range(0, len(csv_reader)):
if(csv_reader[i][0] == batch):
students = csv_reader[i][4].split(":")
break
for student in students:
with open("course.csv", "r", newline = "\n") as f:
csv_reader = list(csv.reader(f, delimiter=","))
all_marks = []
for i in range(1, len(csv_reader)):
all_marks.append(json.loads(csv_reader[i][2]))
total_marks = 0
divs = 0
for subjects in all_marks:
if(isinstance(subjects.get(student), int)):
total_marks += subjects.get(student)
divs += 1
if(divs != 0):
student_performances.append(total_marks/divs)
else:
student_performances.append(0)
total_marks = 0
divs = 0
for x in student_performances:
total_marks += x
divs += 1
if(divs != 0):
performances.append(total_marks/divs)
else:
performances.append(0)
total_marks = 0
divs = 0
for i in range(0, len(batches)):
total_marks += performances[i]
divs += 1
avg_percentage = 0
if(divs != 0):
avg_percentage = total_marks/divs
print("Average percantage obtained by all batches in " + department_id + ": " + str(avg_percentage))
def linePlot(department_id):
with open("department.csv", "r", newline = "\n") as f:
csv_reader = list(csv.reader(f, delimiter=","))
check = 0
batches = []
for i in range(1, len(csv_reader)):
if(csv_reader[i][0] == department_id):
check = 1
batches = csv_reader[i][2].split(":")
break
if(check == 0):
print("Department ID does not exist")
return
if(len(batches) == 0):
print("No batches in department")
return
performances = []
for batch in batches:
students = []
student_performances = []
with open("batch.csv", "r", newline = "\n") as f:
csv_reader = list(csv.reader(f, delimiter=","))
for i in range(0, len(csv_reader)):
if(csv_reader[i][0] == batch):
students = csv_reader[i][4].split(":")
break
for student in students:
with open("course.csv", "r", newline = "\n") as f:
csv_reader = list(csv.reader(f, delimiter=","))
all_marks = []
for i in range(1, len(csv_reader)):
all_marks.append(json.loads(csv_reader[i][2]))
total_marks = 0
divs = 0
for subjects in all_marks:
if(isinstance(subjects.get(student), int)):
total_marks += subjects.get(student)
divs += 1
if(divs != 0):
student_performances.append(total_marks/divs)
else:
student_performances.append(0)
total_marks = 0
divs = 0
for x in student_performances:
total_marks += x
divs += 1
if(divs != 0):
performances.append(total_marks/divs)
else:
performances.append(0)
pyplot.plot(batches, performances)
pyplot.show()