Commit
·
22760f4
1
Parent(s):
6fc553a
Delete streamlit_app_asdm.py
Browse files- streamlit_app_asdm.py +0 -57
streamlit_app_asdm.py
DELETED
@@ -1,57 +0,0 @@
|
|
1 |
-
import pandas as pd
|
2 |
-
import streamlit as st
|
3 |
-
import plotly.graph_objects as go
|
4 |
-
from ASDM.ASDM import Structure
|
5 |
-
|
6 |
-
def load_model(model_path):
|
7 |
-
try:
|
8 |
-
model = Structure(from_xmile=model_path)
|
9 |
-
except FileNotFoundError:
|
10 |
-
st.error(f"File {model_path} not found.")
|
11 |
-
return None
|
12 |
-
return model
|
13 |
-
|
14 |
-
def run_simulation(model, simulation_time, re_investment):
|
15 |
-
model.sim_specs['initial_time'] = 0
|
16 |
-
model.sim_specs['current_time'] = 0
|
17 |
-
model.sim_specs['dt'] = 1
|
18 |
-
model.sim_specs['simulation_time'] = simulation_time
|
19 |
-
model.sim_specs['time_units'] = 'Months'
|
20 |
-
|
21 |
-
model.clear_last_run()
|
22 |
-
|
23 |
-
model.aux_equations['percentageOfSavingsSpentOnCessation'] = str(re_investment)
|
24 |
-
|
25 |
-
model.simulate()
|
26 |
-
|
27 |
-
results = model.export_simulation_result()
|
28 |
-
results_df = pd.DataFrame.from_dict(results)
|
29 |
-
|
30 |
-
columns_to_plot = ["Current_smokers", "Ex_smokers", "Ex_smokers_starting_again"]
|
31 |
-
return results_df['Months'], results_df[columns_to_plot]
|
32 |
-
|
33 |
-
st.title('Smoking Cessation')
|
34 |
-
|
35 |
-
st.markdown("""
|
36 |
-
This simulation estimates the effects of various reinvestment levels in a smoking cessation service within a population of 900 smokers.
|
37 |
-
By varying the proportion of savings that are reinvested into the service, we can observe different outcomes in terms of current smokers, ex-smokers,
|
38 |
-
and ex-smokers who start smoking again over time.
|
39 |
-
""")
|
40 |
-
|
41 |
-
st.subheader('Slide the Slider to Vary Re-Investment Levels')
|
42 |
-
|
43 |
-
model = load_model('models/smoking cessation demo.stmx')
|
44 |
-
|
45 |
-
if model is not None:
|
46 |
-
re_investment = st.slider("Proportion of Savings Spent on Cessation", 0, 100, 45)
|
47 |
-
simulation_time = st.slider("Select the number of months to simulate:", min_value=1, max_value=36, value=24)
|
48 |
-
|
49 |
-
x_values, y_values = run_simulation(model, simulation_time, re_investment)
|
50 |
-
|
51 |
-
st.subheader('Effects of Re-Investment on Smoking Levels')
|
52 |
-
|
53 |
-
fig = go.Figure()
|
54 |
-
for column in y_values.columns:
|
55 |
-
fig.add_trace(go.Scatter(x=x_values, y=y_values[column], mode='lines', name=column))
|
56 |
-
fig.update_layout(xaxis_title='Months', yaxis_title='Number of Smokers', autosize=False, width=800, height=500)
|
57 |
-
st.plotly_chart(fig)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|