-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
executable file
·914 lines (741 loc) · 30.6 KB
/
app.py
File metadata and controls
executable file
·914 lines (741 loc) · 30.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
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
from flask import Flask , render_template , request , redirect, url_for , session , flash , jsonify
from flask_mysqldb import MySQL , MySQLdb
import pandas as pd
import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from datetime import date
app = Flask(__name__,template_folder='template')
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 1
app.config['MYSQL_HOST'] = 'localhost'
app.config['MYSQL_USER'] = 'root'
app.config['MYSQL_PASSWORD'] = 'prashant13'
app.config['MYSQL_DB'] = 'flaskdb'
app.config['MYSQL_CURSORCLASS'] = 'DictCursor'
mysql = MySQL(app)
@app.route('/',methods=["GET","POST"])
def slogin():
if request.method == 'POST':
email = request.form['email']
password = request.form['password']
curl = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
curl.execute("SELECT * FROM users WHERE email=%s",(email,))
user = curl.fetchone()
curl.close()
if user:
if (password == user["password"]):
session['name'] = user['name']
session['branch'] = user['branch']
session['email'] = user['email']
session['year'] = user['year']
session['prn'] = user['prn']
curl2 = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
curl2.execute("select subject,marks from tests where year=%s",[session['year']])
data = curl2.fetchall()
#return str(data)
curl2.close()
if data:
return render_template("testlist.html" , value = data , len=len(data))
else:
return redirect(url_for("sdashboard"))
else:
error = "Password and email not match"
return render_template("home.html" , value = error)
else:
error = "User not found"
return render_template("home.html" , value = error)
else:
return render_template("home.html")
@app.route('/slist' , methods=["GET","POST"])
def slist():
curl = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
curl.execute("select * from users")
data = curl.fetchall()
return render_template("slist.html", value=data)
@app.route('/sdelete/<int:id>' , methods=["GET" , "POST"])
def sdelete(id):
cur = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
cur.execute("DELETE FROM users WHERE id=%s",[id])
mysql.connection.commit()
flash( "User Deleted...")
return redirect(url_for("slist"))
@app.route('/tlist' , methods=["GET","POST"])
def tlist():
curl = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
curl.execute("select * from teacher")
data = curl.fetchall()
return render_template("tlist.html", value=data)
@app.route('/tdelete/<int:id>' , methods=["GET" , "POST"])
def tdelete(id):
cur = mysql.connection.cursor()
cur.execute("DELETE FROM teacher WHERE id=%s",[id])
mysql.connection.commit()
flash("Teacher Deleted...")
return redirect(url_for("tlist"))
@app.route('/tlogin',methods=["GET","POST"])
def tlogin():
if request.method == 'POST':
email = request.form['email']
password = request.form['password']
curl = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
curl.execute("SELECT * FROM teacher WHERE email=%s",[email])
user = curl.fetchone()
curl.close()
if user:
if (password == user["password"]):
session['name'] = user['name']
session['email'] = user['email']
session['subject'] = user['subject']
return render_template("tdashboard.html")
else:
error = "Password and email not match"
return render_template("tlogin.html" , value = error)
else:
error = "User not found"
return render_template("tlogin.html" , value = error)
else:
return render_template("tlogin.html")
@app.route('/alogin',methods=["GET","POST"])
def alogin():
if request.method == 'POST':
email = request.form['email']
password = request.form['password']
curl = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
curl.execute("SELECT * FROM admin WHERE email=%s",[email])
user = curl.fetchone()
curl.close()
if user:
if (password == user["password"]):
session['name'] = user['name']
session['email'] = user['email']
return redirect(url_for("adashboard"))
else:
error = "Password and email not match"
return render_template("alogin.html", value = error)
else:
error = "User not found"
return render_template("alogin.html", value = error)
else:
return render_template("alogin.html")
@app.route('/logout', methods=["GET", "POST"])
def logout():
session.clear()
return render_template("home.html")
@app.route('/sregister', methods=["GET", "POST"])
def sregister():
if request.method == 'GET':
return render_template("sregister.html")
else:
name = request.form['name']
email = request.form['email']
password = request.form['password']
prn = request.form['prn']
year = request.form['year']
branch = request.form['branch']
cur = mysql.connection.cursor()
cur.execute("SELECT * FROM users WHERE email=%s or prn=%s",(email,prn))
user = cur.fetchone()
if user:
error = ("User exist")
return render_template("sregister.html" , value = error)
else:
cur = mysql.connection.cursor()
cur.execute("INSERT INTO users (name, email, password , prn , year , branch) VALUES (%s,%s,%s,%s,%s,%s)",(name,email,password,prn,year,branch))
mysql.connection.commit()
flash("User Created...")
return redirect(url_for('sregister'))
@app.route('/tregister', methods=["GET", "POST"])
def tregister():
if request.method == 'GET':
return render_template("tregister.html")
else:
name = request.form['name']
email = request.form['email']
password = request.form['password']
teacherid = request.form['teacherid']
subject = request.form['subject']
branch = request.form['branch']
cur = mysql.connection.cursor()
cur.execute("SELECT * FROM teacher WHERE email=%s",[email])
user = cur.fetchone()
if user:
error = ("Teacher exist")
return render_template("tregister.html" , value = error)
else:
cur.execute("INSERT INTO teacher (name, email, password , teacherid , subject , branch) VALUES (%s,%s,%s,%s,%s,%s)",(name,email,password,teacherid,subject,branch))
mysql.connection.commit()
flash("Teacher Created")
return redirect(url_for('tregister'))
@app.route('/supdate', methods=["GET", "POST"])
def supdate():
if request.method == 'POST':
email = request.form['email']
password = request.form['password']
prn = request.form['prn']
year = request.form['year']
branch = request.form['branch']
curl = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
curl.execute("SELECT * FROM users WHERE prn=%s",[prn])
user = curl.fetchone()
curl.close()
if len(user) > 0:
if (prn, user["prn"] == user["prn"]):
cur = mysql.connection.cursor()
cur.execute("UPDATE users set email=%s,password=%s,year=%s,branch=%s where prn=%s",(email,password,year,branch,prn))
mysql.connection.commit()
flash("Student Data Updated...")
return redirect(url_for('supdate'))
else:
flash( "Error : prn not found")
else:
flash( "Error user not found")
else:
return render_template("supdate.html")
@app.route('/supdate2/<int:id>')
def supdate2(id):
curl = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
curl.execute("SELECT * FROM users WHERE id=%s",[id])
data = curl.fetchone()
return render_template("supdate2.html",value = data)
@app.route('/tupdate', methods=["GET", "POST"])
def tupdate():
if request.method == 'POST':
email = request.form['email']
password = request.form['password']
teacherid = request.form['teacherid']
subject = request.form['subject']
branch = request.form['branch']
curl = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
curl.execute("SELECT * FROM teacher WHERE teacherid=%s",[teacherid])
user = curl.fetchone()
curl.close()
if len(user) > 0:
if (teacherid, user["teacherid"] == user["teacherid"]):
cur = mysql.connection.cursor()
cur.execute("UPDATE teacher set email=%s,password=%s,subject=%s,branch=%s where teacherid=%s",(email,password,subject,branch,teacherid))
mysql.connection.commit()
flash("Teacher Data Updated")
return redirect(url_for('tupdate'))
else:
flash( "Error : prn not found")
else:
flash( "Error user not found")
else:
return render_template("tupdate.html")
@app.route('/tupdate2/<int:id>')
def tupdate2(id):
curl = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
curl.execute("SELECT * FROM teacher WHERE id=%s",[id])
data = curl.fetchone()
return render_template("tupdate2.html",value = data)
@app.route('/schangepassword', methods=["GET", "POST"])
def schangepassword():
if request.method == 'POST':
prn = request.form['prn']
password = request.form['password']
newpassword = request.form['newpassword']
curl = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
curl.execute("SELECT * FROM users WHERE prn=%s and password=%s",[prn,password])
user = curl.fetchone()
curl.close()
if (prn, user["prn"] == user["prn"]):
if (password, user["password"] == user["password"]):
cur = mysql.connection.cursor()
cur.execute("UPDATE users set password=%s where prn=%s",(newpassword,prn))
mysql.connection.commit()
flash("Password changed")
return redirect(url_for('schangepassword'))
else:
flash("Incorrect Password")
else:
flash( "Incorrect PRN")
else:
return render_template("schangepassword.html")
@app.route('/tchangepassword', methods=["GET", "POST"])
def tchangepassword():
if request.method == 'POST':
teacherid = request.form['teacherid']
password = request.form['password']
newpassword = request.form['newpassword']
curl = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
curl.execute("SELECT * FROM teacher WHERE teacherid=%s and password=%s",[teacherid,password])
user = curl.fetchone()
curl.close()
if (teacherid, user["teacherid"] == user["teacherid"]):
if (password, user["password"] == user["password"]):
cur = mysql.connection.cursor()
cur.execute("UPDATE teacher set password=%s where teacherid=%s",(newpassword,teacherid))
mysql.connection.commit()
flash("Password Changed")
return redirect(url_for('tchangepassword'))
else:
flash( "Incorrect Password")
else:
flash("Incorrect PRN")
else:
return render_template("tchangepassword.html")
@app.route('/sdashboard', methods=["GET", "POST"])
def sdashboard():
flash("Success! Signed In...")
return render_template("sdashboard.html")
@app.route('/tdashboard', methods=["GET", "POST"])
def tdashboard():
flash("Success! Signed In...")
return render_template("tdashboard.html")
@app.route('/adashboard', methods=["GET", "POST"])
def adashboard():
flash("Success! Signed In...")
return render_template("adashboard.html")
@app.route('/forgotpassword', methods=["GET", "POST"])
def forgotpassword():
return render_template("forgotpassword.html")
@app.route('/forgotpassword1', methods=["GET", "POST"])
def forgotpassword1():
return render_template("forgotpassword1.html")
@app.route('/tupload', methods=["GET", "POST"])
def tupload():
if request.method == 'POST':
file = request.files['file']
book = pd.read_csv(file)
subject = request.form['subject']
unit = request.form['unit']
branch = request.form['branch3']
for row in range(len(book)):
rows = (book.iloc[row][0],book.iloc[row][1],book.iloc[row][2],book.iloc[row][3],book.iloc[row][4],book.iloc[row][5],book.iloc[row][6],subject,unit,branch)
cur = mysql.connection.cursor()
cur.execute("INSERT INTO question(question,option1,option2,option3,option4,correctoption,marks,subject,unit,branch) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",rows)
mysql.connection.commit()
flash( "File Uploaded...")
return redirect(url_for('tupload'))
else:
return render_template("qupload.html")
@app.route('/branchch', methods=['POST'])
def branchch():
if request.method=='POST':
id=request.form['branch1']
branch2=str(id)
curl = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
curl.execute("select subject from subjects where branch=%s",[branch2])
data = curl.fetchall()
data1=[]
for i in range(len(data)):
data1.append(data[i]["subject"])
#return str(data1)
return jsonify(data1)
@app.route('/queslist' , methods=["GET","POST"])
def queslist():
subject = session['subject']
curl = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
curl.execute("select * from question where subject=%s",[subject])
data = curl.fetchall()
return render_template("queslist.html", value=data)
@app.route('/update', methods=['POST'])
def update():
if request.method=='POST':
id=request.form['id']
curl = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
curl.execute("select * from question where id=%s",[id])
data = curl.fetchone()
return jsonify(data)
@app.route('/mock',methods= ["POST","GET"])
def mock():
if request.method == 'GET':
branch = session['branch']
curl = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
curl.execute("select distinct subject from question where branch = %s",[branch])
data = curl.fetchall()
curl.close()
data1 = len(data)
return render_template("mock.html" , value = data , len = data1)
@app.route('/mock2',methods= ["POST","GET"])
def mock2():
if request.method=="POST":
leng=20
sub = request.form['sub']
#mar= request.form['mar']
#return str(mar)
curl = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
curl.execute("select * from question where subject=%s order by rand() limit %s",(sub,leng))
data = curl.fetchall()
i=1
for item in data:
item.update({'srno':i})
i=i+1
if i>len(data):
break
curl.close()
return render_template("exam.html", value=data , length=leng)
@app.route('/result', methods=['POST'])
def result():
data=request.json
leng=len(data)-1
option=[]
marks=0
year = session['year']
prn = session['prn']
subject = data[-1][1]
tot=0
for i in range(leng):
tot=tot+int(data[i][3])
#return str(tot)
for i in range(0,leng):
option.append(data[i][0])
if int(option[i])==int(data[i][1]):
marks=marks+int(data[i][3])
result=int((marks/tot)*100)
for i in range(0,leng):
curl1 = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
curl1.execute("insert into result(id,selected,correct) values (%s,%s,%s)",(data[i][2],data[i][0],data[i][1]))
mysql.connection.commit()
curl1.close()
curl = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
curl.execute("insert into final_result(prn,year,subject,marks) values (%s,%s,%s,%s)",(prn,year,subject,result))
mysql.connection.commit()
curl.close()
return jsonify({'marks':result , 'urll': url_for('displayresult',name=result)})
@app.route('/displayresult/<string:name>', methods=['GET','POST'])
def displayresult(name):
curl = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
curl.execute("select * from result")
data = curl.fetchall()
curl.close()
curl1 = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
curl1.execute("select * from question where id in(select id from result)")
data1 = curl1.fetchall()
lengt=len(data1)
curl1.close()
curl2 = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
curl2.execute("delete from result")
curl2.close()
mysql.connection.commit()
return render_template("result_ques.html",value=data1,value1=data,length=lengt,result=name)
@app.route('/exam2',methods= ["POST","GET"])
def ques():
if request.method=="GET":
curl = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
curl.execute("select * from question order by rand() limit 6")
data = curl.fetchall()
i=1
for item in data:
item.update({'srno':i})
i=i+1
if i>len(data):
break
curl.close()
data1=(data[0]["correctoption"],data[1]["correctoption"],data[2]["correctoption"],data[3]["correctoption"],data[4]["correctoption"],data[5]["correctoption"])
curl1 = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
curl1.execute("INSERT into op(opt1,opt2,opt3,opt4,opt5,opt6) VALUES (%s,%s,%s,%s,%s,%s)",data1)
mysql.connection.commit()
return render_template("exam.html", value=data)
else:
option=[]
marks=0
curl = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
curl.execute("select * from op")
data2 = curl.fetchone()
for i in range(0,6):
option.append(request.form['optradio'+str(i+1)])
if option[i]==data2['opt'+str(i+1)]:
marks=marks+1
result=(marks/6)*100
curl1 = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
curl1.execute("delete from op")
mysql.connection.commit()
return "YOU GOT "+str(result)+"%"
@app.route('/practice', methods=["GET","POST"])
def practice():
if request.method == 'GET':
branch = session['branch']
curl = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
curl.execute("select distinct subject from question where branch = %s",[branch])
data = curl.fetchall()
curl.close()
data1 = len(data)
return render_template("practice.html" , value = data , len = data1)
@app.route('/practice2', methods=["GET","POST"])
def practice2():
unit_sub = request.form['unit']
unit_sub1 = (unit_sub[0],unit_sub[2:])
sql = "select * from question where unit=%s and subject=%s order by rand()"
curl = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
curl.execute(sql,unit_sub1)
data = curl.fetchall()
data1 = len(data)
curl.close()
curl1 = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
mysql.connection.commit()
curl1.close()
return render_template("practice2.html", value=data , length = data1)
@app.route('/testseries' , methods=["GET","POST"])
def testseries():
if request.method=="GET":
branch = session['branch']
curl = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
curl.execute("select distinct subject from question where branch = %s",[branch])
data = curl.fetchall()
curl.close()
data1 = len(data)
return render_template("testseries.html" , value = data , len = data1, stri=[""])
@app.route('/testseries2',methods=["GET","POST"])
def testseries2():
if request.method=="POST":
number = int(request.form['number'])
leng=number
sub = request.form['sub']
curl = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
curl.execute("select * from question where subject=%s order by rand() limit %s",(sub,leng))
data = curl.fetchall()
if len(data)<leng:
branch = session['branch']
curl1 = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
curl1.execute("select distinct subject from question where branch = %s",[branch])
data3 = curl1.fetchall()
curl1.close()
data4 = len(data3)
stri="Oops!!! maximum questions for this subject are "+str(len(data))
return render_template("testseries.html" , value = data3 , len = data4, stri=[stri])
i=1
for item in data:
item.update({'srno':i})
i=i+1
if i>len(data):
break
curl.close()
return render_template("exam.html", value=data , length=leng)
@app.route('/ranalysis',methods=["GET","POST"])
def reanalysis():
return render_template("ranalysis.html")
import os
FOLDER= os.path.join('static','p_photo')
app.config['UPLOAD_FOLDER']=FOLDER
i=0
@app.route('/ryear',methods=["GET","POST"])
def ryear():
if request.method == "GET":
return render_template("ryear.html")
else:
yearwise = request.form['ryear']
#subject=request.form['sub']
#return str(subject)
#return str(yearwise)
i=1
curl = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
curl.execute("select * from final_result where year=%s",[yearwise])
data = curl.fetchall()
curl.close()
if data:
dataf = pd.DataFrame.from_dict(data)
arr = np.array(dataf['marks'])
final=[]
final.append(arr[(arr>='0')&(arr<'20')].size)
final.append(arr[(arr>='20')&(arr<'40')].size)
final.append(arr[(arr>='40')&(arr<'60')].size)
final.append(arr[(arr>='60')&(arr<'80')].size)
final.append(arr[(arr>='40')&(arr<'60')].size)
final.append(arr[arr=='100'].size)
#return str(final)
plt.figure(1)
plt.subplot(121)
#plt.figure(figsize=(20,11))
plt.bar(['0','20','40','60','80','100'] ,final)
plt.xlabel('Marks')
plt.ylabel('No of Students')
plt.title('Result Analysis '+str(yearwise))
plt.subplot(122)
plt.pie(final,labels=['0','20','40','60','80','100'],shadow=True)
#return str(dataf)
#plt.legend()
#file_name='static/bar.png'
file_name=os.path.join(app.config['UPLOAD_FOLDER'],str(yearwise)+'_graph.png')
app.config["CACHE_TYPE"] = "null"
plt.savefig(file_name)
plt.close()
i=i+1
return render_template('graph.html',file_name = file_name)
else:
error = "No Data Found"
return render_template('graph.html',value = error)
@app.route('/rsubject',methods=["GET","POST"])
def rsubject():
if request.method == "GET":
curl = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
curl.execute("select distinct subject from question")
data = curl.fetchall()
curl.close()
data1 = len(data)
return render_template("rsubject.html" , value = data , len = data1)
else:
subject=request.form['sub']
#return str(subject)
i=1
curl = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
curl.execute("select * from final_result where subject=%s",[subject])
data = curl.fetchall()
curl.close()
if data:
dataf = pd.DataFrame.from_dict(data)
arr = np.array(dataf['marks'])
final=[]
final.append(arr[arr=='0'].size)
final.append(arr[arr=='20'].size)
final.append(arr[arr=='40'].size)
final.append(arr[arr=='60'].size)
final.append(arr[arr=='80'].size)
final.append(arr[arr=='100'].size)
#return str(final)
plt.figure(1)
plt.subplot(121)
#plt.figure(figsize=(20,11))
plt.bar(['0','20','40','60','80','100'] ,final)
plt.xlabel('Marks')
plt.ylabel('No of Students')
plt.title('Result Analysis' +str(subject))
plt.subplot(122)
plt.pie(final,labels=['0','20','40','60','80','100'],shadow=True)
#return str(dataf)
#plt.legend()
#file_name='static/bar.png'
file_name=os.path.join(app.config['UPLOAD_FOLDER'],str(subject)+'_graph.png')
app.config["CACHE_TYPE"] = "null"
plt.savefig(file_name)
plt.close()
i=i+1
return render_template('graph.html',file_name = file_name)
else:
error = "No Data Found"
return render_template('graph.html',value = error)
@app.after_request
def add_header(response):
# response.cache_control.no_store = True
if 'Cache-Control' not in response.headers:
response.headers['Cache-Control'] = 'no-store'
return response
@app.route('/aqupload', methods=["GET", "POST"])
def aqupload():
if request.method == 'POST':
file = request.files['file']
book = pd.read_csv(file)
subject = request.form['subject']
unit = request.form['unit']
branch = request.form['branch3']
for row in range(len(book)):
rows = (book.iloc[row][0],book.iloc[row][1],book.iloc[row][2],book.iloc[row][3],book.iloc[row][4],book.iloc[row][5],book.iloc[row][6],subject,unit,branch)
cur = mysql.connection.cursor()
cur.execute("INSERT INTO question(question,option1,option2,option3,option4,correctoption,marks,subject,unit,branch) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",rows)
mysql.connection.commit()
flash( "File Uploaded...")
return redirect(url_for('tupload'))
else:
return render_template("aqupload.html")
@app.route('/asupload', methods=["GET", "POST"])
def asupload():
if request.method == 'POST':
file = request.files['file']
book = pd.read_csv(file)
for row in range(len(book)):
rows = (book.iloc[row][0],book.iloc[row][1],book.iloc[row][2],book.iloc[row][3],book.iloc[row][4],book.iloc[row][5])
cur = mysql.connection.cursor()
cur.execute("INSERT INTO users(name,email,password,prn,year,branch) VALUES (%s,%s,%s,%s,%s,%s)",rows)
mysql.connection.commit()
flash( "File Uploaded...")
return redirect(url_for('asupload'))
else:
return render_template("asupload.html")
@app.route('/atupload', methods=["GET", "POST"])
def atupload():
if request.method == 'POST':
file = request.files['file']
book = pd.read_csv(file)
for row in range(len(book)):
rows = (book.iloc[row][0],book.iloc[row][1],book.iloc[row][2],book.iloc[row][3],book.iloc[row][4],book.iloc[row][5])
cur = mysql.connection.cursor()
cur.execute("INSERT INTO teacher(name,email,password,teacherid,subject,branch) VALUES (%s,%s,%s,%s,%s,%s)",rows)
mysql.connection.commit()
flash( "File Uploaded...")
return redirect(url_for('atupload'))
else:
return render_template("atupload.html")
@app.route('/aqlist' , methods=["GET","POST"])
def aqlist():
curl = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
curl.execute("select * from question")
data = curl.fetchall()
return render_template("aqlist.html", value=data)
@app.route('/test',methods=["GET","POST"])
def test():
if request.method == 'GET':
mysql.connection.commit()
curl1 = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
curl1.execute("select * from tests")
data = curl1.fetchall()
curl1.close()
return render_template("test.html",value=data)
else:
subject = request.form['subject']
branch = request.form['branch3']
marks = request.form['marks']
year = request.form['year']
#return str(year)
date1= date.today()
curl1 = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
curl1.execute("select * from tests")
data = curl1.fetchall()
#return str(data)
curl1.close()
#if subject in data["subject"]:
for item in data:
if item["subject"] == subject and item["year"] == year:
flash("Test already exists")
return render_template("test.html",value=data)
#return str(nooooooo)
curl = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
curl.execute("insert into tests(branch,subject,marks,year,date1) values(%s,%s,%s,%s,%s)",[branch,subject,marks,year,date1])
mysql.connection.commit()
curl.close()
flash("Teat created...")
curl2 = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
curl2.execute("select * from tests")
data = curl2.fetchall()
#return str(data)
curl2.close()
return render_template("test.html",value=data)
@app.route('/testdelete/<int:id>' , methods=["GET" , "POST"])
def testdelete(id):
cur = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
cur.execute("DELETE FROM tests WHERE id=%s",[id])
mysql.connection.commit()
flash( "Test Deleted...")
return redirect(url_for("test"))
@app.route('/testpage' , methods=["GET" , "POST"])
def testpage():
subject = request.form["sub"]
curl2 = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
curl2.execute("select marks from tests where subject=%s",[subject])
data = curl2.fetchone()
#return str(data)
curl2.close()
marks=data['marks']
mark1=0.6* int(marks)
mark2=int(marks)-mark1
#return str(mark2)
curl = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
curl.execute("select * from question where subject=%s and marks=1 order by rand() limit %s",(subject,int(mark1)))
data = curl.fetchall()
curl1 = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
curl1.execute("select * from question where subject=%s and marks=2 order by rand() limit %s",(subject,int(mark2/2)))
data1 = curl1.fetchall()
data = data + data1
#return str(len(data))
i=1
for item in data:
item.update({'srno':i})
i=i+1
if i>len(data):
break
curl1.close()
return render_template("exam.html", value=data , length=len(data))
if __name__ == '__main__':
app.secret_key = "^A%DJAJU^JJ123"
app.run(debug=True)
#app.run(host='192.168.31.252', debug=True, port=3134)