data-forge / data-forge-js

JavaScript data transformation and analysis toolkit inspired by Pandas and LINQ.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

gaps data example has the wrong var name

swyxio opened this issue · comments

minor thing

var moment = require('moment');

var dailyShareDataWithGaps = ...

var gapExists = function (pairA, pairB) {
    // Return true if there is a gap longer than a day.
    var startDate = pairA[0];
    var endDate = pairB[0];
    var gapSize = moment(endDate).diff(moment(startDate), 'days');
    return gapSize > 1;
};

var gapFiller = function (pairA, pairB) {
    // Fill values forward.
    var startDate = pairA[0];
    var endDate = pairB[0];
    var gapSize = moment(endDate).diff(moment(startDate), 'days');
    var numEntries = gapSize - 1;

    var startValue = pairA[1];
    var newEntries = [];

    for (var entryIndex = 0; entryIndex < numEntries; ++entryIndex) {
        newEntries.push([
            moment(pairA[0]).add(entryIndex + 1, 'days').toDate(), // New index
            startValue // New value, copy the start value forward to fill the gaps. 
        ]);
    }   

    return newEntries;
}

var sequenceWithoutGaps = sequenceWithGaps.fillGaps(gapExists, gapFiller);

sequenceWithGaps isnt defined

separately - feature request - would be great to have the ability to add Series or Dataframes together

actually.. gapExists is unusable. pairA[0] and pairB[0] are indexes so there is never any difference between them.

Hi thanks for your feedback.

The second line of code in that example is meant to define 'sequenceWithoutGaps'. I've updated the example.

Your statement "pairA[0] and pairB[0] are indexes so there is never any difference between them" doesn't make much sense to me. Why should there be no difference between them?

If you are using date/time as an index and there is a day between each entry then will be a day difference between them normally. Then for any missing days the gapSize will be later than 1 which invokes the gapFiller.