0.0.3 • Published 8 years ago

@danilo.sanchi/timeseries v0.0.3

Weekly downloads
1
License
UNLICENCED
Repository
github
Last release
8 years ago

Time Series

  • Basic Usage
  • API

Basic usage

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.

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.

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

Query

  • from the lower bound date interval.
  • to the upper bound date interval