|
|
|
|
|
"""cvd |
|
|
|
|
|
Automatically generated by Colab. |
|
|
|
|
|
Original file is located at |
|
|
https://colab.research.google.com/drive/1wfYcKQ_zXWiWclB3ioFMEoc4z8FzPQEd |
|
|
""" |
|
|
|
|
|
import streamlit as st |
|
|
import pandas as pd |
|
|
import math |
|
|
|
|
|
|
|
|
coefficients = { |
|
|
'age': 0.05, |
|
|
'sbp': 0.02, |
|
|
'tc': 0.01, |
|
|
'whr': 0.5, |
|
|
'diabetes': 0.8, |
|
|
'smoking': 0.6, |
|
|
'family_history': 0.4 |
|
|
} |
|
|
|
|
|
mean_values = { |
|
|
'age': 50, |
|
|
'sbp': 130, |
|
|
'tc': 200, |
|
|
'whr': 0.90, |
|
|
'diabetes': 0, |
|
|
'smoking': 0, |
|
|
'family_history': 0 |
|
|
} |
|
|
|
|
|
|
|
|
S_t = 0.9 |
|
|
|
|
|
|
|
|
def calculate_f(individual_values, coefficients, mean_values): |
|
|
f_x_M = 0 |
|
|
for key in coefficients: |
|
|
if key in individual_values: |
|
|
term = coefficients[key] * (individual_values[key] - mean_values[key]) |
|
|
f_x_M += term |
|
|
return f_x_M |
|
|
|
|
|
|
|
|
def calculate_cvd_risk(individual_values, coefficients, mean_values, S_t): |
|
|
|
|
|
f_x_M = calculate_f(individual_values, coefficients, mean_values) |
|
|
|
|
|
exp_f_x_M = math.exp(f_x_M) |
|
|
|
|
|
P = 1 - S_t ** exp_f_x_M |
|
|
return P |
|
|
|
|
|
|
|
|
st.title("CVD Risk Calculator") |
|
|
|
|
|
|
|
|
name = st.text_input("Name") |
|
|
last_name = st.text_input("Last Name") |
|
|
worker_code = st.text_input("Worker Code") |
|
|
age = st.number_input("Age", min_value=0, value=30) |
|
|
sbp = st.number_input("Systolic Blood Pressure (mmHg)", min_value=0, value=120) |
|
|
tc = st.number_input("Triglycerides (mg/dL)", min_value=0, value=150) |
|
|
whr = st.number_input("Waist-to-Hip Ratio", min_value=0.0, value=0.85, step=0.01) |
|
|
diabetes = st.selectbox("Diabetes (Yes/No)", [0, 1], format_func=lambda x: "Yes" if x == 1 else "No") |
|
|
smoking = st.selectbox("Smoking (Yes/No)", [0, 1], format_func=lambda x: "Yes" if x == 1 else "No") |
|
|
family_history = st.selectbox("Family History of CVD (Yes/No)", [0, 1], format_func=lambda x: "Yes" if x == 1 else "No") |
|
|
|
|
|
|
|
|
if st.button("Calculate CVD Risk"): |
|
|
|
|
|
individual_values = { |
|
|
'age': age, |
|
|
'sbp': sbp, |
|
|
'tc': tc, |
|
|
'whr': whr, |
|
|
'diabetes': diabetes, |
|
|
'smoking': smoking, |
|
|
'family_history': family_history |
|
|
} |
|
|
|
|
|
|
|
|
risk = calculate_cvd_risk(individual_values, coefficients, mean_values, S_t) |
|
|
|
|
|
|
|
|
st.write(f"The estimated 10-year CVD risk is: {risk * 100:.2f}%") |
|
|
|
|
|
|
|
|
data = { |
|
|
'Name': name, |
|
|
'Last Name': last_name, |
|
|
'Worker Code': worker_code, |
|
|
'Age': age, |
|
|
'Systolic Blood Pressure': sbp, |
|
|
'Triglycerides': tc, |
|
|
'Waist-to-Hip Ratio': whr, |
|
|
'Diabetes': "Yes" if diabetes == 1 else "No", |
|
|
'Smoking': "Yes" if smoking == 1 else "No", |
|
|
'Family History of CVD': "Yes" if family_history == 1 else "No", |
|
|
'CVD Risk (%)': f"{risk * 100:.2f}" |
|
|
} |
|
|
|
|
|
|
|
|
try: |
|
|
df = pd.read_excel('cvd_data.xlsx') |
|
|
df = df.append(data, ignore_index=True) |
|
|
except FileNotFoundError: |
|
|
df = pd.DataFrame([data]) |
|
|
|
|
|
|
|
|
df.to_excel('cvd_data.xlsx', index=False) |
|
|
st.success("Data saved successfully!") |