Spaces:
Runtime error
Runtime error
Update server.py
Browse files12345678910111213141530 unmodified lines46474849505132 unmodified lines8485868788899071 unmodified lines1621631641651661671 unmodified line1691701711721731741751761 unmodified line178179180181182183184185186import osimport pickleimport pandas as pdfrom flask import Flask, request, render_template, sessionfrom datetime import datetimefrom analytics import write_to_csv_departments,write_to_csv_teachersfrom analytics import get_countsfrom teacherdashboard import get_feedback_countsapp = Flask(__name__)app.secret_key = 'hello-world-flask'@app.route('/')30 unmodified lineselse :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_li32 unmodified lines@app.route("/predict", methods=['POST'])def predict():teaching = request.form['teaching']courseContent = request.form['coursecontent']examination = request.form['examination']71 unmodified lines)@app.route("/displayteacherfeedbacks")1 unmodified lineif not session.get('logged_in'):return render_template('login.html')else:df1 = pd.read_csv('dataset/teacherdb.csv')return render_template('teacherfeedbacks.html', tables=[df1.to_html(classes='data', header="true")])@app.route("/display")1 unmodified lineif not session.get('logged_in'):return render_template('login.html')else:df = pd.read_csv('dataset/database.csv')return render_template('feedbacks.html', tables=[df.to_html(classes='data', header="true")])if __name__ == '__main__':app.run()12345678910111213141516171819202130 unmodified lines5253545556575832 unmodified lines91929394959671 unmodified lines1681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302311 unmodified line2332342352362372382392402412422432441 unmodified line246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357import pickleimport pandas as pdfrom flask import Flask, request, render_template, sessionfrom datetime import datetimeimport mysql.connectorapp = 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('/')30 unmodified lineselse :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_li32 unmodified lines@app.route("/predict", methods=['POST'])def predict():teaching = request.form['teaching']courseContent = request.form['coursecontent']examination = request.form['examination']71 unmodified lines)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.indexno_of_feedbacks = len(index)total_feedbacks = len(index)*6df1 = 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_counttotal_neutral_feedbacks = teacher1_neutral_count + teacher2_neutral_count + teacher3_neutral_count + teacher4_neutral_count + teacher5_neutral_count + teacher6_neutral_counttotal_negative_feedbacks = teacher1_negative_count + teacher2_negative_count + teacher3_negative_count +teacher4_negative_count + teacher5_negative_count + teacher6_negative_countli = [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")1 unmodified lineif 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")1 unmodified lineif 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.indexno_of_students = len(index)total_feedbacks = len(index)*6df1 = 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_counttotal_neutral_feedbacks = teaching_neutral_count + coursecontent_neutral_count + examination_neutral_count + labwork_neutral_count + libraryfacilities_neutral_count + extracurricular_neutral_counttotal_negative_feedbacks = teaching_negative_count + coursecontent_negative_count + examination_negative_count +labwork_negative_count + libraryfacilities_negative_count + extracurricular_negative_countli = [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)),\lidef 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.valuesif __name__ == '__main__':app.run()
server.py+180-9