-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSumitJhaD42AIML.py
More file actions
396 lines (370 loc) · 14.6 KB
/
Copy pathSumitJhaD42AIML.py
File metadata and controls
396 lines (370 loc) · 14.6 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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
# -*- coding: utf-8 -*-
"""PythProj.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1jIdlb1ybjd4aKeRFxcg5Fcs06xkAvu6D
"""
import csv
import pandas as pnd
import numpy as nmp
from matplotlib import pyplot as pplt
import time
while True:
ch=int(input("\nType:\n0.Exit\n1.Student\n2.Course\n3.Batch\n4.Department\n5.Examination\nEnter u r choice:"))
def grades(marks):
if marks>=90:
return ["A","Pass"]
elif marks>=80:
return ["B","Pass"]
elif marks>=70:
return ["C","Pass"]
elif marks>=60:
return ["D","Pass"]
elif marks>=50:
return ["E","Pass"]
else:
return ["F","Fail"]
def mrkgrd(df):
L1=[]
L2=[]
for i in df.loc[:,"Marks"]:
L=g(i)
L1.append(L[0])
L2.append(L[1])
df['Grade']=L1
df['Pass/Fail']=L2
return df
def add1(L,a):
str1=''
for i in L:
str1=str1+i+a
str1=str1[:-1]
return str1
if ch==0:
break
elif ch==1:
ch1=int(input("TYPE:\n0.Create Database\n1.input student details\n2.Upndate data\n3.Delete data\n4.Report card(To be generated as a text file result.txt)\nEnter u r choice:"))
if ch1==0:
L1=[['StudentID','Name','Roll','Batch']]
with open("student.csv","a") as r1:
csvwrit=csv.writer(r1)
csvwrit.writerows(L1)
elif ch1==1:
n=int(input("Enter the no. of entries:"))
L1=[]
for i in range(n):
L=[]
StudentID=input("Enter student id:")
Name=input("Enter name:")
Roll=input("Enter roll:")
Batch=input("Enter batch:")
L=[StudentID,Name,Roll,Batch]
L1.append(L)
with open("student.csv","a") as r1:
csvwrit=csv.writer(r1)
csvwrit.writerows(L1)
df=pnd.read_csv("student.csv")
print(df)
elif ch1==3:
df=pnd.read_csv("student.csv")
np_ar = df.to_numpy()
nmp.delete(np_ar,0,axis=1)
p=input("Enter student Id :")
L=[]
for i in np_ar:
if i[0]!=p:
print(i)
L.append(i)
df = pnd.DataFrame(L, columns = ['StudentID','Name','Roll','Batch'])
print(df)
df.to_csv('student.csv', mode='w',index=False)
elif ch1==2:
df=pnd.read_csv("student.csv")
np_ar = df.to_numpy()
nmp.delete(np_ar,0,axis=1)
print(np_ar)
p=input("Enter student Id :")
L=[]
for i in np_ar:
print(i)
if i[0]!=p:
L.append(i)
else:
p1=input("1.Name\n2.Roll\n3.Batch\n")
if p1=='1':
print(i)
p2=input("Enter new name:")
i[1]=p2
print(i)
L.append(i)
elif p1=='2':
print(i)
p2=input("Enter new roll:")
i[2]=p2
print(i)
L.append(i)
elif p1=='3':
print(i)
p2=input("Enter new batch:")
i[3]=p2
print(i)
L.append(i)
print(L)
df = pnd.DataFrame(L, columns = ['StudentID','Name','Roll','Batch'])
print(df)
df.to_csv('student.csv', mode='w',index=False)
elif ch1==4:
df1=pnd.read_csv("student.csv")
df2=pnd.read_csv("course1.csv")
df=pnd.merge(df1,df2,on='StudentID')
p=mrkgrd(df)
dup_df=p.loc[:,["StudentID","Name","Roll","CourseName","Marks","Grade","Pass/Fail"]]
with open("Result.txt", 'w') as f:
grp =dup_df.groupby(['StudentID'])
for i,j in grp:
f.write("\n"+i+"\n")
str1 = j.to_string(header=True, index=False)
f.write(str1)
elif ch==2:
ch2=int(input("0.Create Course database\n1.input course details\n2.View Student performance\n3.Show course histogram\nEnter u r choice:"))
if ch2==0:
L1=[['CourseID','CourseName','Marks']]
L3=[['CourseID','CourseName','Marks','StudentID']]
with open("course.csv","a") as r1:
csvwrit=csv.writer(r1)
csvwrit.writerows(L1)
with open("course1.csv","a") as r1:
csvwrit=csv.writer(r1)
csvwrit.writerows(L3)
elif ch2==1:
n=int(input("Enter the no. of entries:"))
L1=[]
L3=[]
Dict={}
for i in range(n):
L=[]
CourseID=input("Enter course id:")
CourseName=input("Enter course name:")
StudentID=input("Enter student id:")
Marks=input("Enter marks:")
Dict[StudentID]=Marks
L=[CourseID,CourseName,Dict]
L2=[CourseID,CourseName,Marks,StudentID]
L1.append(L)
L3.append(L2)
with open("course.csv","a") as r1:
csvwrit=csv.writer(r1)
csvwrit.writerows(L1)
with open("course1.csv","a") as r1:
csvwrit=csv.writer(r1)
csvwrit.writerows(L3)
df=pnd.read_csv("course.csv")
print(df)
elif ch2==2:
df1=pnd.read_csv("student.csv")
df2=pnd.read_csv("course1.csv")
df=pnd.merge(df1,df2,on='StudentID')
print(df.loc[:,["Roll","Name","Marks"]])
grp=df.groupby(['CourseName'])
for i,j in grp:
print("\n"+i)
print(j.loc[:,["Roll","Name","Marks"]])
elif ch2==3:
df1=pnd.read_csv("student.csv")
df2=pnd.read_csv("course1.csv")
df=pnd.merge(df1,df2,on='StudentID')
p=mrkgrd(df)
dup_df=p.loc[:,["StudentID","Name","Roll","CourseName","Marks","Grade","Pass/Fail"]]
pplt.hist(df['Grade'])
pplt.xlabel('Grade')
pplt.ylabel('No. of students')
pplt.title('Course statistics')
elif ch==3:
ch2=int(input("0.Create Batch database\n1.input Batch Details\n2.View list of all students in a batch\n3.View list of all courses taught in the batch\n4.View complete performance of all students in a batch\n5.Pie Chart of Percentage of all students\nEnter u r choice:"))
if ch2==0:
L1=[['BatchID','BatchName','Department Name','List of course','List of students']]
with open("batch.csv","a") as r1:
csvwrit=csv.writer(r1)
csvwrit.writerows(L1)
L2=[['BatchID','BatchName','Department Name','CourseID']]
L3=[['BatchID','BatchName','Department Name','StudentID']]
with open("batch2.csv","a") as r1:
csvwrit=csv.writer(r1)
csvwrit.writerows(L2)
with open("batch3.csv","a") as r1:
csvwrit=csv.writer(r1)
csvwrit.writerows(L3)
elif ch2==1:
n=int(input("Enter the no. of entries:"))
L1=[]
L2=[]
L3=[]
for i in range(n):
L=[]
BatchID=input("Enter BatchID:")
BatchName=input("Enter BatchName:")
DepartmentName=input("Enter department name:")
t1=list(eval(input("Enter list of courses:")))
t2=list(eval(input("Enter list of students:")))
str1=add1(t1,";")
str2=add1(t2,";")
L=[BatchID,BatchName,DepartmentName,str1,str2]
L1.append(L)
if len(t1)!=1:
for i in t1:
L2p=[BatchID,BatchName,DepartmentName,i]
L2.append(L2p)
else:
L2p=[BatchID,BatchName,DepartmentName,t1[0]]
L2.append(L2p)
if len(t2)!=1:
for i in t2:
L3p=[BatchID,BatchName,DepartmentName,i]
L3.append(L3p)
else:
L3p=[BatchID,BatchName,DepartmentName,t2[0]]
L3.append(L3p)
with open("batch.csv","a") as r1:
csvwrit=csv.writer(r1)
csvwrit.writerows(L1)
with open("batch2.csv","a") as r1:
csvwrit=csv.writer(r1)
csvwrit.writerows(L2)
with open("batch3.csv","a") as r1:
csvwrit=csv.writer(r1)
csvwrit.writerows(L3)
df=pnd.read_csv("batch.csv")
print(df)
elif ch2==2:
df2=pnd.read_csv("batch3.csv")
df1=pnd.read_csv("student.csv")
df=pnd.merge(df1,df2,on='StudentID')
grp=df.groupby(['BatchName'])
for i,j in grp:
print("\n"+i)
print(j.loc[:,["Roll","Name","StudentID"]])
elif ch2==3:
df2=pnd.read_csv("batch2.csv")
df1=pnd.read_csv("course1.csv")
df=pnd.merge(df1,df2,on='CourseID')
grp=df.groupby(['BatchName'])
for i,j in grp:
print("\n"+i)
print(j.loc[:,["BatchID","BatchName","CourseName","CourseID"]])
elif ch2==4:
df2=pnd.read_csv("batch2.csv")
df1=pnd.read_csv("course1.csv")
df4=pnd.merge(df1,df2,on='CourseID')
df3=pnd.read_csv("student.csv")
df=pnd.merge(df3,df4,on='StudentID')
grp=df.groupby(['BatchName'])
for i,j in grp:
print("\n"+i)
print(j.loc[:,["Roll","Name","StudentID",'CourseName','Marks']])
elif ch2==5:
df1=pnd.read_csv("student.csv")
df2=pnd.read_csv("department1.csv")
df=pnd.merge(df1,df2,on='BatchID')
df3=pnd.read_csv("course1.csv")
df4=pnd.merge(df,df3,on='StudentID')
df5=df4.groupby('StudentID')['Marks'].mean()
df5.plot(kind='pie')
elif ch==4:
ch2=int(input("0.Create Department database\n1.input Department\n2.View all batches in a department \n3.View average performance of all batches in the department\n4.Show department statistics Line plot–Average percentage of all students for each batch)\nEnter u r choice:"))
if ch2==0:
L1=[['DepartmentID','Department Name','List of batches']]
with open("department.csv","a") as r1:
csvwrit=csv.writer(r1)
csvwrit.writerows(L1)
L9=[['DepartmentID','Department Name','Batch']]
with open("department1.csv","a") as r1:
csvwrit=csv.writer(r1)
csvwrit.writerows(L9)
elif ch2==1:
n=int(input("Enter the no. of entries:"))
L1=[]
L2=[]
for i in range(n):
L=[]
L3=[]
DepartmentID=input("Enter departmentid:")
DepartmentName=input("Enter department name:")
t1=list(eval(input("Enter list of batches:")))
str1=add1(t1,":")
L=[DepartmentID,DepartmentName,str1]
L1.append(L)
if len(t1)!=1:
for i in t1:
L3=[DepartmentID,DepartmentName,i]
L2.append(L3)
else:
L3=[DepartmentID,DepartmentName,t1[0]]
L2.append(L3)
with open("department1.csv","a") as r2:
csvwrit=csv.writer(r2)
csvwrit.writerows(L2)
with open("department.csv","a") as r1:
csvwrit=csv.writer(r1)
csvwrit.writerows(L1)
df=pnd.read_csv("department.csv")
print(df)
elif ch2==2:
df=pnd.read_csv("department1.csv")
grp=df.groupby(['DepartmentID'])
for i,j in grp:
print("\n"+i)
print(j.loc[:,["BatchID"]])
elif ch2==3:
df1=pnd.read_csv("student.csv")
df2=pnd.read_csv("department1.csv")
df=pnd.merge(df1,df2,on='BatchID')
df3=pnd.read_csv("course1.csv")
df4=pnd.merge(df,df3,on='StudentID')
df5=df4.groupby('BatchID')['Marks'].mean()
print(df5)
elif ch2==4:
df1=pnd.read_csv("student.csv")
df2=pnd.read_csv("department1.csv")
df=pnd.merge(df1,df2,on='BatchID')
df3=pnd.read_csv("course1.csv")
df4=pnd.merge(df,df3,on='StudentID')
df5=df4.groupby('BatchID')['Marks'].mean()
df5.plot(kind='line')
elif ch==5:
ch2=int(input("0.Create Examination database\n1.input Examination details\n2.View performance of all students in the examination\n3.Show examination statistics:\nEnter u r choice:"))
if ch2==0:
L1=[['Marks','CourseName','StudentID']]
with open("examination.csv","a") as r1:
csvwrit=csv.writer(r1)
csvwrit.writerows(L1)
elif ch2==1:
n=int(input("Enter the no. of entries:"))
L1=[]
for i in range(n):
L=[]
Marks=input("Enter marks:")
CourseName=input("Enter coursename:")
StudentID=input("Enter studentid:")
L=[Marks,CourseName,StudentID]
L1.append(L)
with open("examination.csv","a") as r1:
csvwrit=csv.writer(r1)
csvwrit.writerows(L1)
df=pnd.read_csv("examination.csv")
print(df)
elif ch2==2:
df1=pnd.read_csv("student.csv")
df2=pnd.read_csv("course1.csv")
df=pnd.merge(df1,df2,on='StudentID')
grp =df.groupby(['StudentID'])
for i,j in grp:
print("\n"+i)
print(j.loc[:,["CourseName","Marks"]])
elif ch2==3:
df1=pnd.read_csv("student.csv")
df2=pnd.read_csv("course1.csv")
df=pnd.merge(df1,df2,on='StudentID')
grp =df.groupby(['BatchName'])
for i,j in grp:
print("\n"+i)
print(j.loc[:,["Roll","Name","Marks"]])