🐛 FIXED: Highlighting didnt work properly
This commit is contained in:
parent
75fae905bf
commit
1b8cabb2b5
44
Analyser.py
44
Analyser.py
|
@ -62,7 +62,7 @@ class Analyser:
|
||||||
return retList
|
return retList
|
||||||
|
|
||||||
def getCasesGraph(self, country, start_date='2019-12-31', end_date=datetime.now().strftime('%Y-%m-%d'),
|
def getCasesGraph(self, country, start_date='2019-12-31', end_date=datetime.now().strftime('%Y-%m-%d'),
|
||||||
showPlot=False) -> str:
|
plotDpi=200.0, showPlot=False) -> str:
|
||||||
"""
|
"""
|
||||||
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
|
||||||
|
@ -73,7 +73,7 @@ class Analyser:
|
||||||
"""
|
"""
|
||||||
if country in self.getAvailableCountries():
|
if country in self.getAvailableCountries():
|
||||||
fig = plt.figure()
|
fig = plt.figure()
|
||||||
fig.dpi = 200.0
|
fig.dpi = plotDpi
|
||||||
ax = fig.add_subplot(111)
|
ax = fig.add_subplot(111)
|
||||||
plt.title(('Total cases in ' + country))
|
plt.title(('Total cases in ' + country))
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ class Analyser:
|
||||||
return '-1'
|
return '-1'
|
||||||
|
|
||||||
def getCaseIncreaseGraph(self, country, start_date='2019-12-31', end_date=datetime.now().strftime('%Y-%m-%d'),
|
def getCaseIncreaseGraph(self, country, start_date='2019-12-31', end_date=datetime.now().strftime('%Y-%m-%d'),
|
||||||
showPlot=False) -> str:
|
plotDpi=200.0, showPlot=False) -> str:
|
||||||
"""
|
"""
|
||||||
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
|
||||||
|
@ -109,7 +109,7 @@ class Analyser:
|
||||||
"""
|
"""
|
||||||
if country in self.getAvailableCountries():
|
if country in self.getAvailableCountries():
|
||||||
fig = plt.figure()
|
fig = plt.figure()
|
||||||
fig.dpi = 200.0
|
fig.dpi = plotDpi
|
||||||
ax = fig.add_subplot(111)
|
ax = fig.add_subplot(111)
|
||||||
plt.title(('Daily new cases in ' + country))
|
plt.title(('Daily new cases in ' + country))
|
||||||
|
|
||||||
|
@ -146,7 +146,7 @@ class Analyser:
|
||||||
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'),
|
def getDeathGraph(self, country, start_date='2019-12-31', end_date=datetime.now().strftime('%Y-%m-%d'),
|
||||||
showPlot=False) -> str:
|
plotDpi=200.0, showPlot=False) -> str:
|
||||||
"""
|
"""
|
||||||
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
|
||||||
|
@ -157,7 +157,7 @@ class Analyser:
|
||||||
"""
|
"""
|
||||||
if country in self.getAvailableCountries():
|
if country in self.getAvailableCountries():
|
||||||
fig = plt.figure()
|
fig = plt.figure()
|
||||||
fig.dpi = 200.0
|
fig.dpi = plotDpi
|
||||||
ax = fig.add_subplot(111)
|
ax = fig.add_subplot(111)
|
||||||
plt.title(('Total deaths in ' + country))
|
plt.title(('Total deaths in ' + country))
|
||||||
|
|
||||||
|
@ -182,7 +182,7 @@ class Analyser:
|
||||||
return '-1'
|
return '-1'
|
||||||
|
|
||||||
def getDeathIncreaseGraph(self, country, start_date='2019-12-31', end_date=datetime.now().strftime('%Y-%m-%d'),
|
def getDeathIncreaseGraph(self, country, start_date='2019-12-31', end_date=datetime.now().strftime('%Y-%m-%d'),
|
||||||
showPlot=False) -> str:
|
plotDpi=200.0, showPlot=False) -> str:
|
||||||
"""
|
"""
|
||||||
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
|
||||||
|
@ -193,7 +193,7 @@ class Analyser:
|
||||||
"""
|
"""
|
||||||
if country in self.getAvailableCountries():
|
if country in self.getAvailableCountries():
|
||||||
fig = plt.figure()
|
fig = plt.figure()
|
||||||
fig.dpi = 200.0
|
fig.dpi = plotDpi
|
||||||
ax = fig.add_subplot(111)
|
ax = fig.add_subplot(111)
|
||||||
plt.title(('Daily new deaths in ' + country))
|
plt.title(('Daily new deaths in ' + country))
|
||||||
|
|
||||||
|
@ -230,7 +230,7 @@ class Analyser:
|
||||||
return countryTimeData['deaths'].sum()
|
return countryTimeData['deaths'].sum()
|
||||||
|
|
||||||
def getDailyDeathRateGraph(self, country, start_date='2019-12-31', end_date=datetime.now().strftime('%Y-%m-%d'),
|
def getDailyDeathRateGraph(self, country, start_date='2019-12-31', end_date=datetime.now().strftime('%Y-%m-%d'),
|
||||||
showPlot=False) -> str:
|
plotDpi=200.0, showPlot=False) -> str:
|
||||||
"""
|
"""
|
||||||
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
|
||||||
|
@ -241,7 +241,7 @@ class Analyser:
|
||||||
"""
|
"""
|
||||||
if country in self.getAvailableCountries():
|
if country in self.getAvailableCountries():
|
||||||
fig = plt.figure()
|
fig = plt.figure()
|
||||||
fig.dpi = 200.0
|
fig.dpi = plotDpi
|
||||||
ax = fig.add_subplot(111)
|
ax = fig.add_subplot(111)
|
||||||
plt.title(('Daily death rate in ' + country) + ' in %')
|
plt.title(('Daily death rate in ' + country) + ' in %')
|
||||||
|
|
||||||
|
@ -277,7 +277,7 @@ class Analyser:
|
||||||
countryTimeData = countryData.loc[mask]
|
countryTimeData = countryData.loc[mask]
|
||||||
return (countryTimeData['deaths'].sum() / countryTimeData['cases'].sum() * 100)
|
return (countryTimeData['deaths'].sum() / countryTimeData['cases'].sum() * 100)
|
||||||
|
|
||||||
def getIsItOverGraph(self, country, showPlot=False) -> str:
|
def getIsItOverGraph(self, country, plotDpi=200.0, showPlot=False) -> str:
|
||||||
"""
|
"""
|
||||||
Get a logarhytmic graph that shows easily if the exponential growth has stopped.
|
Get a logarhytmic graph that shows easily if the exponential growth has stopped.
|
||||||
:param country: The country to be compared. TODO: Change to a list of countries
|
:param country: The country to be compared. TODO: Change to a list of countries
|
||||||
|
@ -286,7 +286,7 @@ class Analyser:
|
||||||
"""
|
"""
|
||||||
countryString = country
|
countryString = country
|
||||||
fig = plt.figure()
|
fig = plt.figure()
|
||||||
fig.dpi = 200.0
|
fig.dpi = plotDpi
|
||||||
ax = fig.add_subplot(111)
|
ax = fig.add_subplot(111)
|
||||||
plt.title('Is it going to end soon in ' + countryString + '?')
|
plt.title('Is it going to end soon in ' + countryString + '?')
|
||||||
ax.set_ylabel('Case Increase')
|
ax.set_ylabel('Case Increase')
|
||||||
|
@ -310,9 +310,9 @@ class Analyser:
|
||||||
return filePath
|
return filePath
|
||||||
|
|
||||||
def getIncreasePercentageGraph(self, country, start_date='2019-12-31', end_date=datetime.now().strftime('%Y-%m-%d'),
|
def getIncreasePercentageGraph(self, country, start_date='2019-12-31', end_date=datetime.now().strftime('%Y-%m-%d'),
|
||||||
showPlot=False) -> str:
|
plotDpi=200.0, showPlot=False) -> str:
|
||||||
fig = plt.figure()
|
fig = plt.figure()
|
||||||
fig.dpi = 200.0
|
fig.dpi = plotDpi
|
||||||
ax = fig.add_subplot(111)
|
ax = fig.add_subplot(111)
|
||||||
plt.title('Daily Percentage of Case Increase in ' + country)
|
plt.title('Daily Percentage of Case Increase in ' + country)
|
||||||
|
|
||||||
|
@ -334,9 +334,9 @@ class Analyser:
|
||||||
|
|
||||||
return filePath
|
return filePath
|
||||||
|
|
||||||
def getCasesPerMillionGraph(self, country, showPlot=False) -> str:
|
def getCasesPerMillionGraph(self, country, plotDpi=200.0, showPlot=False) -> str:
|
||||||
fig = plt.figure()
|
fig = plt.figure()
|
||||||
fig.dpi = 200.0
|
fig.dpi = plotDpi
|
||||||
ax = fig.add_subplot(111)
|
ax = fig.add_subplot(111)
|
||||||
plt.title('Cases per Million Citizens in ' + country + ' compared to top 20')
|
plt.title('Cases per Million Citizens in ' + country + ' compared to top 20')
|
||||||
|
|
||||||
|
@ -351,12 +351,14 @@ class Analyser:
|
||||||
if country not in largestData['countriesAndTerritories'].unique():
|
if country not in largestData['countriesAndTerritories'].unique():
|
||||||
largestData = largestData.append(timeData.loc[timeData['countriesAndTerritories'] == country])
|
largestData = largestData.append(timeData.loc[timeData['countriesAndTerritories'] == country])
|
||||||
|
|
||||||
|
largestData = largestData.reset_index()
|
||||||
largestData.plot.bar(ax=ax, x="countriesAndTerritories", y="casesPerMillion")
|
largestData.plot.bar(ax=ax, x="countriesAndTerritories", y="casesPerMillion")
|
||||||
|
|
||||||
# Highlight the selected country
|
# Highlight the selected country
|
||||||
for ticks in ax.xaxis.get_major_ticks():
|
for ticks in ax.xaxis.get_major_ticks():
|
||||||
if ticks.label1.get_text() == country:
|
if ticks.label1.get_text() == country:
|
||||||
ax.patches[largestData.index.get_indexer([ticks.label1.get_text])[0]].set_facecolor('r')
|
index = largestData.index[largestData['countriesAndTerritories'] == country]
|
||||||
|
ax.patches[int(index.values[0])].set_facecolor('r')
|
||||||
|
|
||||||
if showPlot:
|
if showPlot:
|
||||||
plt.show(block=True)
|
plt.show(block=True)
|
||||||
|
@ -366,9 +368,9 @@ class Analyser:
|
||||||
|
|
||||||
return filePath
|
return filePath
|
||||||
|
|
||||||
def getDeathsPerMillionGraph(self, country, showPlot=False) -> str:
|
def getDeathsPerMillionGraph(self, country, plotDpi=200.0, showPlot=False) -> str:
|
||||||
fig = plt.figure()
|
fig = plt.figure()
|
||||||
fig.dpi = 200.0
|
fig.dpi = plotDpi
|
||||||
ax = fig.add_subplot(111)
|
ax = fig.add_subplot(111)
|
||||||
plt.title('Deaths per Million Citizens in ' + country + ' compared to top 20')
|
plt.title('Deaths per Million Citizens in ' + country + ' compared to top 20')
|
||||||
|
|
||||||
|
@ -383,12 +385,14 @@ class Analyser:
|
||||||
if country not in largestData['countriesAndTerritories'].unique():
|
if country not in largestData['countriesAndTerritories'].unique():
|
||||||
largestData = largestData.append(timeData.loc[timeData['countriesAndTerritories'] == country])
|
largestData = largestData.append(timeData.loc[timeData['countriesAndTerritories'] == country])
|
||||||
|
|
||||||
|
largestData = largestData.reset_index()
|
||||||
largestData.plot.bar(ax=ax, x="countriesAndTerritories", y="deathsPerMillion")
|
largestData.plot.bar(ax=ax, x="countriesAndTerritories", y="deathsPerMillion")
|
||||||
|
|
||||||
# Highlight the selected country
|
# Highlight the selected country
|
||||||
for ticks in ax.xaxis.get_major_ticks():
|
for ticks in ax.xaxis.get_major_ticks():
|
||||||
if ticks.label1.get_text() == country:
|
if ticks.label1.get_text() == country:
|
||||||
ax.patches[largestData.index.get_indexer([ticks.label1.get_text])[0]].set_facecolor('r')
|
index = largestData.index[largestData['countriesAndTerritories'] == country]
|
||||||
|
ax.patches[int(index.values[0])].set_facecolor('r')
|
||||||
|
|
||||||
if showPlot:
|
if showPlot:
|
||||||
plt.show(block=True)
|
plt.show(block=True)
|
||||||
|
|
209
statsfile.csv
209
statsfile.csv
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user