es2015-library-skeleton

0.0.0-development • Public • Published

combine-historical-data

Build Status Coverage Status Commitizen friendly

Usage

npm install --save @jcoreio/combine-historical-data

combineHistoricalData(...chunks)

import combineHistoricalData from '@jcoreio/combine-historical-data'

Combines timeseries data from the given chunks into a single chunk. Each chunk overwrites any data from previous chunks in its time range.

Ignores data outside of the time range of the first chunk.

Each chunk may specify its own beginTime and endTime, but if it doesn't the time of its first/last data point will be used. The endTime is exclusive, except that when it defaults to the time of the last data point, it's inclusive.

The times must be given in the t property of each chunk. Times outside the chunk's beginTime and endTime (if specified) will be ignored.

All other array properties in chunks are expected to correspond to t and will be combined likewise. All non-array properties will be combined as Object.assign(...chunks) would.

combineWithNaNInsertion(result, chunks, {nanTimeout, [prevTime]})

import combineWithNaNInsertion, {restore} from '@jcoreio/combine-historical-data/lib/combineWithNaNInsertion'

Like combineHistoricalData with several key differences:

  • It destructively modifies result (and will tack beginTime and endTime props onto chunks if missing)
  • If times t1 and t2 are more than nanTimeout apart, it inserts a new point at time t1 + nanTimeout with all NaN values.
  • If chunks can all be appended in order, it's more efficient.
  • It adds an ot field to result, which is the array of original times (no NaN-inserted times)

You can call restore(result) to get rid of the inserted NaN points.

Example

import combineHistoricalData from '@jcoreio/combine-historical-data'
import {expect} from 'chai'

expect(combineHistoricalData(
  {
    beginTime: 0,
    endTime: 100,
    t: [0, 20, 40, 60, 80],
    v: [1, 2, 3, 4, 5],
  },
  {
    t: [19, 30, 41],
    v: [6, 7, 8],
  },
  {
    t: [29, 35],
    v: [9, 10],
  },
  {
    t: [31, 39],
    v: [11, 12],
  },
  {
    t: [101, 105],
    v: [13, 14],
  }
)).to.deep.equal({
  beginTime: 0,
  endTime: 100,
  t: [0, 19, 29, 31, 39, 41, 60, 80],
  v: [1, 6, 9, 11, 12, 8, 4, 5],
})

Dependents (0)

Package Sidebar

Install

npm i es2015-library-skeleton

Weekly Downloads

1

Version

0.0.0-development

License

MIT

Unpacked Size

412 kB

Total Files

10

Last publish

Collaborators

  • jedwards1211