Skip to content

Commit dd5fda9

Browse files
Merge pull request #97 from nickcanz/implement_streamlit_caching
Implement streamlit caching
2 parents 9d0d319 + 78ecdcb commit dd5fda9

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

penn_chime/models.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
from typing import Tuple
22

33
import numpy as np
4+
import streamlit as st
45

56

67
# The SIR model, one time step
8+
@st.cache
79
def sir(y, beta, gamma, N):
810
S, I, R = y
911
Sn = (-beta * S * I) + S
@@ -21,6 +23,7 @@ def sir(y, beta, gamma, N):
2123

2224

2325
# Run the SIR model forward in time
26+
@st.cache
2427
def sim_sir(
2528
S, I, R, beta, gamma, n_days, beta_decay=0
2629
) -> Tuple[np.ndarray, np.ndarray, np.ndarray]:
@@ -37,7 +40,7 @@ def sim_sir(
3740
s, i, r = np.array(s), np.array(i), np.array(r)
3841
return s, i, r
3942

40-
43+
@st.cache
4144
def get_hospitalizations(
4245
infected: np.ndarray, rates: Tuple[float, float, float], market_share: float
4346
) -> Tuple[np.ndarray, np.ndarray, np.ndarray]:

penn_chime/utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import numpy as np
22
import pandas as pd
3+
import streamlit as st
34

4-
5+
@st.cache
56
def build_admissions_df(n_days, hosp, icu, vent) -> pd.DataFrame:
67
days = np.array(range(0, n_days + 1))
78
data_dict = dict(zip(["day", "hosp", "icu", "vent"], [days, hosp, icu, vent]))
@@ -12,7 +13,7 @@ def build_admissions_df(n_days, hosp, icu, vent) -> pd.DataFrame:
1213
projection_admits["day"] = range(projection_admits.shape[0])
1314
return projection_admits
1415

15-
16+
@st.cache
1617
def build_census_df(projection_admits, hosp_los, icu_los, vent_los) -> pd.DataFrame:
1718
"""ALOS for each category of COVID-19 case (total guesses)"""
1819
n_days = np.shape(projection_admits)[0]

0 commit comments

Comments
 (0)