Doses VS. Vaccines

This commit is contained in:
Gabriele De Rosa 2021-02-02 17:52:09 +01:00
parent 91aab39b5f
commit 91e516258b
2 changed files with 36 additions and 18 deletions

35
bot.py
View File

@ -81,32 +81,39 @@ def download():
df.sort_values('data_somministrazione')
# Delete sum data if already exists
df = df[df["area"] != "ITA"]
# Set target counter to numeric
# Set target counters to numeric
df["totale"] = pd.to_numeric(df["totale"])
df["seconda_dose"] = pd.to_numeric(df["seconda_dose"])
# Group by day and sum counters
df = df.groupby(['data_somministrazione'])['totale'].sum().reset_index()
df_doses = df.groupby(['data_somministrazione'])['totale'].sum().reset_index()
df_vaccines = df.groupby(['data_somministrazione'])['seconda_dose'].sum().reset_index()
# Re-set date as ID in new dataframe
df = df.set_index('data_somministrazione')
df_doses = df_doses.set_index('data_somministrazione')
df_vaccines = df_vaccines.set_index('data_somministrazione')
# If there are current day data...
if dt.now() - df.index[-1] < td(days=1):
df = df[:-1] # Ignore the current day because it's often incomplete
if dt.now() - df_doses.index[-1] < td(days=1):
df_doses = df_doses[:-1] # Ignore the current day because it's often incomplete
if dt.now() - df_vaccines.index[-1] < td(days=1):
df_vaccines = df_vaccines[:-1] # Ignore the current day because it's often incomplete
totalVaccines = sum(df["totale"])
lastWeekData = df.loc[df.index > df.index[-1] - td(days=7)]
vaccinesPerDayAverage = sum(lastWeekData["totale"]) / 7
totalDoses = sum(df_doses["totale"])
totalVaccines = sum(df_vaccines["seconda_dose"])
lastWeekData = df_vaccines.loc[df_vaccines.index > df_vaccines.index[-1] - td(days=7)]
vaccinesPerDayAverage = sum(lastWeekData["seconda_dose"]) / 7
remainingDays = (HIT - totalVaccines) / vaccinesPerDayAverage
hitDate = df.index[-1] + td(days=remainingDays)
hitDate = df_vaccines.index[-1] + td(days=remainingDays)
# Generate plot
plt.ylabel("Vaccini al giorno")
plt.ylabel("Vaccinati al giorno")
plt.xlabel("Ultima settimana")
plt.grid(True)
plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d'))
plt.gca().xaxis.set_major_locator(mdates.AutoDateLocator())
plt.gcf().autofmt_xdate()
plt.bar(lastWeekData.index, height=lastWeekData["totale"])
plt.bar(lastWeekData.index, height=lastWeekData["seconda_dose"])
# Trendline
z = np.polyfit(range(0, 7), lastWeekData["totale"], 2)
z = np.polyfit(range(0, 7), lastWeekData["seconda_dose"], 2)
p = np.poly1d(z)
plt.plot(lastWeekData.index, p(range(0, 7)), "r--")
# Secret 4 filenames
@ -123,7 +130,9 @@ def download():
with open('template.html', 'r+') as f:
with open('out/' + webpage_filename, 'w+') as wf:
for line in f.read().splitlines():
if "<!-- totalVaccinations -->" in line:
if "<!-- totalDoses -->" in line:
line = f"{totalDoses}"
elif "<!-- totalVaccinations -->" in line:
line = f"{totalVaccines}"
elif "<!-- totalVaccinationsPerc -->" in line:
line = f"{str(round(totalVaccines / ITALIAN_POPULATION * 100, 2)).replace('.', ',')}%"

View File

@ -40,12 +40,17 @@
La campagna vaccinale in Italia è iniziata da poco e chiaramente non è ancora a regime. Le stime qui effettuate
saranno via via più affidabili con l'aumentare dei dati. <br />
</p>
<hr>
<div class="text-center">
In Italia ci sono <br />
In Italia sono state somministrate <br />
<span class="text-big">
<!-- totalDoses -->
dosi di vaccino</span> <br />
che corrispondono a <br />
<span class="text-big">
<!-- totalVaccinations -->
persone vaccinate</span> <br />
che corrispondono al <br />
persone vaccinate,</span> <br />
ovvero il <br />
<span class="text-big">
<!-- totalVaccinationsPerc -->
della popolazione.
@ -57,7 +62,7 @@
con un ritmo di <br />
<span class="text-big">
<!-- vaccinesPerDay -->
vaccini al giorno.</span> <br />
vaccinati al giorno.</span> <br />
Continuando di questo passo, raggiungeremo l'immunità di gregge il <br />
<span class="text-bigger">
<!-- hitDate -->
@ -71,10 +76,14 @@
giorni.
</span>
</div>
<img alt="Grafico vaccini ultima settimana" src="plot.png" class="img-fluid">
<img alt="Grafico vaccinati ultima settimana" src="plot.png" class="img-fluid">
<p class="pt-2">
I dati non comprendono quelli del giorno attuale perché solitamente incompleti.
</p>
<p class="pt-2">
Dal 2 febbraio 2021 il grafico mostra i dati delle persone vaccinate,
ovvero di chi ha ricevuto entrambe le dosi necessarie per completare il vaccino.
</p>
</div>
</body>
</html>