Compare commits
2 Commits
91aab39b5f
...
ec4c5d9f39
Author | SHA1 | Date |
---|---|---|
Gabriele De Rosa | ec4c5d9f39 | |
Gabriele De Rosa | 91e516258b |
35
bot.py
35
bot.py
|
@ -81,32 +81,39 @@ def download():
|
||||||
df.sort_values('data_somministrazione')
|
df.sort_values('data_somministrazione')
|
||||||
# Delete sum data if already exists
|
# Delete sum data if already exists
|
||||||
df = df[df["area"] != "ITA"]
|
df = df[df["area"] != "ITA"]
|
||||||
# Set target counter to numeric
|
# Set target counters to numeric
|
||||||
df["totale"] = pd.to_numeric(df["totale"])
|
df["totale"] = pd.to_numeric(df["totale"])
|
||||||
|
df["seconda_dose"] = pd.to_numeric(df["seconda_dose"])
|
||||||
# Group by day and sum counters
|
# 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
|
# 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 there are current day data...
|
||||||
if dt.now() - df.index[-1] < td(days=1):
|
if dt.now() - df_doses.index[-1] < td(days=1):
|
||||||
df = df[:-1] # Ignore the current day because it's often incomplete
|
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"])
|
totalDoses = sum(df_doses["totale"])
|
||||||
lastWeekData = df.loc[df.index > df.index[-1] - td(days=7)]
|
totalVaccines = sum(df_vaccines["seconda_dose"])
|
||||||
vaccinesPerDayAverage = sum(lastWeekData["totale"]) / 7
|
lastWeekData = df_vaccines.loc[df_vaccines.index > df_vaccines.index[-1] - td(days=7)]
|
||||||
|
vaccinesPerDayAverage = sum(lastWeekData["seconda_dose"]) / 7
|
||||||
remainingDays = (HIT - totalVaccines) / vaccinesPerDayAverage
|
remainingDays = (HIT - totalVaccines) / vaccinesPerDayAverage
|
||||||
hitDate = df.index[-1] + td(days=remainingDays)
|
hitDate = df_vaccines.index[-1] + td(days=remainingDays)
|
||||||
|
|
||||||
# Generate plot
|
# Generate plot
|
||||||
plt.ylabel("Vaccini al giorno")
|
plt.ylabel("Vaccinati al giorno")
|
||||||
plt.xlabel("Ultima settimana")
|
plt.xlabel("Ultima settimana")
|
||||||
plt.grid(True)
|
plt.grid(True)
|
||||||
plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d'))
|
plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d'))
|
||||||
plt.gca().xaxis.set_major_locator(mdates.AutoDateLocator())
|
plt.gca().xaxis.set_major_locator(mdates.AutoDateLocator())
|
||||||
plt.gcf().autofmt_xdate()
|
plt.gcf().autofmt_xdate()
|
||||||
plt.bar(lastWeekData.index, height=lastWeekData["totale"])
|
plt.bar(lastWeekData.index, height=lastWeekData["seconda_dose"])
|
||||||
# Trendline
|
# Trendline
|
||||||
z = np.polyfit(range(0, 7), lastWeekData["totale"], 2)
|
z = np.polyfit(range(0, 7), lastWeekData["seconda_dose"], 2)
|
||||||
p = np.poly1d(z)
|
p = np.poly1d(z)
|
||||||
plt.plot(lastWeekData.index, p(range(0, 7)), "r--")
|
plt.plot(lastWeekData.index, p(range(0, 7)), "r--")
|
||||||
# Secret 4 filenames
|
# Secret 4 filenames
|
||||||
|
@ -123,7 +130,9 @@ def download():
|
||||||
with open('template.html', 'r+') as f:
|
with open('template.html', 'r+') as f:
|
||||||
with open('out/' + webpage_filename, 'w+') as wf:
|
with open('out/' + webpage_filename, 'w+') as wf:
|
||||||
for line in f.read().splitlines():
|
for line in f.read().splitlines():
|
||||||
if "<!-- totalVaccinations -->" in line:
|
if "<!-- totalDoses -->" in line:
|
||||||
|
line = f"{totalDoses}"
|
||||||
|
elif "<!-- totalVaccinations -->" in line:
|
||||||
line = f"{totalVaccines}"
|
line = f"{totalVaccines}"
|
||||||
elif "<!-- totalVaccinationsPerc -->" in line:
|
elif "<!-- totalVaccinationsPerc -->" in line:
|
||||||
line = f"{str(round(totalVaccines / ITALIAN_POPULATION * 100, 2)).replace('.', ',')}%"
|
line = f"{str(round(totalVaccines / ITALIAN_POPULATION * 100, 2)).replace('.', ',')}%"
|
||||||
|
|
|
@ -40,12 +40,17 @@
|
||||||
La campagna vaccinale in Italia è iniziata da poco e chiaramente non è ancora a regime. Le stime qui effettuate
|
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 />
|
saranno via via più affidabili con l'aumentare dei dati. <br />
|
||||||
</p>
|
</p>
|
||||||
|
<hr>
|
||||||
<div class="text-center">
|
<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">
|
<span class="text-big">
|
||||||
<!-- totalVaccinations -->
|
<!-- totalVaccinations -->
|
||||||
persone vaccinate</span> <br />
|
persone vaccinate,</span> <br />
|
||||||
che corrispondono al <br />
|
ovvero <br />
|
||||||
<span class="text-big">
|
<span class="text-big">
|
||||||
<!-- totalVaccinationsPerc -->
|
<!-- totalVaccinationsPerc -->
|
||||||
della popolazione.
|
della popolazione.
|
||||||
|
@ -57,7 +62,7 @@
|
||||||
con un ritmo di <br />
|
con un ritmo di <br />
|
||||||
<span class="text-big">
|
<span class="text-big">
|
||||||
<!-- vaccinesPerDay -->
|
<!-- vaccinesPerDay -->
|
||||||
vaccini al giorno.</span> <br />
|
vaccinati al giorno.</span> <br />
|
||||||
Continuando di questo passo, raggiungeremo l'immunità di gregge il <br />
|
Continuando di questo passo, raggiungeremo l'immunità di gregge il <br />
|
||||||
<span class="text-bigger">
|
<span class="text-bigger">
|
||||||
<!-- hitDate -->
|
<!-- hitDate -->
|
||||||
|
@ -71,10 +76,14 @@
|
||||||
giorni.
|
giorni.
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</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">
|
<p class="pt-2">
|
||||||
I dati non comprendono quelli del giorno attuale perché solitamente incompleti.
|
I dati non comprendono quelli del giorno attuale perché solitamente incompleti.
|
||||||
</p>
|
</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>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
Loading…
Reference in New Issue