-
Notifications
You must be signed in to change notification settings - Fork 3
/
argentina_api.py
45 lines (40 loc) · 1.8 KB
/
argentina_api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import numpy as np
import pandas as pd
import math
import unicodedata
import collections
import os
from common import *
from argentina_province_parse import *
COVIDStats = collections.namedtuple('COVIDStats', ['date', 'place_name', 'confirmados','muertos', 'recuperados', 'activos'])
class ArgentinaAPI:
"""" API for programatically get info about COVID situation at Argentina provinces. """
def __init__(self,work_dir):
self.work_dir = work_dir
# Download files from Google Drive
self.df_provinces = download_province_table()
self.provinces = list(self.df_provinces.loc['CONFIRMADOS'].index)
def get_stats(self,date):
""" Return a [ COVIDStats ] for the considered date for all provinces """
result = []
for province_name in self.provinces:
result.append(COVIDStats(date = date,
place_name = province_name,
confirmados = self.df_provinces.loc['CONFIRMADOS'].loc[province_name][date],
muertos = self.df_provinces.loc['MUERTOS'].loc[province_name][date],
recuperados = self.df_provinces.loc['RECUPERADOS'].loc[province_name][date],
activos = self.df_provinces.loc['ACTIVOS'].loc[province_name][date]))
return result
if __name__ == '__main__':
import matplotlib.pyplot as plt
from IPython.display import IFrame
import gmplot
api = ArgentinaAPI('./')
date = '26/3/2020'
provinces = api.df_confirmados[date]
provinces = provinces[provinces>0]
if not provinces.empty:
provinces.plot.bar()
plt.savefig('confirmados_nacion.png', bbox_inches = 'tight')
else:
print('No confirmed cases at {}'.format(date))