Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoBuster committed Jan 6, 2021
0 parents commit d79c26b
Show file tree
Hide file tree
Showing 7 changed files with 379 additions and 0 deletions.
145 changes: 145 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# Created by .ignore support plugin (hsz.mobi)
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff:
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/dictionaries

# Sensitive or high-churn files:
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.xml
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml

# Gradle:
.idea/**/gradle.xml
.idea/**/libraries

# Mongo Explorer plugin:
.idea/**/mongoSettings.xml

## File-based project format:
*.iws

## Plugin-specific files:

# IntelliJ
/out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
### Python template
# Byte-compiled / optimized / DLL files
__pycache__/
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# dotenv
.env

# virtualenv
.venv
venv/
ENV/

# Spyder project settings
.spyderproject

# Rope project settings
.ropeproject

# Configuration file
config.py
.idea/misc.xml
*.xml
.idea/OrarioTreniBot.iml
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2021 Marco Aceti

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
77 changes: 77 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@

<!DOCTYPE html>
<html lang="it">
<head>
<title>Quanto manca?</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
<style>
.text-big {
font-size: 130%;
font-weight: bold;
position: relative;
top: -5px;
margin-bottom: -4px;
}
.text-bigger {
font-size: 200%;
font-weight: bold;
position: relative;
top: -5px;
margin-bottom: -4px;
}
</style>
</head>
<body>
<div class="container mt-4 pt-2 px-xl-5">
<h1>Quando torneremo alla normalità?</h1>
<p>
La domanda non ha una risposta precisa.
<a href="https://www.who.int/news-room/q-a-detail/herd-immunity-lockdowns-and-covid-19">Non è ancora chiaro</a>
quale è la percentuale di popolazione che deve essere vaccinata per avere la cosidetta
<b>immunità di gregge</b> o di massa dal virus SARS-Cov-2.
Realisticamente, questo numero si aggira intorno all'<b>80% della popolazione</b>
ovvero circa 48 milioni di persone.
</p>
<h3>Analisi dei dati della campagna vaccinale</h3>
<p class="mb-2">
La campagna vaccinale in Italia è appena iniziata e chiaramente non è ancora a regime, per via di vari fattori
politici e non che questo sito non ha intenzione di trattare o dibattere. <br />
</p>
<div class="text-center">
In Italia ci sono <br />
<span class="text-big">
185748
persone vaccinate.</span> <br />
Ne abbiamo vaccinate <br />
<span class="text-big">
177011
nell'ultima settimana,</span> <br />
con un ritmo di <br />
<span class="text-big">

25287

vaccini al giorno.</span> <br />
Continuando di questo passo, raggiungeremo l'immunità di gregge il: <br />
<span class="text-bigger">
30/03/2026
<span class="d-none d-sm-inline">
15:56:23
</span>
</span> <br />
<span style="position: relative; top: -4px">ovvero fra</span> <br />
<span class="text-bigger" style="position: relative; top: -12px;">
1909
giorni
</span>
</div>
<img alt="Grafico vaccini ultima settimana" src="plot.png" class="img-fluid">
<p class="pt-2">
I dati non comprendono quelli del giorno attuale perché solitamente incompleti.
</p>
</div>
</body>
</html>
57 changes: 57 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import io
from datetime import datetime as dt, timedelta as td

import matplotlib.dates as mdates
import matplotlib.pyplot as plt
import pandas as pd
import requests

DATA_URL = "https://raw.githubusercontent.com/italia/covid19-opendata-vaccini/master/dati/somministrazioni-vaccini" \
"-summary-latest.csv"
ITALIAN_POPULATION = 60_360_000
HIT = ITALIAN_POPULATION / 100 * 80 # We need 80% of population vaccined for herd immunity

r = requests.get(DATA_URL)
df = pd.read_csv(
io.StringIO(r.text),
index_col="data_somministrazione",
)
df.index = pd.to_datetime(
df.index,
format="%Y-%m-%d",
)
df = df.loc[df["area"] == "ITA"]
df = df[:-1] # Ignore the last day because it's often incomplete

