npm install --save @jcoreio/combine-historical-data
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.
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
andt2
are more than nanTimeout apart, it inserts a new point at timet1 + nanTimeout
with allNaN
values. - If
chunks
can all be appended in order, it's more efficient. - It adds an
ot
field toresult
, which is the array of original times (no NaN-inserted times)
You can call restore(result)
to get rid of the inserted NaN points.
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],
})