Skip to content

Latest commit

 

History

History
107 lines (66 loc) · 4.26 KB

README.md

File metadata and controls

107 lines (66 loc) · 4.26 KB

Coronacidades API 🎲

Code style: black Contributors Update master docker build server docker build loader

This repo runs our API for Coronacidades tools, such as FarolCovid. You can access the API here: http://datasource.coronacidades.org/help

Current data

Use it like:

http://datasource.coronacidades.org/br/cities/cases/full

  • br/cities/cases/full: Full history data from Brasil.IO with notification rate and estimated active cases
  • br/cities/cnes: Beds and ventilators data from DataSus/CNES
  • br/cities/farolcovid/main: Data filtered & cities'indicatores for FarolCovid app
  • br/cities/rt: Cities effective reproduction number (Rt) calculations by date
  • br/cities/simulacovid/main: Data filtered to serve SimulaCovid app
  • br/states/farolcovid/main: Data filtered & states' indicators for FarolCovid app
  • br/states/rt: State effective reproduction number (Rt) calculations by date
  • br/states/safereopen/main: States' security and economic priority index for reopening sectors
  • world/owid/heatmap: Our World in Data data to serve the heatmaps

Check data dictionaries here.

Building your local API

⚠️ You need a .env file in root folder with very secretive variables to run some data.

1️⃣ Run Loader

Run the code to load the files

 make loader-build-run

For development

If you want to make changes on the code, you should run the loader with make loader-shell to open the docker image and be able to edit the files directly in your editor.

2️⃣ Run Server

In a different tab, run the Flask server

make server-build-run

For development

If you want to make changes on the code, you should run the loader with make server-shell to open the docker image and be able to edit the files directly in your editor.

3️⃣ All done!

You should see something at localhost:7000/<endpoint>, like http://localhost:7000/br/cities/cases/full

Check the column date_last_refreshed if you made any changes! ;)

Adding new data entrypoints

  • Add the endpoint configuration parameters to endpoints.yaml
- endpoint: 'br/cities/cases/full' # endpoint route following [country]/[unit]/[content]
  python_file: get_cases         # .py that generates data in loader/endpoints/
  update_frequency_minutes: 15  # how often it should be updated in minutes
  • Write a .py file in loader/endpoints/ that generates the endpoint data. This file must be structured as get_{template}.py

Good Practices

Logging

Do not use print to log stuff. You can use the logger in logger.py. It is faily simple to do it.

from logger import logger

logger.debug('Your message {variable}', variable=3)

You have several logging levels: debug, info, warning and error. To change the level you can just call logger.<level>, i.e., logger.info().

  • Usually, debug is used to minor behaviours and it is useful to debug code :).

  • The info level is being used to keep track of the overall expected behaviour.

  • If you use logger.error, the message will also be posted to our slack channel #simulacovid-logs

Read more at loguru.

Production: print logs on Slack

  1. Set the env variable IS_PROD=True
  2. Add secrets folder