Skip to content

Commit 401f4cf

Browse files
committed
Split model from view for PPE
1 parent fc8f7bc commit 401f4cf

File tree

6 files changed

+59
-63
lines changed

6 files changed

+59
-63
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM python:3.7.7-slim-buster
22
ENV PARAMETERS=./defaults/webapp.cfg
3-
ENV PPE_FOLDER=./defaults/assets/
3+
ENV ASSETS=./defaults/assets/
44
ENV PORT=8000
55
WORKDIR /app
66
COPY README.md .

Procfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
web: PARAMETERS=./defaults/webapp.cfg PPE_EXCEL=./defaults/PPE_Usage_Draft_CC_modifications_v2.xlsx STREAMLIT_SERVER_PORT=$PORT streamlit run st_app.py
1+
web: PARAMETERS=./defaults/webapp.cfg ASSETS=./defaults/assets STREAMLIT_SERVER_PORT=$PORT streamlit run st_app.py

src/penn_chime/model/ppe.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"""Personal Protective Equipment."""
2+
3+
import os
4+
from typing import Dict
5+
6+
7+
class PPE:
8+
9+
def __init__(self, env: Dict[str, str]):
10+
"""__init__."""
11+
self.assets = assets = env['ASSETS']
12+
self.filename = filename = "PPE_Calculator_for_COVID-19.xlsx"
13+
self.src = os.path.join(assets, filename)
14+
self.screenshot = os.path.join(assets, 'PPE_Screenshot.jpg')

src/penn_chime/ppe/ppe.py

Lines changed: 0 additions & 47 deletions
This file was deleted.

src/penn_chime/view/st_app.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
import os
44

5-
import altair as alt # type: ignore
6-
import streamlit as st # type: ignore
7-
import i18n # type: ignore
5+
import altair as alt
6+
import streamlit as st
7+
import i18n
88

99
i18n.set('filename_format', '{locale}.{format}')
1010
i18n.set('locale', 'en')
@@ -13,14 +13,15 @@
1313

1414
from ..model.parameters import Parameters
1515
from ..model.sir import Sir
16+
from ..model.ppe import PPE
1617
from .charts import (
1718
build_admits_chart,
1819
build_census_chart,
1920
build_sim_sir_w_date_chart,
2021
)
21-
from ..ppe.ppe import PPE
2222
from .st_display import (
2323
display_download_link,
24+
display_excel_download_link,
2425
display_footer,
2526
display_header,
2627
display_sidebar,
@@ -37,6 +38,7 @@ def main():
3738

3839
d = Parameters.create(os.environ, [])
3940
ppe = PPE(os.environ)
41+
4042
p = display_sidebar(st, d)
4143
m = Sir(p)
4244

@@ -65,7 +67,7 @@ def main():
6567
)
6668

6769
st.subheader(i18n.t("app-PPE-title"))
68-
ppe.display_ppe_download_link(st)
70+
display_excel_download_link(st, ppe.filename, ppe.src)
6971
display_download_link(
7072
st,
7173
p,
@@ -74,14 +76,18 @@ def main():
7476
)
7577

7678
if st.checkbox("Show a screenshot of the tool"):
77-
st.image(image=ppe.ppe_folder+'PPE_Screenshot.jpg',
78-
width=600,
79-
format='JPEG')
79+
st.image(
80+
image=ppe.screenshot,
81+
width=600,
82+
format='JPEG',
83+
)
8084
st.markdown("""
81-
Refer to our <a href="{link_to_docs}">user documentation for instructions on how to use the tool</a>.
82-
""".format(link_to_docs="https://code-for-philly.gitbook.io/chime/ppe-calculator"),
83-
unsafe_allow_html=True
84-
)
85+
Refer to our <a href="{link_to_docs}">user documentation for instructions on how to use the tool</a>.
86+
""".format(
87+
link_to_docs="https://code-for-philly.gitbook.io/chime/ppe-calculator",
88+
),
89+
unsafe_allow_html=True
90+
)
8591

8692
st.subheader(i18n.t("app-SIR-title"))
8793
st.markdown(i18n.t("app-SIR-text"))

src/penn_chime/view/st_display.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
import os
44
import json
55

6+
from logging import INFO, basicConfig, getLogger
67
import pandas as pd
78
import i18n
9+
from sys import stdout
810

911
from ..constants import (
1012
CHANGE_DATE,
@@ -15,9 +17,21 @@
1517
VERSION,
1618
)
1719
from ..model.parameters import Parameters, Disposition
18-
from ..utils import dataframe_to_base64
20+
from ..utils import (
21+
dataframe_to_base64,
22+
excel_to_base64,
23+
)
1924
from .spreadsheet import spreadsheet
2025

26+
27+
basicConfig(
28+
level=INFO,
29+
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
30+
stream=stdout,
31+
)
32+
logger = getLogger(__name__)
33+
34+
2135
hide_menu_style = """
2236
<style>
2337
#MainMenu {visibility: hidden;}
@@ -448,7 +462,6 @@ def display_footer(st):
448462
)
449463
st.markdown(i18n.t("presentation-copyright"))
450464

451-
452465
def display_download_link(st, p, filename: str, df: pd.DataFrame):
453466
csv = dataframe_to_base64(df.rename(p.labels, axis=1))
454467
st.markdown(
@@ -457,3 +470,13 @@ def display_download_link(st, p, filename: str, df: pd.DataFrame):
457470
),
458471
unsafe_allow_html=True,
459472
)
473+
474+
def display_excel_download_link(st, filename: str, src: str):
475+
excel = excel_to_base64(src)
476+
st.markdown("""
477+
Download the PPE Calculator here: <a download="{filename}" href="data:file/xlsx;base64,{excel}">{filename}</a>.
478+
""".format(
479+
excel=excel, filename=filename
480+
),
481+
unsafe_allow_html=True,
482+
)

0 commit comments

Comments
 (0)