示例#1
0
def forecast_each_state(
    country,
    state,
    timeseries,
    beds_data,
    population_data,
    min_date,
    max_date,
    output_dir,
):
    _logger.info(f"Generating data for state: {state}")
    cases = timeseries.get_data(state=state)
    try:
        beds = beds_data.get_beds_by_country_state(country, state)
    except IndexError:
        # Old timeseries data throws an exception if the state does not exist in
        # the dataset.
        _logger.error(f"Failed to get beds data for {state}")
        return
    population = population_data.get_state_level(country, state)
    if not population:
        _logger.warning(f"Missing population for {state}")
        return

    for i, intervention in enumerate(get_interventions()):
        _logger.info(f"Running intervention {i} for {state}")
        results = model_state(cases, beds, population, intervention)
        website_data = prepare_data_for_website(results,
                                                cases,
                                                population,
                                                min_date,
                                                max_date,
                                                interval=4)
        write_results(website_data, output_dir, f"{state}.{i}.json")
示例#2
0
def forecast_each_county(
    min_date,
    max_date,
    country,
    state,
    county,
    fips,
    timeseries,
    beds_data,
    population_data,
    output_dir,
):
    _logger.info(f"Running model for county: {county}, {state} - {fips}")
    cases = timeseries.get_data(state=state, country=country, fips=fips)
    beds = beds_data.get_county_level(state, fips=fips)
    population = population_data.get_county_level(country, state, fips=fips)
    total_cases = sum(cases.cases)
    if not population or not beds or not total_cases:
        _logger.debug(
            f"Missing data, skipping: Beds: {beds} Pop: {population} Total Cases: {total_cases}"
        )
        return

    _logger.info(
        f"Running interventions for {county}, {state}: {fips} - "
        f"total cases: {total_cases} beds: {beds} pop: {population}"
    )

    for i, intervention in enumerate(get_interventions()):
        results = model_state(cases, beds, population, intervention)
        website_data = prepare_data_for_website(
            results, cases, population, min_date, max_date, interval=4
        )

        write_results(website_data, output_dir, f"{state}.{fips}.{i}.json")
示例#3
0
def forecast_each_state(
    country,
    state,
    timeseries,
    beds_data,
    population_data,
    min_date,
    max_date,
    output_dir,
):
    _logger.info(f"Generating data for state: {state}")
    cases = timeseries.get_data(state=state)
    beds = beds_data.get_state_level(state)
    if not beds:
        _logger.error(f"Failed to get beds data for {state}")
        return
    population = population_data.get_state_level(country, state)
    if not population:
        _logger.warning(f"Missing population for {state}")
        return

    for i, intervention in enumerate(build_params.get_interventions()):
        _logger.info(f"Running intervention {i} for {state}")
        results = model_state(cases, beds, population, intervention)
        website_data = prepare_data_for_website(results,
                                                cases,
                                                population,
                                                min_date,
                                                max_date,
                                                interval=4)

        write_results(website_data, output_dir, f"{state}.{i}.json")
示例#4
0
def validate_results(result_dir: str) -> None:
    """
    For each state, check that we have a file for each intervention,
    and that the file is non-empty
    """
    per_state_expected = len(build_params.get_interventions())
    missing_or_empty = []
    for state in build_params.US_STATE_ABBREV.values():
        if state in UNSUPPORTED_REGIONS:
            continue
        for i in range(per_state_expected):
            fname = os.path.join(result_dir, ".".join([state, str(i), "json"]))
            try:
                result = os.stat(fname)
                if result.st_size == 0:
                    missing_or_empty.append(fname)
            except FileNotFoundError:
                missing_or_empty.append(fname)
    if len(missing_or_empty) > 0:
        raise RuntimeError(
            f'Missing or empty expected files: {", ".join(missing_or_empty)}')
示例#5
0
        # Assumes that anyone who needs ICU care and doesn't get it dies
        'case_fatality_rate_hospitals_overwhelmed':
        HOSPITALIZATION_RATE * HOSPITALIZED_CASES_REQUIRING_ICU_CARE,
        'hospital_capacity_change_daily_rate':
        1.05,
        'max_hospital_capacity_factor':
        2.07,
        'initial_hospital_bed_utilization':
        .6,
        'model_interval':
        4,  # In days
        'total_infected_period':
        12,  # In days
        'rolling_intervals_for_current_infected':
        int(round(TOTAL_INFECTED_PERIOD / MODEL_INTERVAL, 0)),
    }
    return CovidTimeseriesModel().forecast(model_parameters=MODEL_PARAMETERS)


if __name__ == '__main__':
    logging.basicConfig(level=logging.INFO)
    dataset = CDSDataset()
    interventions = get_interventions()
    for state in dataset.get_all_states_by_country('USA'):
        for i, intervention in enumerate(interventions):
            _logger.info(f"Running intervention {i} for {state}")
            record_results(
                model_state(dataset, 'USA', state, intervention),
                OUTPUT_DIR, state, i,
                dataset.get_population_by_country_state('USA', state))