Exemplo n.º 1
0
def test_build_api_output_for_intervention(nyc_fips, nyc_model_output_path,
                                           tmp_path):
    county_output = tmp_path / "county"
    us_latest = combined_datasets.build_us_latest_with_all_fields()
    us_timeseries = combined_datasets.build_us_timeseries_with_all_fields()

    nyc_latest = us_latest.get_subset(None, fips=nyc_fips)
    nyc_timeseries = us_timeseries.get_subset(None, fips=nyc_fips)
    all_timeseries_api = api_pipeline.run_on_all_fips_for_intervention(
        nyc_latest, nyc_timeseries, Intervention.STRONG_INTERVENTION,
        nyc_model_output_path.parent)

    api_pipeline.deploy_single_level(Intervention.STRONG_INTERVENTION,
                                     all_timeseries_api, tmp_path,
                                     county_output)
    expected_outputs = [
        "counties.STRONG_INTERVENTION.timeseries.json",
        "counties.STRONG_INTERVENTION.csv",
        "counties.STRONG_INTERVENTION.timeseries.csv",
        "counties.STRONG_INTERVENTION.json",
        "county/36061.STRONG_INTERVENTION.json",
        "county/36061.STRONG_INTERVENTION.timeseries.json",
    ]

    output_paths = [
        str(path.relative_to(tmp_path)) for path in tmp_path.glob("**/*")
        if not path.is_dir()
    ]
    assert sorted(output_paths) == sorted(expected_outputs)
Exemplo n.º 2
0
def generate_api(input_dir, output, summary_output, aggregation_level, state,
                 fips):
    """The entry function for invocation"""

    active_states = [state.abbr for state in us.STATES]
    us_latest = combined_datasets.load_us_latest_dataset().get_subset(
        aggregation_level, state=state, fips=fips, states=active_states)
    us_timeseries = combined_datasets.load_us_timeseries_dataset().get_subset(
        aggregation_level, state=state, fips=fips, states=active_states)

    for intervention in list(Intervention):
        _logger.info(f"Running intervention {intervention.name}")
        all_timeseries = api_pipeline.run_on_all_fips_for_intervention(
            us_latest, us_timeseries, intervention, input_dir)
        county_timeseries = [
            output for output in all_timeseries
            if output.aggregate_level is AggregationLevel.COUNTY
        ]
        api_pipeline.deploy_single_level(intervention, county_timeseries,
                                         summary_output, output)
        state_timeseries = [
            output for output in all_timeseries
            if output.aggregate_level is AggregationLevel.STATE
        ]
        api_pipeline.deploy_single_level(intervention, state_timeseries,
                                         summary_output, output)
def test_build_api_output_for_intervention(nyc_region, tmp_path, rt_dataset,
                                           icu_dataset):
    county_output = tmp_path / "county"
    regional_input = api_pipeline.RegionalInput.from_region_and_intervention(
        nyc_region,
        Intervention.STRONG_INTERVENTION,
        rt_dataset,
        icu_dataset,
    )
    all_timeseries_api = api_pipeline.run_on_all_regional_inputs_for_intervention(
        [regional_input])

    api_pipeline.deploy_single_level(Intervention.STRONG_INTERVENTION,
                                     all_timeseries_api, tmp_path,
                                     county_output)
    expected_outputs = [
        "counties.STRONG_INTERVENTION.timeseries.json",
        "counties.STRONG_INTERVENTION.csv",
        # No projections are being generated so
        # "counties.STRONG_INTERVENTION.timeseries.csv",
        "counties.STRONG_INTERVENTION.json",
        "county/36061.STRONG_INTERVENTION.json",
        "county/36061.STRONG_INTERVENTION.timeseries.json",
    ]

    output_paths = [
        str(path.relative_to(tmp_path)) for path in tmp_path.glob("**/*")
        if not path.is_dir()
    ]

    assert sorted(output_paths) == sorted(expected_outputs)
Exemplo n.º 4
0
def generate_api(input_dir, output, summary_output, aggregation_level, state,
                 fips):
    """The entry function for invocation"""

    # Caching load of us timeseries dataset
    combined_datasets.load_us_timeseries_dataset()

    active_states = [state.abbr for state in us.STATES]
    active_states = active_states + ["PR", "MP"]
    regions = combined_datasets.get_subset_regions(
        aggregation_level=aggregation_level,
        exclude_county_999=True,
        state=state,
        fips=fips,
        states=active_states,
    )

    icu_data_path = input_dir / SummaryArtifact.ICU_METRIC_COMBINED.value
    icu_data = MultiRegionTimeseriesDataset.from_csv(icu_data_path)
    rt_data_path = input_dir / SummaryArtifact.RT_METRIC_COMBINED.value
    rt_data = MultiRegionTimeseriesDataset.from_csv(rt_data_path)

    for intervention in list(Intervention):
        _logger.info(f"Running intervention {intervention.name}")

        _load_input = functools.partial(
            api_pipeline.RegionalInput.from_region_and_intervention,
            intervention=intervention,
            rt_data=rt_data,
            icu_data=icu_data,
        )
        with multiprocessing.Pool(maxtasksperchild=1) as pool:
            regional_inputs = pool.map(_load_input, regions)

        _logger.info(f"Loaded {len(regional_inputs)} regions.")
        all_timeseries = api_pipeline.run_on_all_regional_inputs_for_intervention(
            regional_inputs)
        county_timeseries = [
            output for output in all_timeseries
            if output.aggregate_level is AggregationLevel.COUNTY
        ]
        api_pipeline.deploy_single_level(intervention, county_timeseries,
                                         summary_output, output)
        state_timeseries = [
            output for output in all_timeseries
            if output.aggregate_level is AggregationLevel.STATE
        ]
        api_pipeline.deploy_single_level(intervention, state_timeseries,
                                         summary_output, output)