Added Death Graphs

This commit is contained in:
Patrick Müller 2020-03-30 17:02:56 +02:00
parent 6646e0bbe6
commit 2f2e164e40
3 changed files with 295 additions and 25 deletions

View File

@ -49,6 +49,8 @@ class Analyser:
""" """
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
:param start_date: The start date of the graph
:param end_date: The end date of the graph
:return: The path for the picture of the graph :return: The path for the picture of the graph
""" """
if country in self.getAvailableCountries(): if country in self.getAvailableCountries():
@ -77,12 +79,14 @@ class Analyser:
""" """
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
:param start_date: The start date of the graph
:param end_date: The end date of the graph
:return: The path for the picture of the graph :return: The path for the picture of the graph
""" """
if country in self.getAvailableCountries(): if country in self.getAvailableCountries():
fig = plt.figure() fig = plt.figure()
ax = fig.add_subplot(111) ax = fig.add_subplot(111)
plt.title(('Cases increase graph for ' + country)) plt.title(('Daily case increase graph for ' + country))
countryData = self.df[self.df['countriesAndTerritories'].isin([country])] countryData = self.df[self.df['countriesAndTerritories'].isin([country])]
mask = (countryData['dateRep'] > start_date) & (countryData['dateRep'] <= end_date) mask = (countryData['dateRep'] > start_date) & (countryData['dateRep'] <= end_date)
@ -110,3 +114,61 @@ class Analyser:
mask = (countryData['dateRep'] <= date) mask = (countryData['dateRep'] <= date)
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')) -> 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
:param start_date: The start date of the graph
:param end_date: The end date of the graph
:return: The path for the picture of the graph
"""
if country in self.getAvailableCountries():
fig = plt.figure()
ax = fig.add_subplot(111)
plt.title(('Total deaths graph for ' + country))
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['deaths'] = countryTimeData['deaths'].cumsum()
countryTimeData.plot(ax=ax, x='dateRep', y='deaths')
plt.show(block=True)
filePath = ('graphs/casesGraph_' + country + '_' + datetime.now().strftime('%Y-%m-%d'))
fig.savefig(filePath)
return filePath
else:
print('Unknown country')
return '-1'
def getDeathIncreaseGraph(self, country, start_date='2019-12-31', end_date=datetime.now().strftime('%Y-%m-%d')) -> 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
:param start_date: The start date of the graph
:param end_date: The end date of the graph
:return: The path for the picture of the graph
"""
if country in self.getAvailableCountries():
fig = plt.figure()
ax = fig.add_subplot(111)
plt.title(('Daily deaths graph for ' + country))
countryData = self.df[self.df['countriesAndTerritories'].isin([country])]
mask = (countryData['dateRep'] > start_date) & (countryData['dateRep'] <= end_date)
countryTimeData = countryData.loc[mask]
countryTimeData.plot(ax=ax, x='dateRep', y='deaths')
plt.show(block=True)
filePath = ('graphs/casesIncreaseGraph_' + country + '_' + datetime.now().strftime('%Y-%m-%d'))
fig.savefig(filePath)
return filePath
else:
print('Unknown country')
return '-1'

View File

@ -8,6 +8,7 @@ import sys
from datetime import datetime from datetime import datetime
from PyQt5.QtWidgets import * from PyQt5.QtWidgets import *
from PyQt5.QtGui import * from PyQt5.QtGui import *
from PyQt5.QtCore import QDate
import Analyser as ana import Analyser as ana
@ -24,7 +25,7 @@ class UserInterface(QWidget):
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 # 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(1300) self.setMinimumWidth(1500)
# Layout boxes # Layout boxes
self.header_box = QHBoxLayout() self.header_box = QHBoxLayout()
@ -67,6 +68,13 @@ class UserInterface(QWidget):
self.endDatePicker.setCurrentText(datetime.now().strftime('%Y-%m-%d')) self.endDatePicker.setCurrentText(datetime.now().strftime('%Y-%m-%d'))
picklistBox.addWidget(self.endDatePicker, 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'])
picklistBox.addWidget(self.graphTypePicker, 1)
# Calculate Button # Calculate Button
self.calculateSingleCountryStats = QPushButton('Calculate') self.calculateSingleCountryStats = QPushButton('Calculate')
buttonBox.addWidget(self.calculateSingleCountryStats) buttonBox.addWidget(self.calculateSingleCountryStats)
@ -99,23 +107,28 @@ class UserInterface(QWidget):
def btnstate(self): def btnstate(self):
if self.calculateSingleCountryStats.isChecked(): if self.calculateSingleCountryStats.isChecked():
# To reset the button # To reset the button
print('pressed')
self.calculateSingleCountryStats.toggle() self.calculateSingleCountryStats.toggle()
country = self.countryPicker.currentText() country = self.countryPicker.currentText()
startDate = self.startDatePicker.currentText() startDate = self.startDatePicker.currentText()
endDate = self.endDatePicker.currentText() endDate = self.endDatePicker.currentText()
casesGraphPath = self.analyser.getCasesGraph(country, startDate, endDate)
caseIncreaseGraphPath = self.analyser.getCaseIncreaseGraph(country, startDate, endDate)
self.casesNumber.setText( self.casesNumber.setText(
('<h4>Total case number in ' + country + ' as of ' + endDate + ': ' + str(self.analyser.getTotalCases(country, ('<h4>Total case number in ' + country + ' as of ' + endDate + ': ' + str(self.analyser.getTotalCases(country,
endDate))+'</h4>')) endDate))+'</h4>'))
self.casesGraphPlaceHolder = QLabel(self) casesGraphPath = self.analyser.getCasesGraph(country, startDate, endDate)
self.casesIncreasePlaceHolder = QLabel(self) caseIncreaseGraphPath = self.analyser.getCaseIncreaseGraph(country, startDate, endDate)
deathGraphPath = self.analyser.getDeathGraph(country, startDate, endDate)
deathIncreaseGraphPath = self.analyser.getDeathIncreaseGraph(country, startDate, endDate)
self.graphPlaceHolder = QLabel(self)
self.clearLayout(self.graphBox) self.clearLayout(self.graphBox)
self.graphBox.addWidget(self.casesGraphPlaceHolder) self.graphBox.addWidget(self.graphPlaceHolder)
self.graphBox.addWidget(self.casesIncreasePlaceHolder) if self.graphTypePicker.currentText() == 'Total Cases':
self.casesGraphPlaceHolder.setPixmap(QPixmap(casesGraphPath)) self.graphPlaceHolder.setPixmap(QPixmap(casesGraphPath))
self.casesIncreasePlaceHolder.setPixmap(QPixmap(caseIncreaseGraphPath)) elif self.graphTypePicker.currentText() == 'Case Increase':
self.graphPlaceHolder.setPixmap(QPixmap(caseIncreaseGraphPath))
elif self.graphTypePicker.currentText() == 'Total Deaths':
self.graphPlaceHolder.setPixmap(QPixmap(deathGraphPath))
elif self.graphTypePicker.currentText() == 'Death Increase':
self.graphPlaceHolder.setPixmap(QPixmap(deathIncreaseGraphPath))
def clearLayout(self, layout): def clearLayout(self, layout):
for i in reversed(range(layout.count())): for i in reversed(range(layout.count())):

File diff suppressed because it is too large Load Diff