✨ Added increase percentage graph
This commit is contained in:
parent
2c9e4b3658
commit
80927f470d
44
Analyser.py
44
Analyser.py
|
@ -47,7 +47,8 @@ class Analyser:
|
||||||
retList.sort()
|
retList.sort()
|
||||||
return retList
|
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
|
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
|
||||||
|
@ -81,7 +82,8 @@ class Analyser:
|
||||||
print('Unknown country')
|
print('Unknown country')
|
||||||
return '-1'
|
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
|
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
|
:param country: The country you wish to get the graph for
|
||||||
|
@ -125,7 +127,8 @@ class Analyser:
|
||||||
countryTimeData = countryData.loc[mask]
|
countryTimeData = countryData.loc[mask]
|
||||||
return countryTimeData['cases'].sum()
|
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
|
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
|
||||||
|
@ -159,7 +162,8 @@ class Analyser:
|
||||||
print('Unknown country')
|
print('Unknown country')
|
||||||
return '-1'
|
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
|
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
|
:param country: The country you wish to get the graph for
|
||||||
|
@ -203,7 +207,8 @@ class Analyser:
|
||||||
countryTimeData = countryData.loc[mask]
|
countryTimeData = countryData.loc[mask]
|
||||||
return countryTimeData['deaths'].sum()
|
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
|
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
|
:param country: The country you wish to get the graph for
|
||||||
|
@ -251,12 +256,13 @@ class Analyser:
|
||||||
countryTimeData = countryData.loc[mask]
|
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
|
countryString = country
|
||||||
fig = plt.figure()
|
fig = plt.figure()
|
||||||
fig.dpi = 200.0
|
fig.dpi = 200.0
|
||||||
ax = fig.add_subplot(111)
|
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_ylabel('Case Increase')
|
||||||
ax.set_xlabel('Total Cases')
|
ax.set_xlabel('Total Cases')
|
||||||
for index, country in enumerate([country, 'China', 'South_Korea'], start=1):
|
for index, country in enumerate([country, 'China', 'South_Korea'], start=1):
|
||||||
|
@ -279,3 +285,27 @@ class Analyser:
|
||||||
plt.close()
|
plt.close()
|
||||||
|
|
||||||
return filePath
|
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
|
||||||
|
|
|
@ -24,7 +24,6 @@ class UserInterface(QWidget):
|
||||||
# PyQT Setup
|
# PyQT Setup
|
||||||
self.setWindowTitle('COVID-19 Analytics')
|
self.setWindowTitle('COVID-19 Analytics')
|
||||||
screen_width, screen_height = app.desktop().screenGeometry().width(), app.desktop().screenGeometry().height()
|
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.setGeometry(((screen_width / 2) - 750), ((screen_height / 2) - 375), 1500, 750)
|
||||||
self.setMinimumWidth(1500)
|
self.setMinimumWidth(1500)
|
||||||
|
|
||||||
|
@ -77,7 +76,8 @@ class UserInterface(QWidget):
|
||||||
graphTypePickerLabel = QLabel('<h3>Pick a graph type:</h3>')
|
graphTypePickerLabel = QLabel('<h3>Pick a graph type:</h3>')
|
||||||
labelBox.addWidget(graphTypePickerLabel)
|
labelBox.addWidget(graphTypePickerLabel)
|
||||||
self.graphTypePicker = QComboBox(parent=self)
|
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?'])
|
'Is it going to end soon?'])
|
||||||
picklistBox.addWidget(self.graphTypePicker, 1)
|
picklistBox.addWidget(self.graphTypePicker, 1)
|
||||||
|
|
||||||
|
@ -131,6 +131,7 @@ class UserInterface(QWidget):
|
||||||
+ '%</h4>'))
|
+ '%</h4>'))
|
||||||
casesGraphPath = self.analyser.getCasesGraph(country, startDate, endDate)
|
casesGraphPath = self.analyser.getCasesGraph(country, startDate, endDate)
|
||||||
caseIncreaseGraphPath = self.analyser.getCaseIncreaseGraph(country, startDate, endDate)
|
caseIncreaseGraphPath = self.analyser.getCaseIncreaseGraph(country, startDate, endDate)
|
||||||
|
increasePercentageGraphPath = self.analyser.getIncreasePercentageGraph(country, startDate, endDate)
|
||||||
deathGraphPath = self.analyser.getDeathGraph(country, startDate, endDate)
|
deathGraphPath = self.analyser.getDeathGraph(country, startDate, endDate)
|
||||||
deathIncreaseGraphPath = self.analyser.getDeathIncreaseGraph(country, startDate, endDate)
|
deathIncreaseGraphPath = self.analyser.getDeathIncreaseGraph(country, startDate, endDate)
|
||||||
deathRateGraphPath = self.analyser.getDailyDeathRateGraph(country, startDate, endDate)
|
deathRateGraphPath = self.analyser.getDailyDeathRateGraph(country, startDate, endDate)
|
||||||
|
@ -143,6 +144,8 @@ class UserInterface(QWidget):
|
||||||
self.graphPlaceHolder.setPixmap(QPixmap(casesGraphPath))
|
self.graphPlaceHolder.setPixmap(QPixmap(casesGraphPath))
|
||||||
elif self.graphTypePicker.currentText() == 'Case Increase':
|
elif self.graphTypePicker.currentText() == 'Case Increase':
|
||||||
self.graphPlaceHolder.setPixmap(QPixmap(caseIncreaseGraphPath))
|
self.graphPlaceHolder.setPixmap(QPixmap(caseIncreaseGraphPath))
|
||||||
|
elif self.graphTypePicker.currentText() == 'Increase Percentage':
|
||||||
|
self.graphPlaceHolder.setPixmap(QPixmap(increasePercentageGraphPath))
|
||||||
elif self.graphTypePicker.currentText() == 'Total Deaths':
|
elif self.graphTypePicker.currentText() == 'Total Deaths':
|
||||||
self.graphPlaceHolder.setPixmap(QPixmap(deathGraphPath))
|
self.graphPlaceHolder.setPixmap(QPixmap(deathGraphPath))
|
||||||
elif self.graphTypePicker.currentText() == 'Death Increase':
|
elif self.graphTypePicker.currentText() == 'Death Increase':
|
||||||
|
|
Loading…
Reference in New Issue
Block a user