示例#1
0
    def update_parameters(i, *input_values) -> List[dict]:
        """Reads html form outputs and converts them to a parameter instance

        Returns Parameters
        """
        inputs_dict = SidebarCallbacks.get_formated_values(i, input_values)
        dt = inputs_dict["doubling_time"] if inputs_dict[
            "doubling_time"] else None
        dfh = inputs_dict["date_first_hospitalized"] if not dt else None
        pars = Parameters(
            current_hospitalized=inputs_dict["current_hospitalized"],
            date_first_hospitalized=dfh,
            doubling_time=dt,
            hospitalized=Disposition.create(
                days=inputs_dict["hospitalized_los"],
                rate=inputs_dict["hospitalized_rate"] / 100,
            ),
            icu=Disposition(
                days=inputs_dict["icu_los"],
                rate=inputs_dict["icu_rate"] / 100,
            ),
            infectious_days=inputs_dict["infectious_days"],
            market_share=inputs_dict["market_share"] / 100,
            n_days=inputs_dict["n_days"],
            population=inputs_dict["population"],
            recovered=0,  #FIXME input or pass through from defaults is required!
            relative_contact_rate=inputs_dict["relative_contact_rate"] / 100,
            ventilated=Disposition.create(
                days=inputs_dict["ventilated_los"],
                rate=inputs_dict["ventilated_rate"] / 100,
            ))
        return [{
            "inputs_dict": inputs_dict,
            "parameters": parameters_serializer(pars)
        }]
示例#2
0
def halving_param():
    return Parameters(
        current_date=datetime(year=2020, month=3, day=28),
        current_hospitalized=100,
        doubling_time=6.0,
        hospitalized=Disposition.create(rate=0.05, days=7),
        icu=Disposition.create(rate=0.02, days=9),
        infectious_days=14,
        market_share=0.05,
        mitigation_date=datetime(year=2020, month=3, day=28),
        n_days=60,
        population=500000,
        recovered=0,
        relative_contact_rate=0.7,
        ventilated=Disposition.create(rate=0.01, days=10),
    )
示例#3
0
def fixture_penn_chime_setup() -> Tuple[Parameters, Sir]:
    """Initializes penn_chime parameters and SIR model
    """
    p = Parameters(
        current_hospitalized=69,
        date_first_hospitalized=date(2020, 3, 7),
        doubling_time=None,
        hospitalized=Disposition.create(days=7, rate=0.025),
        icu=Disposition.create(days=9, rate=0.0075),
        infectious_days=14,
        market_share=0.15,
        n_days=100,
        population=3600000,
        recovered=0,
        relative_contact_rate=0.3,
        ventilated=Disposition.create(days=10, rate=0.005),
    )
    return p, Sir(p)
示例#4
0
    def parameters(self):
        '''
        return penn_chime Parameters object populated with instance values
        '''

        doubling_time = self.doubling_time

        if self.date_first_hospitalized:
            doubling_time = None

        mitigation_date = self.mitigation_date
        relative_contact_rate = max(self.relative_contact_rate, EPSILON)

        if relative_contact_rate == EPSILON:
            mitigation_date = None

        return Parameters(
            current_date=timezone.localdate(),
            population=self.population,
            current_hospitalized=self.current_hospitalized,
            date_first_hospitalized=self.date_first_hospitalized,
            doubling_time=doubling_time,
            hospitalized=Disposition(
                days=self.hospitalized_days,
                rate=self.hospitalized_rate,
            ),
            icu=Disposition(
                days=self.icu_days,
                rate=self.icu_rate,
            ),
            infectious_days=self.infectious_days,
            market_share=self.market_share,
            n_days=self.n_days,
            mitigation_date=mitigation_date,
            relative_contact_rate=relative_contact_rate,
            ventilated=Disposition(
                days=self.ventilated_days,
                rate=self.ventilated_rate,
            ),
            recovered=0,  # not implemented
        )
示例#5
0
def parameters_deserializer(p_json: str):
    values = loads(p_json)

    dates = {
        key: parse_date(values[key]).date() if values[key] else None
        for key in (
            "current_date",
            "date_first_hospitalized",
            "mitigation_date",
        )
    }
    return Parameters(
        current_date=dates["current_date"],
        current_hospitalized=values["current_hospitalized"],
        hospitalized=Disposition.create(
            days=values["hospitalized"][0],
            rate=values["hospitalized"][1],
        ),
        icu=Disposition.create(
            days=values["icu"][0],
            rate=values["icu"][1],
        ),
        infectious_days=values["infectious_days"],
        date_first_hospitalized=dates["date_first_hospitalized"],
        doubling_time=values["doubling_time"],
        market_share=values["market_share"],
        max_y_axis=values["max_y_axis"],
        mitigation_date=dates["mitigation_date"],
        n_days=values["n_days"],
        population=values["population"],
        recovered=values["recovered"],
        region=values["region"],
        relative_contact_rate=values["relative_contact_rate"],
        ventilated=Disposition.create(
            days=values["ventilated"][0],
            rate=values["ventilated"][1],
        ),
    )
示例#6
0
def defaults():
    return Parameters(
        region=Regions(
            delaware=564696,
            chester=519293,
            montgomery=826075,
            bucks=628341,
            philly=1581000,
        ),
        current_date=datetime(year=2020, month=3, day=28),
        current_hospitalized=14,
        date_first_hospitalized=datetime(year=2020, month=3, day=7),
        doubling_time=4.0,
        hospitalized=Disposition.create(rate=0.025, days=7),
        icu=Disposition.create(rate=0.0075, days=9),
        infectious_days=14,
        n_days=60,
        market_share=0.15,
        mitigation_date=datetime(year=2020, month=3, day=28),
        recovered=0,
        relative_contact_rate=0.3,
        ventilated=Disposition.create(rate=0.005, days=10),
    )