Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 19 additions & 18 deletions src/covidify/data_prep.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
import pandas as pd
from string import capwords
from difflib import get_close_matches
from datetime import datetime, date, time
from datetime import datetime, date, time

from covidify.sources import github, wiki
from covidify.sources.github_proxy import GithubProxy
from covidify.config import REPO, TMP_FOLDER, TMP_GIT, DATA
from covidify.utils.utils import replace_arg_score

Expand All @@ -34,6 +34,7 @@


############ DATA SELECTION ############
github_data = GithubProxy()

if '_' in country:
country = replace_arg_score(country)
Expand All @@ -42,22 +43,22 @@
country = None

if source == 'JHU':
df = github.get()
df = github_data.get()

elif source == 'wiki':
print('Apologies, the wikipedia source is not ready yet - getting github data')
df = github.get()
df = github_data.get()



############ COUNTRY SELECTION ############

def get_similar_countries(c, country_list):
pos_countries = get_close_matches(c, country_list)

if len(pos_countries) > 0:
print('\033[1;31m'+c, 'was not listed. did you mean', pos_countries[0].capitalize() + '?\033[0;0m')

#Only delete if its a covidify generated folder
if 'Desktop/covidify-output-' in out:
os.system('rm -rf ' + out)
Expand All @@ -67,13 +68,13 @@ def get_similar_countries(c, country_list):
if 'Desktop/covidify-output-' in out:
os.system('rm -rf ' + out)
sys.exit(1)

def check_specified_country(df, country):
'''
let user filter reports by country, if not found
then give a option if the string is similar
'''

# Get all unique countries in the data
country_list = list(map(lambda x:x.lower().strip(), set(df.country.values)))

Expand All @@ -85,7 +86,7 @@ def check_specified_country(df, country):
# give similar option if similarity found
if country.lower() not in country_list:
get_similar_countries(country, country_list)

else:
#Return filtered dataframe
print('... filtering data for', country)
Expand Down Expand Up @@ -170,9 +171,9 @@ def get_top_countries(data):
# Get top N infected countries
tmp_df = data.copy()
tmp_df = tmp_df[tmp_df.file_date == df.file_date.max()]
return tmp_df.groupby(['country']).agg({'confirmed': 'sum'}).sort_values('confirmed',ascending=False).head(top).index
TOP_N_COUNTRIES = get_top_countries(df)
return tmp_df.groupby(['country']).agg({'confirmed': 'sum'}).sort_values('confirmed',ascending=False).head(top).index

TOP_N_COUNTRIES = get_top_countries(df)

tmp_df = df[df.country.isin(TOP_N_COUNTRIES)].copy()

Expand All @@ -188,18 +189,18 @@ def get_day_counts(d, country):
'deaths': 'sum'})
result_df['date'] = data['file_date'].unique()
result_df['country'] = country

result_df = result_df[result_df.confirmed >= 500]
result_df.insert(loc=0, column='day', value=np.arange(len(result_df)))
return result_df

df_list = []

for country in TOP_N_COUNTRIES:
print(' ...', country + ': ' + str(tmp_df[(tmp_df.file_date == df.file_date.max()) &
print(' ...', country + ': ' + str(tmp_df[(tmp_df.file_date == df.file_date.max()) &
(tmp_df.country == country)].confirmed.sum()))
df_list.append(get_day_counts(tmp_df[tmp_df.country == country], country))

log_df = pd.concat(df_list, axis=0, ignore_index=True)


Expand Down Expand Up @@ -227,4 +228,4 @@ def get_day_counts(d, country):
log_df.astype(str).to_csv(os.path.join(save_dir, log_file_name))
print('...', log_file_name)

print('Done!')
print('Done!')
11 changes: 6 additions & 5 deletions src/covidify/list_countries.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'''
This script is for listing countries that have cases of corona virus.
This is so you can decide which country to make a report for.
This is so you can decide which country to make a report for.

'''

Expand All @@ -9,17 +9,18 @@
import click
import covidify
import numpy as np
from covidify.sources import github
from covidify.sources.github_proxy import GithubProxy
from covidify.config import SCRIPT

def get_countries():
print('Getting available countries...')
df = github.get()
github_data = GithubProxy()
df = github_data.get()
df = df[df.confirmed > 0]

countries = sorted(list(set(df.country.values)))

for a,b,c in zip(countries[::3],countries[1::3],countries[2::3]):
print('{:<30}{:<30}{:<}'.format(a,b,c))
print('\n\033[1;31mNUMBER OF COUNTRIES/AREAS INFECTED:\033[0;0m', len(countries))

print('\n\033[1;31mNUMBER OF COUNTRIES/AREAS INFECTED:\033[0;0m', len(countries))
10 changes: 10 additions & 0 deletions src/covidify/sources/data_sources_interface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import abc

class DataInterface(object, metaclass=abc.ABCMeta):

def __init__(self):
pass

@abc.abstractmethod
def get():
raise NotImplementedError('User must define get()')
Loading