From bf87f525e40206e68e139dc14e964f7a96e18ab6 Mon Sep 17 00:00:00 2001 From: Nicolas Thouvenin Date: Wed, 8 Jan 2020 19:17:41 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20start=20parameter=20shoul?= =?UTF-8?q?d=20be=20use=20to=20compute=20the=20size?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/analytics/src/distribute.js | 4 +- packages/analytics/test/data01.json | 1344 ++++++++++++++++++++++++++ packages/analytics/test/tests.js | 17 + 3 files changed, 1363 insertions(+), 2 deletions(-) create mode 100644 packages/analytics/test/data01.json diff --git a/packages/analytics/src/distribute.js b/packages/analytics/src/distribute.js index 111c5d90..13642458 100644 --- a/packages/analytics/src/distribute.js +++ b/packages/analytics/src/distribute.js @@ -32,7 +32,7 @@ import Store from './store'; * @param {String} [value="value"] path to use for value * @param {String} [step=1] step between each valut * @param {Number} [start=min value in the stream] first value to throw - * @param {Number} [size=(min value - max value) in the stream] size of the distribution + * @param {Number} [size=(max value in the stream) - start] size of the distribution * @param {Number} [default=0] default value for missing object * @returns {Object} */ @@ -48,7 +48,7 @@ export default function distribute(data, feed) { if (this.isLast()) { const start = Number(this.getParam('start', this.min)); const step = Number(this.getParam('step', 1)); - const size = Number(this.getParam('size', (this.max - this.min))); + const size = Number(this.getParam('size', (this.max - start))); const leng = Math.ceil(size / step); const stop = start + size; const defval = this.getParam('default', 0); diff --git a/packages/analytics/test/data01.json b/packages/analytics/test/data01.json new file mode 100644 index 00000000..548d9373 --- /dev/null +++ b/packages/analytics/test/data01.json @@ -0,0 +1,1344 @@ +[{ + "id": "9.928", + "value": 1 +}, +{ + "id": "9.916", + "value": 1 +}, +{ + "id": "9.904", + "value": 1 +}, +{ + "id": "9.868", + "value": 1 +}, +{ + "id": "9.844", + "value": 1 +}, +{ + "id": "9.832", + "value": 1 +}, +{ + "id": "9.724", + "value": 1 +}, +{ + "id": "9.64", + "value": 1 +}, +{ + "id": "9.628", + "value": 1 +}, +{ + "id": "9.616", + "value": 1 +}, +{ + "id": "9.568", + "value": 1 +}, +{ + "id": "9.544", + "value": 1 +}, +{ + "id": "9.46", + "value": 2 +}, +{ + "id": "9.424", + "value": 1 +}, +{ + "id": "9.412", + "value": 1 +}, +{ + "id": "9.4", + "value": 1 +}, +{ + "id": "9.364", + "value": 2 +}, +{ + "id": "9.352", + "value": 1 +}, +{ + "id": "9.34", + "value": 1 +}, +{ + "id": "9.328", + "value": 1 +}, +{ + "id": "9.304", + "value": 1 +}, +{ + "id": "9.292", + "value": 1 +}, +{ + "id": "9.268", + "value": 1 +}, +{ + "id": "9.244", + "value": 1 +}, +{ + "id": "9.208", + "value": 1 +}, +{ + "id": "9.142", + "value": 1 +}, +{ + "id": "9.112", + "value": 1 +}, +{ + "id": "9.052", + "value": 1 +}, +{ + "id": "9.04", + "value": 1 +}, +{ + "id": "9.028", + "value": 2 +}, +{ + "id": "9.016", + "value": 1 +}, +{ + "id": "8.992", + "value": 1 +}, +{ + "id": "8.98", + "value": 1 +}, +{ + "id": "8.956", + "value": 1 +}, +{ + "id": "8.944", + "value": 1 +}, +{ + "id": "8.896", + "value": 1 +}, +{ + "id": "8.861", + "value": 1 +}, +{ + "id": "8.848", + "value": 3 +}, +{ + "id": "8.836", + "value": 1 +}, +{ + "id": "8.824", + "value": 2 +}, +{ + "id": "8.812", + "value": 1 +}, +{ + "id": "8.8", + "value": 3 +}, +{ + "id": "8.704", + "value": 1 +}, +{ + "id": "8.692", + "value": 1 +}, +{ + "id": "8.656", + "value": 1 +}, +{ + "id": "8.644", + "value": 1 +}, +{ + "id": "8.619", + "value": 1 +}, +{ + "id": "8.608", + "value": 1 +}, +{ + "id": "8.596", + "value": 1 +}, +{ + "id": "8.572", + "value": 1 +}, +{ + "id": "8.536", + "value": 2 +}, +{ + "id": "8.5", + "value": 1 +}, +{ + "id": "8.485", + "value": 1 +}, +{ + "id": "8.476", + "value": 1 +}, +{ + "id": "8.452", + "value": 1 +}, +{ + "id": "8.44", + "value": 1 +}, +{ + "id": "8.428", + "value": 1 +}, +{ + "id": "8.421", + "value": 1 +}, +{ + "id": "8.416", + "value": 1 +}, +{ + "id": "8.404", + "value": 1 +}, +{ + "id": "8.356", + "value": 1 +}, +{ + "id": "8.344", + "value": 1 +}, +{ + "id": "8.332", + "value": 1 +}, +{ + "id": "8.32", + "value": 1 +}, +{ + "id": "8.308", + "value": 2 +}, +{ + "id": "8.296", + "value": 2 +}, +{ + "id": "8.288", + "value": 1 +}, +{ + "id": "8.284", + "value": 1 +}, +{ + "id": "8.272", + "value": 1 +}, +{ + "id": "8.23", + "value": 1 +}, +{ + "id": "8.224", + "value": 1 +}, +{ + "id": "8.188", + "value": 2 +}, +{ + "id": "8.173", + "value": 1 +}, +{ + "id": "8.116", + "value": 1 +}, +{ + "id": "8.104", + "value": 1 +}, +{ + "id": "8.088", + "value": 1 +}, +{ + "id": "8.068", + "value": 2 +}, +{ + "id": "8.062", + "value": 1 +}, +{ + "id": "8.056", + "value": 2 +}, +{ + "id": "8.047", + "value": 1 +}, +{ + "id": "8.032", + "value": 1 +}, +{ + "id": "8.008", + "value": 1 +}, +{ + "id": "7.996", + "value": 2 +}, +{ + "id": "7.972", + "value": 1 +}, +{ + "id": "7.969", + "value": 1 +}, +{ + "id": "7.948", + "value": 1 +}, +{ + "id": "7.936", + "value": 1 +}, +{ + "id": "7.916", + "value": 1 +}, +{ + "id": "7.9", + "value": 2 +}, +{ + "id": "7.888", + "value": 5 +}, +{ + "id": "7.852", + "value": 1 +}, +{ + "id": "7.816", + "value": 2 +}, +{ + "id": "7.804", + "value": 1 +}, +{ + "id": "7.792", + "value": 1 +}, +{ + "id": "7.74", + "value": 1 +}, +{ + "id": "7.732", + "value": 1 +}, +{ + "id": "7.726", + "value": 1 +}, +{ + "id": "7.68", + "value": 1 +}, +{ + "id": "7.67", + "value": 1 +}, +{ + "id": "7.667", + "value": 1 +}, +{ + "id": "7.66", + "value": 1 +}, +{ + "id": "7.648", + "value": 1 +}, +{ + "id": "7.636", + "value": 2 +}, +{ + "id": "7.624", + "value": 1 +}, +{ + "id": "7.576", + "value": 1 +}, +{ + "id": "7.567", + "value": 1 +}, +{ + "id": "7.564", + "value": 1 +}, +{ + "id": "7.552", + "value": 1 +}, +{ + "id": "7.54", + "value": 1 +}, +{ + "id": "7.528", + "value": 2 +}, +{ + "id": "7.501", + "value": 1 +}, +{ + "id": "7.467", + "value": 1 +}, +{ + "id": "7.456", + "value": 2 +}, +{ + "id": "7.433", + "value": 1 +}, +{ + "id": "7.432", + "value": 1 +}, +{ + "id": "7.411", + "value": 1 +}, +{ + "id": "7.383", + "value": 1 +}, +{ + "id": "7.371", + "value": 1 +}, +{ + "id": "7.311", + "value": 1 +}, +{ + "id": "7.256", + "value": 1 +}, +{ + "id": "7.208", + "value": 1 +}, +{ + "id": "7.142", + "value": 1 +}, +{ + "id": "7.039", + "value": 1 +}, +{ + "id": "7.012", + "value": 54 +}, +{ + "id": "6.943", + "value": 1 +}, +{ + "id": "6.905", + "value": 1 +}, +{ + "id": "6.9", + "value": 1 +}, +{ + "id": "6.898", + "value": 1 +}, +{ + "id": "6.832", + "value": 1 +}, +{ + "id": "6.825", + "value": 1 +}, +{ + "id": "6.814", + "value": 1 +}, +{ + "id": "6.699", + "value": 1 +}, +{ + "id": "6.659", + "value": 1 +}, +{ + "id": "6.551", + "value": 1 +}, +{ + "id": "6.533", + "value": 1 +}, +{ + "id": "6.505", + "value": 1 +}, +{ + "id": "6.489", + "value": 1 +}, +{ + "id": "6.478", + "value": 1 +}, +{ + "id": "6.455", + "value": 1 +}, +{ + "id": "6.28", + "value": 1 +}, +{ + "id": "6.209", + "value": 1 +}, +{ + "id": "6.142", + "value": 1 +}, +{ + "id": "6.134", + "value": 1 +}, +{ + "id": "6.12", + "value": 1 +}, +{ + "id": "6.117", + "value": 1 +}, +{ + "id": "6.106", + "value": 1 +}, +{ + "id": "6.101", + "value": 1 +}, +{ + "id": "6.087", + "value": 1 +}, +{ + "id": "6.075", + "value": 1 +}, +{ + "id": "6.039", + "value": 1 +}, +{ + "id": "6.031", + "value": 1 +}, +{ + "id": "6.023", + "value": 1 +}, +{ + "id": "5.989", + "value": 1 +}, +{ + "id": "5.965", + "value": 1 +}, +{ + "id": "5.941", + "value": 1 +}, +{ + "id": "5.884", + "value": 1 +}, +{ + "id": "5.844", + "value": 1 +}, +{ + "id": "5.816", + "value": 1 +}, +{ + "id": "5.79", + "value": 1 +}, +{ + "id": "5.705", + "value": 1 +}, +{ + "id": "5.68", + "value": 1 +}, +{ + "id": "5.679", + "value": 1 +}, +{ + "id": "5.66", + "value": 1 +}, +{ + "id": "5.656", + "value": 1 +}, +{ + "id": "5.655", + "value": 1 +}, +{ + "id": "5.612", + "value": 1 +}, +{ + "id": "5.485", + "value": 1 +}, +{ + "id": "5.476", + "value": 1 +}, +{ + "id": "5.464", + "value": 1 +}, +{ + "id": "5.445", + "value": 1 +}, +{ + "id": "5.422", + "value": 1 +}, +{ + "id": "5.37", + "value": 1 +}, +{ + "id": "5.369", + "value": 1 +}, +{ + "id": "5.351", + "value": 1 +}, +{ + "id": "5.35", + "value": 1 +}, +{ + "id": "5.282", + "value": 1 +}, +{ + "id": "5.248", + "value": 1 +}, +{ + "id": "5.243", + "value": 1 +}, +{ + "id": "5.102", + "value": 1 +}, +{ + "id": "5.077", + "value": 1 +}, +{ + "id": "5.051", + "value": 1 +}, +{ + "id": "5.017", + "value": 1 +}, +{ + "id": "5.013", + "value": 1 +}, +{ + "id": "5.009", + "value": 1 +}, +{ + "id": "5.005", + "value": 1 +}, +{ + "id": "5.004", + "value": 1 +}, +{ + "id": "5.001", + "value": 5 +}, +{ + "id": "4.996", + "value": 1 +}, +{ + "id": "4.966", + "value": 1 +}, +{ + "id": "4.961", + "value": 1 +}, +{ + "id": "4.953", + "value": 1 +}, +{ + "id": "4.952", + "value": 1 +}, +{ + "id": "4.933", + "value": 1 +}, +{ + "id": "4.927", + "value": 1 +}, +{ + "id": "4.898", + "value": 1 +}, +{ + "id": "4.889", + "value": 2 +}, +{ + "id": "4.862", + "value": 1 +}, +{ + "id": "4.856", + "value": 1 +}, +{ + "id": "4.849", + "value": 1 +}, +{ + "id": "4.841", + "value": 1 +}, +{ + "id": "4.828", + "value": 1 +}, +{ + "id": "4.73", + "value": 1 +}, +{ + "id": "4.724", + "value": 1 +}, +{ + "id": "4.705", + "value": 1 +}, +{ + "id": "4.671", + "value": 1 +}, +{ + "id": "4.653", + "value": 1 +}, +{ + "id": "4.651", + "value": 1 +}, +{ + "id": "4.641", + "value": 2 +}, +{ + "id": "4.634", + "value": 1 +}, +{ + "id": "4.63", + "value": 1 +}, +{ + "id": "4.605", + "value": 1 +}, +{ + "id": "4.598", + "value": 1 +}, +{ + "id": "4.546", + "value": 1 +}, +{ + "id": "4.533", + "value": 1 +}, +{ + "id": "4.505", + "value": 2 +}, +{ + "id": "4.497", + "value": 1 +}, +{ + "id": "4.494", + "value": 1 +}, +{ + "id": "4.493", + "value": 1 +}, +{ + "id": "4.49", + "value": 1 +}, +{ + "id": "4.415", + "value": 1 +}, +{ + "id": "4.413", + "value": 1 +}, +{ + "id": "4.365", + "value": 1 +}, +{ + "id": "4.344", + "value": 1 +}, +{ + "id": "4.325", + "value": 1 +}, +{ + "id": "4.317", + "value": 1 +}, +{ + "id": "4.307", + "value": 1 +}, +{ + "id": "4.305", + "value": 1 +}, +{ + "id": "4.291", + "value": 1 +}, +{ + "id": "4.286", + "value": 1 +}, +{ + "id": "4.246", + "value": 1 +}, +{ + "id": "4.209", + "value": 1 +}, +{ + "id": "4.197", + "value": 1 +}, +{ + "id": "4.178", + "value": 1 +}, +{ + "id": "4.173", + "value": 1 +}, +{ + "id": "4.157", + "value": 1 +}, +{ + "id": "4.152", + "value": 1 +}, +{ + "id": "4.125", + "value": 1 +}, +{ + "id": "4.085", + "value": 1 +}, +{ + "id": "3.977", + "value": 2 +}, +{ + "id": "3.961", + "value": 1 +}, +{ + "id": "3.953", + "value": 1 +}, +{ + "id": "3.897", + "value": 1 +}, +{ + "id": "3.885", + "value": 1 +}, +{ + "id": "3.862", + "value": 1 +}, +{ + "id": "3.848", + "value": 1 +}, +{ + "id": "3.825", + "value": 1 +}, +{ + "id": "3.803", + "value": 1 +}, +{ + "id": "3.799", + "value": 1 +}, +{ + "id": "3.794", + "value": 1 +}, +{ + "id": "3.789", + "value": 1 +}, +{ + "id": "3.775", + "value": 1 +}, +{ + "id": "3.773", + "value": 1 +}, +{ + "id": "3.77", + "value": 1 +}, +{ + "id": "3.761", + "value": 1 +}, +{ + "id": "3.757", + "value": 1 +}, +{ + "id": "3.754", + "value": 1 +}, +{ + "id": "3.718", + "value": 1 +}, +{ + "id": "3.717", + "value": 2 +}, +{ + "id": "3.713", + "value": 1 +}, +{ + "id": "3.693", + "value": 1 +}, +{ + "id": "3.689", + "value": 1 +}, +{ + "id": "3.633", + "value": 1 +}, +{ + "id": "3.621", + "value": 1 +}, +{ + "id": "3.613", + "value": 1 +}, +{ + "id": "3.609", + "value": 1 +}, +{ + "id": "3.569", + "value": 1 +}, +{ + "id": "3.567", + "value": 1 +}, +{ + "id": "3.561", + "value": 1 +}, +{ + "id": "3.552", + "value": 1 +}, +{ + "id": "3.489", + "value": 1 +}, +{ + "id": "3.461", + "value": 2 +}, +{ + "id": "3.453", + "value": 1 +}, +{ + "id": "3.452", + "value": 1 +}, +{ + "id": "3.449", + "value": 1 +}, +{ + "id": "3.441", + "value": 1 +}, +{ + "id": "3.42", + "value": 1 +}, +{ + "id": "3.377", + "value": 1 +}, +{ + "id": "3.317", + "value": 1 +}, +{ + "id": "3.289", + "value": 1 +}, +{ + "id": "3.285", + "value": 1 +}, +{ + "id": "3.261", + "value": 1 +}, +{ + "id": "3.257", + "value": 1 +}, +{ + "id": "3.249", + "value": 1 +}, +{ + "id": "3.237", + "value": 1 +}, +{ + "id": "3.213", + "value": 1 +}, +{ + "id": "3.189", + "value": 1 +}, +{ + "id": "3.165", + "value": 1 +}, +{ + "id": "3.153", + "value": 1 +}, +{ + "id": "3.141", + "value": 1 +}, +{ + "id": "3.129", + "value": 1 +}, +{ + "id": "3.117", + "value": 1 +}, +{ + "id": "3.114", + "value": 1 +}, +{ + "id": "3.093", + "value": 1 +}, +{ + "id": "3.069", + "value": 1 +}, +{ + "id": "3.033", + "value": 1 +}, +{ + "id": "2.953", + "value": 1 +}, +{ + "id": "2.949", + "value": 1 +}, +{ + "id": "2.925", + "value": 2 +}, +{ + "id": "2.923", + "value": 1 +}, +{ + "id": "2.913", + "value": 1 +}, +{ + "id": "2.901", + "value": 1 +}, +{ + "id": "2.889", + "value": 1 +}, +{ + "id": "2.854", + "value": 1 +}, +{ + "id": "2.829", + "value": 1 +}, +{ + "id": "2.805", + "value": 1 +}, +{ + "id": "2.769", + "value": 2 +}, +{ + "id": "2.757", + "value": 1 +}, +{ + "id": "2.749", + "value": 1 +}, +{ + "id": "2.726", + "value": 1 +}, +{ + "id": "2.725", + "value": 1 +}, +{ + "id": "2.717", + "value": 1 +}, +{ + "id": "2.685", + "value": 1 +}, +{ + "id": "2.684", + "value": 1 +}, +{ + "id": "2.673", + "value": 1 +}, +{ + "id": "2.651", + "value": 1 +}, +{ + "id": "2.617", + "value": 1 +}, +{ + "id": "2.589", + "value": 1 +}, +{ + "id": "2.577", + "value": 1 +}, +{ + "id": "2.573", + "value": 1 +}, +{ + "id": "2.553", + "value": 1 +}, +{ + "id": "2.525", + "value": 1 +}, +{ + "id": "2.505", + "value": 1 +}, +{ + "id": "2.386", + "value": 1 +}, +{ + "id": "2.361", + "value": 1 +}, +{ + "id": "2.349", + "value": 1 +}, +{ + "id": "2.229", + "value": 1 +}, +{ + "id": "2.062", + "value": 4 +}, +{ + "id": "2.033", + "value": 3 +}, +{ + "id": "2.029", + "value": 4 +}, +{ + "id": "2.025", + "value": 15 +}, +{ + "id": "2.021", + "value": 26 +}, +{ + "id": "2.019", + "value": 1 +}, +{ + "id": "2.017", + "value": 10 +}, +{ + "id": "2.016", + "value": 3 +}, +{ + "id": "2.013", + "value": 31 +}, +{ + "id": "10", + "value": 25 +}] diff --git a/packages/analytics/test/tests.js b/packages/analytics/test/tests.js index 6181111b..6a5a1be8 100644 --- a/packages/analytics/test/tests.js +++ b/packages/analytics/test/tests.js @@ -2,6 +2,8 @@ const assert = require('assert'); const from = require('from'); const ezs = require('../../core/src'); +const data01 = require('./data01.json'); + ezs.use(require('../src')); describe('test', () => { @@ -564,6 +566,21 @@ describe('test', () => { }); }); + it('distribute #5', (done) => { + const res = []; + from(data01) + .pipe(ezs('groupingByModulo', { modulo: 1 })) + .pipe(ezs('summing')) + .pipe(ezs('distribute', { step: 1, start: 1 })) + .on('data', (chunk) => { + res.push(chunk); + }) + .on('end', () => { + assert.equal(10, res.length); + done(); + }); + }); + it('greater #1', (done) => { const res = []; from([