diff --git a/Analyser.py b/Analyser.py index 2868be1..fac43d5 100644 --- a/Analyser.py +++ b/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: """ diff --git a/Main.py b/Main.py index e7ac1f3..27cde52 100644 --- a/Main.py +++ b/Main.py @@ -10,4 +10,4 @@ import Analyser as ana if __name__ == '__main__': analyser = ana.Analyser() 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')