-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresany.py
373 lines (299 loc) · 12 KB
/
resany.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
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
#------------ welcome to my project code --------------------------------------------
#-------------------- importing the modules ------------------------------------
import mysql.connector
from tkinter import *
from tkinter.filedialog import askopenfilename
import matplotlib.pyplot as plt
#-------------------- modules imported -------------------------------------------
#--------------------- defin ing functions -----------------------------------------------------
#------------------------linereader function definition------------------------------
def line_reader(p):
c,k=0,0
for j in range(len(p)):
try:
if (p[j]=='M' or p[j]=='F') and type(eval(p[j+1]))==int:
k+=j
break
else:
continue
except:
continue
for i in range(1,k):
if (p[i]=='M' or p[i]=='F') and (p[i+1]).isnumeric==True:
break
else:
c+=1
if c==1:
continue
else:
p[1]=p[1]+' '+p[i]
for x in range(2,c+1):
del p[2]
if p[-1]=='PASS':
p.append('NULL')
p.append('NULL')
elif len(p)==20:
p.append('NULL')
return p
#---------------End of Linereader definiton----------------------------------------------------------------
#-----------------------PI Calculator--------------------------------------------------------
#-----------------subject wise--------------------------------------------------------
def subpi(subject,table,db):
mydb = mysql.connector.connect(
host="localhost",
user="root",
passwd="",
)
my = mydb.cursor()
my.execute('USE '+db)
t=table
my.execute(" select count(*) from "+t+" ;")
sub=subject
for x in my:
no_s=x[0]
my.execute(" select count(*) from "+t+" where "+sub+" = 'A1';")
for x in my:
a1=x[0]
my.execute(" select count(*) from "+t+" where "+sub+" = 'A2';")
for x in my:
a2=x[0]
my.execute(" select count(*) from "+t+" where "+sub+" = 'B1';")
for x in my:
b1=x[0]
my.execute(" select count(*) from "+t+" where "+sub+" = 'B2';")
for x in my:
b2=x[0]
my.execute(" select count(*) from "+t+" where "+sub+" = 'c1';")
for x in my:
c1=x[0]
my.execute(" select count(*) from "+t+" where "+sub+" = 'c2';")
for x in my:
c2=x[0]
my.execute(" select count(*) from "+t+" where "+sub+" = 'd1';")
for x in my:
d1=x[0]
my.execute(" select count(*) from "+t+" where "+sub+" = 'd2';")
for x in my:
d2=x[0]
pi=(8*a1 + 7*a2 + 6*b1 + 5*b2 + 4*c1 + 3*c2 + 2*d1 + 1*d2) * 100/(no_s * 8)
print('PI =',pi)
return pi
#---------------------------total pi---------------------------------------------
def totalpi(table,db):
mydb = mysql.connector.connect(
host="localhost",
user="root",
passwd="",
)
t=table
my = mydb.cursor()
my.execute('USE '+db)
my.execute(" select count(*) from "+t+" ;")
for x in my:
no_s=x[0]
sub=['grade_1','grade_2','grade_3','grade_4','grade_5']
a1,a2,b1,b2,c1,c2,d1,d2=0,0,0,0,0,0,0,0
for i in sub:
my.execute(" select count(*) from "+t+" where "+i+" = 'A1' ;")
for x in my:
a1+=x[0]
for i in sub:
my.execute(" select count(*) from "+t+" where "+i+" = 'A2' ;")
for x in my:
a2+=x[0]
for i in sub:
my.execute(" select count(*) from "+t+" where "+i+" = 'B1' ;")
for x in my:
b1+=x[0]
for i in sub:
my.execute(" select count(*) from "+t+" where "+i+" = 'B2' ;")
for x in my:
b2+=x[0]
for i in sub:
my.execute(" select count(*) from "+t+" where "+i+" = 'C1' ;")
for x in my:
c1+=x[0]
for i in sub:
my.execute(" select count(*) from "+t+" where "+i+" = 'C2' ;")
for x in my:
c2+=x[0]
for i in sub:
my.execute(" select count(*) from "+t+" where "+i+" = 'D1' ;")
for x in my:
d1+=x[0]
for i in sub:
my.execute(" select count(*) from "+t+" where "+i+" = 'D2' ;")
for x in my:
d2+=x[0]
pi=(8*a1 + 7*a2 + 6*b1 + 5*b2 + 4*c1 + 3*c2 + 2*d1 + 1*d2) * 100/(no_s * 40)
print('PI =',pi)
#---------------------------End of pi function definition----------------------------
'''
Now the main game begins
'''
def main():
while 1:
a=input('\nAre you using it for the first time? (y/n): ')
if a=='y':
db=input('Name your database: ')
mydb = mysql.connector.connect(
host="localhost",
user="root",
passwd="")
my = mydb.cursor()
try:
my.execute("CREATE DATABASE "+db)
my.execute("USE "+db)
except:
print("Database already exists!")
my.execute("USE "+db)
break
elif a=='n':
try:
db=input('Enter the name of your database:')
mydb = mysql.connector.connect(
host="localhost",
user="root",
passwd="",)
my = mydb.cursor()
my.execute("USE "+db)
break
except:
print('Database does not exist')
else:
print('you must enter in y or n.....')
while 1:
m=mydb.cursor()
b=input('\nDo you want to create a new table? (if yes press y or press any key to continue): ')
if b=='y':
print('\nSelect the result text file from browse menu')
a = askopenfilename()
print(a)
f=open(a)
lines=f.readlines()
lin = 0
with open(a, 'r') as f:
for l in f:
lin += 1
for i in range(0,lin):
j=lines[i]
p=j.split()
try:
if type(eval(p[0]))==int:
a1=line_reader(p)
a1=tuple(a1)
elif len(p)==0:
continue
else:
continue
except:
continue
while 1:
tname=input('Enter new table name: ')
try:
m.execute("CREATE TABLE "+tname+" (ROLL_NO INT(20) PRIMARY KEY,NAME_OF_CANDIDATE VARCHAR(50) NOT NULL,SEX CHAR(2),SUB1_CD VARCHAR(4),MARKS_1 INT(4) , GRADE_1 VARCHAR(5) ,SUB2_CD VARCHAR(4) , MARKS_2 INT(4) , GRADE_2 VARCHAR(5) ,SUB3_CD VARCHAR(4) , MARKS_3 INT(4) , GRADE_3 VARCHAR(5) ,SUB4_CD VARCHAR(4) , MARKS_4 INT(4) , GRADE_4 VARCHAR(5) ,SUB5_CD VARCHAR(4) , MARKS_5 INT(4) , GRADE_5 VARCHAR(5) ,RESULT VARCHAR(5) , COMP1_SUB_CD VARCHAR(4) , COMP2_SUB_CD VARCHAR(4) )")
break
except:
inp=input('Table already exists, Do you want to overwrite it?(y/n):')
if inp == 'y':
m.execute("DROP TABLE "+tname)
m.execute("CREATE TABLE "+tname+" (ROLL_NO INT(20) PRIMARY KEY,NAME_OF_CANDIDATE VARCHAR(50) NOT NULL,SEX CHAR(2),SUB1_CD VARCHAR(4),MARKS_1 INT(4) , GRADE_1 VARCHAR(5) ,SUB2_CD VARCHAR(4) , MARKS_2 INT(4) , GRADE_2 VARCHAR(5) ,SUB3_CD VARCHAR(4) , MARKS_3 INT(4) , GRADE_3 VARCHAR(5) ,SUB4_CD VARCHAR(4) , MARKS_4 INT(4) , GRADE_4 VARCHAR(5) ,SUB5_CD VARCHAR(4) , MARKS_5 INT(4) , GRADE_5 VARCHAR(5) ,RESULT VARCHAR(5) , COMP1_SUB_CD VARCHAR(4) , COMP2_SUB_CD VARCHAR(4) )")
mydb.commit()
break
elif inp == 'n':
continue
else:
print("You should have entered in 'y' or 'n'")
print("Table created now entering values.....")
for i in range(0,lin):
j=lines[i]
p=j.split()
try:
if type(eval(p[0]))==int:
a1=line_reader(p)
cmd_1='INSERT INTO '+tname+'(ROLL_NO,NAME_OF_CANDIDATE,SEX,SUB1_CD,MARKS_1,GRADE_1,SUB2_CD,MARKS_2,GRADE_2,SUB3_CD,MARKS_3,GRADE_3,SUB4_CD, MARKS_4,GRADE_4,SUB5_CD,MARKS_5,GRADE_5,RESULT,COMP1_SUB_CD,COMP2_SUB_CD)VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)'
m.execute(cmd_1,tuple(a1))
mydb.commit()
elif len(p)==0:
continue
else:
continue
except:
continue
mydb.commit()
print('\nYour newly created table')
print()
m.execute("SELECT * FROM "+tname)
for i1 in m:
print(i1)
break
else:
l=[]
while 1:
tname=input('\nEnter table name: ')
choice_1=input('Want to view the contents? (if yes press y or press any key): ')
if choice_1=='y':
try:
x=0
my.execute("SELECT * FROM "+tname)
for i in my:
print(i)
break
except:
print('Table does not exist')
else:
break
break
mydb.commit()
mydb.close()
#----------pi part---------------------------------------------------------------------------------------
while 1:
inp=input('\nDO YOU WANT TO CHECK PI (y,n):')
print()
if inp=='y':
try:
table=tname
print('\nTOTAL PI')
totalpi(table,db)
print('\nFor English')
p1=subpi('grade_1',table,db)
print('\nFor Hindi')
p2=subpi('grade_2',table,db)
print('\nFor Mathematics')
p3=subpi('grade_3',table,db)
print('\nFor Science')
p4=subpi('grade_4',table,db)
print('\nFor Social Science')
p5=subpi('grade_5',table,db)
print('\nThank you for using this software, Hope your day goes well..........')
x=['English','Hindi','Mathematics','Science','Social Science']
y=[p1,p2,p3,p4,p5]
plt.bar(x,y)
plt.title('PI variation with subject')
plt.xlabel('Subjects')
plt.ylabel('Performance Index')
plt.show()
break
except:
print('ENTER DATA CORRECTLY!')
elif inp=='n':
print('OK BYE')
break
else:
print("Enter either 'y' or 'n' ")
print('\nThank you for using this software, Hope your day goes well..........')
# main()
root = Tk()
root.title('RESULT ANALYSIS SOFTWARE')
titl = Label(root, text='RESULT ANALYSIS SOFTWARE')
titl.grid(row=0,column=0,columnspan=20)
titl.config(font=('arial',20,'underline'),bg='white')
titl = Label(root, text=' MADE BY PRASUN KUMAR DAS')
titl.grid(row=2,column=0,columnspan=20)
titl.config(font=('arial',10),bg='white')
b= Button(root, text="LETS GET STARTED", command=main,bg='orange')
b.grid(row=3,column=1,columnspan=20)
b.config(font=('helvetica', 15, 'bold'))
titl = Label(root, text='THANK YOU FOR USING OUR PROGRAM')
titl.grid(row=4,column=0,columnspan=20)
titl.config(font=('arial',10),bg='white')