diff --git a/Analyser.py b/Analyser.py index 4f70487..6cf92d8 100644 --- a/Analyser.py +++ b/Analyser.py @@ -401,3 +401,47 @@ class Analyser: plt.close() return filePath + + def getDoubleRateCompareGraph(self, country, plotDpi=200.0, showPlot=False) -> str: + fig = plt.figure() + fig.dpi = plotDpi + ax = fig.add_subplot(111) + plt.title('Double Rate Forecast vs Reality in ' + country) + + data = self.df + mask = (data['countriesAndTerritories'] == country) + data = data.loc[mask] + data = data.sort_values('dateRep') + data['doubleRateForecast'] = data['totalCases'] / data['cases'] + data['doubleRateReality'] = None + data = data.reset_index() + + for index in data.index.values: + indexData = data.iloc[index] + # If there are cases in this country already + if indexData['totalCases'] > 0: + double = int(indexData['totalCases']) * 2 + doubleDay = data.loc[(data['totalCases'] >= double)] + # If there is a day with double the value of cases + if len(doubleDay['dateRep'].unique()) > 0: + doubleDay = doubleDay.loc[(doubleDay['dateRep'] == doubleDay['dateRep'].unique()[0])] + + indexDayDatetime = datetime.strptime(str(indexData['dateRep'])[:10], '%Y-%m-%d') + doubleDayDatetime = datetime.strptime(str(doubleDay['dateRep'].values)[2:12], '%Y-%m-%d') + + difference = (doubleDayDatetime - indexDayDatetime).days + + copyData = data.loc[(data['dateRep'] == indexData['dateRep'])] + copyData['doubleRateReality'] = difference + data.update(copyData) + + data.plot(ax=ax, x='dateRep', y='doubleRateForecast') + data.plot(ax=ax, x='dateRep', y='doubleRateReality') + + if showPlot: + plt.show(block=True) + filePath = ('graphs/doubleRateCompareGraph_' + country + '_' + datetime.now().strftime('%Y-%m-%d')) + fig.savefig(filePath) + plt.close() + + return filePath \ No newline at end of file diff --git a/UserInterface.py b/UserInterface.py index ecdd6c9..a23dae5 100644 --- a/UserInterface.py +++ b/UserInterface.py @@ -79,7 +79,8 @@ class UserInterface(QMainWindow): self.graphTypePicker = QComboBox(parent=self) self.graphTypePicker.addItems( ['Total Cases', 'Case Increase', 'Increase Percentage', 'Cases per Million', 'Total Deaths', - 'Death Increase', 'Death Rate', 'Deaths per Million', 'Is it going to end soon?']) + 'Death Increase', 'Death Rate', 'Deaths per Million', 'Is it going to end soon?', + 'Double Rate Compare']) picklistBox.addWidget(self.graphTypePicker, 1) # Calculate Button @@ -167,6 +168,9 @@ class UserInterface(QMainWindow): elif self.graphTypePicker.currentText() == 'Deaths per Million': deathsPerMillionGraphPath = self.analyser.getDeathsPerMillionGraph(country) self.graphPlaceHolder.setPixmap(QPixmap(deathsPerMillionGraphPath)) + elif self.graphTypePicker.currentText() == 'Double Rate Compare': + doubleRateCompareGraphPath = self.analyser.getDoubleRateCompareGraph(country) + self.graphPlaceHolder.setPixmap(QPixmap(doubleRateCompareGraphPath)) def clearLayout(self, layout): for i in reversed(range(layout.count())):