2020-03-29 20:23:30 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
Project: Analyse worldwide COVID-19 Data and provide graphs etc.
|
|
|
|
|
|
|
|
@author Patrick Müller
|
|
|
|
"""
|
|
|
|
import sys
|
|
|
|
from datetime import datetime
|
|
|
|
from PyQt5.QtWidgets import *
|
|
|
|
from PyQt5.QtGui import *
|
2020-03-30 15:02:56 +00:00
|
|
|
from PyQt5.QtCore import QDate
|
2020-03-29 20:23:30 +00:00
|
|
|
import Analyser as ana
|
|
|
|
|
|
|
|
|
|
|
|
class UserInterface(QWidget):
|
|
|
|
def __init__(self, app):
|
|
|
|
super().__init__()
|
|
|
|
# Get Analyser instance and required stuff from it
|
|
|
|
self.analyser = ana.Analyser()
|
|
|
|
countries = self.analyser.getAvailableCountries()
|
|
|
|
dates = self.analyser.getAvailableDates()
|
|
|
|
|
|
|
|
# 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)
|
2020-03-30 15:02:56 +00:00
|
|
|
self.setMinimumWidth(1500)
|
2020-03-29 20:23:30 +00:00
|
|
|
|
|
|
|
# Layout boxes
|
|
|
|
self.header_box = QHBoxLayout()
|
|
|
|
h2box1 = QHBoxLayout()
|
|
|
|
labelBox = QHBoxLayout()
|
|
|
|
picklistBox = QHBoxLayout()
|
|
|
|
buttonBox = QHBoxLayout()
|
|
|
|
caseNumberBox = QHBoxLayout()
|
|
|
|
self.graphBox = QHBoxLayout()
|
|
|
|
|
|
|
|
# Heading
|
|
|
|
heading = QLabel('<h1>COVID-19 Analytics</h1>')
|
|
|
|
self.header_box.addWidget(heading)
|
|
|
|
|
|
|
|
# Sub-Header
|
|
|
|
subheader1 = QLabel('<h2>Statistics about one country</h2>')
|
|
|
|
h2box1.addWidget(subheader1)
|
|
|
|
|
|
|
|
# Country Picker
|
|
|
|
countryPickerLabel = QLabel('<h3>Pick a country:</h3>')
|
|
|
|
labelBox.addWidget(countryPickerLabel)
|
|
|
|
self.countryPicker = QComboBox(parent=self)
|
|
|
|
self.countryPicker.addItems(countries)
|
|
|
|
self.countryPicker.setCurrentText('Germany')
|
|
|
|
picklistBox.addWidget(self.countryPicker, 1)
|
|
|
|
|
|
|
|
# Start Date Picker
|
|
|
|
startDatePickerLabel = QLabel('<h3>Pick a start date:</h3>')
|
|
|
|
labelBox.addWidget(startDatePickerLabel)
|
|
|
|
self.startDatePicker = QComboBox(parent=self)
|
|
|
|
self.startDatePicker.addItems(dates)
|
|
|
|
self.startDatePicker.setCurrentText('2019-12-31')
|
|
|
|
picklistBox.addWidget(self.startDatePicker, 1)
|
|
|
|
|
|
|
|
# End Date Picker
|
|
|
|
endDatePickerLabel = QLabel('<h3>Pick an end date:</h3>')
|
|
|
|
labelBox.addWidget(endDatePickerLabel)
|
|
|
|
self.endDatePicker = QComboBox(parent=self)
|
|
|
|
self.endDatePicker.addItems(dates)
|
|
|
|
self.endDatePicker.setCurrentText(datetime.now().strftime('%Y-%m-%d'))
|
|
|
|
picklistBox.addWidget(self.endDatePicker, 1)
|
|
|
|
|
2020-03-30 15:02:56 +00:00
|
|
|
# Graph Type Picker
|
|
|
|
graphTypePickerLabel = QLabel('<h3>Pick a graph type:</h3>')
|
|
|
|
labelBox.addWidget(graphTypePickerLabel)
|
|
|
|
self.graphTypePicker = QComboBox(parent=self)
|
2020-03-30 15:36:59 +00:00
|
|
|
self.graphTypePicker.addItems(['Total Cases', 'Case Increase', 'Total Deaths', 'Death Increase', 'Death Rate'])
|
2020-03-30 15:02:56 +00:00
|
|
|
picklistBox.addWidget(self.graphTypePicker, 1)
|
|
|
|
|
2020-03-29 20:23:30 +00:00
|
|
|
# Calculate Button
|
|
|
|
self.calculateSingleCountryStats = QPushButton('Calculate')
|
|
|
|
buttonBox.addWidget(self.calculateSingleCountryStats)
|
|
|
|
self.calculateSingleCountryStats.setCheckable(True)
|
|
|
|
self.calculateSingleCountryStats.clicked.connect(self.btnstate)
|
|
|
|
|
|
|
|
# Total cases number
|
|
|
|
self.casesNumber = QLabel('<h4>Total Case Number: NaN</h4>')
|
|
|
|
caseNumberBox.addWidget(self.casesNumber)
|
|
|
|
|
|
|
|
# Generate Layout
|
|
|
|
layout = QVBoxLayout()
|
|
|
|
layout.addLayout(self.header_box)
|
|
|
|
layout.addSpacing(50)
|
|
|
|
layout.addLayout(h2box1)
|
|
|
|
layout.addSpacing(10)
|
|
|
|
layout.addLayout(labelBox)
|
|
|
|
layout.addLayout(picklistBox)
|
|
|
|
layout.addSpacing(10)
|
|
|
|
layout.addLayout(buttonBox)
|
|
|
|
layout.addSpacing(10)
|
|
|
|
layout.addLayout(caseNumberBox)
|
|
|
|
layout.addSpacing(10)
|
|
|
|
layout.addLayout(self.graphBox)
|
|
|
|
layout.addStretch(1)
|
|
|
|
|
|
|
|
self.setLayout(layout)
|
|
|
|
self.show()
|
|
|
|
|
|
|
|
def btnstate(self):
|
|
|
|
if self.calculateSingleCountryStats.isChecked():
|
|
|
|
# To reset the button
|
|
|
|
self.calculateSingleCountryStats.toggle()
|
|
|
|
country = self.countryPicker.currentText()
|
|
|
|
startDate = self.startDatePicker.currentText()
|
|
|
|
endDate = self.endDatePicker.currentText()
|
|
|
|
self.casesNumber.setText(
|
|
|
|
('<h4>Total case number in ' + country + ' as of ' + endDate + ': ' + str(self.analyser.getTotalCases(country,
|
|
|
|
endDate))+'</h4>'))
|
2020-03-30 15:02:56 +00:00
|
|
|
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)
|
2020-03-30 15:36:59 +00:00
|
|
|
deathRateGraphPath = self.analyser.getDailyDeathRateGraph(country, startDate, endDate)
|
2020-03-30 15:02:56 +00:00
|
|
|
self.graphPlaceHolder = QLabel(self)
|
2020-03-29 20:23:30 +00:00
|
|
|
self.clearLayout(self.graphBox)
|
2020-03-30 15:02:56 +00:00
|
|
|
self.graphBox.addWidget(self.graphPlaceHolder)
|
2020-03-30 15:36:59 +00:00
|
|
|
|
2020-03-30 15:02:56 +00:00
|
|
|
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))
|
2020-03-30 15:36:59 +00:00
|
|
|
elif self.graphTypePicker.currentText() == 'Death Rate':
|
|
|
|
self.graphPlaceHolder.setPixmap(QPixmap(deathRateGraphPath))
|
2020-03-29 20:23:30 +00:00
|
|
|
|
|
|
|
def clearLayout(self, layout):
|
|
|
|
for i in reversed(range(layout.count())):
|
|
|
|
widgetToRemove = layout.itemAt(i).widget()
|
|
|
|
# remove it from the layout list
|
|
|
|
layout.removeWidget(widgetToRemove)
|
|
|
|
# remove it from the gui
|
|
|
|
widgetToRemove.setParent(None)
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
app = QApplication(sys.argv)
|
|
|
|
ex = UserInterface(app)
|
|
|
|
sys.exit(app.exec_())
|