Page 172 - FULL REPORT 30012024
P. 172
bmi_category= 'Obesity'
if stroke_level in ["Moderate", "High"]:
if smoking_status == "smokes":
personalized_advice.append("Consider quitting smoking to
significantly reduce your stroke risk.")
if hypertension == 1: # Assuming 1 means hypertension is
present
personalized_advice.append("Manage your blood pressure
through regular monitoring and medication if prescribed.")
if heart_disease == 1:
personalized_advice.append("Ensure regular cardiovascular
check-ups and follow your doctor's advice for heart health.")
if bmi_category == "Overweight" or bmi_category == "Obesity":
personalized_advice.append("Aim for a healthy weight
through diet and exercise to lower your stroke risk.")
if not personalized_advice:
personalized_advice = [" "]
personalized_advice_str = json.dumps(personalized_advice)
user_data = {
'gender': gender,
'age': age,
'hypertension': hypertension,
'heart_disease': heart_disease,
'weight': weight,
'height': height,
'bmi': bmi,
'smoking_status': smoking_status,
'ever_married': ever_married,
'work_type': work_type,
'Residence_type': Residence_type,
'stroke_level' : stroke_level,
'stroke_risk': stroke_risk
}
insert_query = """
INSERT INTO userdata (gender, age, hypertension, heart_disease,
weight, height, bmi, smoking_status, ever_married, work_type,
residence_type, stroke_level, stroke_risk)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
"""
mydb = get_db_connection()
cursor = mydb.cursor()
cursor.execute(insert_query, list(user_data.values()))
mydb.commit()
155