✨ Added logarhytmic graph that shows if the exponential growth has stopped
This commit is contained in:
parent
bd0bf56a1a
commit
fd15b2bf87
40
Analyser.py
40
Analyser.py
|
@ -8,6 +8,7 @@ import numpy as np
|
|||
import pandas as pd
|
||||
import matplotlib.pyplot as plt
|
||||
import tkinter as tk
|
||||
import random
|
||||
|
||||
"""
|
||||
Fields in csv:
|
||||
|
@ -57,6 +58,7 @@ class Analyser:
|
|||
"""
|
||||
if country in self.getAvailableCountries():
|
||||
fig = plt.figure()
|
||||
fig.dpi = 200.0
|
||||
ax = fig.add_subplot(111)
|
||||
plt.title(('Total cases in ' + country))
|
||||
|
||||
|
@ -90,6 +92,7 @@ class Analyser:
|
|||
"""
|
||||
if country in self.getAvailableCountries():
|
||||
fig = plt.figure()
|
||||
fig.dpi = 200.0
|
||||
ax = fig.add_subplot(111)
|
||||
plt.title(('Daily new cases in ' + country))
|
||||
|
||||
|
@ -133,6 +136,7 @@ class Analyser:
|
|||
"""
|
||||
if country in self.getAvailableCountries():
|
||||
fig = plt.figure()
|
||||
fig.dpi = 200.0
|
||||
ax = fig.add_subplot(111)
|
||||
plt.title(('Total deaths in ' + country))
|
||||
|
||||
|
@ -166,6 +170,7 @@ class Analyser:
|
|||
"""
|
||||
if country in self.getAvailableCountries():
|
||||
fig = plt.figure()
|
||||
fig.dpi = 200.0
|
||||
ax = fig.add_subplot(111)
|
||||
plt.title(('Daily new deaths in ' + country))
|
||||
|
||||
|
@ -209,6 +214,7 @@ class Analyser:
|
|||
"""
|
||||
if country in self.getAvailableCountries():
|
||||
fig = plt.figure()
|
||||
fig.dpi = 200.0
|
||||
ax = fig.add_subplot(111)
|
||||
plt.title(('Daily death rate in ' + country) + ' in %')
|
||||
|
||||
|
@ -245,17 +251,31 @@ class Analyser:
|
|||
countryTimeData = countryData.loc[mask]
|
||||
return (countryTimeData['deaths'].sum()/countryTimeData['cases'].sum()*100)
|
||||
|
||||
def testGraph(self, country, start_date='2019-12-31', end_date=datetime.now().strftime('%Y-%m-%d'), showPlot=False) -> str:
|
||||
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['totalCases'] = countryTimeData['cases'].cumsum()
|
||||
countryTimeData['totalDeaths'] = countryTimeData['deaths'].cumsum()
|
||||
countryTimeData['deathRate'] = countryTimeData['totalDeaths'] / countryTimeData['totalCases'] * 100
|
||||
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?')
|
||||
ax.set_ylabel('Case Increase')
|
||||
ax.set_xlabel('Total Cases')
|
||||
for index, country in enumerate([country, 'China', 'South_Korea'], start=1):
|
||||
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['totalCases'] = countryTimeData['cases'].cumsum()
|
||||
countryTimeData[country] = countryTimeData['cases'].rolling(7).mean()
|
||||
|
||||
countryTimeData.plot.scatter(x='totalCases', y='cases', c='deaths')
|
||||
try:
|
||||
countryTimeData.plot(ax=ax, x='totalCases', y=country, loglog=True)
|
||||
except:
|
||||
print('Error occured')
|
||||
|
||||
if showPlot:
|
||||
plt.show(block=True)
|
||||
plt.close()
|
||||
filePath = ('graphs/isItOverGraph_' + countryString + '_' + datetime.now().strftime('%Y-%m-%d'))
|
||||
fig.savefig(filePath)
|
||||
plt.close()
|
||||
|
||||
return filePath
|
||||
|
|
2
Main.py
2
Main.py
|
@ -10,5 +10,5 @@ import UserInterface as UI
|
|||
|
||||
if __name__ == '__main__':
|
||||
fetcher.updateStatsFile()
|
||||
ana.Analyser().testGraph('Germany', showPlot=True)
|
||||
#ana.Analyser().getIsItOverGraph('Germany', showPlot=True)
|
||||
UI.main()
|
||||
|
|
|
@ -47,9 +47,13 @@ class UserInterface(QWidget):
|
|||
# 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')
|
||||
# self.countryPicker = QComboBox(parent=self)
|
||||
# self.countryPicker.addItems(countries)
|
||||
# self.countryPicker.setCurrentText('Germany')
|
||||
# picklistBox.addWidget(self.countryPicker, 1)
|
||||
self.countryPicker = QLineEdit()
|
||||
self.countryPicker.setCompleter(QCompleter(countries))
|
||||
self.countryPicker.setText('Germany')
|
||||
picklistBox.addWidget(self.countryPicker, 1)
|
||||
|
||||
# Start Date Picker
|
||||
|
@ -72,7 +76,8 @@ class UserInterface(QWidget):
|
|||
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', 'Total Deaths', 'Death Increase', 'Death Rate',
|
||||
'Is it going to end soon?'])
|
||||
picklistBox.addWidget(self.graphTypePicker, 1)
|
||||
|
||||
# Calculate Button
|
||||
|
@ -108,13 +113,18 @@ class UserInterface(QWidget):
|
|||
if self.calculateSingleCountryStats.isChecked():
|
||||
# To reset the button
|
||||
self.calculateSingleCountryStats.toggle()
|
||||
country = self.countryPicker.currentText()
|
||||
if self.countryPicker.text() in self.analyser.getAvailableCountries():
|
||||
country = self.countryPicker.text()
|
||||
else:
|
||||
self.casesNumber.setText(('<h4>Unknown country <font color="red">' + self.countryPicker.text() + ''
|
||||
+ '</font>. Please try again with the given options</h4>'))
|
||||
return
|
||||
startDate = self.startDatePicker.currentText()
|
||||
endDate = self.endDatePicker.currentText()
|
||||
self.casesNumber.setText(
|
||||
('<h4>Statistics for ' + country
|
||||
+ ' as of ' + endDate + ': <font color="red">Total Cases:</font> '
|
||||
+ str(self.analyser.getTotalCases(country,endDate))
|
||||
('<h4>Statistics for <font color="red">' + country
|
||||
+ '</font> as of ' + endDate + ': <font color="red">Total Cases:</font> '
|
||||
+ str(self.analyser.getTotalCases(country, endDate))
|
||||
+ ', <font color="red">Total Deaths:</font> ' + str(self.analyser.getTotalDeaths(country, endDate))
|
||||
+ ', <font color="red">Death Rate:</font> ' + str(self.analyser.getDeathRate(country, endDate))[:4]
|
||||
+ '%</h4>'))
|
||||
|
@ -123,6 +133,7 @@ class UserInterface(QWidget):
|
|||
deathGraphPath = self.analyser.getDeathGraph(country, startDate, endDate)
|
||||
deathIncreaseGraphPath = self.analyser.getDeathIncreaseGraph(country, startDate, endDate)
|
||||
deathRateGraphPath = self.analyser.getDailyDeathRateGraph(country, startDate, endDate)
|
||||
isItOverGraph = self.analyser.getIsItOverGraph(country, startDate, endDate)
|
||||
self.graphPlaceHolder = QLabel(self)
|
||||
self.clearLayout(self.graphBox)
|
||||
self.graphBox.addWidget(self.graphPlaceHolder)
|
||||
|
@ -137,6 +148,8 @@ class UserInterface(QWidget):
|
|||
self.graphPlaceHolder.setPixmap(QPixmap(deathIncreaseGraphPath))
|
||||
elif self.graphTypePicker.currentText() == 'Death Rate':
|
||||
self.graphPlaceHolder.setPixmap(QPixmap(deathRateGraphPath))
|
||||
elif self.graphTypePicker.currentText() == 'Is it going to end soon?':
|
||||
self.graphPlaceHolder.setPixmap(QPixmap(isItOverGraph))
|
||||
|
||||
def clearLayout(self, layout):
|
||||
for i in reversed(range(layout.count())):
|
||||
|
|
Loading…
Reference in New Issue
Block a user