MattStammers commited on
Commit
f7eb114
1 Parent(s): 5a9df93

working base model

Browse files
Files changed (2) hide show
  1. requirements.txt +151 -0
  2. streamlit_app_asdm.py +57 -0
requirements.txt ADDED
@@ -0,0 +1,151 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ altair==5.0.1 ; python_version >= '3.7'
2
+ anyio==3.7.1 ; python_version >= '3.7'
3
+ argon2-cffi==21.3.0 ; python_version >= '3.6'
4
+ argon2-cffi-bindings==21.2.0 ; python_version >= '3.6'
5
+ arrow==1.2.3 ; python_version >= '3.6'
6
+ arviz==0.12.1 ; python_version >= '3.7'
7
+ asdm==0.0.3
8
+ asttokens==2.2.1
9
+ async-lru==2.0.3 ; python_version >= '3.8'
10
+ attrs==23.1.0 ; python_version >= '3.7'
11
+ babel==2.12.1 ; python_version >= '3.7'
12
+ backcall==0.2.0
13
+ beautifulsoup4==4.12.2 ; python_full_version >= '3.6.0'
14
+ bleach==6.0.0 ; python_version >= '3.7'
15
+ blinker==1.6.2 ; python_version >= '3.7'
16
+ cachetools==5.3.1 ; python_version >= '3.7'
17
+ certifi==2023.5.7 ; python_version >= '3.6'
18
+ cffi==1.15.1
19
+ cftime==1.6.2 ; python_version >= '3.7'
20
+ charset-normalizer==3.2.0 ; python_full_version >= '3.7.0'
21
+ click==8.1.5 ; python_version >= '3.7'
22
+ colorama==0.4.6 ; platform_system == 'Windows'
23
+ comm==0.1.3 ; python_version >= '3.6'
24
+ contourpy==1.1.0 ; python_version >= '3.8'
25
+ cycler==0.11.0 ; python_version >= '3.6'
26
+ debugpy==1.6.7 ; python_version >= '3.7'
27
+ decorator==5.1.1 ; python_version >= '3.5'
28
+ defusedxml==0.7.1 ; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'
29
+ deprecat==2.1.1 ; python_version >= '3.6'
30
+ dill==0.3.6 ; python_version >= '3.7'
31
+ et-xmlfile==1.1.0 ; python_version >= '3.6'
32
+ exceptiongroup==1.1.2 ; python_version < '3.11'
33
+ executing==1.2.0
34
+ fastjsonschema==2.17.1
35
+ fastprogress==1.0.3 ; python_version >= '3.6'
36
+ filelock==3.12.2 ; python_version >= '3.7'
37
+ fonttools==4.41.0 ; python_version >= '3.8'
38
+ fqdn==1.5.1
39
+ gitdb==4.0.10 ; python_version >= '3.7'
40
+ gitpython==3.1.32 ; python_version >= '3.7'
41
+ idna==3.4 ; python_version >= '3.5'
42
+ importlib-metadata==6.8.0 ; python_version >= '3.8'
43
+ ipykernel==6.24.0
44
+ ipython==8.14.0 ; python_version >= '3.9'
45
+ ipywidgets==8.0.7 ; python_version >= '3.7'
46
+ isoduration==20.11.0
47
+ jedi==0.18.2 ; python_version >= '3.6'
48
+ jinja2==3.1.2 ; python_version >= '3.7'
49
+ json5==0.9.14
50
+ jsonpointer==2.4
51
+ jsonschema==4.18.3 ; python_version >= '3.8'
52
+ jsonschema-specifications==2023.6.1 ; python_version >= '3.8'
53
+ jupyter-client==8.3.0 ; python_version >= '3.8'
54
+ jupyter-core==5.3.1 ; python_version >= '3.8'
55
+ jupyter-events==0.6.3 ; python_version >= '3.7'
56
+ jupyter-lsp==2.2.0 ; python_version >= '3.8'
57
+ jupyter-server==2.7.0 ; python_version >= '3.8'
58
+ jupyter-server-terminals==0.4.4 ; python_version >= '3.8'
59
+ jupyterlab==4.0.3
60
+ jupyterlab-pygments==0.2.2 ; python_version >= '3.7'
61
+ jupyterlab-server==2.23.0 ; python_version >= '3.7'
62
+ jupyterlab-widgets==3.0.8 ; python_version >= '3.7'
63
+ kiwisolver==1.4.4 ; python_version >= '3.7'
64
+ lxml==4.9.3 ; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'
65
+ markdown-it-py==3.0.0 ; python_version >= '3.8'
66
+ markupsafe==2.1.3 ; python_version >= '3.7'
67
+ matplotlib==3.7.2 ; python_version >= '3.8'
68
+ matplotlib-inline==0.1.6 ; python_version >= '3.5'
69
+ mdurl==0.1.2 ; python_version >= '3.7'
70
+ mistune==3.0.1 ; python_version >= '3.7'
71
+ nbclient==0.8.0 ; python_full_version >= '3.8.0'
72
+ nbconvert==7.6.0 ; python_version >= '3.7'
73
+ nbformat==5.9.1 ; python_version >= '3.8'
74
+ nest-asyncio==1.5.6 ; python_version >= '3.5'
75
+ netcdf4==1.6.4 ; python_version >= '3.7'
76
+ networkx==3.1 ; python_version >= '3.8'
77
+ notebook-shim==0.2.3 ; python_version >= '3.7'
78
+ numpy==1.22.1 ; python_version >= '3.8'
79
+ openpyxl==3.1.2 ; python_version >= '3.6'
80
+ overrides==7.3.1 ; python_version >= '3.6'
81
+ packaging==23.1 ; python_version >= '3.7'
82
+ pandas==2.0.3 ; python_version >= '3.8'
83
+ pandocfilters==1.5.0 ; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
84
+ parso==0.8.3 ; python_version >= '3.6'
85
+ patsy==0.5.3
86
+ pickleshare==0.7.5
87
+ pillow==9.5.0 ; python_version >= '3.7'
88
+ platformdirs==3.9.1 ; python_version >= '3.7'
89
+ plotly==5.15.0
90
+ prometheus-client==0.17.1 ; python_version >= '3.6'
91
+ prompt-toolkit==3.0.39 ; python_full_version >= '3.7.0'
92
+ protobuf==4.23.4 ; python_version >= '3.7'
93
+ psutil==5.9.5 ; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
94
+ pure-eval==0.2.2
95
+ pyarrow==12.0.1 ; python_version >= '3.7'
96
+ pycparser==2.21
97
+ pydeck==0.8.1b0 ; python_version >= '3.7'
98
+ pygments==2.15.1 ; python_version >= '3.7'
99
+ pymc3==3.11.5 ; python_version >= '3.7'
100
+ pympler==1.0.1 ; python_version >= '3.6'
101
+ pyparsing==3.0.9 ; python_full_version >= '3.6.8'
102
+ python-dateutil==2.8.2 ; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
103
+ python-json-logger==2.0.7 ; python_version >= '3.6'
104
+ pytz==2023.3
105
+ pytz-deprecation-shim==0.1.0.post0 ; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4, 3.5'
106
+ pywin32==306 ; sys_platform == 'win32' and platform_python_implementation != 'PyPy'
107
+ pywinpty==2.0.11 ; os_name == 'nt'
108
+ pyyaml==6.0 ; python_version >= '3.6'
109
+ pyzmq==25.1.0 ; python_version >= '3.6'
110
+ referencing==0.29.1 ; python_version >= '3.8'
111
+ requests==2.31.0 ; python_version >= '3.7'
112
+ rfc3339-validator==0.1.4 ; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'
113
+ rfc3986-validator==0.1.1 ; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'
114
+ rich==13.4.2 ; python_full_version >= '3.7.0'
115
+ rpds-py==0.8.10 ; python_version >= '3.8'
116
+ scipy==1.7.3 ; python_version < '3.11' and python_version >= '3.7'
117
+ semver==3.0.1 ; python_version >= '3.7'
118
+ send2trash==1.8.2 ; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'
119
+ setuptools==68.0.0 ; python_version >= '3.7'
120
+ six==1.16.0 ; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
121
+ smmap==5.0.0 ; python_version >= '3.6'
122
+ sniffio==1.3.0 ; python_version >= '3.7'
123
+ soupsieve==2.4.1 ; python_version >= '3.7'
124
+ stack-data==0.6.2
125
+ streamlit==1.24.1
126
+ tenacity==8.2.2 ; python_version >= '3.6'
127
+ terminado==0.17.1 ; python_version >= '3.7'
128
+ theano-pymc==1.1.2
129
+ tinycss2==1.2.1 ; python_version >= '3.7'
130
+ toml==0.10.2 ; python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'
131
+ tomli==2.0.1 ; python_version < '3.11'
132
+ toolz==0.12.0 ; python_version >= '3.5'
133
+ tornado==6.3.2 ; python_version >= '3.8'
134
+ tqdm==4.65.0 ; python_version >= '3.7'
135
+ traitlets==5.9.0 ; python_version >= '3.7'
136
+ typing-extensions==4.7.1 ; python_version >= '3.7'
137
+ tzdata==2023.3 ; python_version >= '2'
138
+ tzlocal==4.3.1 ; python_version >= '3.7'
139
+ uri-template==1.3.0
140
+ urllib3==2.0.3 ; python_version >= '3.7'
141
+ validators==0.20.0 ; python_version >= '3.4'
142
+ watchdog==3.0.0 ; platform_system != 'Darwin'
143
+ wcwidth==0.2.6
144
+ webcolors==1.13
145
+ webencodings==0.5.1
146
+ websocket-client==1.6.1 ; python_version >= '3.7'
147
+ widgetsnbextension==4.0.8 ; python_version >= '3.7'
148
+ wrapt==1.15.0 ; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'
149
+ xarray==2023.6.0 ; python_version >= '3.9'
150
+ xarray-einstats==0.6.0 ; python_version >= '3.9'
151
+ zipp==3.16.2 ; python_version >= '3.8'
streamlit_app_asdm.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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)