2.1.1 • Published 4 years ago

@kuuki/gios-events v2.1.1

Weekly downloads
13
License
ISC
Repository
-
Last release
4 years ago

lerna GitHub

@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 (not null 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.

2.1.1

4 years ago

2.1.0

4 years ago

2.0.5

4 years ago

2.0.3

4 years ago

2.0.4

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.1

4 years ago