Added increase percentage graph

This commit is contained in:
Patrick Müller 2020-04-01 21:59:26 +02:00
parent 2c9e4b3658
commit 80927f470d
2 changed files with 46 additions and 13 deletions

View File

@ -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

View File

@ -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,14 +69,15 @@ 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('<h3>Pick a graph type:</h3>')
labelBox.addWidget(graphTypePickerLabel)
self.graphTypePicker = QComboBox(parent=self)
self.graphTypePicker.addItems(['Total Cases', 'Case Increase', 'Total Deaths', 'Death Increase', 'Death Rate',
self.graphTypePicker.addItems(
['Total Cases', 'Case Increase', 'Increase Percentage', 'Total Deaths', 'Death Increase', 'Death Rate',
'Is it going to end soon?'])
picklistBox.addWidget(self.graphTypePicker, 1)
@ -131,6 +131,7 @@ class UserInterface(QWidget):
+ '%</h4>'))
casesGraphPath = self.analyser.getCasesGraph(country, startDate, endDate)
caseIncreaseGraphPath = self.analyser.getCaseIncreaseGraph(country, startDate, endDate)
increasePercentageGraphPath = self.analyser.getIncreasePercentageGraph(country, startDate, endDate)
deathGraphPath = self.analyser.getDeathGraph(country, startDate, endDate)
deathIncreaseGraphPath = self.analyser.getDeathIncreaseGraph(country, startDate, endDate)
deathRateGraphPath = self.analyser.getDailyDeathRateGraph(country, startDate, endDate)
@ -143,6 +144,8 @@ class UserInterface(QWidget):
self.graphPlaceHolder.setPixmap(QPixmap(casesGraphPath))
elif self.graphTypePicker.currentText() == 'Case Increase':
self.graphPlaceHolder.setPixmap(QPixmap(caseIncreaseGraphPath))
elif self.graphTypePicker.currentText() == 'Increase Percentage':
self.graphPlaceHolder.setPixmap(QPixmap(increasePercentageGraphPath))
elif self.graphTypePicker.currentText() == 'Total Deaths':
self.graphPlaceHolder.setPixmap(QPixmap(deathGraphPath))
elif self.graphTypePicker.currentText() == 'Death Increase':