results/format-covid-forecast/format_data_state_case.py
def add_to_dataframe(dataframe, forecast, observed):
    """
    Given a dataframe, forecast, and observed data, 
    generate a pandas dataframe of incident cases.
    """
    # Write incident forecasts.
    cum_week = 0
    forecast_date_str = FORECAST_DATE.strftime("%Y-%m-%d")
    for target_end_date_str in sorted(forecast.keys()):
        target_end_date = datetime.datetime.strptime(target_end_date_str, "%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:
            cum_week += 1
            target = str(cum_week) + " wk ahead inc case"
            last_week_date = target_end_date - datetime.timedelta(7)
            last_week_date_str = last_week_date.strftime("%Y-%m-%d")

            if last_week_date_str in observed:
                for state_id in forecast[target_end_date_str].keys():
                    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=max(forecast[target_end_date_str][state_id]-observed[last_week_date_str][state_id], 0)
                        ), ignore_index=True)
            
                
            elif last_week_date_str in forecast:
                for state_id in forecast[target_end_date_str].keys():
                    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=max(forecast[target_end_date_str][state_id]-forecast[last_week_date_str][state_id], 0)
                        ), ignore_index=True)

    return dataframe

    Given a dataframe, forecast, and observed data, 
    generate a pandas dataframe of incident cases.
    
Given a dataframe, forecast, and observed data,
generate a pandas dataframe of incident cases.
Given a dataframe forecast and observed data generate a pandas dataframe of incident cases .
def add_to_dataframe(dataframe, forecast, observed):
    cum_week = 0
    forecast_date_str = FORECAST_DATE.strftime("%Y-%m-%d")
    for target_end_date_str in sorted(forecast.keys()):
        target_end_date = datetime.datetime.strptime(target_end_date_str, "%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:
            cum_week += 1
            target = str(cum_week) + " wk ahead inc case"
            last_week_date = target_end_date - datetime.timedelta(7)
            last_week_date_str = last_week_date.strftime("%Y-%m-%d")
            if last_week_date_str in observed:
                for state_id in forecast[target_end_date_str].keys():
                    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=max(forecast[target_end_date_str][state_id]-observed[last_week_date_str][state_id], 0)
                        ), ignore_index=True)
            elif last_week_date_str in forecast:
                for state_id in forecast[target_end_date_str].keys():
                    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=max(forecast[target_end_date_str][state_id]-forecast[last_week_date_str][state_id], 0)
                        ), ignore_index=True)
    return dataframe
def add_to_dataframe ( dataframe , forecast , observed ) : cum_week = 0 forecast_date_str = FORECAST_DATE . strftime ( "%Y-%m-%d" ) for target_end_date_str in sorted ( forecast . keys ( ) ) : target_end_date = datetime . datetime . strptime ( target_end_date_str , "%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 : cum_week += 1 target = str ( cum_week ) + " wk ahead inc case" last_week_date = target_end_date - datetime . timedelta ( 7 ) last_week_date_str = last_week_date . strftime ( "%Y-%m-%d" ) if last_week_date_str in observed : for state_id in forecast [ target_end_date_str ] . keys ( ) : 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 = max ( forecast [ target_end_date_str ] [ state_id ] - observed [ last_week_date_str ] [ state_id ] , 0 ) ) , ignore_index = True ) elif last_week_date_str in forecast : for state_id in forecast [ target_end_date_str ] . keys ( ) : 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 = max ( forecast [ target_end_date_str ] [ state_id ] - forecast [ last_week_date_str ] [ state_id ] , 0 ) ) , ignore_index = True ) return dataframe
Given a dataframe, forecast, and observed data,
generate a pandas dataframe of incident cases.
Given a dataframe forecast and observed data generate a pandas dataframe of incident cases .
"""
    Given a dataframe, forecast, and observed data, 
    generate a pandas dataframe of incident cases.
    """ # Write incident forecasts. # Terminate the loop after 8 weeks of forecasts. # Skip forecasts before the forecast date.
dataframe
forecast
observed