Skip to content

Commit 873e14c

Browse files
committed
Remove get_defaults
1 parent fe8f41a commit 873e14c

File tree

20 files changed

+328
-238
lines changed

20 files changed

+328
-238
lines changed

Dockerfile

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
FROM python:3.7.7-slim-buster
2-
RUN mkdir /app
2+
ENV PARAMETERS=./defaults/webapp.cfg
33
WORKDIR /app
4+
RUN mkdir /app
5+
# Creating an empty src dir is a (hopefully) temporary hack to improve layer caching and speed up image builds
6+
# todo fix once the Pipfile, setup.py, requirements.txt, pyprojec.toml build/dist story is figured out
7+
RUN mkdir /src
48
COPY README.md .
59
COPY setup.cfg .
610
COPY setup.py .
7-
COPY requirements.txt .
8-
# Creating an empty src dir is a (hopefully) temporary hack to improve layer caching and speed up image builds
9-
# todo fix once the Pipfile, setup.py, requirements.txt, pyprojec.toml build/dist story is figured out
10-
RUN mkdir src && pip install -q .
1111
COPY .streamlit .streamlit
12-
COPY settings.cfg .
12+
COPY defaults defaults
1313
COPY src src
14+
RUN pip install -q .
1415

1516
CMD ["streamlit", "run", "src/app.py"]
1617

Dockerfile.dash

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ WORKDIR /code
44

55
ARG PORT
66
ENV PORT $PORT
7+
ENV PARAMETERS=./defaults/webapp.cfg
78

8-
COPY requirements.txt requirements.txt
9-
RUN pip install -r requirements.txt
10-
9+
COPY README.md .
10+
COPY setup.py .
11+
COPY setup.cfg .
12+
COPY defaults defaults
1113
COPY src src
14+
RUN pip install -q .
1215

1316
# EXPOSE $PORT
1417

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
--current-hospitalized 14
2-
--doubling-time 4.0
1+
--current-hospitalized 69
2+
--doubling_time 4.0
33
--hospitalized-days 7
44
--hospitalized-rate 0.025
55
--icu-days 9
66
--icu-rate 0.0075
77
--infectious-days 14
88
--market_share 0.15
9-
--n-days 60
10-
--population 4119405
9+
--n-days 100
10+
--population 3600000
11+
--recovered 0
1112
--relative-contact-rate 0.3
1213
--ventilated-days 10
1314
--ventilated-rate 0.005

defaults/readme.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Webapps need default values for both date_first_hosptalized and doubling_time. The ui overrides one of them.
2+
3+
CLI needs either date_first_hospitalized xor doubling_time.

defaults/webapp.cfg

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--current-hospitalized 69
2+
--date-first-hospitalized 2020-03-07
3+
--doubling-time 4.0
4+
--hospitalized-days 7
5+
--hospitalized-rate 0.025
6+
--icu-days 9
7+
--icu-rate 0.0075
8+
--infectious-days 14
9+
--market_share 0.15
10+
--n-days 100
11+
--population 3600000
12+
--recovered 0
13+
--relative-contact-rate 0.3
14+
--ventilated-days 10
15+
--ventilated-rate 0.005

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Setup file for chime
22
"""
3-
__version__ = "1.1.2" # update VERSION in constants.py
3+
__version__ = "1.1.3" # update VERSION in constants.py
44
__author__ = "Predictive Healthcare @ Penn Medicine"
55

66
from os import path

src/app.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
"""App."""
22

3+
import os
4+
35
import altair as alt # type: ignore
46
import streamlit as st # type: ignore
57

8+
from penn_chime.parameters import Parameters
69
from penn_chime.presentation import (
710
display_download_link,
811
display_footer,
912
display_header,
1013
display_sidebar,
1114
hide_menu_style,
1215
)
13-
from penn_chime.settings import get_defaults
1416
from penn_chime.models import SimSirModel
1517
from penn_chime.charts import (
1618
build_admits_chart,
@@ -26,7 +28,7 @@
2628
# In dev, this should be shown
2729
st.markdown(hide_menu_style, unsafe_allow_html=True)
2830

29-
d = get_defaults()
31+
d = Parameters.create(os.environ, [])
3032
p = display_sidebar(st, d)
3133
m = SimSirModel(p)
3234

src/chime_dash/__init__.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44
dash instance defined here
55
"""
66

7-
from dash import Dash
7+
import os
88
from typing import TypeVar
9+
10+
from dash import Dash
11+
from penn_chime.parameters import Parameters
12+
913
from chime_dash.app.config import from_object
10-
from penn_chime.settings import get_defaults
1114
from chime_dash.app.pages.root import Root
1215
from chime_dash.app.utils.callbacks import wrap_callbacks
1316

@@ -31,7 +34,10 @@ def create_app(context: str = 'prod') -> DashAppInstance:
3134
Env = from_object(context)
3235

3336
LANGUAGE = Env.LANG
34-
body = Root(LANGUAGE, get_defaults())
37+
body = Root(
38+
LANGUAGE,
39+
Parameters.create(os.environ, []),
40+
)
3541

3642
App = Dash(
3743
__name__,

src/chime_dash/app/components/base.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,9 @@
1212
from dash_html_components import Div
1313

1414
from penn_chime.parameters import Parameters
15-
from penn_chime.settings import get_defaults
1615

1716
from chime_dash.app.utils.templates import read_localization_yml, read_localization_markdown
1817

19-
DEFAULTS = get_defaults()
20-
2118

2219
class Component(ABC):
2320
"""Base component for rendering dash html objects and registering callbacks
@@ -32,7 +29,7 @@ class Component(ABC):
3229
external_stylesheets: List[str] = []
3330
external_scripts: List[str] = []
3431

35-
def __init__(self, language: str = "en", defaults: Parameters = DEFAULTS):
32+
def __init__(self, language: str = "en", defaults: Parameters = None):
3633
"""Initializes the component
3734
"""
3835
self.language = language
@@ -94,7 +91,7 @@ def content(self) -> Union[str, Dict[str, str], None]:
9491
class Page(Component):
9592
callbacks_cls = None
9693

97-
def __init__(self, language: str = "en", defaults: Parameters = DEFAULTS):
94+
def __init__(self, language: str = "en", defaults: Parameters = None):
9895
super().__init__(language, defaults)
9996
self.callbacks_cls(self)
10097

src/chime_dash/app/components/navbar.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,14 @@
1111
from chime_dash.app.components.menu import Menu
1212

1313
from penn_chime.parameters import Parameters
14-
from penn_chime.settings import get_defaults
15-
16-
DEFAULTS = get_defaults()
1714

1815

1916
class Navbar(Component):
2017
"""Navigation bar contains menu and brand
2118
TODO refactor / design input on style and layout
2219
"""
2320

24-
def __init__(self, language: str = "en", defaults: Parameters = DEFAULTS):
21+
def __init__(self, language: str = "en", defaults: Parameters = None):
2522
"""Sets up self, menu and header
2623
"""
2724
super().__init__(language, defaults=defaults)

0 commit comments

Comments
 (0)