Page 176 - FULL REPORT 30012024
P. 176
result = cursor.fetchall()
return jsonify(result)
finally:
cursor.close()
mydb.close()
@app.route('/data/stroke-risk-by-residence')
def stroke_risk_by_residence():
mydb = get_db_connection()
try:
cursor = mydb.cursor(dictionary=True)
query = "SELECT residence_type, AVG(stroke_risk) as
avg_stroke_risk FROM userdata GROUP BY residence_type"
cursor.execute(query)
result = cursor.fetchall()
return jsonify(result)
finally:
cursor.close()
mydb.close()
# Chart in /admin/home -------------------------------------------------
start
# Admin Data Route
@app.route('/admin/data', methods=['GET'])
def admindata():
if 'admin' in session:
mydb = get_db_connection()
cursor = mydb.cursor()
cursor.execute("SELECT * FROM userdata")
user_data = cursor.fetchall()
cursor.close()
mydb.close()
return render_template('admindata.html', user_data=user_data)
else:
flash('Please log in to view this page', 'danger')
return redirect(url_for('adminpage'))
if __name__ == '__main__':
app.run(debug=True)
159