✨ Added Death Graphs
This commit is contained in:
parent
6646e0bbe6
commit
2f2e164e40
64
Analyser.py
64
Analyser.py
|
@ -49,6 +49,8 @@ class Analyser:
|
|||
"""
|
||||
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():
|
||||
|
@ -77,12 +79,14 @@ class Analyser:
|
|||
"""
|
||||
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(('Cases increase graph for ' + country))
|
||||
plt.title(('Daily case increase graph for ' + country))
|
||||
|
||||
countryData = self.df[self.df['countriesAndTerritories'].isin([country])]
|
||||
mask = (countryData['dateRep'] > start_date) & (countryData['dateRep'] <= end_date)
|
||||
|
@ -110,3 +114,61 @@ class Analyser:
|
|||
mask = (countryData['dateRep'] <= date)
|
||||
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')) -> 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'
|
|
@ -8,6 +8,7 @@ import sys
|
|||
from datetime import datetime
|
||||
from PyQt5.QtWidgets import *
|
||||
from PyQt5.QtGui import *
|
||||
from PyQt5.QtCore import QDate
|
||||
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 = 3840, 2160
|
||||
self.setGeometry(((screen_width / 2) - 750), ((screen_height / 2) - 375), 1500, 750)
|
||||
self.setMinimumWidth(1300)
|
||||
self.setMinimumWidth(1500)
|
||||
|
||||
# Layout boxes
|
||||
self.header_box = QHBoxLayout()
|
||||
|
@ -67,6 +68,13 @@ class UserInterface(QWidget):
|
|||
self.endDatePicker.setCurrentText(datetime.now().strftime('%Y-%m-%d'))
|
||||
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
|
||||
self.calculateSingleCountryStats = QPushButton('Calculate')
|
||||
buttonBox.addWidget(self.calculateSingleCountryStats)
|
||||
|
@ -99,23 +107,28 @@ class UserInterface(QWidget):
|
|||
def btnstate(self):
|
||||
if self.calculateSingleCountryStats.isChecked():
|
||||
# To reset the button
|
||||
print('pressed')
|
||||
self.calculateSingleCountryStats.toggle()
|
||||
country = self.countryPicker.currentText()
|
||||
startDate = self.startDatePicker.currentText()
|
||||
endDate = self.endDatePicker.currentText()
|
||||
casesGraphPath = self.analyser.getCasesGraph(country, startDate, endDate)
|
||||
caseIncreaseGraphPath = self.analyser.getCaseIncreaseGraph(country, startDate, endDate)
|
||||
self.casesNumber.setText(
|
||||
('<h4>Total case number in ' + country + ' as of ' + endDate + ': ' + str(self.analyser.getTotalCases(country,
|
||||
endDate))+'</h4>'))
|
||||
self.casesGraphPlaceHolder = QLabel(self)
|
||||
self.casesIncreasePlaceHolder = QLabel(self)
|
||||
casesGraphPath = self.analyser.getCasesGraph(country, startDate, endDate)
|
||||
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.graphBox.addWidget(self.casesGraphPlaceHolder)
|
||||
self.graphBox.addWidget(self.casesIncreasePlaceHolder)
|
||||
self.casesGraphPlaceHolder.setPixmap(QPixmap(casesGraphPath))
|
||||
self.casesIncreasePlaceHolder.setPixmap(QPixmap(caseIncreaseGraphPath))
|
||||
self.graphBox.addWidget(self.graphPlaceHolder)
|
||||
if self.graphTypePicker.currentText() == 'Total Cases':
|
||||
self.graphPlaceHolder.setPixmap(QPixmap(casesGraphPath))
|
||||
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):
|
||||
for i in reversed(range(layout.count())):
|
||||
|
|
223
statsfile.csv
223
statsfile.csv
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user