def test_other_formats(self): assert utils.pc(0.5) == "50%" assert utils.pm(0.05) == "50‰" assert utils.p10k(0.005) == "50‱" assert utils.p100k(0.0005) == "50/100k" assert utils.safe_int(3.14) == 3 assert utils.safe_int(float("nan")) == 0
def healthcare_params(region, title=__("Hospital capacity"), occupancy=0.75, where=st): """ Return a dictionary with hospital and icu capacities from user input. Returns: icu_capacity (float): surge system capacity of ICUs icu_full_capacity (float): total system capacity of ICUs hospital_capacity (float): surge system capacity of regular beds hospital_full_capacity (float): total system capacity of regular beds """ region = mundi.region(region) where.header(str(title)) def get(title, capacity, rate, key=None): where.subheader(title) total = where.number_input(_("Total capacity"), min_value=0, value=int(capacity), key=key + "_total") occupied = where.number_input(_("Occupied"), min_value=0, value=int(capacity * rate), key=key + "_used") if occupied > total: where.warning(_("Using more beds than total capacity")) msg = markdown( OCCUPANCY_MSG.format(n=fmt(total - occupied), rate=pc(occupied / total), globalrate=pc(rate))) html(f'<span style="font-size: smaller;">{msg}</span>', where=where) return max(total - occupied, 0) h_cap = safe_int(region.hospital_capacity) icu_cap = safe_int(region.icu_capacity) return { "icu_full_capacity": icu_cap, "hospital_full_capacity": h_cap, "icu_capacity": get(_("ICU beds"), icu_cap, occupancy, key="icu"), "hospital_capacity": get(_("Clinical beds"), h_cap, occupancy, key="hospital"), }
def get_confirmed_daily_cases_for_region(region, disease=covid19) -> int: """ Return the number of newly confirmed cases per day. """ region = mundi.region(region) df = region.pydemic.epidemic_curve(disease) return safe_int(df["cases"].diff().iloc[-7:].mean())
def get_confirmed_deaths_for_region(region, disease) -> int: """ List of confirmed deaths for region. """ cases = get_cases_for_region(region, disease) return safe_int(cases["deaths"].max())
def get_confirmed_cases_for_region(region, disease=covid19): """ List of confirmed cases for the given region. """ cases = get_cases_for_region(region, disease) return safe_int(cases["cases"].max())