results/format-covid-forecast/format_data_state_death.py
def load_truth_cumulative_deaths():
    """
    Load the observed cumulative deaths from the data source.
    Return A 2D dictionary structuring of <date_str, <state_id, value>>
    An example looks like:
    { 
        "2020-06-17" : {
            "10": 1000,
            "11": 2000,
            ...
        }, 
        "2020-06-18" : {
            "10": 1100,
            "11": 2100,
            ...
        }, 
    }
    """
    dataset = {}
    URL = "https://raw.githubusercontent.com/reichlab/covid19-forecast-hub/master/data-truth/truth-Cumulative%20Deaths.csv"

    f = io.StringIO(urllib.request.urlopen(URL).read().decode('utf-8'))
    reader = csv.reader(f)
    header = next(reader, None)

    location_col = -1
    date_col = -1
    value_col = -1

    for i in range(0, len(header)):
        if (header[i] == "location"):
            location_col = i
        elif (header[i] == "date"):
            date_col = i
        elif (header[i] == "value"):
            value_col = i

    for row in reader:
        state_id = row[location_col]
        date = row[date_col]
        val = int(row[value_col])
        if date not in dataset:
            dataset[date] = {}
                
        dataset[date][state_id] = val

    return dataset

    Load the observed cumulative deaths from the data source.
    Return A 2D dictionary structuring of <date_str, <state_id, value>>
    An example looks like:
    { 
        "2020-06-17" : {
            "10": 1000,
            "11": 2000,
            ...
        }, 
        "2020-06-18" : {
            "10": 1100,
            "11": 2100,
            ...
        }, 
    }
    
Load the observed cumulative deaths from the data source.
Load the observed cumulative deaths from the data source .
def load_truth_cumulative_deaths():
    dataset = {}
    URL = "https://raw.githubusercontent.com/reichlab/covid19-forecast-hub/master/data-truth/truth-Cumulative%20Deaths.csv"
    f = io.StringIO(urllib.request.urlopen(URL).read().decode('utf-8'))
    reader = csv.reader(f)
    header = next(reader, None)
    location_col = -1
    date_col = -1
    value_col = -1
    for i in range(0, len(header)):
        if (header[i] == "location"):
            location_col = i
        elif (header[i] == "date"):
            date_col = i
        elif (header[i] == "value"):
            value_col = i
    for row in reader:
        state_id = row[location_col]
        date = row[date_col]
        val = int(row[value_col])
        if date not in dataset:
            dataset[date] = {}
        dataset[date][state_id] = val
    return dataset
def load_truth_cumulative_deaths ( ) : dataset = { } URL = "https://raw.githubusercontent.com/reichlab/covid19-forecast-hub/master/data-truth/truth-Cumulative%20Deaths.csv" f = io . StringIO ( urllib . request . urlopen ( URL ) . read ( ) . decode ( 'utf-8' ) ) reader = csv . reader ( f ) header = next ( reader , None ) location_col = - 1 date_col = - 1 value_col = - 1 for i in range ( 0 , len ( header ) ) : if ( header [ i ] == "location" ) : location_col = i elif ( header [ i ] == "date" ) : date_col = i elif ( header [ i ] == "value" ) : value_col = i for row in reader : state_id = row [ location_col ] date = row [ date_col ] val = int ( row [ value_col ] ) if date not in dataset : dataset [ date ] = { } dataset [ date ] [ state_id ] = val return dataset
Load the observed cumulative deaths from the data source.
Load the observed cumulative deaths from the data source .
"""
    Load the observed cumulative deaths from the data source.
    Return A 2D dictionary structuring of <date_str, <state_id, value>>
    An example looks like:
    { 
        "2020-06-17" : {
            "10": 1000,
            "11": 2000,
            ...
        }, 
        "2020-06-18" : {
            "10": 1100,
            "11": 2100,
            ...
        }, 
    }
    """