diff --git a/Analyser.py b/Analyser.py index f057247..5d32b13 100644 --- a/Analyser.py +++ b/Analyser.py @@ -31,7 +31,7 @@ class Analyser: # Pandas Settings pd.set_option('display.max_row', 50) pd.set_option('display.max_column', 10) - + self.df = pd.read_csv('statsfile.csv') self.df['dateRep'] = pd.to_datetime(self.df['dateRep'], format='%d/%m/%Y') @@ -47,7 +47,8 @@ class Analyser: retList.sort() return retList - def getCasesGraph(self, country, start_date='2019-12-31', end_date=datetime.now().strftime('%Y-%m-%d'), showPlot=False) -> str: + def getCasesGraph(self, country, start_date='2019-12-31', end_date=datetime.now().strftime('%Y-%m-%d'), + showPlot=False) -> 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 @@ -81,7 +82,8 @@ class Analyser: print('Unknown country') return '-1' - def getCaseIncreaseGraph(self, country, start_date='2019-12-31', end_date=datetime.now().strftime('%Y-%m-%d'), showPlot=False) -> str: + def getCaseIncreaseGraph(self, country, start_date='2019-12-31', end_date=datetime.now().strftime('%Y-%m-%d'), + showPlot=False) -> str: """ 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 @@ -125,7 +127,8 @@ class Analyser: countryTimeData = countryData.loc[mask] return countryTimeData['cases'].sum() - def getDeathGraph(self, country, start_date='2019-12-31', end_date=datetime.now().strftime('%Y-%m-%d'), showPlot=False) -> str: + def getDeathGraph(self, country, start_date='2019-12-31', end_date=datetime.now().strftime('%Y-%m-%d'), + showPlot=False) -> 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 @@ -159,7 +162,8 @@ class Analyser: print('Unknown country') return '-1' - def getDeathIncreaseGraph(self, country, start_date='2019-12-31', end_date=datetime.now().strftime('%Y-%m-%d'), showPlot=False) -> str: + def getDeathIncreaseGraph(self, country, start_date='2019-12-31', end_date=datetime.now().strftime('%Y-%m-%d'), + showPlot=False) -> str: """ 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 @@ -203,7 +207,8 @@ class Analyser: countryTimeData = countryData.loc[mask] return countryTimeData['deaths'].sum() - def getDailyDeathRateGraph(self, country, start_date='2019-12-31', end_date=datetime.now().strftime('%Y-%m-%d'), showPlot=False) -> str: + def getDailyDeathRateGraph(self, country, start_date='2019-12-31', end_date=datetime.now().strftime('%Y-%m-%d'), + showPlot=False) -> str: """ 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 @@ -249,14 +254,15 @@ class Analyser: countryData = self.df[self.df['countriesAndTerritories'].isin([country])] mask = (countryData['dateRep'] <= date) countryTimeData = countryData.loc[mask] - return (countryTimeData['deaths'].sum()/countryTimeData['cases'].sum()*100) + return (countryTimeData['deaths'].sum() / countryTimeData['cases'].sum() * 100) - def getIsItOverGraph(self, country, start_date='2019-12-31', end_date=datetime.now().strftime('%Y-%m-%d'), showPlot=False) -> str: + def getIsItOverGraph(self, country, start_date='2019-12-31', end_date=datetime.now().strftime('%Y-%m-%d'), + showPlot=False) -> str: countryString = country fig = plt.figure() fig.dpi = 200.0 ax = fig.add_subplot(111) - plt.title('Is it going to end soon?') + plt.title('Is it going to end soon in ' + countryString + '?') ax.set_ylabel('Case Increase') ax.set_xlabel('Total Cases') for index, country in enumerate([country, 'China', 'South_Korea'], start=1): @@ -279,3 +285,27 @@ class Analyser: plt.close() return filePath + + def getIncreasePercentageGraph(self, country, start_date='2019-12-31', end_date=datetime.now().strftime('%Y-%m-%d'), + showPlot=False) -> str: + fig = plt.figure() + fig.dpi = 200.0 + ax = fig.add_subplot(111) + plt.title('Daily Percentage of Case Increase in ' + country) + + countryData = self.df[self.df['countriesAndTerritories'].isin([country])] + countryData = countryData.sort_values('dateRep') + countryData['totalCases'] = countryData['cases'].cumsum() + countryData['increasePercentage'] = countryData['cases'] / countryData['totalCases'] * 100 + mask = (countryData['dateRep'] >= start_date) & (countryData['dateRep'] <= end_date) + countryTimeData = countryData.loc[mask] + + countryTimeData.plot(ax=ax, x='dateRep', y='increasePercentage') + + if showPlot: + plt.show(block=True) + filePath = ('graphs/increasePercentageGraph_' + country + '_' + datetime.now().strftime('%Y-%m-%d')) + fig.savefig(filePath) + plt.close() + + return filePath diff --git a/UserInterface.py b/UserInterface.py index 845715c..be172e4 100644 --- a/UserInterface.py +++ b/UserInterface.py @@ -24,7 +24,6 @@ class UserInterface(QWidget): # PyQT Setup self.setWindowTitle('COVID-19 Analytics') screen_width, screen_height = app.desktop().screenGeometry().width(), app.desktop().screenGeometry().height() - # screen_width, screen_height = 3840, 2160 self.setGeometry(((screen_width / 2) - 750), ((screen_height / 2) - 375), 1500, 750) self.setMinimumWidth(1500) @@ -70,15 +69,16 @@ class UserInterface(QWidget): labelBox.addWidget(endDatePickerLabel) self.endDatePicker = QComboBox(parent=self) self.endDatePicker.addItems(dates) - self.endDatePicker.setCurrentText(dates[len(dates)-1]) + self.endDatePicker.setCurrentText(dates[len(dates) - 1]) picklistBox.addWidget(self.endDatePicker, 1) # Graph Type Picker graphTypePickerLabel = QLabel('