Пример #1
0
def get_county_data():
    path = common.get_data_path(os.path.abspath(os.path.dirname(__file__)),
                                'seven_day_county.csv')
    with open(path, 'r') as read_obj:
        df = pd.read_csv(read_obj)
    df['date'] = pd.to_datetime(df['date'])
    return df
Пример #2
0
def get_territory_list(territory_key='country'):
    """
    Searches .csv file and returns unique regions from region column. Creates
    list of tuples, where the first field is the name of the web page, and the
    second is the page's url.
    :param territory_key: str determining which .csv file to search and filter
    :return: alphabetically sorted list of tuples
    """
    if territory_key == 'country':
        csv_file_name = 'world'
    elif territory_key == 'state':
        csv_file_name = 'states'
    else:
        csv_file_name = 'seven_day_county'
    csv_file_name += '.csv'

    path = common.get_data_path(os.path.abspath(os.path.dirname(__file__)),
                                csv_file_name)
    with open(path, 'r') as read_obj:
        df = pd.read_csv(read_obj)

    if territory_key == 'country':
        territory_list = df.country.unique()
        territory_list = [w.replace('_', ' ') for w in territory_list]

    elif territory_key == 'state':
        territory_list = df.state.unique()

    else:
        territory_list = df.state.unique()

    territory_list = sorted(territory_list)
    return territory_list
Пример #3
0
def get_state_pop():
    path = common.get_data_path(os.path.abspath(os.path.dirname(__file__)), 'states_population.csv')
    d = {}
    with open(path, 'r') as read_obj:
        reader = csv.DictReader(read_obj)
        for row in reader:
            d[row['state']] = int(row['population_2019'])
    return d
Пример #4
0
def get_site_last_updated():
    """
    get last updated time stamp
    """
    path = common.get_data_path(os.path.abspath(os.path.dirname(__file__)),
                                'site_last_updated.csv')
    with open(path, 'r') as read_obj:
        lines = read_obj.readlines()
    d = datetime.datetime.strptime(
        lines[1][0:19], '%Y-%m-%d %H:%M:%S').strftime("%Y-%m-%d %H:%M:%S")
    return d
Пример #5
0
def get_world_data_week():
    """
    get the data from BQ, grouped by week
    """
    path = common.get_data_path(os.path.abspath(os.path.dirname(__file__)),
                                'world_week.csv')
    with open(path, 'r') as read_obj:
        df = pd.read_csv(read_obj)
    df['country'] = df['country'].str.replace('_', ' ')
    df['date'] = pd.to_datetime(df['date'])
    df['dates'] = df['date']
    return df
Пример #6
0
def get_totals():
    path = common.get_data_path(os.path.abspath(os.path.dirname(__file__)),
                                'states_totals.csv')
    d = {}
    with open(path, 'r') as read_obj:
        reader = csv.DictReader(read_obj)
        for row in reader:
            d[row['state']] = {
                'deaths': int(row['deaths']),
                'cases': int(row['cases'])
            }
    return d
Пример #7
0
def get_world_data_day():
    """
    Get the data by day for world

    return: df
    """
    path = common.get_data_path(os.path.abspath(os.path.dirname(__file__)),
                                'world.csv')
    with open(path, 'r') as read_obj:
        df = pd.read_csv(read_obj)
    df['country'] = df['country'].str.replace('_', ' ')
    df['date'] = pd.to_datetime(df['date'])
    df['dates'] = df['date']
    return df
Пример #8
0
def get_data_deaths():
    path = common.get_data_path(os.path.abspath(os.path.dirname(__file__)), 'states_deaths_ranked.csv')
    with open(path, 'r') as read_obj:
        df = pd.read_csv(read_obj)
    df['date'] = pd.to_datetime(df['date'])
    return df
Пример #9
0
def _get_pop_df():
    path = common.get_data_path(os.path.abspath(os.path.dirname(__file__)), 'states_population.csv')
    df = pd.read_csv(path)
    return df
Пример #10
0
def _get_state_df():
    path = common.get_data_path(os.path.abspath(os.path.dirname(__file__)), 'states.csv')
    df = pd.read_csv(path)
    df['date'] = pd.to_datetime(df['date'])
    return df