results/format-covid-forecast/format_data_state_death.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.
    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

        # Daily cumulative report.
        """
        target = str((target_end_date - FORECAST_DATE).days) + " day ahead cum death"
        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=forecast[target_end_date_str][state_id]
                ), ignore_index=True)
        """

        # 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 :
            cum_week += 1
            target = str(cum_week) + " wk ahead cum death"
            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=forecast[target_end_date_str][state_id]
                    ), ignore_index=True)
                
    # 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

        target = str((target_end_date - FORECAST_DATE).days) + " day ahead inc death"

        # Daily Incident report.
        """
        prev_date = target_end_date - datetime.timedelta(1)
        prev_date_str = prev_date.strftime("%Y-%m-%d")

        if prev_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=forecast[target_end_date_str][state_id]-observed[prev_date_str][state_id]
                    ), ignore_index=True)

        elif prev_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=forecast[target_end_date_str][state_id]-forecast[prev_date_str][state_id]
                    ), ignore_index=True)
        """

        if target_end_date >= FIRST_WEEK and target_end_date.weekday() == 5:
            cum_week += 1
            target = str(cum_week) + " wk ahead inc death"

            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 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)
    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 cum death"
            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=forecast[target_end_date_str][state_id]
                    ), ignore_index=True)
    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
        target = str((target_end_date - FORECAST_DATE).days) + " day ahead inc death"
        if target_end_date >= FIRST_WEEK and target_end_date.weekday() == 5:
            cum_week += 1
            target = str(cum_week) + " wk ahead inc death"
            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 generate_dataframe ( forecast , observed ) : dataframe = pd . DataFrame ( columns = COLUMNS , dtype = str ) 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 """
        target = str((target_end_date - FORECAST_DATE).days) + " day ahead cum death"
        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=forecast[target_end_date_str][state_id]
                ), ignore_index=True)
        """ if target_end_date >= FIRST_WEEK and target_end_date . weekday ( ) == 5 : cum_week += 1 target = str ( cum_week ) + " wk ahead cum death" 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 = forecast [ target_end_date_str ] [ state_id ] ) , ignore_index = True ) 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 target = str ( ( target_end_date - FORECAST_DATE ) . days ) + " day ahead inc death" """
        prev_date = target_end_date - datetime.timedelta(1)
        prev_date_str = prev_date.strftime("%Y-%m-%d")

        if prev_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=forecast[target_end_date_str][state_id]-observed[prev_date_str][state_id]
                    ), ignore_index=True)

        elif prev_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=forecast[target_end_date_str][state_id]-forecast[prev_date_str][state_id]
                    ), ignore_index=True)
        """ if target_end_date >= FIRST_WEEK and target_end_date . weekday ( ) == 5 : cum_week += 1 target = str ( cum_week ) + " wk ahead inc death" 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 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. # Daily cumulative report. """
        target = str((target_end_date - FORECAST_DATE).days) + " day ahead cum death"
        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=forecast[target_end_date_str][state_id]
                ), ignore_index=True)
        """ # 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. # Daily Incident report. """
        prev_date = target_end_date - datetime.timedelta(1)
        prev_date_str = prev_date.strftime("%Y-%m-%d")

        if prev_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=forecast[target_end_date_str][state_id]-observed[prev_date_str][state_id]
                    ), ignore_index=True)

        elif prev_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=forecast[target_end_date_str][state_id]-forecast[prev_date_str][state_id]
                    ), ignore_index=True)
        """
forecast
observed