Spaces:
Runtime error
Runtime error
File size: 17,219 Bytes
39f528e 84c69ed 39f528e 84c69ed e1ddffb 39f528e 84c69ed 39f528e 84c69ed 39f528e 84c69ed 39f528e 84c69ed 39f528e 84c69ed e1ddffb |
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 |
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() |