CanAirIO fixed stations API for fetch published data

Overview

The current fixed stations are stored in an InfluxDB database service, each station write a data series time in separated tables. We will change it to different schema soon. For now the next endpoints are enabled.

Data visualization

For now, the shared series time of each stations could be listed in our Grafana dashboard here:

CanAirIO grafana

Mobile track visualization

Data endpoint

Each series time could be fetched via the next endpoint:

http://influxdb.canair.io:8086/query

the full documentation of InfluxDB query syntax could be consulted here

For example:

Linux

curl -G 'http://influxdb.canair.io:8086/query?db=canairio' --data-urlencode 'q=select * from "PM25_Berlin_CanAirIO_v2" WHERE time >= now() - 12h' > PM25_Berlin_CanAirIO_v2.json

Windows

curl -Headers @{"accept"="application/json"}  'http://influxdb.canair.io:8086/query?db=canairio' -Body @{"q" = 'select * from "PM2.5_BOG_TUN_EstacionTunal" WHERE time >= now() - 12h'}  -OutFile PM2.5_BOG_TUN_EstacionTunal.json

If you want to get the data with a specific time resolution, you need a agregation function in the select section of the query and group the results by the resolution time, in the next example we use the agregation function mean() for all the variables, you can use the same or one of median(), count(), min(), max(), sum(), first(), last(), spread() or stddev().

Note the last part of the query, we add the sql clause GROUP BY time(resolution_time)

curl -G 'http://influxdb.canair.io:8086/query?db=canairio' --data-urlencode 'q=select mean(*) from "PM25_Berlin_CanAirIO_v2" WHERE time >= now() - 12h GROUP BY time(1m)' > PM25_Berlin_CanAirIO_v2.json

The last couple of examples return the data in json format, if you want to get the data in CSV format you need to add the header “Accept: application/csv” to the curl request using the parameter -H like show the next example:

curl -H 'Accept:application/csv' -G 'http://influxdb.canair.io:8086/query?db=canairio' --data-urlencode 'q=select mean(*) from "PM25_Berlin_CanAirIO_v2" WHERE time >= now() - 12h GROUP BY time(1m) FILL(none)' > PM25_Berlin_CanAirIO_v2.csv

Fixed stations names

For get the complete list of fixed stations names:

curl -G 'http://influxdb.canair.io:8086/query?db=canairio' --data-urlencode 'q=show measurements'

But the more important stations of CanAirIO with more stable data is listed here.

Python example

In your OS please install before the python3-virtualenv package, then:

create and activate your virtual space:

virtualenv venv && source venv/bin/activate

install the next package for run the test:

pip3 install influxdb ipython

Query

enter to ipython console with the command ipython and execute the next lines for import the influxDb client and instance it:

from influxdb import InfluxDBClient
client = InfluxDBClient(host='influxdb.canair.io', port=8086, database='canairio')

after that, run a query:

client.query('select * from "PM2.5_BOG_FON_Hayuelos_E01" WHERE time >= now() - 10m')

you should have an output similar to next:

python output from fixed station query

Stations names

for get the all names of fixed stations:

client.get_list_measurements()

All tracks request

For now we don’t have this development, CanAirIO is a opensource initiative and you able to send any pull request for help us in improve our API. For now we have published some backups of last one year, for example:

CanAirIO full snap - fixed stations

Please read the README file in the link for details.

Tags: api