|
@@ -7,7 +7,10 @@ import requests
|
|
|
|
|
|
|
|
import data
|
|
import data
|
|
|
|
|
|
|
|
-_FNAME = 'https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_19-covid-Confirmed.csv'
|
|
|
|
|
|
|
+_URLS = {
|
|
|
|
|
+ 'cases': 'https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_19-covid-Confirmed.csv',
|
|
|
|
|
+ 'deaths': 'https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_19-covid-Deaths.csv',
|
|
|
|
|
+}
|
|
|
_DATES_START_AT = 4
|
|
_DATES_START_AT = 4
|
|
|
_REGIONS = [
|
|
_REGIONS = [
|
|
|
('Sweden', ['Sweden']),
|
|
('Sweden', ['Sweden']),
|
|
@@ -18,10 +21,11 @@ _REGIONS = [
|
|
|
('Europe', ['Italy', 'Sweden', 'Ireland']),
|
|
('Europe', ['Italy', 'Sweden', 'Ireland']),
|
|
|
]
|
|
]
|
|
|
_MARKERS = ['o', 'x', 'D']
|
|
_MARKERS = ['o', 'x', 'D']
|
|
|
|
|
+_MIN_COUNT = 10
|
|
|
|
|
|
|
|
|
|
|
|
|
-def write_fig(regions_label, regions, dates, region_data, start_date_idx, scale, normalize):
|
|
|
|
|
- title = scale
|
|
|
|
|
|
|
+def write_fig(url_label, regions_label, regions, dates, region_data, start_date_idx, scale, normalize):
|
|
|
|
|
+ title = '%s-%s' % (url_label, scale)
|
|
|
if normalize:
|
|
if normalize:
|
|
|
title += '-normalized'
|
|
title += '-normalized'
|
|
|
|
|
|
|
@@ -73,32 +77,32 @@ def write_fig(regions_label, regions, dates, region_data, start_date_idx, scale,
|
|
|
plt.close()
|
|
plt.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
-def run(regions_label, regions, dates, region_data):
|
|
|
|
|
|
|
+def run(url_label, regions_label, regions, dates, region_data):
|
|
|
start_date_idx = None
|
|
start_date_idx = None
|
|
|
for i, (series, region) in enumerate(zip(region_data, regions)):
|
|
for i, (series, region) in enumerate(zip(region_data, regions)):
|
|
|
for j, count in enumerate(series):
|
|
for j, count in enumerate(series):
|
|
|
- if count >= 10:
|
|
|
|
|
|
|
+ if count >= _MIN_COUNT:
|
|
|
if start_date_idx is None:
|
|
if start_date_idx is None:
|
|
|
start_date_idx = j-1 if j else j
|
|
start_date_idx = j-1 if j else j
|
|
|
else:
|
|
else:
|
|
|
start_date_idx = min(start_date_idx, j-1 if j else j)
|
|
start_date_idx = min(start_date_idx, j-1 if j else j)
|
|
|
|
|
|
|
|
if start_date_idx is None:
|
|
if start_date_idx is None:
|
|
|
- print 'No data for %s; aborting' % label
|
|
|
|
|
|
|
+ print 'No data for %s-%s; aborting' % (url_label, regions_label)
|
|
|
return
|
|
return
|
|
|
|
|
|
|
|
if not os.path.isdir('figs'):
|
|
if not os.path.isdir('figs'):
|
|
|
os.mkdir('figs')
|
|
os.mkdir('figs')
|
|
|
- if not os.path.isdir('figs/%s' % label):
|
|
|
|
|
- os.mkdir('figs/%s' % label)
|
|
|
|
|
|
|
+ if not os.path.isdir('figs/%s' % regions_label):
|
|
|
|
|
+ os.mkdir('figs/%s' % regions_label)
|
|
|
|
|
|
|
|
for scale in ['linear', 'log']:
|
|
for scale in ['linear', 'log']:
|
|
|
for normalize in [True, False]:
|
|
for normalize in [True, False]:
|
|
|
- write_fig(regions_label, regions, dates, region_data, start_date_idx, scale, normalize)
|
|
|
|
|
|
|
+ write_fig(url_label, regions_label, regions, dates, region_data, start_date_idx, scale, normalize)
|
|
|
|
|
|
|
|
|
|
|
|
|
-def load():
|
|
|
|
|
- raw = requests.get(_FNAME).content
|
|
|
|
|
|
|
+def load(url):
|
|
|
|
|
+ raw = requests.get(url).content
|
|
|
|
|
|
|
|
dates = None
|
|
dates = None
|
|
|
|
|
|
|
@@ -125,8 +129,9 @@ def print_regions(counts):
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
if __name__ == "__main__":
|
|
|
- dates, counts = load()
|
|
|
|
|
|
|
+ for url_label, url in _URLS.items():
|
|
|
|
|
+ dates, counts = load(url)
|
|
|
|
|
|
|
|
- for label, regions in _REGIONS:
|
|
|
|
|
- region_data = [counts[region] for region in regions]
|
|
|
|
|
- run(label, regions, dates, region_data)
|
|
|
|
|
|
|
+ for region_label, regions in _REGIONS:
|
|
|
|
|
+ regions_data = [counts[region] for region in regions]
|
|
|
|
|
+ run(url_label, region_label, regions, dates, regions_data)
|