def test_generate_timeseries_for_fips( include_projections, nyc_model_output_path, nyc_region, nyc_rt_dataset, nyc_icu_dataset, ): us_latest = combined_datasets.load_us_latest_dataset() us_timeseries = combined_datasets.load_us_timeseries_dataset() nyc_latest = us_latest.get_record_for_fips(nyc_region.fips) nyc_timeseries = us_timeseries.get_one_region(nyc_region) intervention = Intervention.OBSERVED_INTERVENTION model_output = CANPyseirLocationOutput.load_from_path( nyc_model_output_path) metrics_series, latest_metric = api_pipeline.generate_metrics_and_latest( nyc_timeseries, nyc_rt_dataset, nyc_icu_dataset) region_summary = generate_api.generate_region_summary( nyc_latest, latest_metric, model_output) region_timeseries = generate_api.generate_region_timeseries( region_summary, nyc_timeseries, metrics_series, model_output) summary = generate_api.generate_region_summary(nyc_latest, latest_metric, model_output) assert summary.dict() == region_timeseries.region_summary.dict() # Double checking that serialized json does not contain NaNs, all values should # be serialized using the simplejson wrapper. assert "NaN" not in region_timeseries.json()
def build_timeseries_for_fips(intervention, us_latest, us_timeseries, model_output_dir, fips) -> Optional[RegionSummaryWithTimeseries]: fips_latest = us_latest.get_record_for_fips(fips) if intervention is Intervention.SELECTED_INTERVENTION: state = fips_latest[CommonFields.STATE] intervention = get_can_projection.get_intervention_for_state(state) model_output = CANPyseirLocationOutput.load_from_model_output_if_exists( fips, intervention, model_output_dir) if not model_output and intervention is not Intervention.OBSERVED_INTERVENTION: # All model output is currently tied to a specific intervention. However, # we want to generate results for regions that don't have a fit result, but we're not # duplicating non-model outputs. return None try: region_summary = api.generate_region_summary(fips_latest, model_output) fips_timeseries = us_timeseries.get_subset(None, fips=fips) region_timeseries = api.generate_region_timeseries( region_summary, fips_timeseries, model_output) except Exception: logger.error(f"failed to run output", fips=fips) return None return region_timeseries
def test_generate_timeseries_for_fips(include_projections, nyc_model_output_path, nyc_fips): 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_record_for_fips(nyc_fips) nyc_timeseries = us_timeseries.get_subset(None, fips=nyc_fips) intervention = Intervention.OBSERVED_INTERVENTION model_output = CANPyseirLocationOutput.load_from_path( nyc_model_output_path) region_summary = generate_api.generate_region_summary( nyc_latest, model_output) region_timeseries = generate_api.generate_region_timeseries( region_summary, nyc_timeseries, model_output) summary = generate_api.generate_region_summary(nyc_latest, model_output) assert summary.dict() == region_timeseries.region_summary.dict() # Double checking that serialized json does not contain NaNs, all values should # be serialized using the simplejson wrapper. assert "NaN" not in region_timeseries.json()
def build_timeseries_for_region( regional_input: RegionalInput, ) -> Optional[RegionSummaryWithTimeseries]: intervention = regional_input.intervention if intervention is Intervention.SELECTED_INTERVENTION: intervention = get_can_projection.get_intervention_for_state( regional_input.state) try: metrics_timeseries, metrics_latest = generate_metrics_and_latest( regional_input.timeseries, regional_input.rt_data, regional_input.icu_data, ) region_summary = api.generate_region_summary(regional_input.latest, metrics_latest, None) region_timeseries = api.generate_region_timeseries( region_summary, regional_input.timeseries, metrics_timeseries, None) except Exception: logger.exception(f"Failed to build timeseries for fips.") return None return region_timeseries
def test_build_summary_for_fips(include_projections, nyc_model_output_path, nyc_fips): us_latest = combined_datasets.build_us_latest_with_all_fields() nyc_latest = us_latest.get_record_for_fips(nyc_fips) model_output = None expected_projections = None intervention = Intervention.OBSERVED_INTERVENTION if include_projections: model_output = CANPyseirLocationOutput.load_from_path( nyc_model_output_path) expected_projections = Projections( totalHospitalBeds=ResourceUsageProjection(peakShortfall=0, peakDate=datetime.date( 2020, 4, 15), shortageStartDate=None), ICUBeds=None, Rt=model_output.latest_rt, RtCI90=model_output.latest_rt_ci90, ) intervention = Intervention.STRONG_INTERVENTION summary = generate_api.generate_region_summary(nyc_latest, model_output) expected = RegionSummary( population=nyc_latest["population"], stateName="New York", countyName="New York County", fips="36061", lat=None, long=None, actuals=Actuals( population=nyc_latest["population"], intervention="STRONG_INTERVENTION", cumulativeConfirmedCases=nyc_latest["cases"], cumulativeDeaths=nyc_latest["deaths"], cumulativePositiveTests=nyc_latest["positive_tests"], cumulativeNegativeTests=nyc_latest["negative_tests"], hospitalBeds={ # Manually calculated from capacity calculation in generate_api.py "capacity": 12763, "totalCapacity": nyc_latest["max_bed_count"], "currentUsageCovid": 0, "currentUsageTotal": None, "typicalUsageRate": nyc_latest["all_beds_occupancy_rate"], }, ICUBeds={ "capacity": nyc_latest["icu_beds"], "totalCapacity": nyc_latest["icu_beds"], "currentUsageCovid": 0, "currentUsageTotal": 0, "typicalUsageRate": nyc_latest["icu_occupancy_rate"], }, contactTracers=nyc_latest["contact_tracers_count"], ), lastUpdatedDate=datetime.datetime.utcnow(), projections=expected_projections, ) import pprint pprint.pprint(expected.actuals.ICUBeds.dict()) pprint.pprint(summary.actuals.ICUBeds.dict()) assert expected.dict() == summary.dict()