results/format-covid-forecast/format_data_state_death_quantile.py
def generate_dataframe(forecast, observed):
    """
    Given our forecast and observed data, generate a pandas dataframe according to reichlab's required format.
    """
    dataframe = pd.DataFrame(columns=COLUMNS, dtype=str)

    # Write cumulative forecasts.
    forecast_date_str = FORECAST_DATE.strftime("%Y-%m-%d")
    for cum_week in sorted(forecast.keys()):
        target_end_date = FIRST_WEEK + ((cum_week - 1) * datetime.timedelta(7))
        target_end_date_str = target_end_date.strftime("%Y-%m-%d")
        # Terminate the loop after 8 weeks of forecasts.
        if cum_week >= 8:
            break

        # Skip forecasts before the forecast date.
        if target_end_date <= FORECAST_DATE:
            continue

        # Write a row for "weeks ahead" if forecast end day is a Saturday.
        if target_end_date >= FIRST_WEEK and target_end_date.weekday() == 5:
            target = str(cum_week) + " wk ahead cum death"
            for state_id in forecast[cum_week].keys():
                for quantile in forecast[cum_week][state_id].keys():
                    val = observed[(FORECAST_DATE - datetime.timedelta(1)).strftime("%Y-%m-%d")][state_id]
                    for i in range(1, cum_week + 1):
                        val += forecast[i][state_id][quantile]
                    if quantile == "point":
                        dataframe = dataframe.append(
                            generate_new_row(
                                forecast_date=forecast_date_str,
                                target=target,
                                target_end_date=target_end_date_str,
                                location=str(state_id),
                                type="point",
                                quantile="NA",
                                value=val
                            ), ignore_index=True)
                    else:
                        dataframe = dataframe.append(
                            generate_new_row(
                                forecast_date=forecast_date_str,
                                target=target,
                                target_end_date=target_end_date_str,
                                location=str(state_id),
                                type="quantile",
                                quantile=quantile,
                                value=val
                            ), ignore_index=True)

    # Write incident forecasts.
    forecast_date_str = FORECAST_DATE.strftime("%Y-%m-%d")
    for cum_week in sorted(forecast.keys()):
        target_end_date = FIRST_WEEK + ((cum_week - 1) * datetime.timedelta(7))
        target_end_date_str = target_end_date.strftime("%Y-%m-%d")
        # Terminate the loop after 8 weeks of forecasts.
        if cum_week >= 8:
            break

        # Skip forecasts before the forecast date.
        if target_end_date <= FORECAST_DATE:
            continue

        if target_end_date >= FIRST_WEEK and target_end_date.weekday() == 5:
            target = str(cum_week) + " wk ahead inc death"
            for state_id in forecast[cum_week].keys():
                for quantile in forecast[cum_week][state_id].keys():
                    if quantile == "point":
                        dataframe = dataframe.append(
                            generate_new_row(
                                forecast_date=forecast_date_str,
                                target=target,
                                target_end_date=target_end_date_str,
                                location=str(state_id),
                                type="point",
                                quantile="NA",
                                value=forecast[cum_week][state_id][quantile]
                            ), ignore_index=True)
                    else:
                        dataframe = dataframe.append(
                            generate_new_row(
                                forecast_date=forecast_date_str,
                                target=target,
                                target_end_date=target_end_date_str,
                                location=str(state_id),
                                type="quantile",
                                quantile=quantile,
                                value=forecast[cum_week][state_id][quantile]
                            ), ignore_index=True)

    return dataframe

    Given our forecast and observed data, generate a pandas dataframe according to reichlab's required format.
    
