Skip to content

gaetanosettembre/covidashit

 
 

Repository files navigation

COVID-19 Italy Monitor | #StayAtHome

Awesome Open Source Love Made with Pthon

alt_text

Versione Italiana qui

A simple dashboard to display and monitor the official data of the COVID-19 outbreak in Italy released by the Civil Protection Dept. and updated on a daily basis.

The app is deployed on Heroku here

Pandemic data from the official CP Dept repository

Vaccine data from the official open-data repository/

For developers

The WebApp requires Python 3.8+ and reads the data from a mongoDB. It employs a Flask server with gunicorn in front of it. Furthermore, it employs Flask-babel for the italian translation, as English is set as primary language. The script make_pot.sh creates the files needed by Babel for the translations. A Batch version of the script is provided for Windows users. The app language is decided upon the client request (browser / OS).

The front-end lives under covidashit/templates and it uses JS to create the chart object, which is built using HighCharts.

In order for the app to be operational, a mongoDB must be populated (see here for the creation of an Atlas mongoDB free cluster). Additionally, mongo collections must be updated on a daily basis. The Flask contains a number of API whose purpose is to update the DB every time the master branch of the CP Dept repository is updated, via a GitHub webhook (see the GitHub workflow here). Ultimately, the webhooks for the following APIs must be set on the CP forked repository:

  • POST /update/national
  • POST /update/national/series
  • POST /update/national/trends
  • POST /update/regional
  • POST /update/regional/breakdown
  • POST /update/regional/series
  • POST /update/regional/trends
  • POST /update/provincial
  • POST /update/provincial/breakdown
  • POST /update/provincial/series
  • POST /update/provincial/trends
  • POST /update/vax/
  • POST /update/vax/summary

Local deployment (DEV)

  • create and activate a virtual environment (follow this)
  • install the requirements in requirements.txt

The .env file contains all the env vars needed by the webapp. In particular, the MONGO_URI and the various collection names string must be set. Before the Flask server is started, but after the virtual environment has been activated, the DB must be populated. For this purpose a Flask CLI, that populates the various collections, is included. This, with a very basic ETL procedure, will populate the various collections on the DB with the official data released by the Civil Protection Dept.

Clone the repo, cd into it, activate the virtual environment, and run the procedure

flask create-collections

then run the worker

celery -A celery_worker.celery worker

and, in a new shell, run the application server

flask run

Flask will be listening at http://127.0.0.1:5000

Local deployment (PROD)

First, replace the value of APPLICATION_ENV in .env with production

Procfile

to test the Procfile configuration, Simply run the heroku CLI

heroku local

Docker

To test the containerization locally spawn the container with:

docker-compose up -d

The docker container will be listening at http://127.0.0.1:PORT with PORT being set in the .env file

Stop it with

docker-compose down

Deployment on Heroku

The app can be deployed on Heroku either as a docker container or simply using the Procfile

Plots API

The app provides an API to produce a server-side plot with matplotlib. The API can return a JSON response with the base64-encoded image, or the bytes content to be saved as a file.

Resource URL

https://www.covidash.it/api/plot

Query parameters

Data type

data_type = [national, regional, provincial]

Var name

varname = [nuovi_positivi, ingressi_terapia_intensiva, deceduti_g, tamponi_g,
 totale_ospedalizzati_g, nuovi_positivi_ma, deceduti_g_ma, 
 ingressi_terapia_intensiva_ma, tamponi_g_ma, totale_ospedalizzati_g_ma, 
 totale_positivi, terapia_intensiva, ricoverati_con_sintomi, 
 totale_ospedalizzati, isolamento_domiciliare, totale_casi, deceduti, 
 tamponi, dimessi_guariti]

for data_type = [national, regional]

varname = [nuovi_positivi, nuovi_positivi_ma, totale_casi]

for data_type = [provincial]

Area (regions)

area = [Abruzzo, Basilicata, Calabria, Campania, Emilia-Romagna, Friuli Venezia Giulia,
 Lazio, Liguria, Lombardia, Marche, Molise, Piemonte, Puglia, Sardegna, 
 Sicilia, Toscana, P.A. Bolzano, P.A. Trento, Umbria, Valle d'Aosta, Veneto]

Area (provinces)

area = [Chieti, L'Aquila, Pescara, Teramo, Matera, Potenza, Catanzaro, Cosenza,
Crotone, Reggio di Calabria, Vibo Valentia, Avellino, Benevento, Caserta, 
Napoli, Salerno, Bologna, Ferrara, Forlì-Cesena, Modena, Parma, Piacenza, 
Ravenna, Reggio nell'Emilia, Rimini, Gorizia, Pordenone, Trieste, Udine, 
Frosinone, Latina, Rieti, Roma, Viterbo, Genova, Imperia, La Spezia, Savona, 
Bergamo, Brescia, Como, Cremona, Lecco, Lodi, Mantova, Milano, 
Monza e della Brianza, Pavia, Sondrio, Varese, Ancona, Ascoli Piceno, Fermo, 
Macerata, Pesaro e Urbino, Campobasso, Isernia, Alessandria, Asti, Biella, 
Cuneo, Novara, Torino, Verbano-Cusio-Ossola, Vercelli, Bari, 
Barletta-Andria-Trani, Brindisi, Lecce, Foggia, Taranto, Cagliari, Nuoro, 
Sassari, Sud Sardegna, Agrigento, Caltanissetta, Catania, Enna, Messina, 
Palermo, Ragusa, Siracusa, Trapani, Arezzo, Firenze, Grosseto, Livorno, Lucca,
Massa Carrara, Pisa, Pistoia, Prato, Siena, Perugia, Terni, Aosta, Belluno, 
Padova, Rovigo, Treviso, Venezia, Verona, Vicenza]

Examples

National plot

GET /api/plot?data_type=national&varname=<varname>

Regional plot

GET /api/plot?data_type=regional&area=<region>&varname=<varname>

Provincial plot

GET /api/plot?data_type=provincial&area=<province>&varname=[nuovi_positivi,nuovi_positivi_ma,totale_casi]>

To get the base64-encoded image in a JSON response

JSON

Request

curl --request GET \ 
     --url 'https://www.covidash.it/api/plot?data_type=national&varname=totale_casi'

Response

{
    "errors":[],
    "img":"iVBORw0KGgoAA...",
    "status":"ok"
}

To download the file

Request

curl --request GET \
     --url 'https://www.covidash.it/api/plot?data_type=national&varname=totale_casi&download=true' \
     --output plot.png

The plot will be saved in ./plot.png

Plot preview

alt_text

Donation

If you liked this project or if I saved you some time, feel free to buy me a beer. Cheers!

paypal

About

COVID-19 Italy Pandemic and Vaccines Dashboard

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 54.8%
  • HTML 35.0%
  • JavaScript 7.5%
  • CSS 1.9%
  • Shell 0.4%
  • Dockerfile 0.3%
  • Batchfile 0.1%