data-forge
Version:
JavaScript data transformation and analysis toolkit inspired by Pandas and LINQ.
47 lines • 1.81 kB
JavaScript
"use strict";
//
// Iterates an underlying iterable in the 'windows'.
//
Object.defineProperty(exports, "__esModule", { value: true });
var dataframe_1 = require("../dataframe");
var DataFrameRollingWindowIterator = /** @class */ (function () {
function DataFrameRollingWindowIterator(columnNames, iterable, period) {
this.columnNames = columnNames;
this.iterable = iterable;
this.period = period;
}
DataFrameRollingWindowIterator.prototype.next = function () {
if (!this.curWindow) {
this.curWindow = [];
this.iterator = this.iterable[Symbol.iterator]();
for (var i = 0; i < this.period; ++i) {
var curPos = this.iterator.next();
if (curPos.done) {
// Underlying iterator doesn't have required number of elements.
return { done: true };
}
this.curWindow.push(curPos.value);
}
}
else {
this.curWindow.shift(); // Remove first item from window.
var curPos = this.iterator.next();
if (curPos.done) {
// Underlying iterator doesn't have enough elements left.
return { done: true };
}
this.curWindow.push(curPos.value); // Add next item to window.
}
var window = new dataframe_1.DataFrame({
columnNames: this.columnNames,
pairs: this.curWindow
});
return {
value: window,
done: false,
};
};
return DataFrameRollingWindowIterator;
}());
exports.DataFrameRollingWindowIterator = DataFrameRollingWindowIterator;
//# sourceMappingURL=dataframe-rolling-window-iterator.js.map