Given our forecast and observed data, generate a pandas dataframe according to reichlab's required format.
Given our forecast and observed data generate a pandas dataframe according to reichlab ' s required format .
def generate_dataframe(forecast, observed):
    dataframe = pd.DataFrame(columns=COLUMNS, dtype=str)
    forecast_date_str = FORECAST_DATE.strftime("%Y-%m-%d")
    for cum_week in sorted(forecast.keys()):
        target_end_date = FIRST_WEEK + ((cum_week - 1) * datetime.timedelta(7))
        target_end_date_str = target_end_date.strftime("%Y-%m-%d")
        if cum_week >= 8:
            break
        if target_end_date <= FORECAST_DATE:
            continue
        if target_end_date >= FIRST_WEEK and target_end_date.weekday() == 5:
            target = str(cum_week) + " wk ahead cum death"
            for state_id in forecast[cum_week].keys():
                for quantile in forecast[cum_week][state_id].keys():
                    val = observed[(FORECAST_DATE - datetime.timedelta(1)).strftime("%Y-%m-%d")][state_id]
                    for i in range(1, cum_week + 1):
                        val += forecast[i][state_id][quantile]
                    if quantile == "point":
                        dataframe = dataframe.append(
                            generate_new_row(
                                forecast_date=forecast_date_str,
                                target=target,
                                target_end_date=target_end_date_str,
                                location=str(state_id),
                                type="point",
                                quantile="NA",
                                value=val
                            ), ignore_index=True)
                    else:
                        dataframe = dataframe.append(
                            generate_new_row(
                                forecast_date=forecast_date_str,
                                target=target,
                                target_end_date=target_end_date_str,
                                location=str(state_id),
                                type="quantile",
                                quantile=quantile,
                                value=val
                            ), ignore_index=True)
    forecast_date_str = FORECAST_DATE.strftime("%Y-%m-%d")
    for cum_week in sorted(forecast.keys()):
        target_end_date = FIRST_WEEK + ((cum_week - 1) * datetime.timedelta(7))
        target_end_date_str = target_end_date.strftime("%Y-%m-%d")
        if cum_week >= 8:
            break
        if target_end_date <= FORECAST_DATE:
            continue
        if target_end_date >= FIRST_WEEK and target_end_date.weekday() == 5:
            target = str(cum_week) + " wk ahead inc death"
            for state_id in forecast[cum_week].keys():
                for quantile in forecast[cum_week][state_id].keys():
                    if quantile == "point":
                        dataframe = dataframe.append(
                            generate_new_row(
                                forecast_date=forecast_date_str,
                                target=target,
                                target_end_date=target_end_date_str,
                                location=str(state_id),
                                type="point",
                                quantile="NA",
                                value=forecast[cum_week][state_id][quantile]
                            ), ignore_index=True)
                    else:
                        dataframe = dataframe.append(
                            generate_new_row(
                                forecast_date=forecast_date_str,
                                target=target,
                                target_end_date=target_end_date_str,
                                location=str(state_id),
                                type="quantile",
                                quantile=quantile,
                                value=forecast[cum_week][state_id][quantile]
                            ), ignore_index=True)
    return dataframe
def generate_dataframe ( forecast , observed ) : dataframe = pd . DataFrame ( columns = COLUMNS , dtype = str ) forecast_date_str = FORECAST_DATE . strftime ( "%Y-%m-%d" ) for cum_week in sorted ( forecast . keys ( ) ) : target_end_date = FIRST_WEEK + ( ( cum_week - 1 ) * datetime . timedelta ( 7 ) ) target_end_date_str = target_end_date . strftime ( "%Y-%m-%d" ) if cum_week >= 8 : break if target_end_date <= FORECAST_DATE : continue if target_end_date >= FIRST_WEEK and target_end_date . weekday ( ) == 5 : target = str ( cum_week ) + " wk ahead cum death" for state_id in forecast [ cum_week ] . keys ( ) : for quantile in forecast [ cum_week ] [ state_id ] . keys ( ) : val = observed [ ( FORECAST_DATE - datetime . timedelta ( 1 ) ) . strftime ( "%Y-%m-%d" ) ] [ state_id ] for i in range ( 1 , cum_week + 1 ) : val += forecast [ i ] [ state_id ] [ quantile ] if quantile == "point" : dataframe = dataframe . append ( generate_new_row ( forecast_date = forecast_date_str , target = target , target_end_date = target_end_date_str , location = str ( state_id ) , type = "point" , quantile = "NA" , value = val ) , ignore_index = True ) else : dataframe = dataframe . append ( generate_new_row ( forecast_date = forecast_date_str , target = target , target_end_date = target_end_date_str , location = str ( state_id ) , type = "quantile" , quantile = quantile , value = val ) , ignore_index = True ) forecast_date_str = FORECAST_DATE . strftime ( "%Y-%m-%d" ) for cum_week in sorted ( forecast . keys ( ) ) : target_end_date = FIRST_WEEK + ( ( cum_week - 1 ) * datetime . timedelta ( 7 ) ) target_end_date_str = target_end_date . strftime ( "%Y-%m-%d" ) if cum_week >= 8 : break if target_end_date <= FORECAST_DATE : continue if target_end_date >= FIRST_WEEK and target_end_date . weekday ( ) == 5 : target = str ( cum_week ) + " wk ahead inc death" for state_id in forecast [ cum_week ] . keys ( ) : for quantile in forecast [ cum_week ] [ state_id ] . keys ( ) : if quantile == "point" : dataframe = dataframe . append ( generate_new_row ( forecast_date = forecast_date_str , target = target , target_end_date = target_end_date_str , location = str ( state_id ) , type = "point" , quantile = "NA" , value = forecast [ cum_week ] [ state_id ] [ quantile ] ) , ignore_index = True ) else : dataframe = dataframe . append ( generate_new_row ( forecast_date = forecast_date_str , target = target , target_end_date = target_end_date_str , location = str ( state_id ) , type = "quantile" , quantile = quantile , value = forecast [ cum_week ] [ state_id ] [ quantile ] ) , ignore_index = True ) return dataframe
Given our forecast and observed data, generate a pandas dataframe according to reichlab's required format.
Given our forecast and observed data generate a pandas dataframe according to reichlab ' s required format .
"""
    Given our forecast and observed data, generate a pandas dataframe according to reichlab's required format.
    """ # Write cumulative forecasts. # Terminate the loop after 8 weeks of forecasts. # Skip forecasts before the forecast date. # Write a row for "weeks ahead" if forecast end day is a Saturday. # Write incident forecasts. # Terminate the loop after 8 weeks of forecasts. # Skip forecasts before the forecast date.
forecast
observed