Пример #1
0
def _generate_api_for_projections(model_output: CANPyseirLocationOutput):
    _hospital_beds = ResourceUsageProjection(
        peakDate=model_output.peak_hospitalizations_date,
        shortageStartDate=model_output.hospitals_shortfall_date,
        peakShortfall=model_output.peak_hospitalizations_shortfall,
    )
    projections = Projections(
        totalHospitalBeds=_hospital_beds,
        ICUBeds=None,
        Rt=model_output.latest_rt,
        RtCI90=model_output.latest_rt_ci90,
    )
    return projections
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()