import pickle import pandas as pd from flask import Flask, request, render_template, session from datetime import datetime import mysql.connector app = Flask(__name__) mysql = mysql.connector.connect( host='sql12.freemysqlhosting.net', user='sql12655233', password='NlICXIsXJu', database='sql12655233', port=3306, ) app.secret_key = 'EASA-Final-abhi-2023' @app.route('/') def index(): return render_template('index.html') @app.route('/login', methods=['POST']) def do_admin_login(): if request.form['password'] == 'admin' and request.form['username'] == 'admin': session['logged_in'] = True return root() elif request.form['password'] == 'hod' and request.form['username'] == 'hod': session['logged_in'] = True return hoddashboard() elif request.form['password'] == 'teacher1' and request.form['username'] == 'teacher1': session['logged_in'] = True return teacherdashboard(1) elif request.form['password'] == 'teacher2' and request.form['username'] == 'teacher2': session['logged_in'] = True return teacherdashboard(2) elif request.form['password'] == 'teacher3' and request.form['username'] == 'teacher3': session['logged_in'] = True return teacherdashboard(3) elif request.form['password'] == 'teacher4' and request.form['username'] == 'teacher4': session['logged_in'] = True return teacherdashboard(4) elif request.form['password'] == 'teacher5' and request.form['username'] == 'teacher5': session['logged_in'] = True return teacherdashboard(5) elif request.form['password'] == 'teacher6' and request.form['username'] == 'teacher6': session['logged_in'] = True return teacherdashboard(6) else : return render_template('loginerror.html') def teacherdashboard(teachernumber): ttf, teachers_total_positive_feedbacks, teachers_total_negative_feedbacks, teachers_total_neutral_feedbacks, teachers_li = get_feedback_counts() ttp, ttn, ttneu, tcp, tcn, tcneu, tep, ten, teneu, tlwp, tlwn, tlwneu, tlfp, tlfn, tlfneu, tecp, tecn, tecneu = teachers_li ttp = int(round(ttp/ttf *100));ttn = int(round(ttn/ttf *100));ttneu = int(round(ttneu/ttf *100)) tcp = int(round(tcp / ttf * 100));tcn = int(round(tcn/ttf *100));tcneu = int(round(tcneu/ttf *100)) tep = int(round(tep / ttf * 100));ten = int(round(ten/ttf *100));teneu = int(round(teneu/ttf *100)) tlwp = int(round(tlwp / ttf * 100));tlwn = int(round(tlwn/ttf *100));tlwneu = int(round(tlwneu/ttf *100)) tlfp = int(round(tlfp / ttf * 100));tlfn = int(round(tlfn/ttf *100));tlfneu = int(round(tlfneu/ttf *100)) tecp = int(round(tecp / ttf * 100));tecn = int(round(tecn/ttf *100));tecneu = int(round(tecneu/ttf *100)) if teachernumber == 1: return render_template('teacherdashboard.html',ttf=ttf,ttp=ttp, ttn=ttn, ttneu=ttneu) elif teachernumber == 2: return render_template('teacherdashboard.html',ttf=ttf,ttp=tcp, ttn=tcn, ttneu=tcneu) elif teachernumber == 3: return render_template('teacherdashboard.html',ttf=ttf,ttp=tep, ttn=ten, ttneu=teneu) elif teachernumber == 4: return render_template('teacherdashboard.html',ttf=ttf,ttp=tlwp, ttn=tlwn, ttneu=tlwneu) elif teachernumber == 5: return render_template('teacherdashboard.html',ttf=ttf,ttp=tlfp, ttn=tlfn, ttneu=tlfneu) else: return render_template('teacherdashboard.html',ttf=ttf,ttp=tecp, ttn=tecn, ttneu=tecneu) @app.route('/login', methods=['GET']) def login(): return render_template('login.html') @app.route("/logout") def logout(): session['logged_in'] = False return render_template('index.html') @app.route("/predict", methods=['POST']) def predict(): teaching = request.form['teaching'] courseContent = request.form['coursecontent'] examination = request.form['examination'] labWork = request.form['labwork'] libraryFacilities = request.form['libraryfacilities'] extraCurricular = request.form['extracurricular'] teacher1 = request.form['teacher1'] teacher2 = request.form['teacher2'] teacher3 = request.form['teacher3'] teacher4 = request.form['teacher4'] teacher5 = request.form['teacher5'] teacher6 = request.form['teacher6'] model = pickle.load(open('SVM classifier.pkl', 'rb')) teachingscore = model.predict(pd.array([teaching])) courseContentscore = model.predict(pd.array([courseContent])) examinationscore = model.predict(pd.array([examination])) labWorkscore = model.predict(pd.array([labWork])) libraryFacilitiesscore = model.predict(pd.array([libraryFacilities])) extraCurricularscore = model.predict(pd.array([extraCurricular])) time = datetime.now().strftime("%m/%d/%Y (%H:%M:%S)") teacher1score = model.predict(pd.array([teacher1])) teacher2score = model.predict(pd.array([teacher2])) teacher3score = model.predict(pd.array([teacher3])) teacher4score = model.predict(pd.array([teacher4])) teacher5score = model.predict(pd.array([teacher5])) teacher6score = model.predict(pd.array([teacher6])) write_to_csv_departments(time,teachingscore[0],teaching,courseContentscore[0],courseContent, examinationscore[0],examination,labWorkscore[0],labWork,libraryFacilitiesscore[0], libraryFacilities,extraCurricularscore[0],extraCurricular) write_to_csv_teachers(teacher1,teacher1score[0],teacher2,teacher2score[0],teacher3,teacher3score[0], teacher4,teacher4score[0],teacher5,teacher5score[0],teacher6,teacher6score[0]) return render_template('thankyoupage.html') @app.route('/admin') def root(): if not session.get('logged_in'): return render_template('login.html') else: total_feedbacks, total_positive_feedbacks, total_negative_feedbacks, total_neutral_feedbacks, li = get_counts() tp,tn,tneu,cp,cn,cneu,ep,en,eneu,lwp,lwn,lwneu,lfp,lfn,lfneu,ecp,ecn,ecneu = li teachers_total_feedbacks, teachers_total_positive_feedbacks, teachers_total_negative_feedbacks, teachers_total_neutral_feedbacks, teachers_li = get_feedback_counts() ttp, ttn, ttneu, tcp, tcn, tcneu, tep, ten, teneu, tlwp, tlwn, tlwneu, tlfp, tlfn, tlfneu, tecp, tecn, tecneu = teachers_li return render_template('admin.html',tf = total_feedbacks,tpf = total_positive_feedbacks,tnegf = total_negative_feedbacks, tneuf= total_neutral_feedbacks, tp=tp,tn=tn,tneu=tneu,cp=cp,cn=cn,cneu=cneu,ep=ep,en=en,eneu=eneu, lwp=lwp,lwn=lwn,lwneu=lwneu,lfp=lfp,lfn=lfn,lfneu=lfneu,ecp=ecp, ecn=ecn,ecneu=ecneu, ttf = teachers_total_feedbacks, ttpf = teachers_total_positive_feedbacks, ttnegf = teachers_total_negative_feedbacks, ttneuf = teachers_total_neutral_feedbacks,ttp = ttp, ttn = ttn, ttneu = ttneu, tcp = tcp, tcn = tcn, tcneu = tcneu, tep = tep, ten = ten, teneu = teneu,tlwp = tlwp, tlwn = tlwn, tlwneu = tlwneu, tlfp = tlfp, tlfn = tlfn, tlfneu = tlfneu, tecp = tecp,tecn = tecn, tecneu = tecneu ) @app.route("/hoddashboard") def hoddashboard(): if not session.get('logged_in'): return render_template('login.html') else : teachers_total_feedbacks, teachers_total_positive_feedbacks, teachers_total_negative_feedbacks, teachers_total_neutral_feedbacks, teachers_li = get_feedback_counts() ttp, ttn, ttneu, tcp, tcn, tcneu, tep, ten, teneu, tlwp, tlwn, tlwneu, tlfp, tlfn, tlfneu, tecp, tecn, tecneu = teachers_li return render_template('hoddashboard.html', ttf=teachers_total_feedbacks, ttpf=teachers_total_positive_feedbacks, ttnegf=teachers_total_negative_feedbacks, ttneuf=teachers_total_neutral_feedbacks, ttp=ttp, ttn=ttn, ttneu=ttneu, tcp=tcp, tcn=tcn, tcneu=tcneu, tep=tep, ten=ten, teneu=teneu, tlwp=tlwp, tlwn=tlwn, tlwneu=tlwneu, tlfp=tlfp, tlfn=tlfn, tlfneu=tlfneu, tecp=tecp, tecn=tecn, tecneu=tecneu ) def get_feedback_counts(): cursor = mysql.cursor(dictionary=True) cursor.execute("SELECT * FROM `mytable2`") res_dct = cursor.fetchall() df = pd.DataFrame(res_dct) index = df.index no_of_feedbacks = len(index) total_feedbacks = len(index)*6 df1 = df.groupby('teacher1score').count()[['teacher1']] teacher1_negative_count = df1['teacher1'][-1] teacher1_neutral_count = df1['teacher1'][0] teacher1_positive_count = df1['teacher1'][1] df1 = df.groupby('teacher2score').count()[['teacher2']] teacher2_negative_count = df1['teacher2'][-1] teacher2_neutral_count = df1['teacher2'][0] teacher2_positive_count = df1['teacher2'][1] df1 = df.groupby('teacher3score').count()[['teacher3']] teacher3_negative_count = df1['teacher3'][-1] teacher3_neutral_count = df1['teacher3'][0] teacher3_positive_count = df1['teacher3'][1] df1 = df.groupby('teacher4score').count()[['teacher4']] teacher4_negative_count = df1['teacher4'][-1] teacher4_neutral_count = df1['teacher4'][0] teacher4_positive_count = df1['teacher4'][1] df1 = df.groupby('teacher5score').count()[['teacher5']] teacher5_negative_count = df1['teacher5'][-1] teacher5_neutral_count = df1['teacher5'][0] teacher5_positive_count = df1['teacher5'][1] df1 = df.groupby('teacher6score').count()[['teacher6']] teacher6_negative_count = df1['teacher6'][-1] teacher6_neutral_count = df1['teacher6'][0] teacher6_positive_count = df1['teacher6'][1] total_positive_feedbacks = teacher1_positive_count + teacher2_positive_count + teacher3_positive_count + teacher4_positive_count + teacher5_positive_count + teacher6_positive_count total_neutral_feedbacks = teacher1_neutral_count + teacher2_neutral_count + teacher3_neutral_count + teacher4_neutral_count + teacher5_neutral_count + teacher6_neutral_count total_negative_feedbacks = teacher1_negative_count + teacher2_negative_count + teacher3_negative_count +teacher4_negative_count + teacher5_negative_count + teacher6_negative_count li = [teacher1_positive_count,teacher1_negative_count,teacher1_neutral_count, teacher2_positive_count,teacher2_negative_count,teacher2_neutral_count, teacher3_positive_count,teacher3_negative_count,teacher3_neutral_count, teacher4_positive_count,teacher4_negative_count,teacher4_neutral_count, teacher5_positive_count,teacher5_negative_count,teacher5_neutral_count, teacher6_positive_count,teacher6_negative_count,teacher6_neutral_count] return no_of_feedbacks,\ int(round(total_positive_feedbacks / total_feedbacks * 100)),\ int(round(total_negative_feedbacks / total_feedbacks * 100)),\ int(round(total_neutral_feedbacks / total_feedbacks * 100)),\ li @app.route("/displayteacherfeedbacks") def displayteacherfeedbacks(): if not session.get('logged_in'): return render_template('login.html') else: cursor = mysql.cursor(dictionary=True) cursor.execute("SELECT * FROM `mytable2`") res_dct = cursor.fetchall() df = pd.DataFrame(res_dct) return render_template('teacherfeedbacks.html', tables=[df.to_html(classes='data', header="true")]) @app.route("/display") def display(): if not session.get('logged_in'): return render_template('login.html') else: cursor = mysql.cursor(dictionary=True) cursor.execute("SELECT * FROM `mytable`") res_dct = cursor.fetchall() df = pd.DataFrame(res_dct) return render_template('feedbacks.html', tables=[df.to_html(classes='data', header="true")]) def write_to_csv_departments(time,teachingscore,teaching,courseContentscore,courseContent, examinationscore,examination,labWorkscore,labWork,libraryFacilitiesscore, libraryFacilities,extraCurricularscore,extraCurricular): cursor = mysql.cursor(dictionary=True) cursor.execute("INSERT INTO `mytable`(`Timestamp`, `teachingscore`, `teaching`, `courseContentscore`, `courseContent`, `examinationscore`, `examination`, `labWorkscore`, `labWork`, `libraryFacilitiesscore`, `libraryFacilities`, `extraCurricularscore`, `extraCurricular`) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);", ( time, teachingscore, teaching, courseContentscore,courseContent, examinationscore,examination,labWorkscore,labWork,libraryFacilitiesscore,libraryFacilities,extraCurricularscore,extraCurricular, )) mysql.commit() cursor.close() def write_to_csv_teachers(teacher1,teacher1score,teacher2,teacher2score,teacher3,teacher3score, teacher4,teacher4score,teacher5,teacher5score,teacher6,teacher6score): cursor = mysql.cursor(dictionary=True) cursor.execute("INSERT INTO `mytable2`(`teacher1`, `teacher1score`, `teacher2`, `teacher2score`, `teacher3`, `teacher3score`, `teacher4`, `teacher4score`, `teacher5`, `teacher5score`, `teacher6`, `teacher6score`) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)", ( teacher1, teacher1score, teacher2, teacher2score, teacher3, teacher3score, teacher4, teacher4score, teacher5, teacher5score, teacher6, teacher6score, )) mysql.commit() cursor.close() def get_counts(): cursor = mysql.cursor(dictionary=True) cursor.execute("SELECT * FROM `mytable`") res_dct = cursor.fetchall() df = pd.DataFrame(res_dct) index = df.index no_of_students = len(index) total_feedbacks = len(index)*6 df1 = df.groupby('teachingscore').count()[['teaching']] teaching_negative_count = df1['teaching'][-1] teaching_neutral_count = df1['teaching'][0] teaching_positive_count = df1['teaching'][1] df1 = df.groupby('coursecontentscore').count()[['coursecontent']] coursecontent_negative_count = df1['coursecontent'][-1] coursecontent_neutral_count = df1['coursecontent'][0] coursecontent_positive_count = df1['coursecontent'][1] df1 = df.groupby('examinationscore').count()[['examination']] examination_negative_count = df1['examination'][-1] examination_neutral_count = df1['examination'][0] examination_positive_count = df1['examination'][1] df1 = df.groupby('labworkscore').count()[['labwork']] labwork_negative_count = df1['labwork'][-1] labwork_neutral_count = df1['labwork'][0] labwork_positive_count = df1['labwork'][1] df1 = df.groupby('libraryfacilitiesscore').count()[['libraryfacilities']] libraryfacilities_negative_count = df1['libraryfacilities'][-1] libraryfacilities_neutral_count = df1['libraryfacilities'][0] libraryfacilities_positive_count = df1['libraryfacilities'][1] df1 = df.groupby('extracurricularscore').count()[['extracurricular']] extracurricular_negative_count = df1['extracurricular'][-1] extracurricular_neutral_count = df1['extracurricular'][0] extracurricular_positive_count = df1['extracurricular'][1] total_positive_feedbacks = teaching_positive_count + coursecontent_positive_count + examination_positive_count + labwork_positive_count + libraryfacilities_positive_count + extracurricular_positive_count total_neutral_feedbacks = teaching_neutral_count + coursecontent_neutral_count + examination_neutral_count + labwork_neutral_count + libraryfacilities_neutral_count + extracurricular_neutral_count total_negative_feedbacks = teaching_negative_count + coursecontent_negative_count + examination_negative_count +labwork_negative_count + libraryfacilities_negative_count + extracurricular_negative_count li = [teaching_positive_count,teaching_negative_count,teaching_neutral_count, coursecontent_positive_count,coursecontent_negative_count,coursecontent_neutral_count, examination_positive_count,examination_negative_count,examination_neutral_count, labwork_positive_count,labwork_negative_count,labwork_neutral_count, libraryfacilities_positive_count,libraryfacilities_negative_count,libraryfacilities_neutral_count, extracurricular_positive_count,extracurricular_negative_count,extracurricular_neutral_count] return no_of_students,\ int(round(total_positive_feedbacks / total_feedbacks * 100)),\ int(round(total_negative_feedbacks / total_feedbacks * 100)),\ int(round(total_neutral_feedbacks / total_feedbacks * 100)),\ li def get_tables(): cursor = mysql.cursor(dictionary=True) cursor.execute("SELECT * FROM `mytable`") res_dct = cursor.fetchall() df = pd.DataFrame(res_dct) df = df.tail(5) return [df.to_html(classes='data')] def get_titles(): cursor = mysql.cursor(dictionary=True) cursor.execute("SELECT * FROM `mytable`") res_dct = cursor.fetchall() df = pd.DataFrame(res_dct) return df.columns.values if __name__ == '__main__': app.run()