Added direct access to total death count and death rate by date

This commit is contained in:
Patrick Müller 2020-03-30 19:57:40 +02:00
parent 64d2950d59
commit 334f71e1b7
3 changed files with 46 additions and 4 deletions

View File

@ -106,7 +106,7 @@ class Analyser:
def getTotalCases(self, country, date=datetime.now().strftime('%Y-%m-%d')) -> int:
"""
Get the current total cases for the entered country
Get the total cases for the entered country and date
:param country: The country you want the case number for. Access available countries via getAvailableCountries()
:param date: The date for which the case number is returned. Standard is the current date. Format YYYY-MM-DD
:return: The case number
@ -174,6 +174,18 @@ class Analyser:
print('Unknown country')
return '-1'
def getTotalDeaths(self, country, date=datetime.now().strftime('%Y-%m-%d')) -> int:
"""
Get the total deaths for the entered country and date
:param country: The country you want the case number for. Access available countries via getAvailableCountries()
:param date: The date for which the case number is returned. Standard is the current date. Format YYYY-MM-DD
:return: The case number
"""
countryData = self.df[self.df['countriesAndTerritories'].isin([country])]
mask = (countryData['dateRep'] <= date)
countryTimeData = countryData.loc[mask]
return countryTimeData['deaths'].sum()
def getDailyDeathRateGraph(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
@ -204,4 +216,29 @@ class Analyser:
return filePath
else:
print('Unknown country')
return '-1'
return '-1'
def getDeathRate(self, country, date=datetime.now().strftime('%Y-%m-%d')) -> int:
"""
Get the death rate for the entered country and date
:param country: The country you want the case number for. Access available countries via getAvailableCountries()
:param date: The date for which the case number is returned. Standard is the current date. Format YYYY-MM-DD
:return: The case number
"""
countryData = self.df[self.df['countriesAndTerritories'].isin([country])]
mask = (countryData['dateRep'] <= date)
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')) -> 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
countryTimeData.plot.scatter(x='totalCases', y='cases', c='deaths')
plt.show(block=True)

View File

@ -10,4 +10,5 @@ import UserInterface as UI
if __name__ == '__main__':
fetcher.updateStatsFile()
ana.Analyser().testGraph('Germany')
UI.main()

View File

@ -112,8 +112,12 @@ class UserInterface(QWidget):
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>'))
('<h4>Statistics for ' + country
+ ' 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>'))
casesGraphPath = self.analyser.getCasesGraph(country, startDate, endDate)
caseIncreaseGraphPath = self.analyser.getCaseIncreaseGraph(country, startDate, endDate)
deathGraphPath = self.analyser.getDeathGraph(country, startDate, endDate)