Page 174 - FULL REPORT 30012024
P. 174
session.pop('admin', None)
session['admin_logging_out'] = True
flash('You have been logged out.', 'success')
return redirect(url_for('adminpage'))
@app.route('/admin/home')
def admindashboard():
if 'admin' in session and session['admin']:
return render_template('admindashboard.html')
else:
flash('You need to log in as an admin to access this page.',
'danger')
return redirect(url_for('adminpage'))
# Chart in /admin/home -------------------------------------------------
start
##---Card
@app.route('/data/count-users')
def count_users():
mydb = get_db_connection()
try:
cursor = mydb.cursor(dictionary=True)
query = "SELECT COUNT(*) as count FROM userdata"
cursor.execute(query)
result = cursor.fetchone()
return jsonify(result)
finally:
cursor.close()
mydb.close()
@app.route('/data/count-risk-levels')
def count_risk_levels():
mydb = get_db_connection()
try:
cursor = mydb.cursor(dictionary=True)
query = "SELECT stroke_level, COUNT(*) as count FROM userdata
GROUP BY stroke_level"
cursor.execute(query)
result = cursor.fetchall()
return jsonify(result)
finally:
cursor.close()
mydb.close()
##--Card End
@app.route('/data/stroke-risk')
def stroke_risk_data():
mydb = get_db_connection()
try:
cursor = mydb.cursor(dictionary=True)
query = "SELECT age, AVG(stroke_risk) as avg_stroke_risk FROM
userdata GROUP BY age"
157