Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/danielsan80/avanscoperta_timeseries

Avanscoperta Nodejs workshop: timeseries
https://github.com/danielsan80/avanscoperta_timeseries

avanscoperta learn nodejs workshop

Last synced: about 8 hours ago
JSON representation

Avanscoperta Nodejs workshop: timeseries

Awesome Lists containing this project

README

        

# Time Series

* Basic Usage
* API


Basic usage
-----------

```js
var timeseries = require('timeseries')

var timeserie = timeseries(mongodbConn, pino);

// 2) put a key & value
timeserie.addPoint(new Date(), 'smog', 45, callback);

timeserie.addPoint(new Date(), 'smog', 45, callback);

var stream = timeserie.fetchSerie('smog', {
from: aWeekAgo,
to: new Date(),
});

...

```


## API

* timeseries(mongodbConn, logger)
* timeserie.addPoint(date, type, value, callback)
* timeserie.fetchSerie(type, query = {})

--------------------------------------------------------

### timeseries(mongodbConn, logger)
timeseries() is the main entry point for creating a new timeserie instance.

--------------------------------------------------------

### timeserie.addPoint(date, type, value, callback)
timeserie.addPoint() method will add a new point for a specified `type` at the specified `date`. `value` should be a number.

```js
timeserie.addPoint(new Date(), 'smog', 42, function (err) {
if (err) throw err
})
```

--------------------------------------------------------

### timeserie.fetchSerie(type, query)
timeserie.fetchSerie() method will fetch the point collection for a given `type` matching a given `query`.
This will return a stream of points.

```js
var stream = timeserie.fetchSerie('smog', {
from: aWeekAgoDate,
to: new Date()
})
```
#### `Query`

* `from` the lower bound date interval.
* `to` the upper bound date interval