✨ can now plot total cases and case increase
This commit is contained in:
parent
44c61830df
commit
b8ac53724d
61
Analyser.py
61
Analyser.py
|
@ -32,24 +32,71 @@ class Analyser:
|
|||
|
||||
df = pd.read_csv('2020-03-28_11-00.csv', encoding='windows-1252')
|
||||
df['dateRep'] = pd.to_datetime(df['dateRep'])
|
||||
print(df['dateRep'].head())
|
||||
|
||||
def getAvailableCountries(self):
|
||||
return self.df['countriesAndTerritories'].unique()
|
||||
|
||||
def getCasesGraph(self, country) -> str:
|
||||
def getCasesGraph(self, country, start_date='2019-12-31', end_date=datetime.now().strftime('%Y-%m-%d')) -> str:
|
||||
"""
|
||||
Get a graph with the absolute number of cases by day for the entered country
|
||||
:param country: The country you wish to get the graph for
|
||||
:return: The path for the picture of the graph
|
||||
"""
|
||||
fig = plt.figure()
|
||||
ax = fig.add_subplot(111)
|
||||
if country in self.getAvailableCountries():
|
||||
fig = plt.figure()
|
||||
ax = fig.add_subplot(111)
|
||||
|
||||
countryData = self.df[self.df['countriesAndTerritories'].isin([country])]
|
||||
print(countryData['cases'].sum())
|
||||
# casesPerDayDict = {}
|
||||
# for date in self.df['dateRep']:
|
||||
# casesPerDayDict[date] = self.getTotalCases(country, date)
|
||||
|
||||
return 'abc'
|
||||
countryData = self.df[self.df['countriesAndTerritories'].isin([country])]
|
||||
mask = (countryData['dateRep'] > start_date) & (countryData['dateRep'] <= end_date)
|
||||
countryTimeData = countryData.loc[mask]
|
||||
countryTimeData = countryTimeData.sort_values('dateRep')
|
||||
countryTimeData['cases'] = countryTimeData['cases'].cumsum()
|
||||
|
||||
print(countryTimeData.head())
|
||||
|
||||
countryTimeData.plot(ax=ax, x='dateRep', y='cases')
|
||||
|
||||
plt.show(block=True)
|
||||
|
||||
# TODO Change return
|
||||
return 'abc'
|
||||
else:
|
||||
print('Unknown country')
|
||||
# TODO Change return
|
||||
return 'abc'
|
||||
|
||||
def getCaseIncreaseGraph(self, country):
|
||||
"""
|
||||
Get a graph with the daily increase number of cases for the entered country
|
||||
:param country: The country you wish to get the graph for
|
||||
:return: The path for the picture of the graph
|
||||
"""
|
||||
if country in self.getAvailableCountries():
|
||||
fig = plt.figure()
|
||||
ax = fig.add_subplot(111)
|
||||
|
||||
# casesPerDayDict = {}
|
||||
# for date in self.df['dateRep']:
|
||||
# casesPerDayDict[date] = self.getTotalCases(country, date)
|
||||
|
||||
countryData = self.df[self.df['countriesAndTerritories'].isin([country])]
|
||||
mask = (countryData['dateRep'] <= datetime.now().strftime('%Y-%m-%d'))
|
||||
countryTimeData = countryData.loc[mask]
|
||||
|
||||
countryTimeData.plot(ax=ax, x='dateRep', y='cases')
|
||||
|
||||
plt.show(block=True)
|
||||
|
||||
# TODO Change return
|
||||
return 'abc'
|
||||
else:
|
||||
print('Unknown country')
|
||||
# TODO Change return
|
||||
return 'abc'
|
||||
|
||||
def getTotalCases(self, country, date=datetime.now().strftime('%Y-%m-%d')) -> int:
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue
Block a user