Skip to content

Commit

Permalink
Merge pull request #36 from mmastand/max_left_side
Browse files Browse the repository at this point in the history
Max left side
  • Loading branch information
mmastand authored Apr 1, 2020
2 parents 6aa18d3 + b5d8cea commit 3358ac0
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 23 deletions.
44 changes: 25 additions & 19 deletions src/penn_chime/hc_param_import_export.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import base64
import datetime
from datetime import (
datetime,
date,
timedelta,
)
import json
import io
from typing import Tuple
Expand All @@ -10,19 +14,18 @@
Disposition,
)


def constants_from_uploaded_file(file: io.StringIO) -> Tuple[Parameters, dict]:
imported_params = json.loads(file.read())
parameters = Parameters(
population=imported_params["RegionalPopulation"],
doubling_time=float(imported_params["DoublingTimeBeforeSocialDistancing"]) if "DoublingTimeBeforeSocialDistancing" in imported_params else 4.0,
date_first_hospitalized=datetime.datetime.fromisoformat(imported_params["FirstHospitalizedCaseDate"]) if "FirstHospitalizedCaseDate" in imported_params else None,
date_first_hospitalized=date.fromisoformat(imported_params["FirstHospitalizedCaseDate"]) if "FirstHospitalizedCaseDate" in imported_params else None,
first_hospitalized_date_known=imported_params.get("FirstHospitalizedDateKnown", False), # Added in v2.0.0
# known_infected=imported_params.get("CurrentlyKnownRegionalInfections", 510), # Deprecated in v1.1.1
n_days=imported_params["NumberOfDaysToProject"],
market_share=float(imported_params["HospitalMarketShare"]),
relative_contact_rate=float(imported_params["SocialDistancingPercentReduction"]),
social_distancing_start_date=datetime.date.fromisoformat(imported_params["SocialDistancingStartDate"], (datetime.date.today() - datetime.timedelta(hours=6)).isoformat()),
social_distancing_start_date=date.fromisoformat(imported_params["SocialDistancingStartDate"]) if "SocialDistancingStartDate" in imported_params else (date.today() - timedelta(hours=6)).isoformat(),
hospitalized=Disposition(float(imported_params["HospitalizationPercentage"]), imported_params["HospitalLengthOfStay"]),
icu=Disposition(float(imported_params["ICUPercentage"]), imported_params["ICULengthOfStay"]),
ventilators=Disposition(float(imported_params["VentilatorsPercentage"]),imported_params["VentLengthOfStay"]),
Expand All @@ -35,45 +38,48 @@ def constants_from_uploaded_file(file: io.StringIO) -> Tuple[Parameters, dict]:
covid_ventilators=imported_params["TotalNumberOfVentsForNCPatients"],

covid_census_value=imported_params["CurrentlyHospitalizedCovidPatients"],
covid_census_date = datetime.date.fromisoformat(imported_params.get("CurrentlyHospitalizedCovidPatientsDate", (datetime.date.today() - datetime.timedelta(hours=6)).isoformat())),
covid_census_date = date.fromisoformat(imported_params["CurrentlyHospitalizedCovidPatientsDate"]) if "CurrentlyHospitalizedCovidPatientsDate" in imported_params else (date.today() - timedelta(hours=6)).isoformat(),
# selected_offset = imported_params.get("SelectedOffsetDays", -1), # Deprecated in v2.0.0
author=imported_params.get("Author", "Jane Doe"), # Added in v2.0.0
scenario=imported_params.get("Scenario", "COVID-19 Model"), # Added in v2.0.0
)
return parameters


