can now plot total cases and case increase

This commit is contained in:
Patrick Müller 2020-03-28 21:45:50 +01:00
parent 44c61830df
commit b8ac53724d
2 changed files with 55 additions and 8 deletions

View File

@ -32,23 +32,70 @@ class Analyser:
df = pd.read_csv('2020-03-28_11-00.csv', encoding='windows-1252') df = pd.read_csv('2020-03-28_11-00.csv', encoding='windows-1252')
df['dateRep'] = pd.to_datetime(df['dateRep']) df['dateRep'] = pd.to_datetime(df['dateRep'])
print(df['dateRep'].head())
def getAvailableCountries(self): def getAvailableCountries(self):
return self.df['countriesAndTerritories'].unique() 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 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 :param country: The country you wish to get the graph for
:return: The path for the picture of the graph :return: The path for the picture of the graph
""" """
if country in self.getAvailableCountries():
fig = plt.figure() fig = plt.figure()
ax = fig.add_subplot(111) ax = fig.add_subplot(111)
countryData = self.df[self.df['countriesAndTerritories'].isin([country])] # casesPerDayDict = {}
print(countryData['cases'].sum()) # for date in self.df['dateRep']:
# casesPerDayDict[date] = self.getTotalCases(country, date)
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' return 'abc'
def getTotalCases(self, country, date=datetime.now().strftime('%Y-%m-%d')) -> int: def getTotalCases(self, country, date=datetime.now().strftime('%Y-%m-%d')) -> int:

View File

@ -10,4 +10,4 @@ import Analyser as ana
if __name__ == '__main__': if __name__ == '__main__':
analyser = ana.Analyser() analyser = ana.Analyser()
country = input('What country do you want the graph for: ') country = input('What country do you want the graph for: ')
print(analyser.getTotalCases(country, '2020-03-28')) analyser.getCasesGraph(country, start_date='2020-02-14')