Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -12,9 +12,9 @@ import string
|
|
12 |
|
13 |
mysql = mysql.connector.connect(
|
14 |
host='sql12.freemysqlhosting.net',
|
15 |
-
user='
|
16 |
-
password='
|
17 |
-
database='
|
18 |
port=3306,
|
19 |
)
|
20 |
|
@@ -35,21 +35,21 @@ def index():
|
|
35 |
def home():
|
36 |
if request.method == 'GET':
|
37 |
if 'email' in session:
|
38 |
-
app.config['MYSQL_DB'] = '
|
39 |
curh = mysql.cursor()
|
40 |
if session['usertype'] == 0:
|
41 |
-
curh.execute("SELECT `assessid`, `name` FROM
|
42 |
typedata = curh.fetchall()
|
43 |
|
44 |
converted_tuple = tuple({'assessid': item[0], 'name': item[1]} for item in typedata)
|
45 |
|
46 |
-
curh.execute("SELECT `id`, `type` FROM
|
47 |
given = curh.fetchall()
|
48 |
isdone = []
|
49 |
for give in given:
|
50 |
isdone.append(give[1])
|
51 |
|
52 |
-
curh.execute("SELECT `name`, `happy`, `datetime` FROM `
|
53 |
previous = curh.fetchall()
|
54 |
|
55 |
preprocessed_data = []
|
@@ -72,7 +72,7 @@ def home():
|
|
72 |
|
73 |
if request.method == 'POST':
|
74 |
if 'email' in session:
|
75 |
-
app.config['MYSQL_DB'] = '
|
76 |
|
77 |
curh = mysql.cursor()
|
78 |
|
@@ -80,7 +80,7 @@ def home():
|
|
80 |
fname = request.form['fname']
|
81 |
femail = request.form['femail']
|
82 |
feedback = request.form['feedback']
|
83 |
-
curh.execute("INSERT INTO `
|
84 |
mysql.commit()
|
85 |
curh.close()
|
86 |
session['feed'] = 1
|
@@ -89,7 +89,7 @@ def home():
|
|
89 |
|
90 |
session['type'] = request.form['type']
|
91 |
|
92 |
-
curh.execute("SELECT `id`, `type` FROM
|
93 |
given = curh.fetchone()
|
94 |
mysql.commit()
|
95 |
curh.close()
|
@@ -113,16 +113,16 @@ def register():
|
|
113 |
if request.method == 'POST':
|
114 |
database = request.form['database']
|
115 |
if database == 'database1':
|
116 |
-
app.config['MYSQL_DB'] = '
|
117 |
session['database'] = app.config['MYSQL_DB']
|
118 |
elif database == 'database2':
|
119 |
-
app.config['MYSQL_DB'] = '
|
120 |
session['database'] = app.config['MYSQL_DB']
|
121 |
|
122 |
name = request.form['name']
|
123 |
email = request.form['email']
|
124 |
cur = mysql.cursor()
|
125 |
-
cur.execute("SELECT * FROM
|
126 |
user = cur.fetchone()
|
127 |
mysql.commit()
|
128 |
cur.close()
|
@@ -163,16 +163,16 @@ def register():
|
|
163 |
@app.route('/verify/<otp>')
|
164 |
def verify(otp):
|
165 |
if str(session['otp']) == otp:
|
166 |
-
app.config['MYSQL_DB'] = '
|
167 |
|
168 |
cur = mysql.cursor()
|
169 |
-
cur.execute("INSERT INTO
|
170 |
|
171 |
if session['pretype'] == 'student':
|
172 |
-
cur.execute("UPDATE `
|
173 |
session['usertype'] = 0
|
174 |
elif session['pretype'] == 'admin':
|
175 |
-
cur.execute("UPDATE `
|
176 |
session['usertype'] = 1
|
177 |
|
178 |
mysql.commit()
|
@@ -197,15 +197,15 @@ def login():
|
|
197 |
now = datetime.datetime.now()
|
198 |
database = request.form['database']
|
199 |
if database == 'database1':
|
200 |
-
app.config['MYSQL_DB'] = '
|
201 |
elif database == 'database2':
|
202 |
-
app.config['MYSQL_DB'] = '
|
203 |
|
204 |
email = request.form['email']
|
205 |
password = request.form['password'].encode('utf-8')
|
206 |
|
207 |
curl = mysql.cursor()
|
208 |
-
curl.execute("SELECT * FROM
|
209 |
user = curl.fetchone()
|
210 |
|
211 |
if user != None:
|
@@ -214,11 +214,11 @@ def login():
|
|
214 |
session['id'] = user[0]
|
215 |
session['name'] = user[2]
|
216 |
session['email'] = user[3]
|
217 |
-
session['database'] = '
|
218 |
|
219 |
print(session)
|
220 |
|
221 |
-
curl.execute("INSERT INTO
|
222 |
mysql.commit()
|
223 |
curl.close()
|
224 |
|
@@ -247,13 +247,13 @@ def forgot():
|
|
247 |
return render_template("forgot.html")
|
248 |
|
249 |
if request.method == 'POST':
|
250 |
-
app.config['MYSQL_DB'] = '
|
251 |
|
252 |
email = request.form['email']
|
253 |
session['email'] = email
|
254 |
|
255 |
curl = mysql.cursor()
|
256 |
-
curl.execute("SELECT * FROM
|
257 |
user = curl.fetchone()
|
258 |
|
259 |
mysql.commit()
|
@@ -301,13 +301,13 @@ def change():
|
|
301 |
return render_template("change.html")
|
302 |
|
303 |
if request.method == 'POST':
|
304 |
-
app.config['MYSQL_DB'] = '
|
305 |
|
306 |
password = request.form['password'].encode('utf-8')
|
307 |
hash_password = bcrypt.hashpw(password, bcrypt.gensalt())
|
308 |
|
309 |
curl = mysql.cursor()
|
310 |
-
curl.execute("UPDATE `
|
311 |
|
312 |
mysql.commit()
|
313 |
curl.close()
|
@@ -327,16 +327,16 @@ def admin():
|
|
327 |
|
328 |
if request.method == 'GET':
|
329 |
if 'email' in session:
|
330 |
-
app.config['MYSQL_DB'] = '
|
331 |
|
332 |
cura = mysql.cursor()
|
333 |
|
334 |
-
cura.execute("SELECT `assessid`, `name` FROM
|
335 |
typedata = cura.fetchall()
|
336 |
|
337 |
typedata_tuple = tuple({'assessid': item[0], 'name': item[1]} for item in typedata)
|
338 |
|
339 |
-
cura.execute("SELECT `id`, `type` FROM
|
340 |
given = cura.fetchall()
|
341 |
|
342 |
given_tuple = tuple({'id': item[0], 'type': item[1]} for item in given)
|
@@ -345,17 +345,17 @@ def admin():
|
|
345 |
for give in given:
|
346 |
isdone.append(give[1])
|
347 |
|
348 |
-
cura.execute("SELECT `id`, `name`, `email`, `isdone` FROM `
|
349 |
res = cura.fetchall()
|
350 |
|
351 |
res_tuple = tuple({'id': item[0], 'name': item[1], 'email': item[2], 'isdone': item[3]} for item in res)
|
352 |
|
353 |
-
cura.execute("SELECT `assessId`, `name`, `description`, `Questions`, `average` FROM `
|
354 |
que = cura.fetchall()
|
355 |
|
356 |
que_tuple = tuple({'assessId': item[0], 'name': item[1], 'description': item[2], 'Questions': item[3], 'average': item[4]} for item in que)
|
357 |
|
358 |
-
cura.execute("SELECT `id`, `type`, `name` FROM `
|
359 |
abc = cura.fetchall()
|
360 |
|
361 |
abc_tuple = tuple({'id': item[0], 'type': item[1], 'name': item[2]} for item in abc)
|
@@ -368,7 +368,7 @@ def admin():
|
|
368 |
ts = len(res)
|
369 |
tas = len(isdone)
|
370 |
|
371 |
-
cura.execute("SELECT `name`, `email`, `feedback` FROM `
|
372 |
feeds = cura.fetchall()
|
373 |
|
374 |
feeds_tuple = tuple({'name': item[0], 'email': item[1], 'feedback': item[2]} for item in feeds)
|
@@ -379,7 +379,7 @@ def admin():
|
|
379 |
return render_template("admin.html", typedata=typedata_tuple, given=given_tuple, result=res_tuple, assess=que_tuple, abc=abc_tuple, ts=ts, ahi=ahi, tas=tas, feeds= feeds_tuple)
|
380 |
|
381 |
if request.method == "POST":
|
382 |
-
app.config['MYSQL_DB'] = '
|
383 |
|
384 |
if 'resid' in request.form:
|
385 |
resid = request.form.get('resid')
|
@@ -393,7 +393,7 @@ def admin():
|
|
393 |
elif 'delete' in request.form:
|
394 |
cura = mysql.cursor()
|
395 |
deleteId = request.form['delete']
|
396 |
-
cura.execute("DELETE FROM `
|
397 |
mysql.commit()
|
398 |
cura.close()
|
399 |
return redirect(url_for('admin'))
|
@@ -407,10 +407,10 @@ def form():
|
|
407 |
return redirect(url_for('login'))
|
408 |
|
409 |
if request.method == "GET":
|
410 |
-
app.config['MYSQL_DB'] = '
|
411 |
typeid = session['type']
|
412 |
curf = mysql.cursor()
|
413 |
-
curf.execute("SELECT `name`, `description`, `Questions`, `types` FROM
|
414 |
questions = curf.fetchone()
|
415 |
|
416 |
mysql.commit()
|
@@ -419,7 +419,7 @@ def form():
|
|
419 |
return render_template("form.html", questions=questions)
|
420 |
|
421 |
if request.method == "POST":
|
422 |
-
app.config['MYSQL_DB'] = '
|
423 |
|
424 |
data = request.form.to_dict()
|
425 |
|
@@ -437,16 +437,16 @@ def form():
|
|
437 |
now = datetime.datetime.now()
|
438 |
cur = mysql.cursor()
|
439 |
|
440 |
-
query = "INSERT INTO `
|
441 |
cur.execute(query, (session['id'], session['type'], json.dumps(inp), json.dumps(compound), now,))
|
442 |
|
443 |
-
query = "UPDATE `
|
444 |
cur.execute(query, (1, session['id'],))
|
445 |
|
446 |
-
cur.execute("SELECT * FROM `
|
447 |
res = cur.fetchone()
|
448 |
|
449 |
-
cur.execute("SELECT qval FROM `
|
450 |
qval = cur.fetchone()
|
451 |
|
452 |
multi = eval(qval[0])
|
@@ -460,17 +460,17 @@ def form():
|
|
460 |
|
461 |
happy_index = round(sum(scaled_values) / len(scaled_values), 2)
|
462 |
|
463 |
-
query = "UPDATE `
|
464 |
cur.execute(query, (happy_index, session['id'], session['type'],))
|
465 |
|
466 |
-
cur.execute("SELECT `happy` FROM `
|
467 |
avg_dict = cur.fetchall()
|
468 |
|
469 |
avg_list = [d[0] for d in avg_dict if isinstance(d[0], float)] + [item for d in avg_dict if isinstance(d[0], (list, tuple)) for item in d[0]]
|
470 |
|
471 |
avg_score = round(sum(avg_list)/len(avg_list), 2)
|
472 |
|
473 |
-
query = "UPDATE `
|
474 |
cur.execute(query, (avg_score, session['type'],))
|
475 |
|
476 |
mysql.commit()
|
@@ -495,7 +495,7 @@ def custom():
|
|
495 |
return render_template('custom.html')
|
496 |
|
497 |
if request.method == "POST":
|
498 |
-
app.config['MYSQL_DB'] = '
|
499 |
|
500 |
data = request.form.to_dict()
|
501 |
|
@@ -528,7 +528,7 @@ def custom():
|
|
528 |
now = datetime.datetime.now()
|
529 |
cur = mysql.cursor()
|
530 |
|
531 |
-
query = "INSERT INTO `
|
532 |
cur.execute(query, (name, describ, json.dumps(inp), json.dumps(types), json.dumps(compound),))
|
533 |
|
534 |
mysql.commit()
|
@@ -544,13 +544,13 @@ def result():
|
|
544 |
if 'email' not in session:
|
545 |
return redirect(url_for('home'))
|
546 |
|
547 |
-
app.config['MYSQL_DB'] = '
|
548 |
curr = mysql.cursor()
|
549 |
|
550 |
-
curr.execute("SELECT * FROM `
|
551 |
res = curr.fetchone()
|
552 |
|
553 |
-
curr.execute("SELECT result FROM `
|
554 |
avg = curr.fetchall()
|
555 |
|
556 |
dynamic = [list(eval(d[0])) for d in avg]
|
@@ -567,10 +567,10 @@ def result():
|
|
567 |
for i in range(1, len(dyna) + 1):
|
568 |
ques.append("Question " + str(i) + "")
|
569 |
|
570 |
-
curr.execute("SELECT * FROM
|
571 |
questions = curr.fetchone()
|
572 |
|
573 |
-
curr.execute("SELECT * FROM
|
574 |
suggests = curr.fetchall()
|
575 |
response = []
|
576 |
mapper = eval(questions[4])
|
@@ -702,7 +702,7 @@ def result():
|
|
702 |
suggest_dict = dict(sorted(result_dict.items()))
|
703 |
|
704 |
curr.execute(
|
705 |
-
"SELECT `Questions`,`response`, `result`, `datetime` FROM `
|
706 |
(session['id'], session['type'],))
|
707 |
details = curr.fetchone()
|
708 |
|
@@ -714,13 +714,13 @@ def result():
|
|
714 |
|
715 |
@app.route('/logout')
|
716 |
def logout():
|
717 |
-
app.config['MYSQL_DB'] = '
|
718 |
now = datetime.datetime.now()
|
719 |
curo = mysql.cursor()
|
720 |
if 'id' in session:
|
721 |
-
curo.execute("INSERT INTO
|
722 |
else:
|
723 |
-
curo.execute("INSERT INTO
|
724 |
|
725 |
mysql.commit()
|
726 |
curo.close()
|
@@ -738,4 +738,4 @@ def handle_error(error):
|
|
738 |
|
739 |
if __name__=='__main__':
|
740 |
app.run(debug=True, host="0.0.0.0")
|
741 |
-
# app.run(debug=True)
|
|
|
12 |
|
13 |
mysql = mysql.connector.connect(
|
14 |
host='sql12.freemysqlhosting.net',
|
15 |
+
user='sql12673861',
|
16 |
+
password='gURFKWEA9G',
|
17 |
+
database='sql12673861',
|
18 |
port=3306,
|
19 |
)
|
20 |
|
|
|
35 |
def home():
|
36 |
if request.method == 'GET':
|
37 |
if 'email' in session:
|
38 |
+
app.config['MYSQL_DB'] = 'sql12673861'
|
39 |
curh = mysql.cursor()
|
40 |
if session['usertype'] == 0:
|
41 |
+
curh.execute("SELECT `assessid`, `name` FROM `h_assessments`")
|
42 |
typedata = curh.fetchall()
|
43 |
|
44 |
converted_tuple = tuple({'assessid': item[0], 'name': item[1]} for item in typedata)
|
45 |
|
46 |
+
curh.execute("SELECT `id`, `type` FROM `h_custom` WHERE id=%s", (session['id'],))
|
47 |
given = curh.fetchall()
|
48 |
isdone = []
|
49 |
for give in given:
|
50 |
isdone.append(give[1])
|
51 |
|
52 |
+
curh.execute("SELECT `name`, `happy`, `datetime` FROM `h_custom`, `h_assessments` WHERE custom.type = assessments.assessId AND id=%s", (session['id'],))
|
53 |
previous = curh.fetchall()
|
54 |
|
55 |
preprocessed_data = []
|
|
|
72 |
|
73 |
if request.method == 'POST':
|
74 |
if 'email' in session:
|
75 |
+
app.config['MYSQL_DB'] = 'sql12673861'
|
76 |
|
77 |
curh = mysql.cursor()
|
78 |
|
|
|
80 |
fname = request.form['fname']
|
81 |
femail = request.form['femail']
|
82 |
feedback = request.form['feedback']
|
83 |
+
curh.execute("INSERT INTO `h_feedbacks`(`name`, `email`, `feedback`) VALUES (%s, %s, %s)", (fname, femail, feedback,))
|
84 |
mysql.commit()
|
85 |
curh.close()
|
86 |
session['feed'] = 1
|
|
|
89 |
|
90 |
session['type'] = request.form['type']
|
91 |
|
92 |
+
curh.execute("SELECT `id`, `type` FROM `h_custom` WHERE id=%s AND type=%s", (session['id'], session['type'],))
|
93 |
given = curh.fetchone()
|
94 |
mysql.commit()
|
95 |
curh.close()
|
|
|
113 |
if request.method == 'POST':
|
114 |
database = request.form['database']
|
115 |
if database == 'database1':
|
116 |
+
app.config['MYSQL_DB'] = 'sql12673861'
|
117 |
session['database'] = app.config['MYSQL_DB']
|
118 |
elif database == 'database2':
|
119 |
+
app.config['MYSQL_DB'] = 'sql12673861'
|
120 |
session['database'] = app.config['MYSQL_DB']
|
121 |
|
122 |
name = request.form['name']
|
123 |
email = request.form['email']
|
124 |
cur = mysql.cursor()
|
125 |
+
cur.execute("SELECT * FROM `h_users` WHERE email = %s", (email,))
|
126 |
user = cur.fetchone()
|
127 |
mysql.commit()
|
128 |
cur.close()
|
|
|
163 |
@app.route('/verify/<otp>')
|
164 |
def verify(otp):
|
165 |
if str(session['otp']) == otp:
|
166 |
+
app.config['MYSQL_DB'] = 'sql12673861'
|
167 |
|
168 |
cur = mysql.cursor()
|
169 |
+
cur.execute("INSERT INTO `h_users` (name, email, password) VALUES (%s,%s,%s)", (session['name'], session['email'], session['hash'],))
|
170 |
|
171 |
if session['pretype'] == 'student':
|
172 |
+
cur.execute("UPDATE `h_users` SET `usertype` = %s WHERE `email`=%s", (0, session['email'],))
|
173 |
session['usertype'] = 0
|
174 |
elif session['pretype'] == 'admin':
|
175 |
+
cur.execute("UPDATE `h_users` SET `usertype` = %s WHERE `email`=%s", (1, session['email'],))
|
176 |
session['usertype'] = 1
|
177 |
|
178 |
mysql.commit()
|
|
|
197 |
now = datetime.datetime.now()
|
198 |
database = request.form['database']
|
199 |
if database == 'database1':
|
200 |
+
app.config['MYSQL_DB'] = 'sql12673861'
|
201 |
elif database == 'database2':
|
202 |
+
app.config['MYSQL_DB'] = 'sql12673861'
|
203 |
|
204 |
email = request.form['email']
|
205 |
password = request.form['password'].encode('utf-8')
|
206 |
|
207 |
curl = mysql.cursor()
|
208 |
+
curl.execute("SELECT * FROM `h_users` WHERE email=%s", (email,))
|
209 |
user = curl.fetchone()
|
210 |
|
211 |
if user != None:
|
|
|
214 |
session['id'] = user[0]
|
215 |
session['name'] = user[2]
|
216 |
session['email'] = user[3]
|
217 |
+
session['database'] = 'sql12673861'
|
218 |
|
219 |
print(session)
|
220 |
|
221 |
+
curl.execute("INSERT INTO `h_session` (id, email, action, actionC, datetime) VALUES (%s, %s, %s, %s, %s)", (session['id'], session['email'], 'Logged In - Session Started', 1, now,))
|
222 |
mysql.commit()
|
223 |
curl.close()
|
224 |
|
|
|
247 |
return render_template("forgot.html")
|
248 |
|
249 |
if request.method == 'POST':
|
250 |
+
app.config['MYSQL_DB'] = 'sql12673861'
|
251 |
|
252 |
email = request.form['email']
|
253 |
session['email'] = email
|
254 |
|
255 |
curl = mysql.cursor()
|
256 |
+
curl.execute("SELECT * FROM `h_users` WHERE email=%s", (email,))
|
257 |
user = curl.fetchone()
|
258 |
|
259 |
mysql.commit()
|
|
|
301 |
return render_template("change.html")
|
302 |
|
303 |
if request.method == 'POST':
|
304 |
+
app.config['MYSQL_DB'] = 'sql12673861'
|
305 |
|
306 |
password = request.form['password'].encode('utf-8')
|
307 |
hash_password = bcrypt.hashpw(password, bcrypt.gensalt())
|
308 |
|
309 |
curl = mysql.cursor()
|
310 |
+
curl.execute("UPDATE `h_users` SET `password`=%s WHERE email=%s", (hash_password, session['email'],))
|
311 |
|
312 |
mysql.commit()
|
313 |
curl.close()
|
|
|
327 |
|
328 |
if request.method == 'GET':
|
329 |
if 'email' in session:
|
330 |
+
app.config['MYSQL_DB'] = 'sql12673861'
|
331 |
|
332 |
cura = mysql.cursor()
|
333 |
|
334 |
+
cura.execute("SELECT `assessid`, `name` FROM `h_assessments`")
|
335 |
typedata = cura.fetchall()
|
336 |
|
337 |
typedata_tuple = tuple({'assessid': item[0], 'name': item[1]} for item in typedata)
|
338 |
|
339 |
+
cura.execute("SELECT `id`, `type` FROM `h_custom`")
|
340 |
given = cura.fetchall()
|
341 |
|
342 |
given_tuple = tuple({'id': item[0], 'type': item[1]} for item in given)
|
|
|
345 |
for give in given:
|
346 |
isdone.append(give[1])
|
347 |
|
348 |
+
cura.execute("SELECT `id`, `name`, `email`, `isdone` FROM `h_users` WHERE `usertype` = 0")
|
349 |
res = cura.fetchall()
|
350 |
|
351 |
res_tuple = tuple({'id': item[0], 'name': item[1], 'email': item[2], 'isdone': item[3]} for item in res)
|
352 |
|
353 |
+
cura.execute("SELECT `assessId`, `name`, `description`, `Questions`, `average` FROM `h_assessments`")
|
354 |
que = cura.fetchall()
|
355 |
|
356 |
que_tuple = tuple({'assessId': item[0], 'name': item[1], 'description': item[2], 'Questions': item[3], 'average': item[4]} for item in que)
|
357 |
|
358 |
+
cura.execute("SELECT `id`, `type`, `name` FROM `h_custom`, `h_assessments` WHERE h_custom.type = h_assessments.assessId")
|
359 |
abc = cura.fetchall()
|
360 |
|
361 |
abc_tuple = tuple({'id': item[0], 'type': item[1], 'name': item[2]} for item in abc)
|
|
|
368 |
ts = len(res)
|
369 |
tas = len(isdone)
|
370 |
|
371 |
+
cura.execute("SELECT `name`, `email`, `feedback` FROM `h_feedbacks`")
|
372 |
feeds = cura.fetchall()
|
373 |
|
374 |
feeds_tuple = tuple({'name': item[0], 'email': item[1], 'feedback': item[2]} for item in feeds)
|
|
|
379 |
return render_template("admin.html", typedata=typedata_tuple, given=given_tuple, result=res_tuple, assess=que_tuple, abc=abc_tuple, ts=ts, ahi=ahi, tas=tas, feeds= feeds_tuple)
|
380 |
|
381 |
if request.method == "POST":
|
382 |
+
app.config['MYSQL_DB'] = 'sql12673861'
|
383 |
|
384 |
if 'resid' in request.form:
|
385 |
resid = request.form.get('resid')
|
|
|
393 |
elif 'delete' in request.form:
|
394 |
cura = mysql.cursor()
|
395 |
deleteId = request.form['delete']
|
396 |
+
cura.execute("DELETE FROM `h_assessments` WHERE `assessId`= %s", (deleteId,))
|
397 |
mysql.commit()
|
398 |
cura.close()
|
399 |
return redirect(url_for('admin'))
|
|
|
407 |
return redirect(url_for('login'))
|
408 |
|
409 |
if request.method == "GET":
|
410 |
+
app.config['MYSQL_DB'] = 'sql12673861'
|
411 |
typeid = session['type']
|
412 |
curf = mysql.cursor()
|
413 |
+
curf.execute("SELECT `name`, `description`, `Questions`, `types` FROM `h_assessments` WHERE assessid = %s", (typeid,))
|
414 |
questions = curf.fetchone()
|
415 |
|
416 |
mysql.commit()
|
|
|
419 |
return render_template("form.html", questions=questions)
|
420 |
|
421 |
if request.method == "POST":
|
422 |
+
app.config['MYSQL_DB'] = 'sql12673861'
|
423 |
|
424 |
data = request.form.to_dict()
|
425 |
|
|
|
437 |
now = datetime.datetime.now()
|
438 |
cur = mysql.cursor()
|
439 |
|
440 |
+
query = "INSERT INTO `h_custom` (`Id`, `type`, `response`, `result`, `datetime`) VALUES (%s, %s, %s, %s, %s)"
|
441 |
cur.execute(query, (session['id'], session['type'], json.dumps(inp), json.dumps(compound), now,))
|
442 |
|
443 |
+
query = "UPDATE `h_users` SET `isdone`=%s WHERE `id`=%s"
|
444 |
cur.execute(query, (1, session['id'],))
|
445 |
|
446 |
+
cur.execute("SELECT * FROM `h_custom` WHERE id=%s AND type=%s", (session['id'], session['type'],))
|
447 |
res = cur.fetchone()
|
448 |
|
449 |
+
cur.execute("SELECT qval FROM `h_assessments` WHERE assessId=%s", (session['type'],))
|
450 |
qval = cur.fetchone()
|
451 |
|
452 |
multi = eval(qval[0])
|
|
|
460 |
|
461 |
happy_index = round(sum(scaled_values) / len(scaled_values), 2)
|
462 |
|
463 |
+
query = "UPDATE `h_custom` SET `happy`=%s WHERE `id`=%s AND `type`=%s"
|
464 |
cur.execute(query, (happy_index, session['id'], session['type'],))
|
465 |
|
466 |
+
cur.execute("SELECT `happy` FROM `h_custom` WHERE type=%s", (session['type'],))
|
467 |
avg_dict = cur.fetchall()
|
468 |
|
469 |
avg_list = [d[0] for d in avg_dict if isinstance(d[0], float)] + [item for d in avg_dict if isinstance(d[0], (list, tuple)) for item in d[0]]
|
470 |
|
471 |
avg_score = round(sum(avg_list)/len(avg_list), 2)
|
472 |
|
473 |
+
query = "UPDATE `h_assessments` SET `average`=%s WHERE `assessId`=%s"
|
474 |
cur.execute(query, (avg_score, session['type'],))
|
475 |
|
476 |
mysql.commit()
|
|
|
495 |
return render_template('custom.html')
|
496 |
|
497 |
if request.method == "POST":
|
498 |
+
app.config['MYSQL_DB'] = 'sql12673861'
|
499 |
|
500 |
data = request.form.to_dict()
|
501 |
|
|
|
528 |
now = datetime.datetime.now()
|
529 |
cur = mysql.cursor()
|
530 |
|
531 |
+
query = "INSERT INTO `h_assessments` (`name`, `description`, `Questions`, `types`, `qval`) VALUES (%s, %s, %s, %s, %s)"
|
532 |
cur.execute(query, (name, describ, json.dumps(inp), json.dumps(types), json.dumps(compound),))
|
533 |
|
534 |
mysql.commit()
|
|
|
544 |
if 'email' not in session:
|
545 |
return redirect(url_for('home'))
|
546 |
|
547 |
+
app.config['MYSQL_DB'] = 'sql12673861'
|
548 |
curr = mysql.cursor()
|
549 |
|
550 |
+
curr.execute("SELECT * FROM `h_custom` WHERE id=%s AND type=%s", (session['id'], session['type'],))
|
551 |
res = curr.fetchone()
|
552 |
|
553 |
+
curr.execute("SELECT `result` FROM `h_custom` WHERE type=%s", (session['type'],))
|
554 |
avg = curr.fetchall()
|
555 |
|
556 |
dynamic = [list(eval(d[0])) for d in avg]
|
|
|
567 |
for i in range(1, len(dyna) + 1):
|
568 |
ques.append("Question " + str(i) + "")
|
569 |
|
570 |
+
curr.execute("SELECT * FROM `h_assessments` WHERE assessid = %s", (session['type'],))
|
571 |
questions = curr.fetchone()
|
572 |
|
573 |
+
curr.execute("SELECT * FROM `h_suggestions`")
|
574 |
suggests = curr.fetchall()
|
575 |
response = []
|
576 |
mapper = eval(questions[4])
|
|
|
702 |
suggest_dict = dict(sorted(result_dict.items()))
|
703 |
|
704 |
curr.execute(
|
705 |
+
"SELECT `Questions`,`response`, `result`, `datetime` FROM `h_custom`, `h_assessments` WHERE `id`=%s AND `type`=%s AND h_custom.type = h_assessments.assessId",
|
706 |
(session['id'], session['type'],))
|
707 |
details = curr.fetchone()
|
708 |
|
|
|
714 |
|
715 |
@app.route('/logout')
|
716 |
def logout():
|
717 |
+
app.config['MYSQL_DB'] = 'sql12673861'
|
718 |
now = datetime.datetime.now()
|
719 |
curo = mysql.cursor()
|
720 |
if 'id' in session:
|
721 |
+
curo.execute("INSERT INTO `h_session` (id, email, action, actionC, datetime) VALUES (%s, %s, %s, %s, %s)", (session['id'], session['email'], 'Logged Out - Session Terminated', 0, now,))
|
722 |
else:
|
723 |
+
curo.execute("INSERT INTO `h_session` (email, action, actionC, datetime) VALUES (%s, %s, %s, %s)", (session['email'], 'Logged Out - Session Terminated', 0, now,))
|
724 |
|
725 |
mysql.commit()
|
726 |
curo.close()
|
|
|
738 |
|
739 |
if __name__=='__main__':
|
740 |
app.run(debug=True, host="0.0.0.0")
|
741 |
+
# app.run(debug=True)
|