def param_download_widget(st, parameters, as_date, max_y_axis_set, max_y_axis):
if parameters.author == "Jane Doe" or parameters.scenario == "COVID Model":
def param_download_widget(st, parameters, max_y_axis_set, max_y_axis):
if parameters.author == "Jane Doe" or parameters.scenario == "COVID-19 Model":
st.sidebar.markdown("""
**Enter a unique author name and scenario name to enable parameter download.**""")
else:
filename = "ModelParameters" + "_" + parameters.author + "_" + parameters.scenario + "_" + datetime.now().isoformat() + ".json"
out_obj = {

"FirstHospitalizedCaseDate": date.today().isoformat() if parameters.date_first_hospitalized == None else parameters.date_first_hospitalized.isoformat(),
"FirstHospitalizedDateKnown": parameters.first_hospitalized_date_known,
"SocialDistancingStartDate": parameters.social_distancing_start_date.isoformat(),
"Author": parameters.author,
"Scenario": parameters.scenario,
"NumberOfDaysToProject": parameters.n_days,
"DoublingTimeBeforeSocialDistancing": parameters.doubling_time,
"DoublingTimeBeforeSocialDistancing": 4.0 if parameters.doubling_time == None else parameters.doubling_time,
"SocialDistancingPercentReduction": parameters.relative_contact_rate,
"HospitalizationPercentage": parameters.hospitalized.rate,
"ICUPercentage": parameters.icu.rate,
"VentilatorsPercentage": parameters.ventilators.rate,
"HospitalLengthOfStay": parameters.hospitalized.length_of_stay,
"ICULengthOfStay": parameters.icu.length_of_stay,
"VentLengthOfStay": parameters.ventilators.length_of_stay,
"HospitalLengthOfStay": parameters.hospitalized.days,
"ICULengthOfStay": parameters.icu.days,
"VentLengthOfStay": parameters.ventilators.days,
"HospitalMarketShare": parameters.market_share,
"RegionalPopulation": parameters.susceptible,
"PresentResultAsDates": as_date,
"RegionalPopulation": parameters.population,
"MaxYAxisSet":max_y_axis_set,
"MaxYAxis":max_y_axis,

"TotalNumberOfBedsForNCPatients": parameters.total_non_covid_beds,
"TotalNumberOfICUBedsForNCPatients": parameters.total_non_covid_icu_beds,
"TotalNumberOfVentsForNCPatients": parameters.total_non_covid_vents,
"TotalNumberOfBedsForNCPatients": parameters.total_covid_beds,
"TotalNumberOfICUBedsForNCPatients": parameters.icu_covid_beds,
"TotalNumberOfVentsForNCPatients": parameters.covid_ventilators,

"CurrentlyHospitalizedCovidPatients": parameters.current_hospitalized,
"CurrentlyHospitalizedCovidPatientsDate": parameters.census_date.isoformat(),
"SelectedOffsetDays": parameters.selected_offset,
"CurrentlyHospitalizedCovidPatients": parameters.covid_census_value,
"CurrentlyHospitalizedCovidPatientsDate": parameters.covid_census_date.isoformat(),
# "SelectedOffsetDays": parameters.selected_offset, # Deprecated in v2.0.0
}
out_json = json.dumps(out_obj)
b64_json = base64.b64encode(out_json.encode()).decode()
Expand Down
22 changes: 18 additions & 4 deletions src/penn_chime/presentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
from .utils import dataframe_to_base64
from .parameters import Parameters, Disposition
from .models import SimSirModel as Model
from .hc_param_import_export import constants_from_uploaded_file
from .hc_param_import_export import (
constants_from_uploaded_file,
param_download_widget
)

hide_menu_style = """
<style>
Expand Down Expand Up @@ -197,13 +200,13 @@ def display_sidebar(st, d: Parameters) -> Parameters:
author_input = TextInput(
st_obj,
"Author Name",
value="Jane Doe" if uploaded_file is None else raw_imported["Author"]
value="Jane Doe" if uploaded_file is None else d.author
)

scenario_input = TextInput(
st_obj,
"Scenario Name",
value="COVID Model" if uploaded_file is None else raw_imported["Scenario"]
value="COVID Model" if uploaded_file is None else d.scenario
)

n_days_input = NumberInput(
Expand Down Expand Up @@ -398,7 +401,8 @@ def display_sidebar(st, d: Parameters) -> Parameters:
if max_y_axis_set:
max_y_axis = max_y_axis_input()

return Parameters(

parameters = Parameters(
covid_census_value=covid_census_value,
covid_census_date=covid_census_date,
hospitalized=Disposition(hospitalized_rate, hospitalized_days),
Expand All @@ -416,8 +420,18 @@ def display_sidebar(st, d: Parameters) -> Parameters:
max_y_axis=max_y_axis,
n_days=n_days,
population=population,
author=author,
scenario=scenario,
)

param_download_widget(
st,
parameters,
max_y_axis_set=max_y_axis_set,
max_y_axis=max_y_axis
)

return parameters

def display_more_info(
st, model: Model, parameters: Parameters, defaults: Parameters, notes: str = "",
Expand Down

0 comments on commit 3358ac0

Please sign in to comment.