lastWeekData = df.loc[df.index > df.index[-1] - td(days=7)]
vaccinesPerDayAverage = sum(lastWeekData["totale"]) / 7
remainingDays = HIT / vaccinesPerDayAverage
hitDate = dt.now() + td(days=remainingDays)

# Generate plot
plt.ylabel("Vaccini 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.savefig("plot.png", dpi=300, bbox_inches='tight')

# Generate template
with open("template.html", "r+") as f:
with open("index.html", "w+") as wf:
for line in f.read().splitlines():
if "<!-- totalVaccinations -->" in line:
line = f"{sum(df['totale'])}"
elif "<!-- totalVaccinationsLastWeek -->" in line:
line = f"{int(vaccinesPerDayAverage*7)}"
elif "<!-- vaccinesPerDay -->" in line:
line = f"{int(vaccinesPerDayAverage)}"
elif "<!-- hitDate -->" in line:
line = f"{hitDate.strftime('%d/%m/%Y')}"
elif "<!-- hitHour -->" in line:
line = f"{hitDate.strftime('%H:%M:%S')}"
elif "<!-- daysRemaining -->" in line:
line = f"{int(remainingDays)}"
wf.write("\n" + line)
Binary file added plot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pandas
matplotlib
requests
76 changes: 76 additions & 0 deletions template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<!DOCTYPE html>
<html lang="it">
<head>
<title>Quanto manca?</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
<style>
.text-big {
font-size: 130%;
font-weight: bold;
position: relative;
top: -5px;
margin-bottom: -4px;
}
.text-bigger {
font-size: 200%;
font-weight: bold;
position: relative;
top: -5px;
margin-bottom: -4px;
}
</style>
</head>
<body>
<div class="container mt-4 pt-2 px-xl-5">
<h1>Quando torneremo alla normalità?</h1>
<p>
La domanda non ha una risposta precisa.
<a href="https://www.who.int/news-room/q-a-detail/herd-immunity-lockdowns-and-covid-19">Non è ancora chiaro</a>
quale è la percentuale di popolazione che deve essere vaccinata per avere la cosidetta
<b>immunità di gregge</b> o di massa dal virus SARS-Cov-2.
Realisticamente, questo numero si aggira intorno all'<b>80% della popolazione</b>
ovvero circa 48 milioni di persone.
</p>
<h3>Analisi dei dati della campagna vaccinale</h3>
<p class="mb-2">
La campagna vaccinale in Italia è appena iniziata e chiaramente non è ancora a regime, per via di vari fattori
politici e non che questo sito non ha intenzione di trattare o dibattere. <br />
</p>
<div class="text-center">
In Italia ci sono <br />
<span class="text-big">
<!-- totalVaccinations -->
persone vaccinate.</span> <br />
Ne abbiamo vaccinate <br />
<span class="text-big">
<!-- totalVaccinationsLastWeek -->
nell'ultima settimana,</span> <br />
con un ritmo di <br />
<span class="text-big">

<!-- vaccinesPerDay -->

vaccini al giorno.</span> <br />
Continuando di questo passo, raggiungeremo l'immunità di gregge il: <br />
<span class="text-bigger">
<!-- hitDate -->
<span class="d-none d-sm-inline">
<!-- hitHour -->
</span>
</span> <br />
<span style="position: relative; top: -4px">ovvero fra</span> <br />
<span class="text-bigger" style="position: relative; top: -12px;">
<!-- daysRemaining -->
giorni
</span>
</div>
<img alt="Grafico vaccini ultima settimana" src="plot.png" class="img-fluid">
<p class="pt-2">
I dati non comprendono quelli del giorno attuale perché solitamente incompleti.
</p>
</div>
</body>
</html>

0 comments on commit d79c26b

Please sign in to comment.