Example #1
0
def test_web_download_data(webclient):
    curve_conf = {
        "population": 600000,
        "N_init": 10,
        "R": 1.2,
        "intervention_start": 15,
        "intervention_end": 25,
        "intervention_decrease": 70.0,
        "t_incubation": 5,
        "t_infectious": 9,
        "t_death": 32.0,
        "mild_recovery": 11.0,
        "bed_stay": 28.0,
        "bed_rate": 0.2,
        "bed_wait": 5,
        "beta": 1.236,
        "sigma": 1.1,
        "gamma": 1.1,
    }
    sir_conf = {"t_max": 200, "dt": 1.0}

    curve = arcovid19.load_infection_curve(**curve_conf)
    expected = curve.do_SIR(**sir_conf)

    data = {"model": "do_SIR"}
    data.update(curve_conf)
    data.update(sir_conf)
    response = webclient.post("/download_model", data=data)

    ectype = (
        "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")

    assert response.status_code == 200
    assert response.headers["Content-Type"] == ectype

    # validate result
    result = pd.read_excel(io.BytesIO(response.data), sheet_name="Data")
    result = result.set_index("ts")

    # validate in the 8 decimal place
    np.testing.assert_array_almost_equal(result, expected.df, decimal=8)

    config = pd.read_excel(io.BytesIO(response.data), sheet_name="Config")
    config = config.set_index("Attribute")

    assert config.to_dict()["Value"] == data
Example #2
0
def test_always_return_model_frame():

    curve_conf = {
        'population': 600000,
        'N_init': 10,
        'R': 1.2,
        'intervention_start': 15.0,
        'intervention_end': 25.0,
        'intervention_decrease': 70.0,
        't_incubation': 5.0,
        't_infectious': 9.0
    }
    m_conf = {'t_max': 200.0, 'dt': 1.0}

    curve = arcovid19.load_infection_curve(**curve_conf)
    for mname in dir(curve):
        method = getattr(curve, mname)
        if mname.startswith("do_") and callable(method):
            result = method(**m_conf)
            assert isinstance(result, ModelResultFrame)
            assert result.model_name == mname.split("_")[-1]
Example #3
0
def test_SEIR_migration():
    expected = pd.read_excel(TEST_DATA_PATH / "test_SEIR_migration.xlsx")
    expected = expected.set_index("ts")
    expected.index = expected.index.astype(float)

    curve_conf = {
        'population': 600000,
        'N_init': 10,
        'R': 1.2,
        'intervention_start': 15.0,
        'intervention_end': 25.0,
        'intervention_decrease': 70.0,
        't_incubation': 5.0,
        't_infectious': 9.0
    }
    seir_conf = {'t_max': 200.0, 'dt': 1.0}

    curve = arcovid19.load_infection_curve(**curve_conf)
    result = curve.do_SEIR(**seir_conf)

    np.testing.assert_array_almost_equal(result.df, expected, decimal=8)
    assert result.model_name == "SEIR"
Example #4
0
def test_SEIRF_plot_migration():
    expected = pd.read_excel(TEST_DATA_PATH / "test_SEIRF_migration.xlsx")
    expected = expected.set_index("ts")
    expected.index = expected.index.astype(float)

    curve_conf = {
        'population': 600000,
        'N_init': 10,
        'R': 1.2,
        'intervention_start': 15.0,
        'intervention_end': 25.0,
        'intervention_decrease': 70.0,
        't_incubation': 5.0,
        't_infectious': 9.0
    }
    sir_conf = {'t_max': 200.0, 'dt': 1.0}

    curve = arcovid19.load_infection_curve(**curve_conf)
    result = curve.do_SEIRF(**sir_conf)

    fig, ax = plt.subplots()
    result.plot(ax=ax, only=["S", "E", "I", "R", "F"], fill=True, log=True)

    return fig