@kuuki/gios-events v2.1.1
@kuuki/gios-events
is an event based api wrapper for GIOS written in TypeScript.
GIOS stands for (CHIEF INSPECTORATE FOR ENVIRONMENTAL PROTECTION).
This library provides the following functionality:
- Load the state from the API.
- Retrieve all measurement stations from the local state.
- Retrieve all measurement station sensors from the local state.
- Retrieve latest measurements of a sensor (up to 62h back) with time series granularity of 1 hour (from the local state).
- Retrieve air quality index for a station.
Provided events:
stations_refreshed
- Stations refreshed event.station_joined
- New station joined event.station_left
- Station left event.sensors_refreshed
- Sensors refreshed event.sensor_joined
- New sensor joined event.sensor_left
- Sensor left event.data_refreshed
- Measurement data refreshed event.data
- Raw data being processed and classified.measurement
- New and valid (notnull
and never registed in local state) measurement event.measurement_update
- Measurement update event (Any measurement could change after a while. Check GIOS docs for further details).error
- TODO
About
This library focuses on providing a strictly typed API definition and access to EventEmitter
, exposing further functionality.
What's basically happening is, that the state is stored locally and updated once in a while, providing you with highly flexible events, that you can attach event listeners to.
If you need something less sophisticated, check out @kuuki/gios
.
Installation
@kuuki/gios
requires Node.js to run on the backend.
$ npm install --save @kuuki/gios @kuuki/gios-events
Usage
(async() => {
const eventApi = new giosEvents.GiosAirQualityEventsService(
new gios.GiosAirQualityService(),
{
stations: "*/15 * * * *", // every 15 minutes
sensors: "*/15 * * * *",
measurements: "*/5 * * * *"
}
);
await eventApi.initialize();
// any measurements that have never been registered and are not null
eventApi.on("measurement", (stationId, sensor, measurement) => {
// find the station (to gather more metadata)
const station = eventApi.findStation(stationId);
console.log({
station,
sensor,
measurement,
op: "insert"
});
})
eventApi.on("measurement_update", (stationId, sensor, measurement) => {
// find the station (to gather more metadata)
const station = eventApi.findStation(stationId);
console.log({
station,
sensor,
measurement,
op: "upsert"
});
})
})();
Documentation
Generated docs are placed in the root /docs
folder, you can preview them under this link, however the d.ts
files should do just fine if you have your code editor and environment set up correctly.
Gios API
The official API docs can be viewed at Gios.