diff --git a/docs/plugin-analytics.md b/docs/plugin-analytics.md index f08218c5..bc1e5b03 100644 --- a/docs/plugin-analytics.md +++ b/docs/plugin-analytics.md @@ -16,101 +16,39 @@ npm install @ezs/analytics #### Table of Contents -- [keys](#keys) -- [count](#count) - [output](#output) -- [slice](#slice) -- [value](#value) -- [drop](#drop) -- [graph](#graph) -- [maximizing](#maximizing) -- [pair](#pair) -- [pluck](#pluck) - [topics](#topics) -- [exploding](#exploding) -- [summing](#summing) -- [less](#less) - [minimizing](#minimizing) -- [groupingByEquality](#groupingbyequality) -- [distribute](#distribute) -- [groupingByHamming](#groupingbyhamming) -- [groupingByLevenshtein](#groupingbylevenshtein) +- [maximizing](#maximizing) - [groupingByModulo](#groupingbymodulo) - [reducing](#reducing) - [aggregate](#aggregate) -- [sort](#sort) +- [slice](#slice) - [distinct](#distinct) +- [exploding](#exploding) +- [graph](#graph) +- [pair](#pair) - [merging](#merging) +- [summing](#summing) - [filter](#filter) +- [value](#value) - [greater](#greater) +- [pluck](#pluck) +- [drop](#drop) +- [groupingByHamming](#groupingbyhamming) +- [groupingByLevenshtein](#groupingbylevenshtein) +- [keys](#keys) +- [groupingByEquality](#groupingbyequality) - [multiply](#multiply) +- [less](#less) +- [count](#count) +- [distribute](#distribute) +- [sort](#sort) - [distance](#distance) - [segment](#segment) - [tune](#tune) - [statistics](#statistics) -### keys - -Take `Object` and throws all its keys - -```json -[{ -}] -``` - -Script: - -```ini -[use] -plugin = analytics - -[keys] -``` - -Output: - -```json -[ -] -``` - -#### Parameters - -- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** - -Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** - -### count - -Take `Object` object getting some fields with json path, and do ... - -```json -[{ -}] -``` - -Script: - -```ini -[use] -plugin = analytics - -[count] -``` - -Output: - -```json -[ -] -``` - -#### Parameters - -- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** - -Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** - ### output Format the output with data a meta @@ -157,10 +95,9 @@ Output Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** -### slice +### topics -Take `Object` and throw the same object only if it is in the section of the -stream between start and start + size. stream is numbered from 1 +Take `Object` and take values with [value] path (must be an array) ```json [{ @@ -173,7 +110,7 @@ Script: [use] plugin = analytics -[drop] +[topics] ``` Output: @@ -185,14 +122,15 @@ Output: #### Parameters -- `start` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** start of the slice (optional, default `0`) -- `size` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** size of the slice (optional, default `10`) +- `id` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for id (optional, default `id`) +- `value` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for value (optional, default `value`) Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** -### value +### minimizing -Take `Object` object and getting the value field +Take special `Object` like `{id, value}` and replace `value` with the min of +`value`s ```json [{ @@ -205,7 +143,7 @@ Script: [use] plugin = analytics -[value] +[drop] ``` Output: @@ -217,17 +155,21 @@ Output: #### Parameters -- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the pah of the value field (optional, default `value`) +- `id` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for id (optional, default `id`) +- `value` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for value (optional, default `value`) Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** -### drop +### maximizing -Take `Object` and throw the same object only if there the value of the select field is not equals than a value +Take special `Object` like `{id, value}` and replace `value` with the max of `value`s ```json -[{ -}] +[ + { id: 'toul', value: [1, 2, 3] }, + { id: 'nancy', value: [2, 3, 4] }, + { id: 'neufchateau', value: [3, 4, 5] }, +] ``` Script: @@ -236,26 +178,30 @@ Script: [use] plugin = analytics -[drop] +[maximizing] ``` Output: ```json [ + { "id": "toul", "value": 3 }, + { "id": "nancy", "value": 4 }, + { "id": "neufchateau", "value": 5 } ] ``` #### Parameters -- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path of the field to compare (optional, default `"value"`) -- `if` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** value to compare (optional, default `""`) +- `id` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for id (optional, default `id`) +- `value` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for value (optional, default `value`) Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** -### graph +### groupingByModulo -Take `Object` object getting some fields with json path, and do ... +Take `Object` like `{ id, value }` and reduce all `value`s with the same +modulo computation in a ansingle object ```json [{ @@ -268,7 +214,7 @@ Script: [use] plugin = analytics -[graph] +[groupingByModulo] ``` Output: @@ -280,16 +226,21 @@ Output: #### Parameters -- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** +- `id` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for id (optional, default `id`) +- `value` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for value (optional, default `value`) Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** -### maximizing +### reducing -Take special `Object` like `{id, value}` and replace `value` with the max of `value`s +Take `Object` group value of `{ id, value }` objectpath ```json [{ + { id: 'x', value: 2 }, + { id: 't', value: 2 }, + { id: 'x', value: 3 }, + { id: 'x', value: 5 }, }] ``` @@ -299,13 +250,15 @@ Script: [use] plugin = analytics -[maximizing] +[reducing] ``` Output: ```json [ + { id: 'x', value: [2, 3, 5] }, + { id: 't', value: [2] }, ] ``` @@ -316,12 +269,16 @@ Output: Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** -### pair +### aggregate -Take `Object` object getting some fields with json path, and do ... +Aggregate by id and count ```json [{ + { id: 'x', value: 2 }, + { id: 't', value: 2 }, + { id: 'x', value: 3 }, + { id: 'x', value: 5 }, }] ``` @@ -331,29 +288,41 @@ Script: [use] plugin = analytics -[pair] +[aggregate] +path = id ``` Output: ```json [ + { id: 'x', value: [ 2, 3, 5] }, + { id: 't', value: [ 2 ] }, ] ``` #### Parameters -- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** +- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for id (optional, default `id`) +- `value` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for value (if not found 1 is the default value) (optional, default `value`) Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** -### pluck +### slice -Take `Object` object getting value of fields (with json `path`) and throws an -object for each value +Take `Object` and throw the same object only if it is in the section of the +stream between start and start + size. stream is numbered from 1 ```json [{ + { id: 2000, value: 1 }, + { id: 2001, value: 2 }, + { id: 2003, value: 3 }, + { id: 2005, value: 4 }, + { id: 2007, value: 5 }, + { id: 2009, value: 6 }, + { id: 2011, value: 7 }, + { id: 2013, value: 8 }, }] ``` @@ -363,28 +332,36 @@ Script: [use] plugin = analytics -[pluck] +[drop] ``` Output: ```json [ +{ "id": 2001, "value": 2 }, +{ "id": 2003, "value": 3 }, ] ``` #### Parameters -- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use form group by (optional, default `id`) +- `start` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** start of the slice (optional, default `0`) +- `size` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** size of the slice (optional, default `10`) Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** -### topics +### distinct -Take `Object` and take values with [value] path (must be an array) +Take `Object` object getting some fields with json path, and do ... ```json [{ + { a: 'x', b: 'z' }, + { a: 't', b: 'z' }, + { a: 't', b: 'z' }, + { a: 'x', b: 'z' }, + { a: 'x', b: 'z' }, }] ``` @@ -394,20 +371,25 @@ Script: [use] plugin = analytics -[topics] +[distinct] +path = a ``` Output: ```json [ + { id: 'x', value: 1 }, + { id: 't', value: 1 }, + { id: 't', value: 1 }, + { id: 'x', value: 1 }, + { id: 'x', value: 1 }, ] ``` #### Parameters -- `id` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for id (optional, default `id`) -- `value` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for value (optional, default `value`) +- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path (optional, default `"id"`) Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** @@ -417,7 +399,10 @@ Take `Object` and take values with [value] path (must be an array) and throw object of each value. The new object is build with [id] and eac value. ```json -[{ +[ + { departure: ['tokyo', 'nancy'], arrival: 'toul' }, + { departure: ['paris', 'nancy'], arrival: 'toul' }, + { departure: ['london', 'berlin'], arrival: 'toul' }, }] ``` @@ -434,6 +419,12 @@ Output: ```json [ + { "id": "toul", "value": "tokyo" }, + { "id": "toul", "value": "nancy" }, + { "id": "toul", "value": "paris" }, + { "id": "toul", "value": "nancy" }, + { "id": "toul", "value": "london" }, + { "id": "toul", "value": "berlin" } ] ``` @@ -444,13 +435,15 @@ Output: Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** -### summing +### graph -Take special `Object` like `{id, value}` and replace `value` with the sum of -`value`s +Take `Object` and throw a new special object (id, value) for each combination of values ```json -[{ +[ + { cities: ['berlin', 'nancy', 'toul'] }, + { cities: ['paris', 'nancy', 'toul']}, + { cities: ['paris', 'berlin', 'toul'] }, }] ``` @@ -460,31 +453,40 @@ Script: [use] plugin = analytics -[summing] +[graph] +path = cities ``` Output: ```json [ + { "id": [ "berlin", "nancy" ], "value": 1 }, + { "id": [ "berlin", "toul" ], "value": 2 }, + { "id": [ "nancy", "toul" ], "value": 2 }, + { "id": [ "nancy", "paris" ], "value": 1 }, + { "id": [ "paris", "toul" ], "value": 2 }, + { "id": [ "berlin", "paris" ], "value": 1 } ] ``` #### Parameters -- `id` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for id (optional, default `id`) -- `value` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for value (optional, default `value`) +- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** -### less +### pair -Take `Object` and throw the same object only if the value of the selected -field is less (or equal) than a value +Take `Object` object getting some fields with json path, and +throw all pair of value from two fields ```json -[{ -}] +[ + { departure: ['tokyo', 'nancy'], arrival: 'toul' }, + { departure: ['paris', 'nancy'], arrival: 'toul' }, + { departure: ['london', 'berlin'], arrival: 'toul' }, +] ``` Script: @@ -493,28 +495,33 @@ Script: [use] plugin = analytics -[less] +[pair] +path = departure +path = arrival ``` Output: ```json [ + { "id": [ "tokyo", "toul" ], "value": 1 }, +{ "id": [ "nancy", "toul" ], "value": 1 }, +{ "id": [ "paris", "toul" ], "value": 1 }, + { "id": [ "nancy", "toul" ], "value": 1 }, + { "id": [ "london", "toul" ], "value": 1 }, + { "id": [ "berlin", "toul" ], "value": 1 } ] ``` #### Parameters -- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path of the field to compare (optional, default `value`) -- `than` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** value to compare (optional, default `0`) -- `strict` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** less than but not equal (optional, default `false`) +- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** -### minimizing +### merging -Take special `Object` like `{id, value}` and replace `value` with the min of -`value`s +Take special `Object` like `{id, value}` and replace `value` with the merge of `value`s ```json [{ @@ -527,7 +534,7 @@ Script: [use] plugin = analytics -[drop] +[merging] ``` Output: @@ -544,14 +551,17 @@ Output: Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** -### groupingByEquality +### summing -Take `Object` like `{ id, value }` and reduce all values with the same `id` -in a single object +Take special `Object` like `{id, value}` and replace `value` with the sum of +`value`s ```json -[{ -}] +[ + { "id": "A", "value": [1, 1, 1] }, + { "id": "B", "value": [1] }, + { "id": "C", "value": [1, 1, 1, 1] }, +] ``` Script: @@ -560,14 +570,23 @@ Script: [use] plugin = analytics -[groupingByEquality] +[summing] ``` Output: ```json -[ -] +[{ + "id": "A", "value": 3 +}, +{ + "id": "B", + "value": 1 +}, +{ + "id": "C", + "value": 4 +}] ``` #### Parameters @@ -577,13 +596,67 @@ Output: Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** -### distribute +### filter -Take `Object` like { id, value } and throw a serie of number value +Take `Object` and throw the same object only if there the value of the select field is equals than a value + +- ```json + [ + { id: 2000, value: 1 }, + { id: 2001, value: 2 }, + { id: 2003, value: 3 }, + { id: 2005, value: 4 }, + { id: 2007, value: 5 }, + { id: 2003, value: 3 }, + { id: 2011, value: 7 }, + { id: 2013, value: 8 }, + ] + ``` + + + Script: + + ```ini + [use] + plugin = analytics + + [filter] + path = id + if = 2003 + if = 2013 + +Output: ```json -[{ -}] + [ + { id: 2003, value: 3 }, + { id: 2003, value: 3 }, + { id: 2013, value: 8 }, + ] +``` + +#### Parameters + +- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path of the field to compare (optional, default `"value"`) +- `if` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** value to compare (optional, default `""`) + +Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** + +### value + +Take `Object` object and getting the value field + +```json +[ + { id: 2000, value: 1 }, + { id: 2001, value: 2 }, + { id: 2003, value: 3 }, + { id: 2005, value: 4 }, + { id: 2007, value: 5 }, + { id: 2009, value: 6 }, + { id: 2011, value: 7 }, + { id: 2013, value: 8 }, +] ``` Script: @@ -592,35 +665,47 @@ Script: [use] plugin = analytics -[distribute] +[value] +path = id ``` Output: ```json [ +2000, +2001, +2003, +2005, +2007, +2009, +2011, +2013 ] ``` #### Parameters -- `id` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for id (optional, default `"id"`) -- `value` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for value (optional, default `"value"`) -- `step` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** step between each valut (optional, default `1`) -- `start` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** first value to throw (optional, default `minvalueinthestream`) -- `size` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** size of the distribution (optional, default `(maxvalue-minvalue)inthestream`) -- `default` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** default value for missing object (optional, default `0`) +- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the pah of the value field (optional, default `value`) Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** -### groupingByHamming +### greater -Take `Object` like `{ id, value }` and reduce all `value` with `id` which -have the same Hamming distance in a single object +Take `Object` and throw the same object only if the value of the selected +field is greater (or equal) than a value ```json -[{ -}] +[ + { id: 2000, value: 1 }, + { id: 2001, value: 2 }, + { id: 2003, value: 3 }, + { id: 2005, value: 4 }, + { id: 2007, value: 5 }, + { id: 2009, value: 6 }, + { id: 2011, value: 7 }, + { id: 2013, value: 8 }, +] ``` Script: @@ -629,65 +714,99 @@ Script: [use] plugin = analytics -[groupingByHamming] +[greater] +than = 3 +strict = true ``` Output: ```json [ + { id: 2005, value: 4 }, + { id: 2007, value: 5 }, + { id: 2009, value: 6 }, + { id: 2011, value: 7 }, + { id: 2013, value: 8 }, ] ``` #### Parameters -- `id` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for id (optional, default `"id"`) -- `value` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for value (optional, default `"value"`) +- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path of the field to compare (optional, default `"value"`) +- `than` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** value to compare (optional, default `0`) +- `strict` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** greater than but not equal (optional, default `false`) Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** -### groupingByLevenshtein - -Take `Object` like `{ id, value }` and reduce all `value`s with -`id` which have the same Levenshtein distance in a single object +### pluck -- ```json - [{ - }] - ``` +Take `Object` object getting value of fields (with json `path`) and throws an +object for each value +```json +[ + { city: 'tokyo', year: 2000, count: 1 }, + { city: 'paris', year: 2001, count: 2 }, + { city: 'london', year: 2003, count: 3 }, + { city: 'nancy', year: 2005, count: 4 }, + { city: 'berlin', year: 2007, count: 5 }, + { city: 'madrid', year: 2009, count: 6 }, + { city: 'stockholm', year: 2011, count: 7 }, + { city: 'bruxelles', year: 2013, count: 8 }, +] +``` - Script: +Script: - ```ini - [use] - plugin = analytics +```ini +[use] +plugin = analytics - [groupingByLevenshtein] +[pluck] +path = year +``` Output: ```json [ +{ "id": "year", "value": 2000 }, +{ "id": "year", "value": 2001 }, +{ "id": "year", "value": 2003 }, +{ "id": "year", "value": 2005 }, +{ "id": "year", "value": 2007 }, +{ "id": "year", "value": 2009 }, +{ "id": "year", "value": 2011 }, +{ "id": "year", "value": 2013 } ] ``` #### Parameters -- `id` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for id (optional, default `id`) -- `value` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for value (optional, default `value`) -- `distance` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** minimal levenshtein distance to have a same id (optional, default `1`) +- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use form group by (optional, default `id`) Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** -### groupingByModulo +### drop -Take `Object` like `{ id, value }` and reduce all `value`s with the same -modulo computation in a ansingle object +Take `Object` and throw the same object only if there the value of the select field is not equals than a value ```json -[{ -}] +[ + { + "departure": "nancy", + "arrival": "paris", + }, + { + "departure": "nancy", + "arrival": "toul", + }, + { + "departure": "paris", + "arrival": "londre", + } +] ``` Script: @@ -696,34 +815,92 @@ Script: [use] plugin = analytics -[groupingByModulo] +[drop] ``` Output: +```json +[{ + "departure": "nancy", + "arrival": "paris" +}, +{ + "departure": "nancy", + "arrival": "toul" +}] +``` + +#### Parameters + +- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path of the field to compare (optional, default `"value"`) +- `if` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** value to compare (optional, default `""`) + +Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** + +### groupingByHamming + +Take `Object` like `{ id, value }` and reduce all `value` with `id` which +have the same Hamming distance in a single object + +- ```json + [ + { "id": "lorem", "value": 1 }, + { "id": "Lorem", "value": 1 }, + { "id": "loren", "value": 1 }, + { "id": "korem", "value": 1 }, + { "id": "olrem", "value": 1 }, + { "id": "toto", "value": 1 }, + { "id": "titi", "value": 1 }, + { "id": "lorem", "value": 1 } + ] + ``` + + + Script: + + ```ini + [use] + plugin = analytics + + [groupingByHamming] + distance = 1 + + [summing] + +Output: + ```json [ + { "id": [ "lorem", "Lorem", "loren", "korem" ], "value": 5 }, + { "id": [ "olrem" ], "value": 1 }, + { "id": [ "toto", "titi" ], "value": 2 } ] ``` #### Parameters -- `id` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for id (optional, default `id`) -- `value` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for value (optional, default `value`) +- `id` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for id (optional, default `"id"`) +- `value` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for value (optional, default `"value"`) Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** -### reducing +### groupingByLevenshtein -Take `Object` group value of `{ id, value }` objectpath +Take `Object` like `{ id, value }` and reduce all `value`s with +`id` which have the same Levenshtein distance in a single object ```json -[{ - { id: 'x', value: 2 }, - { id: 't', value: 2 }, - { id: 'x', value: 3 }, - { id: 'x', value: 5 }, -}] +[ + { "id": "lorem", "value": 1 }, + { "id": "Lorem", "value": 1 }, + { "id": "loren", "value": 1 }, + { "id": "korem", "value": 1 }, + { "id": "olrem", "value": 1 }, + { "id": "toto", "value": 1 }, + { "id": "titi", "value": 1 }, + { "id": "lorem", "value": 1 } +] ``` Script: @@ -732,15 +909,18 @@ Script: [use] plugin = analytics -[reducing] +[groupingByLevenshtein] +distance = 2 + +[summing] ``` Output: ```json [ - { id: 'x', value: [2, 3, 5] }, - { id: 't', value: [2] }, + { "id": [ "lorem", "Lorem", "loren", "korem", "olrem" ], "value": 6 }, + { "id": [ "toto", "titi" ], "value": 2 } ] ``` @@ -748,20 +928,25 @@ Output: - `id` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for id (optional, default `id`) - `value` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for value (optional, default `value`) +- `distance` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** minimal levenshtein distance to have a same id (optional, default `1`) Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** -### aggregate +### keys -Aggregate by id and count +Take `Object` and throws all its keys ```json -[{ - { id: 'x', value: 2 }, - { id: 't', value: 2 }, - { id: 'x', value: 3 }, - { id: 'x', value: 5 }, -}] +[ + { city: 'tokyo', year: 2000, count: 1 }, + { city: 'paris', year: 2001, count: 2 }, + { city: 'london', year: 2003, count: 3 }, + { city: 'nancy', year: 2005, count: 4 }, + { city: 'berlin', year: 2007, count: 5 }, + { city: 'madrid', year: 2009, count: 6 }, + { city: 'stockholm', year: 2011, count: 7 }, + { city: 'bruxelles', year: 2013, count: 8 }, +] ``` Script: @@ -770,33 +955,52 @@ Script: [use] plugin = analytics +[keys] [aggregate] -path = id +[summing] ``` Output: ```json [ - { id: 'x', value: [ 2, 3, 5] }, - { id: 't', value: [ 2 ] }, +{ + "id": "city", + "value": 8 +}, +{ + "id": "year", + "value": 8 +}, +{ + "id": "count", + "value": 8 +}⏎ ] ``` #### Parameters -- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for id (optional, default `id`) -- `value` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for value (if not found 1 is the default value) (optional, default `value`) +- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** -### sort +### groupingByEquality -Take all `Object` and sort them with dedicated key +Take `Object` like `{ id, value }` and reduce all values with the same `id` +in a single object ```json -[{ -}] +[ + { "id": "lorem", "value": 1 }, + { "id": "Lorem", "value": 1 }, + { "id": "loren", "value": 1 }, + { "id": "korem", "value": 1 }, + { "id": "olrem", "value": 1 }, + { "id": "toto", "value": 1 }, + { "id": "titi", "value": 1 }, + { "id": "lorem", "value": 1 } +] ``` Script: @@ -805,33 +1009,41 @@ Script: [use] plugin = analytics -[sort] +[groupingByEquality] + +[summing] ``` Output: ```json [ + { "id": [ "lorem" ], "value": 2 }, + { "id": [ "Lorem" ], "value": 1 }, + { "id": [ "loren" ], "value": 1 }, + { "id": [ "korem" ], "value": 1 }, + { "id": [ "olrem" ], "value": 1 }, + { "id": [ "toto" ], "value": 1 }, + { "id": [ "titi" ], "value": 1 } ] ``` #### Parameters -- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for id (optional, default `id`) +- `id` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for id (optional, default `id`) +- `value` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for value (optional, default `value`) Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** -### distinct +### multiply -Take `Object` object getting some fields with json path, and do ... +Take `Object` and throw the same object only if there the value of the select field is equals than a value +Input file: ```json [{ - { a: 'x', b: 'z' }, - { a: 't', b: 'z' }, - { a: 't', b: 'z' }, - { a: 'x', b: 'z' }, - { a: 'x', b: 'z' }, + a: 1, + b: 2, }] ``` @@ -841,34 +1053,56 @@ Script: [use] plugin = analytics -[distinct] -path = a +[multiply] +path = factor +value = X +value = Y +value = Z ``` Output: ```json -[ - { id: 'x', value: 1 }, - { id: 't', value: 1 }, - { id: 't', value: 1 }, - { id: 'x', value: 1 }, - { id: 'x', value: 1 }, +[{ + a: 1, + b: 2, + factor: X +}, +{ + a: 1, + b: 2, + factor: Y +}, +{ + a: 1, + b: 2, + factor: Z +}, ] ``` #### Parameters -- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path (optional, default `"id"`) +- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path of the field to add (optional, default `"factor"`) +- `value` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** value(s) to set factor field (optional, default `""`) Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** -### merging +### less -Take special `Object` like `{id, value}` and replace `value` with the merge of `value`s +Take `Object` and throw the same object only if the value of the selected +field is less (or equal) than a value ```json [{ + { id: 2000, value: 1 }, + { id: 2001, value: 2 }, + { id: 2003, value: 3 }, + { id: 2005, value: 4 }, + { id: 2007, value: 5 }, + { id: 2009, value: 6 }, + { id: 2011, value: 7 }, + { id: 2013, value: 8 }, }] ``` @@ -878,76 +1112,106 @@ Script: [use] plugin = analytics -[merging] +[less] +path = value +than = 4 ``` Output: ```json -[ -] +[{ + "id": 2000, + "value": 1 +}, +{ + "id": 2001, + "value": 2 +}, +{ + "id": 2003, + "value": 3 +}, +{ + "id": 2005, + "value": 4 +}] ``` #### Parameters -- `id` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for id (optional, default `id`) -- `value` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for value (optional, default `value`) +- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path of the field to compare (optional, default `value`) +- `than` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** value to compare (optional, default `0`) +- `strict` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** less than but not equal (optional, default `false`) Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** -### filter +### count -Take `Object` and throw the same object only if there the value of the select field is equals than a value +Take `Object` and throw special `Object` like `{id, value}` if key(s) was found +id is the key, value is equal to 1 (if found) -- ```json - [ - { id: 2000, value: 1 }, - { id: 2001, value: 2 }, - { id: 2003, value: 3 }, - { id: 2005, value: 4 }, - { id: 2007, value: 5 }, - { id: 2003, value: 3 }, - { id: 2011, value: 7 }, - { id: 2013, value: 8 }, - ] - ``` +```json +[ + { + "a": "nancy", + "b": "lucy", + "c": "geny", + }, + { + "a": "lorem", + "b": "loret", + }, + { + "a": "fred", + } +] +``` +Script: - Script: +```ini +[use] +plugin = analytics - ```ini - [use] - plugin = analytics +[count] +path = a +path = b +path = c - [filter] - path = id - if = 2003 - if = 2013 +[aggregate] +[summing] +``` Output: ```json - [ - { id: 2003, value: 3 }, - { id: 2003, value: 3 }, - { id: 2013, value: 8 }, - ] +[{ + "id": "a", + "value": 3 +}, +{ + "id": "b", + "value": 2 +}, +{ + "id": "c", + "value": 1 +}] ``` #### Parameters -- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path of the field to compare (optional, default `"value"`) -- `if` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** value to compare (optional, default `""`) +- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** -### greater +### distribute -Take `Object` and throw the same object only if the value of the selected -field is greater (or equal) than a value +Take `Object` like { id, value } and throw a serie of number value ```json -[{ +[ { id: 2000, value: 1 }, { id: 2001, value: 2 }, { id: 2003, value: 3 }, @@ -956,7 +1220,7 @@ field is greater (or equal) than a value { id: 2009, value: 6 }, { id: 2011, value: 7 }, { id: 2013, value: 8 }, -}] +] ``` Script: @@ -965,40 +1229,55 @@ Script: [use] plugin = analytics -[greater] -than = 3 -strict = true +[distribute] ``` Output: ```json [ - { id: 2005, value: 4 }, - { id: 2007, value: 5 }, - { id: 2009, value: 6 }, - { id: 2011, value: 7 }, - { id: 2013, value: 8 }, + { "id": 2000, "value": 1 }, + { "id": 2001, "value": 2 }, + { "id": 2002, "value": 0 }, + { "id": 2003, "value": 3 }, + { "id": 2004, "value": 0 }, + { "id": 2005, "value": 4 }, + { "id": 2006, "value": 0 }, + { "id": 2007, "value": 5 }, + { "id": 2008, "value": 0 }, + { "id": 2009, "value": 6 }, + { "id": 2010, "value": 0 }, + { "id": 2011, "value": 7 }, + { "id": 2012, "value": 0 }, + { "id": 2013, "value": 8 } ] ``` #### Parameters -- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path of the field to compare (optional, default `"value"`) -- `than` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** value to compare (optional, default `0`) -- `strict` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** greater than but not equal (optional, default `false`) +- `id` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for id (optional, default `"id"`) +- `value` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for value (optional, default `"value"`) +- `step` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** step between each value (optional, default `1`) +- `start` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** first value to throw (optional, default `minvalueinthestream`) +- `size` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** size of the distribution (optional, default `(maxvalue-minvalue)inthestream`) +- `default` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** default value for missing object (optional, default `0`) Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** -### multiply +### sort -Take `Object` and throw the same object only if there the value of the select field is equals than a value -Input file: +Take all `Object` and sort them with dedicated key ```json [{ - a: 1, - b: 2, + { id: 2000, value: 1 }, + { id: 2001, value: 2 }, + { id: 2003, value: 3 }, + { id: 2005, value: 4 }, + { id: 2007, value: 5 }, + { id: 2009, value: 6 }, + { id: 2011, value: 7 }, + { id: 2013, value: 8 }, }] ``` @@ -1008,38 +1287,30 @@ Script: [use] plugin = analytics -[multiply] -path = factor -value = X -value = Y -value = Z +[sort] +path = value +reverse = true ``` Output: ```json -[{ - a: 1, - b: 2, - factor: X -}, -{ - a: 1, - b: 2, - factor: Y -}, -{ - a: 1, - b: 2, - factor: Z -}, +[ +{ "id": 2013, "value": 8 }, +{ "id": 2011, "value": 7 }, +{ "id": 2009, "value": 6 }, +{ "id": 2007, "value": 5 }, +{ "id": 2005, "value": 4 }, +{ "id": 2003, "value": 3 }, +{ "id": 2001, "value": 2 }, +{ "id": 2000, "value": 1 } ] ``` #### Parameters -- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path of the field to add (optional, default `"factor"`) -- `value` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** value(s) to set factor field (optional, default `""`) +- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for id (optional, default `id`) +- `reverse` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** reverser order (optional, default `false`) Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** diff --git a/packages/analytics/README.md b/packages/analytics/README.md index f08218c5..bc1e5b03 100644 --- a/packages/analytics/README.md +++ b/packages/analytics/README.md @@ -16,101 +16,39 @@ npm install @ezs/analytics #### Table of Contents -- [keys](#keys) -- [count](#count) - [output](#output) -- [slice](#slice) -- [value](#value) -- [drop](#drop) -- [graph](#graph) -- [maximizing](#maximizing) -- [pair](#pair) -- [pluck](#pluck) - [topics](#topics) -- [exploding](#exploding) -- [summing](#summing) -- [less](#less) - [minimizing](#minimizing) -- [groupingByEquality](#groupingbyequality) -- [distribute](#distribute) -- [groupingByHamming](#groupingbyhamming) -- [groupingByLevenshtein](#groupingbylevenshtein) +- [maximizing](#maximizing) - [groupingByModulo](#groupingbymodulo) - [reducing](#reducing) - [aggregate](#aggregate) -- [sort](#sort) +- [slice](#slice) - [distinct](#distinct) +- [exploding](#exploding) +- [graph](#graph) +- [pair](#pair) - [merging](#merging) +- [summing](#summing) - [filter](#filter) +- [value](#value) - [greater](#greater) +- [pluck](#pluck) +- [drop](#drop) +- [groupingByHamming](#groupingbyhamming) +- [groupingByLevenshtein](#groupingbylevenshtein) +- [keys](#keys) +- [groupingByEquality](#groupingbyequality) - [multiply](#multiply) +- [less](#less) +- [count](#count) +- [distribute](#distribute) +- [sort](#sort) - [distance](#distance) - [segment](#segment) - [tune](#tune) - [statistics](#statistics) -### keys - -Take `Object` and throws all its keys - -```json -[{ -}] -``` - -Script: - -```ini -[use] -plugin = analytics - -[keys] -``` - -Output: - -```json -[ -] -``` - -#### Parameters - -- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** - -Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** - -### count - -Take `Object` object getting some fields with json path, and do ... - -```json -[{ -}] -``` - -Script: - -```ini -[use] -plugin = analytics - -[count] -``` - -Output: - -```json -[ -] -``` - -#### Parameters - -- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** - -Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** - ### output Format the output with data a meta @@ -157,10 +95,9 @@ Output Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** -### slice +### topics -Take `Object` and throw the same object only if it is in the section of the -stream between start and start + size. stream is numbered from 1 +Take `Object` and take values with [value] path (must be an array) ```json [{ @@ -173,7 +110,7 @@ Script: [use] plugin = analytics -[drop] +[topics] ``` Output: @@ -185,14 +122,15 @@ Output: #### Parameters -- `start` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** start of the slice (optional, default `0`) -- `size` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** size of the slice (optional, default `10`) +- `id` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for id (optional, default `id`) +- `value` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for value (optional, default `value`) Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** -### value +### minimizing -Take `Object` object and getting the value field +Take special `Object` like `{id, value}` and replace `value` with the min of +`value`s ```json [{ @@ -205,7 +143,7 @@ Script: [use] plugin = analytics -[value] +[drop] ``` Output: @@ -217,17 +155,21 @@ Output: #### Parameters -- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the pah of the value field (optional, default `value`) +- `id` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for id (optional, default `id`) +- `value` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for value (optional, default `value`) Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** -### drop +### maximizing -Take `Object` and throw the same object only if there the value of the select field is not equals than a value +Take special `Object` like `{id, value}` and replace `value` with the max of `value`s ```json -[{ -}] +[ + { id: 'toul', value: [1, 2, 3] }, + { id: 'nancy', value: [2, 3, 4] }, + { id: 'neufchateau', value: [3, 4, 5] }, +] ``` Script: @@ -236,26 +178,30 @@ Script: [use] plugin = analytics -[drop] +[maximizing] ``` Output: ```json [ + { "id": "toul", "value": 3 }, + { "id": "nancy", "value": 4 }, + { "id": "neufchateau", "value": 5 } ] ``` #### Parameters -- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path of the field to compare (optional, default `"value"`) -- `if` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** value to compare (optional, default `""`) +- `id` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for id (optional, default `id`) +- `value` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for value (optional, default `value`) Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** -### graph +### groupingByModulo -Take `Object` object getting some fields with json path, and do ... +Take `Object` like `{ id, value }` and reduce all `value`s with the same +modulo computation in a ansingle object ```json [{ @@ -268,7 +214,7 @@ Script: [use] plugin = analytics -[graph] +[groupingByModulo] ``` Output: @@ -280,16 +226,21 @@ Output: #### Parameters -- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** +- `id` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for id (optional, default `id`) +- `value` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for value (optional, default `value`) Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** -### maximizing +### reducing -Take special `Object` like `{id, value}` and replace `value` with the max of `value`s +Take `Object` group value of `{ id, value }` objectpath ```json [{ + { id: 'x', value: 2 }, + { id: 't', value: 2 }, + { id: 'x', value: 3 }, + { id: 'x', value: 5 }, }] ``` @@ -299,13 +250,15 @@ Script: [use] plugin = analytics -[maximizing] +[reducing] ``` Output: ```json [ + { id: 'x', value: [2, 3, 5] }, + { id: 't', value: [2] }, ] ``` @@ -316,12 +269,16 @@ Output: Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** -### pair +### aggregate -Take `Object` object getting some fields with json path, and do ... +Aggregate by id and count ```json [{ + { id: 'x', value: 2 }, + { id: 't', value: 2 }, + { id: 'x', value: 3 }, + { id: 'x', value: 5 }, }] ``` @@ -331,29 +288,41 @@ Script: [use] plugin = analytics -[pair] +[aggregate] +path = id ``` Output: ```json [ + { id: 'x', value: [ 2, 3, 5] }, + { id: 't', value: [ 2 ] }, ] ``` #### Parameters -- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** +- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for id (optional, default `id`) +- `value` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for value (if not found 1 is the default value) (optional, default `value`) Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** -### pluck +### slice -Take `Object` object getting value of fields (with json `path`) and throws an -object for each value +Take `Object` and throw the same object only if it is in the section of the +stream between start and start + size. stream is numbered from 1 ```json [{ + { id: 2000, value: 1 }, + { id: 2001, value: 2 }, + { id: 2003, value: 3 }, + { id: 2005, value: 4 }, + { id: 2007, value: 5 }, + { id: 2009, value: 6 }, + { id: 2011, value: 7 }, + { id: 2013, value: 8 }, }] ``` @@ -363,28 +332,36 @@ Script: [use] plugin = analytics -[pluck] +[drop] ``` Output: ```json [ +{ "id": 2001, "value": 2 }, +{ "id": 2003, "value": 3 }, ] ``` #### Parameters -- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use form group by (optional, default `id`) +- `start` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** start of the slice (optional, default `0`) +- `size` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** size of the slice (optional, default `10`) Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** -### topics +### distinct -Take `Object` and take values with [value] path (must be an array) +Take `Object` object getting some fields with json path, and do ... ```json [{ + { a: 'x', b: 'z' }, + { a: 't', b: 'z' }, + { a: 't', b: 'z' }, + { a: 'x', b: 'z' }, + { a: 'x', b: 'z' }, }] ``` @@ -394,20 +371,25 @@ Script: [use] plugin = analytics -[topics] +[distinct] +path = a ``` Output: ```json [ + { id: 'x', value: 1 }, + { id: 't', value: 1 }, + { id: 't', value: 1 }, + { id: 'x', value: 1 }, + { id: 'x', value: 1 }, ] ``` #### Parameters -- `id` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for id (optional, default `id`) -- `value` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for value (optional, default `value`) +- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path (optional, default `"id"`) Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** @@ -417,7 +399,10 @@ Take `Object` and take values with [value] path (must be an array) and throw object of each value. The new object is build with [id] and eac value. ```json -[{ +[ + { departure: ['tokyo', 'nancy'], arrival: 'toul' }, + { departure: ['paris', 'nancy'], arrival: 'toul' }, + { departure: ['london', 'berlin'], arrival: 'toul' }, }] ``` @@ -434,6 +419,12 @@ Output: ```json [ + { "id": "toul", "value": "tokyo" }, + { "id": "toul", "value": "nancy" }, + { "id": "toul", "value": "paris" }, + { "id": "toul", "value": "nancy" }, + { "id": "toul", "value": "london" }, + { "id": "toul", "value": "berlin" } ] ``` @@ -444,13 +435,15 @@ Output: Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** -### summing +### graph -Take special `Object` like `{id, value}` and replace `value` with the sum of -`value`s +Take `Object` and throw a new special object (id, value) for each combination of values ```json -[{ +[ + { cities: ['berlin', 'nancy', 'toul'] }, + { cities: ['paris', 'nancy', 'toul']}, + { cities: ['paris', 'berlin', 'toul'] }, }] ``` @@ -460,31 +453,40 @@ Script: [use] plugin = analytics -[summing] +[graph] +path = cities ``` Output: ```json [ + { "id": [ "berlin", "nancy" ], "value": 1 }, + { "id": [ "berlin", "toul" ], "value": 2 }, + { "id": [ "nancy", "toul" ], "value": 2 }, + { "id": [ "nancy", "paris" ], "value": 1 }, + { "id": [ "paris", "toul" ], "value": 2 }, + { "id": [ "berlin", "paris" ], "value": 1 } ] ``` #### Parameters -- `id` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for id (optional, default `id`) -- `value` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for value (optional, default `value`) +- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** -### less +### pair -Take `Object` and throw the same object only if the value of the selected -field is less (or equal) than a value +Take `Object` object getting some fields with json path, and +throw all pair of value from two fields ```json -[{ -}] +[ + { departure: ['tokyo', 'nancy'], arrival: 'toul' }, + { departure: ['paris', 'nancy'], arrival: 'toul' }, + { departure: ['london', 'berlin'], arrival: 'toul' }, +] ``` Script: @@ -493,28 +495,33 @@ Script: [use] plugin = analytics -[less] +[pair] +path = departure +path = arrival ``` Output: ```json [ + { "id": [ "tokyo", "toul" ], "value": 1 }, +{ "id": [ "nancy", "toul" ], "value": 1 }, +{ "id": [ "paris", "toul" ], "value": 1 }, + { "id": [ "nancy", "toul" ], "value": 1 }, + { "id": [ "london", "toul" ], "value": 1 }, + { "id": [ "berlin", "toul" ], "value": 1 } ] ``` #### Parameters -- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path of the field to compare (optional, default `value`) -- `than` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** value to compare (optional, default `0`) -- `strict` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** less than but not equal (optional, default `false`) +- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** -### minimizing +### merging -Take special `Object` like `{id, value}` and replace `value` with the min of -`value`s +Take special `Object` like `{id, value}` and replace `value` with the merge of `value`s ```json [{ @@ -527,7 +534,7 @@ Script: [use] plugin = analytics -[drop] +[merging] ``` Output: @@ -544,14 +551,17 @@ Output: Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** -### groupingByEquality +### summing -Take `Object` like `{ id, value }` and reduce all values with the same `id` -in a single object +Take special `Object` like `{id, value}` and replace `value` with the sum of +`value`s ```json -[{ -}] +[ + { "id": "A", "value": [1, 1, 1] }, + { "id": "B", "value": [1] }, + { "id": "C", "value": [1, 1, 1, 1] }, +] ``` Script: @@ -560,14 +570,23 @@ Script: [use] plugin = analytics -[groupingByEquality] +[summing] ``` Output: ```json -[ -] +[{ + "id": "A", "value": 3 +}, +{ + "id": "B", + "value": 1 +}, +{ + "id": "C", + "value": 4 +}] ``` #### Parameters @@ -577,13 +596,67 @@ Output: Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** -### distribute +### filter -Take `Object` like { id, value } and throw a serie of number value +Take `Object` and throw the same object only if there the value of the select field is equals than a value + +- ```json + [ + { id: 2000, value: 1 }, + { id: 2001, value: 2 }, + { id: 2003, value: 3 }, + { id: 2005, value: 4 }, + { id: 2007, value: 5 }, + { id: 2003, value: 3 }, + { id: 2011, value: 7 }, + { id: 2013, value: 8 }, + ] + ``` + + + Script: + + ```ini + [use] + plugin = analytics + + [filter] + path = id + if = 2003 + if = 2013 + +Output: ```json -[{ -}] + [ + { id: 2003, value: 3 }, + { id: 2003, value: 3 }, + { id: 2013, value: 8 }, + ] +``` + +#### Parameters + +- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path of the field to compare (optional, default `"value"`) +- `if` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** value to compare (optional, default `""`) + +Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** + +### value + +Take `Object` object and getting the value field + +```json +[ + { id: 2000, value: 1 }, + { id: 2001, value: 2 }, + { id: 2003, value: 3 }, + { id: 2005, value: 4 }, + { id: 2007, value: 5 }, + { id: 2009, value: 6 }, + { id: 2011, value: 7 }, + { id: 2013, value: 8 }, +] ``` Script: @@ -592,35 +665,47 @@ Script: [use] plugin = analytics -[distribute] +[value] +path = id ``` Output: ```json [ +2000, +2001, +2003, +2005, +2007, +2009, +2011, +2013 ] ``` #### Parameters -- `id` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for id (optional, default `"id"`) -- `value` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for value (optional, default `"value"`) -- `step` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** step between each valut (optional, default `1`) -- `start` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** first value to throw (optional, default `minvalueinthestream`) -- `size` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** size of the distribution (optional, default `(maxvalue-minvalue)inthestream`) -- `default` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** default value for missing object (optional, default `0`) +- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the pah of the value field (optional, default `value`) Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** -### groupingByHamming +### greater -Take `Object` like `{ id, value }` and reduce all `value` with `id` which -have the same Hamming distance in a single object +Take `Object` and throw the same object only if the value of the selected +field is greater (or equal) than a value ```json -[{ -}] +[ + { id: 2000, value: 1 }, + { id: 2001, value: 2 }, + { id: 2003, value: 3 }, + { id: 2005, value: 4 }, + { id: 2007, value: 5 }, + { id: 2009, value: 6 }, + { id: 2011, value: 7 }, + { id: 2013, value: 8 }, +] ``` Script: @@ -629,65 +714,99 @@ Script: [use] plugin = analytics -[groupingByHamming] +[greater] +than = 3 +strict = true ``` Output: ```json [ + { id: 2005, value: 4 }, + { id: 2007, value: 5 }, + { id: 2009, value: 6 }, + { id: 2011, value: 7 }, + { id: 2013, value: 8 }, ] ``` #### Parameters -- `id` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for id (optional, default `"id"`) -- `value` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for value (optional, default `"value"`) +- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path of the field to compare (optional, default `"value"`) +- `than` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** value to compare (optional, default `0`) +- `strict` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** greater than but not equal (optional, default `false`) Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** -### groupingByLevenshtein - -Take `Object` like `{ id, value }` and reduce all `value`s with -`id` which have the same Levenshtein distance in a single object +### pluck -- ```json - [{ - }] - ``` +Take `Object` object getting value of fields (with json `path`) and throws an +object for each value +```json +[ + { city: 'tokyo', year: 2000, count: 1 }, + { city: 'paris', year: 2001, count: 2 }, + { city: 'london', year: 2003, count: 3 }, + { city: 'nancy', year: 2005, count: 4 }, + { city: 'berlin', year: 2007, count: 5 }, + { city: 'madrid', year: 2009, count: 6 }, + { city: 'stockholm', year: 2011, count: 7 }, + { city: 'bruxelles', year: 2013, count: 8 }, +] +``` - Script: +Script: - ```ini - [use] - plugin = analytics +```ini +[use] +plugin = analytics - [groupingByLevenshtein] +[pluck] +path = year +``` Output: ```json [ +{ "id": "year", "value": 2000 }, +{ "id": "year", "value": 2001 }, +{ "id": "year", "value": 2003 }, +{ "id": "year", "value": 2005 }, +{ "id": "year", "value": 2007 }, +{ "id": "year", "value": 2009 }, +{ "id": "year", "value": 2011 }, +{ "id": "year", "value": 2013 } ] ``` #### Parameters -- `id` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for id (optional, default `id`) -- `value` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for value (optional, default `value`) -- `distance` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** minimal levenshtein distance to have a same id (optional, default `1`) +- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use form group by (optional, default `id`) Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** -### groupingByModulo +### drop -Take `Object` like `{ id, value }` and reduce all `value`s with the same -modulo computation in a ansingle object +Take `Object` and throw the same object only if there the value of the select field is not equals than a value ```json -[{ -}] +[ + { + "departure": "nancy", + "arrival": "paris", + }, + { + "departure": "nancy", + "arrival": "toul", + }, + { + "departure": "paris", + "arrival": "londre", + } +] ``` Script: @@ -696,34 +815,92 @@ Script: [use] plugin = analytics -[groupingByModulo] +[drop] ``` Output: +```json +[{ + "departure": "nancy", + "arrival": "paris" +}, +{ + "departure": "nancy", + "arrival": "toul" +}] +``` + +#### Parameters + +- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path of the field to compare (optional, default `"value"`) +- `if` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** value to compare (optional, default `""`) + +Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** + +### groupingByHamming + +Take `Object` like `{ id, value }` and reduce all `value` with `id` which +have the same Hamming distance in a single object + +- ```json + [ + { "id": "lorem", "value": 1 }, + { "id": "Lorem", "value": 1 }, + { "id": "loren", "value": 1 }, + { "id": "korem", "value": 1 }, + { "id": "olrem", "value": 1 }, + { "id": "toto", "value": 1 }, + { "id": "titi", "value": 1 }, + { "id": "lorem", "value": 1 } + ] + ``` + + + Script: + + ```ini + [use] + plugin = analytics + + [groupingByHamming] + distance = 1 + + [summing] + +Output: + ```json [ + { "id": [ "lorem", "Lorem", "loren", "korem" ], "value": 5 }, + { "id": [ "olrem" ], "value": 1 }, + { "id": [ "toto", "titi" ], "value": 2 } ] ``` #### Parameters -- `id` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for id (optional, default `id`) -- `value` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for value (optional, default `value`) +- `id` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for id (optional, default `"id"`) +- `value` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for value (optional, default `"value"`) Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** -### reducing +### groupingByLevenshtein -Take `Object` group value of `{ id, value }` objectpath +Take `Object` like `{ id, value }` and reduce all `value`s with +`id` which have the same Levenshtein distance in a single object ```json -[{ - { id: 'x', value: 2 }, - { id: 't', value: 2 }, - { id: 'x', value: 3 }, - { id: 'x', value: 5 }, -}] +[ + { "id": "lorem", "value": 1 }, + { "id": "Lorem", "value": 1 }, + { "id": "loren", "value": 1 }, + { "id": "korem", "value": 1 }, + { "id": "olrem", "value": 1 }, + { "id": "toto", "value": 1 }, + { "id": "titi", "value": 1 }, + { "id": "lorem", "value": 1 } +] ``` Script: @@ -732,15 +909,18 @@ Script: [use] plugin = analytics -[reducing] +[groupingByLevenshtein] +distance = 2 + +[summing] ``` Output: ```json [ - { id: 'x', value: [2, 3, 5] }, - { id: 't', value: [2] }, + { "id": [ "lorem", "Lorem", "loren", "korem", "olrem" ], "value": 6 }, + { "id": [ "toto", "titi" ], "value": 2 } ] ``` @@ -748,20 +928,25 @@ Output: - `id` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for id (optional, default `id`) - `value` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for value (optional, default `value`) +- `distance` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** minimal levenshtein distance to have a same id (optional, default `1`) Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** -### aggregate +### keys -Aggregate by id and count +Take `Object` and throws all its keys ```json -[{ - { id: 'x', value: 2 }, - { id: 't', value: 2 }, - { id: 'x', value: 3 }, - { id: 'x', value: 5 }, -}] +[ + { city: 'tokyo', year: 2000, count: 1 }, + { city: 'paris', year: 2001, count: 2 }, + { city: 'london', year: 2003, count: 3 }, + { city: 'nancy', year: 2005, count: 4 }, + { city: 'berlin', year: 2007, count: 5 }, + { city: 'madrid', year: 2009, count: 6 }, + { city: 'stockholm', year: 2011, count: 7 }, + { city: 'bruxelles', year: 2013, count: 8 }, +] ``` Script: @@ -770,33 +955,52 @@ Script: [use] plugin = analytics +[keys] [aggregate] -path = id +[summing] ``` Output: ```json [ - { id: 'x', value: [ 2, 3, 5] }, - { id: 't', value: [ 2 ] }, +{ + "id": "city", + "value": 8 +}, +{ + "id": "year", + "value": 8 +}, +{ + "id": "count", + "value": 8 +}⏎ ] ``` #### Parameters -- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for id (optional, default `id`) -- `value` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for value (if not found 1 is the default value) (optional, default `value`) +- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** -### sort +### groupingByEquality -Take all `Object` and sort them with dedicated key +Take `Object` like `{ id, value }` and reduce all values with the same `id` +in a single object ```json -[{ -}] +[ + { "id": "lorem", "value": 1 }, + { "id": "Lorem", "value": 1 }, + { "id": "loren", "value": 1 }, + { "id": "korem", "value": 1 }, + { "id": "olrem", "value": 1 }, + { "id": "toto", "value": 1 }, + { "id": "titi", "value": 1 }, + { "id": "lorem", "value": 1 } +] ``` Script: @@ -805,33 +1009,41 @@ Script: [use] plugin = analytics -[sort] +[groupingByEquality] + +[summing] ``` Output: ```json [ + { "id": [ "lorem" ], "value": 2 }, + { "id": [ "Lorem" ], "value": 1 }, + { "id": [ "loren" ], "value": 1 }, + { "id": [ "korem" ], "value": 1 }, + { "id": [ "olrem" ], "value": 1 }, + { "id": [ "toto" ], "value": 1 }, + { "id": [ "titi" ], "value": 1 } ] ``` #### Parameters -- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for id (optional, default `id`) +- `id` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for id (optional, default `id`) +- `value` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for value (optional, default `value`) Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** -### distinct +### multiply -Take `Object` object getting some fields with json path, and do ... +Take `Object` and throw the same object only if there the value of the select field is equals than a value +Input file: ```json [{ - { a: 'x', b: 'z' }, - { a: 't', b: 'z' }, - { a: 't', b: 'z' }, - { a: 'x', b: 'z' }, - { a: 'x', b: 'z' }, + a: 1, + b: 2, }] ``` @@ -841,34 +1053,56 @@ Script: [use] plugin = analytics -[distinct] -path = a +[multiply] +path = factor +value = X +value = Y +value = Z ``` Output: ```json -[ - { id: 'x', value: 1 }, - { id: 't', value: 1 }, - { id: 't', value: 1 }, - { id: 'x', value: 1 }, - { id: 'x', value: 1 }, +[{ + a: 1, + b: 2, + factor: X +}, +{ + a: 1, + b: 2, + factor: Y +}, +{ + a: 1, + b: 2, + factor: Z +}, ] ``` #### Parameters -- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path (optional, default `"id"`) +- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path of the field to add (optional, default `"factor"`) +- `value` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** value(s) to set factor field (optional, default `""`) Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** -### merging +### less -Take special `Object` like `{id, value}` and replace `value` with the merge of `value`s +Take `Object` and throw the same object only if the value of the selected +field is less (or equal) than a value ```json [{ + { id: 2000, value: 1 }, + { id: 2001, value: 2 }, + { id: 2003, value: 3 }, + { id: 2005, value: 4 }, + { id: 2007, value: 5 }, + { id: 2009, value: 6 }, + { id: 2011, value: 7 }, + { id: 2013, value: 8 }, }] ``` @@ -878,76 +1112,106 @@ Script: [use] plugin = analytics -[merging] +[less] +path = value +than = 4 ``` Output: ```json -[ -] +[{ + "id": 2000, + "value": 1 +}, +{ + "id": 2001, + "value": 2 +}, +{ + "id": 2003, + "value": 3 +}, +{ + "id": 2005, + "value": 4 +}] ``` #### Parameters -- `id` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for id (optional, default `id`) -- `value` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for value (optional, default `value`) +- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path of the field to compare (optional, default `value`) +- `than` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** value to compare (optional, default `0`) +- `strict` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** less than but not equal (optional, default `false`) Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** -### filter +### count -Take `Object` and throw the same object only if there the value of the select field is equals than a value +Take `Object` and throw special `Object` like `{id, value}` if key(s) was found +id is the key, value is equal to 1 (if found) -- ```json - [ - { id: 2000, value: 1 }, - { id: 2001, value: 2 }, - { id: 2003, value: 3 }, - { id: 2005, value: 4 }, - { id: 2007, value: 5 }, - { id: 2003, value: 3 }, - { id: 2011, value: 7 }, - { id: 2013, value: 8 }, - ] - ``` +```json +[ + { + "a": "nancy", + "b": "lucy", + "c": "geny", + }, + { + "a": "lorem", + "b": "loret", + }, + { + "a": "fred", + } +] +``` +Script: - Script: +```ini +[use] +plugin = analytics - ```ini - [use] - plugin = analytics +[count] +path = a +path = b +path = c - [filter] - path = id - if = 2003 - if = 2013 +[aggregate] +[summing] +``` Output: ```json - [ - { id: 2003, value: 3 }, - { id: 2003, value: 3 }, - { id: 2013, value: 8 }, - ] +[{ + "id": "a", + "value": 3 +}, +{ + "id": "b", + "value": 2 +}, +{ + "id": "c", + "value": 1 +}] ``` #### Parameters -- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path of the field to compare (optional, default `"value"`) -- `if` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** value to compare (optional, default `""`) +- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** -### greater +### distribute -Take `Object` and throw the same object only if the value of the selected -field is greater (or equal) than a value +Take `Object` like { id, value } and throw a serie of number value ```json -[{ +[ { id: 2000, value: 1 }, { id: 2001, value: 2 }, { id: 2003, value: 3 }, @@ -956,7 +1220,7 @@ field is greater (or equal) than a value { id: 2009, value: 6 }, { id: 2011, value: 7 }, { id: 2013, value: 8 }, -}] +] ``` Script: @@ -965,40 +1229,55 @@ Script: [use] plugin = analytics -[greater] -than = 3 -strict = true +[distribute] ``` Output: ```json [ - { id: 2005, value: 4 }, - { id: 2007, value: 5 }, - { id: 2009, value: 6 }, - { id: 2011, value: 7 }, - { id: 2013, value: 8 }, + { "id": 2000, "value": 1 }, + { "id": 2001, "value": 2 }, + { "id": 2002, "value": 0 }, + { "id": 2003, "value": 3 }, + { "id": 2004, "value": 0 }, + { "id": 2005, "value": 4 }, + { "id": 2006, "value": 0 }, + { "id": 2007, "value": 5 }, + { "id": 2008, "value": 0 }, + { "id": 2009, "value": 6 }, + { "id": 2010, "value": 0 }, + { "id": 2011, "value": 7 }, + { "id": 2012, "value": 0 }, + { "id": 2013, "value": 8 } ] ``` #### Parameters -- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path of the field to compare (optional, default `"value"`) -- `than` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** value to compare (optional, default `0`) -- `strict` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** greater than but not equal (optional, default `false`) +- `id` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for id (optional, default `"id"`) +- `value` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for value (optional, default `"value"`) +- `step` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** step between each value (optional, default `1`) +- `start` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** first value to throw (optional, default `minvalueinthestream`) +- `size` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** size of the distribution (optional, default `(maxvalue-minvalue)inthestream`) +- `default` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** default value for missing object (optional, default `0`) Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** -### multiply +### sort -Take `Object` and throw the same object only if there the value of the select field is equals than a value -Input file: +Take all `Object` and sort them with dedicated key ```json [{ - a: 1, - b: 2, + { id: 2000, value: 1 }, + { id: 2001, value: 2 }, + { id: 2003, value: 3 }, + { id: 2005, value: 4 }, + { id: 2007, value: 5 }, + { id: 2009, value: 6 }, + { id: 2011, value: 7 }, + { id: 2013, value: 8 }, }] ``` @@ -1008,38 +1287,30 @@ Script: [use] plugin = analytics -[multiply] -path = factor -value = X -value = Y -value = Z +[sort] +path = value +reverse = true ``` Output: ```json -[{ - a: 1, - b: 2, - factor: X -}, -{ - a: 1, - b: 2, - factor: Y -}, -{ - a: 1, - b: 2, - factor: Z -}, +[ +{ "id": 2013, "value": 8 }, +{ "id": 2011, "value": 7 }, +{ "id": 2009, "value": 6 }, +{ "id": 2007, "value": 5 }, +{ "id": 2005, "value": 4 }, +{ "id": 2003, "value": 3 }, +{ "id": 2001, "value": 2 }, +{ "id": 2000, "value": 1 } ] ``` #### Parameters -- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path of the field to add (optional, default `"factor"`) -- `value` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** value(s) to set factor field (optional, default `""`) +- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for id (optional, default `id`) +- `reverse` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** reverser order (optional, default `false`) Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** diff --git a/packages/analytics/src/count.js b/packages/analytics/src/count.js index c31c56a3..2f39e957 100644 --- a/packages/analytics/src/count.js +++ b/packages/analytics/src/count.js @@ -1,11 +1,24 @@ import get from 'lodash.get'; import core from './core'; /** - * Take `Object` object getting some fields with json path, and do ... + * Take `Object` and throw special `Object` like `{id, value}` if key(s) was found + * id is the key, value is equal to 1 (if found) * * ```json - * [{ - * }] + * [ + * { + * "a": "nancy", + * "b": "lucy", + * "c": "geny", + * }, + * { + * "a": "lorem", + * "b": "loret", + * }, + * { + * "a": "fred", + * } + * ] * ``` * * Script: @@ -15,14 +28,30 @@ import core from './core'; * plugin = analytics * * [count] + * path = a + * path = b + * path = c + * + * [aggregate] + * [summing] * * ``` * * Output: * * ```json - * [ - * ] + * [{ + * "id": "a", + * "value": 3 + * }, + * { + * "id": "b", + * "value": 2 + * }, + * { + * "id": "c", + * "value": 1 + * }] * ``` * * @name count diff --git a/packages/analytics/src/distribute.js b/packages/analytics/src/distribute.js index 52ac0eff..91c3ff87 100644 --- a/packages/analytics/src/distribute.js +++ b/packages/analytics/src/distribute.js @@ -6,8 +6,16 @@ import Store from './store'; * Take `Object` like { id, value } and throw a serie of number value * * ```json - * [{ - * }] + * [ + * { id: 2000, value: 1 }, + * { id: 2001, value: 2 }, + * { id: 2003, value: 3 }, + * { id: 2005, value: 4 }, + * { id: 2007, value: 5 }, + * { id: 2009, value: 6 }, + * { id: 2011, value: 7 }, + * { id: 2013, value: 8 }, + * ] * ``` * * Script: @@ -24,13 +32,27 @@ import Store from './store'; * * ```json * [ + * { "id": 2000, "value": 1 }, + * { "id": 2001, "value": 2 }, + * { "id": 2002, "value": 0 }, + * { "id": 2003, "value": 3 }, + * { "id": 2004, "value": 0 }, + * { "id": 2005, "value": 4 }, + * { "id": 2006, "value": 0 }, + * { "id": 2007, "value": 5 }, + * { "id": 2008, "value": 0 }, + * { "id": 2009, "value": 6 }, + * { "id": 2010, "value": 0 }, + * { "id": 2011, "value": 7 }, + * { "id": 2012, "value": 0 }, + * { "id": 2013, "value": 8 } * ] * ``` * * @name distribute * @param {String} [id="id"] path to use for id * @param {String} [value="value"] path to use for value - * @param {String} [step=1] step between each valut + * @param {String} [step=1] step between each value * @param {Number} [start=min value in the stream] first value to throw * @param {Number} [size=(max value - min value) in the stream] size of the distribution * @param {Number} [default=0] default value for missing object diff --git a/packages/analytics/src/drop.js b/packages/analytics/src/drop.js index 7fa376fd..c8d19291 100644 --- a/packages/analytics/src/drop.js +++ b/packages/analytics/src/drop.js @@ -4,8 +4,20 @@ import get from 'lodash.get'; * Take `Object` and throw the same object only if there the value of the select field is not equals than a value * * ```json - * [{ - * }] + * [ + * { + * "departure": "nancy", + * "arrival": "paris", + * }, + * { + * "departure": "nancy", + * "arrival": "toul", + * }, + * { + * "departure": "paris", + * "arrival": "londre", + * } + * ] * ``` * * Script: @@ -21,8 +33,14 @@ import get from 'lodash.get'; * Output: * * ```json - * [ - * ] + * [{ + * "departure": "nancy", + * "arrival": "paris" + * }, + * { + * "departure": "nancy", + * "arrival": "toul" + * }] * ``` * * @name drop diff --git a/packages/analytics/src/exploding.js b/packages/analytics/src/exploding.js index 185941e7..353173c6 100644 --- a/packages/analytics/src/exploding.js +++ b/packages/analytics/src/exploding.js @@ -5,7 +5,10 @@ import core from './core'; * and throw object of each value. The new object is build with [id] and eac value. * * ```json - * [{ + * [ + * { departure: ['tokyo', 'nancy'], arrival: 'toul' }, + * { departure: ['paris', 'nancy'], arrival: 'toul' }, + * { departure: ['london', 'berlin'], arrival: 'toul' }, * }] * ``` * @@ -23,6 +26,12 @@ import core from './core'; * * ```json * [ + * { "id": "toul", "value": "tokyo" }, + * { "id": "toul", "value": "nancy" }, + * { "id": "toul", "value": "paris" }, + * { "id": "toul", "value": "nancy" }, + * { "id": "toul", "value": "london" }, + * { "id": "toul", "value": "berlin" } * ] * ``` * diff --git a/packages/analytics/src/graph.js b/packages/analytics/src/graph.js index 73d58b48..499fe0f6 100644 --- a/packages/analytics/src/graph.js +++ b/packages/analytics/src/graph.js @@ -2,10 +2,13 @@ import get from 'lodash.get'; import core from './core'; /** - * Take `Object` object getting some fields with json path, and do ... + * Take `Object` and throw a new special object (id, value) for each combination of values * * ```json - * [{ + * [ + * { cities: ['berlin', 'nancy', 'toul'] }, + * { cities: ['paris', 'nancy', 'toul']}, + * { cities: ['paris', 'berlin', 'toul'] }, * }] * ``` * @@ -16,6 +19,7 @@ import core from './core'; * plugin = analytics * * [graph] + * path = cities * * ``` * @@ -23,6 +27,12 @@ import core from './core'; * * ```json * [ + * { "id": [ "berlin", "nancy" ], "value": 1 }, + * { "id": [ "berlin", "toul" ], "value": 2 }, + * { "id": [ "nancy", "toul" ], "value": 2 }, + * { "id": [ "nancy", "paris" ], "value": 1 }, + * { "id": [ "paris", "toul" ], "value": 2 }, + * { "id": [ "berlin", "paris" ], "value": 1 } * ] * ``` * diff --git a/packages/analytics/src/greater.js b/packages/analytics/src/greater.js index 65b6db85..d1572130 100644 --- a/packages/analytics/src/greater.js +++ b/packages/analytics/src/greater.js @@ -5,7 +5,7 @@ import get from 'lodash.get'; * field is greater (or equal) than a value * * ```json - * [{ + * [ * { id: 2000, value: 1 }, * { id: 2001, value: 2 }, * { id: 2003, value: 3 }, @@ -14,7 +14,7 @@ import get from 'lodash.get'; * { id: 2009, value: 6 }, * { id: 2011, value: 7 }, * { id: 2013, value: 8 }, - * }] + * ] * ``` * * Script: diff --git a/packages/analytics/src/groupingByEquality.js b/packages/analytics/src/groupingByEquality.js index b06c845d..8045df80 100644 --- a/packages/analytics/src/groupingByEquality.js +++ b/packages/analytics/src/groupingByEquality.js @@ -8,8 +8,16 @@ const equalTo = (id) => (item) => item.id.some((key) => key === id); * in a single object * * ```json - * [{ - * }] + * [ + * { "id": "lorem", "value": 1 }, + * { "id": "Lorem", "value": 1 }, + * { "id": "loren", "value": 1 }, + * { "id": "korem", "value": 1 }, + * { "id": "olrem", "value": 1 }, + * { "id": "toto", "value": 1 }, + * { "id": "titi", "value": 1 }, + * { "id": "lorem", "value": 1 } + * ] * ``` * * Script: @@ -20,12 +28,21 @@ const equalTo = (id) => (item) => item.id.some((key) => key === id); * * [groupingByEquality] * + * [summing] + * * ``` * * Output: * * ```json * [ + * { "id": [ "lorem" ], "value": 2 }, + * { "id": [ "Lorem" ], "value": 1 }, + * { "id": [ "loren" ], "value": 1 }, + * { "id": [ "korem" ], "value": 1 }, + * { "id": [ "olrem" ], "value": 1 }, + * { "id": [ "toto" ], "value": 1 }, + * { "id": [ "titi" ], "value": 1 } * ] * ``` * diff --git a/packages/analytics/src/groupingByHamming.js b/packages/analytics/src/groupingByHamming.js index 6a3da2bd..ca05e6e5 100644 --- a/packages/analytics/src/groupingByHamming.js +++ b/packages/analytics/src/groupingByHamming.js @@ -9,9 +9,17 @@ const equalTo = (id, distance) => (item) => item.id.some((key) => hammingDistanc * Take `Object` like `{ id, value }` and reduce all `value` with `id` which * have the same Hamming distance in a single object * - * ```json - * [{ - * }] + * * ```json + * [ + * { "id": "lorem", "value": 1 }, + * { "id": "Lorem", "value": 1 }, + * { "id": "loren", "value": 1 }, + * { "id": "korem", "value": 1 }, + * { "id": "olrem", "value": 1 }, + * { "id": "toto", "value": 1 }, + * { "id": "titi", "value": 1 }, + * { "id": "lorem", "value": 1 } + * ] * ``` * * Script: @@ -21,6 +29,9 @@ const equalTo = (id, distance) => (item) => item.id.some((key) => hammingDistanc * plugin = analytics * * [groupingByHamming] + * distance = 1 + * + * [summing] * * ``` * @@ -28,6 +39,9 @@ const equalTo = (id, distance) => (item) => item.id.some((key) => hammingDistanc * * ```json * [ + * { "id": [ "lorem", "Lorem", "loren", "korem" ], "value": 5 }, + * { "id": [ "olrem" ], "value": 1 }, + * { "id": [ "toto", "titi" ], "value": 2 } * ] * ``` * diff --git a/packages/analytics/src/groupingByLevenshtein.js b/packages/analytics/src/groupingByLevenshtein.js index bc71c057..6fba5013 100644 --- a/packages/analytics/src/groupingByLevenshtein.js +++ b/packages/analytics/src/groupingByLevenshtein.js @@ -9,9 +9,17 @@ const equalTo = (id, distance) => (item) => item.id.some((key) => levenshteinDis * Take `Object` like `{ id, value }` and reduce all `value`s with * `id` which have the same Levenshtein distance in a single object * - * * ```json - * [{ - * }] + * ```json + * [ + * { "id": "lorem", "value": 1 }, + * { "id": "Lorem", "value": 1 }, + * { "id": "loren", "value": 1 }, + * { "id": "korem", "value": 1 }, + * { "id": "olrem", "value": 1 }, + * { "id": "toto", "value": 1 }, + * { "id": "titi", "value": 1 }, + * { "id": "lorem", "value": 1 } + * ] * ``` * * Script: @@ -21,6 +29,9 @@ const equalTo = (id, distance) => (item) => item.id.some((key) => levenshteinDis * plugin = analytics * * [groupingByLevenshtein] + * distance = 2 + * + * [summing] * * ``` * @@ -28,6 +39,8 @@ const equalTo = (id, distance) => (item) => item.id.some((key) => levenshteinDis * * ```json * [ + * { "id": [ "lorem", "Lorem", "loren", "korem", "olrem" ], "value": 6 }, + * { "id": [ "toto", "titi" ], "value": 2 } * ] * ``` * diff --git a/packages/analytics/src/keys.js b/packages/analytics/src/keys.js index 3233f360..1c242e0c 100644 --- a/packages/analytics/src/keys.js +++ b/packages/analytics/src/keys.js @@ -3,8 +3,16 @@ import core from './core'; * Take `Object` and throws all its keys * * ```json - * [{ - * }] + * [ + * { city: 'tokyo', year: 2000, count: 1 }, + * { city: 'paris', year: 2001, count: 2 }, + * { city: 'london', year: 2003, count: 3 }, + * { city: 'nancy', year: 2005, count: 4 }, + * { city: 'berlin', year: 2007, count: 5 }, + * { city: 'madrid', year: 2009, count: 6 }, + * { city: 'stockholm', year: 2011, count: 7 }, + * { city: 'bruxelles', year: 2013, count: 8 }, + * ] * ``` * * Script: @@ -14,6 +22,8 @@ import core from './core'; * plugin = analytics * * [keys] + * [aggregate] + * [summing] * * ``` * @@ -21,6 +31,18 @@ import core from './core'; * * ```json * [ + * { + * "id": "city", + * "value": 8 + * }, + * { + * "id": "year", + * "value": 8 + * }, + * { + * "id": "count", + * "value": 8 + * }⏎ * ] * ``` * diff --git a/packages/analytics/src/less.js b/packages/analytics/src/less.js index 1ca2abc3..0a13f31b 100644 --- a/packages/analytics/src/less.js +++ b/packages/analytics/src/less.js @@ -6,6 +6,14 @@ import get from 'lodash.get'; * * ```json * [{ + * { id: 2000, value: 1 }, + * { id: 2001, value: 2 }, + * { id: 2003, value: 3 }, + * { id: 2005, value: 4 }, + * { id: 2007, value: 5 }, + * { id: 2009, value: 6 }, + * { id: 2011, value: 7 }, + * { id: 2013, value: 8 }, * }] * ``` * @@ -16,14 +24,30 @@ import get from 'lodash.get'; * plugin = analytics * * [less] + * path = value + * than = 4 * * ``` * * Output: * * ```json - * [ - * ] + * [{ + * "id": 2000, + * "value": 1 + * }, + * { + * "id": 2001, + * "value": 2 + * }, + * { + * "id": 2003, + * "value": 3 + * }, + * { + * "id": 2005, + * "value": 4 + * }] * ``` * * @name less diff --git a/packages/analytics/src/maximizing.js b/packages/analytics/src/maximizing.js index a89ffb60..b2c4b375 100644 --- a/packages/analytics/src/maximizing.js +++ b/packages/analytics/src/maximizing.js @@ -4,8 +4,11 @@ import core from './core'; * Take special `Object` like `{id, value}` and replace `value` with the max of `value`s * * ```json - * [{ - * }] + * [ + * { id: 'toul', value: [1, 2, 3] }, + * { id: 'nancy', value: [2, 3, 4] }, + * { id: 'neufchateau', value: [3, 4, 5] }, + * ] * ``` * * Script: @@ -22,6 +25,9 @@ import core from './core'; * * ```json * [ + * { "id": "toul", "value": 3 }, + * { "id": "nancy", "value": 4 }, + * { "id": "neufchateau", "value": 5 } * ] * ``` * diff --git a/packages/analytics/src/pair.js b/packages/analytics/src/pair.js index 72ca9254..4a040121 100644 --- a/packages/analytics/src/pair.js +++ b/packages/analytics/src/pair.js @@ -2,11 +2,15 @@ import get from 'lodash.get'; import core from './core'; /** - * Take `Object` object getting some fields with json path, and do ... + * Take `Object` object getting some fields with json path, and + * throw all pair of value from two fields * * ```json - * [{ - * }] + * [ + * { departure: ['tokyo', 'nancy'], arrival: 'toul' }, + * { departure: ['paris', 'nancy'], arrival: 'toul' }, + * { departure: ['london', 'berlin'], arrival: 'toul' }, + * ] * ``` * * Script: @@ -16,6 +20,8 @@ import core from './core'; * plugin = analytics * * [pair] + * path = departure + * path = arrival * * ``` * @@ -23,6 +29,12 @@ import core from './core'; * * ```json * [ + * { "id": [ "tokyo", "toul" ], "value": 1 }, + * { "id": [ "nancy", "toul" ], "value": 1 }, + * { "id": [ "paris", "toul" ], "value": 1 }, + * { "id": [ "nancy", "toul" ], "value": 1 }, + * { "id": [ "london", "toul" ], "value": 1 }, + * { "id": [ "berlin", "toul" ], "value": 1 } * ] * ``` * diff --git a/packages/analytics/src/pluck.js b/packages/analytics/src/pluck.js index 88c65e56..a4807354 100644 --- a/packages/analytics/src/pluck.js +++ b/packages/analytics/src/pluck.js @@ -5,8 +5,16 @@ import core from './core'; * object for each value * * ```json - * [{ - * }] + * [ + * { city: 'tokyo', year: 2000, count: 1 }, + * { city: 'paris', year: 2001, count: 2 }, + * { city: 'london', year: 2003, count: 3 }, + * { city: 'nancy', year: 2005, count: 4 }, + * { city: 'berlin', year: 2007, count: 5 }, + * { city: 'madrid', year: 2009, count: 6 }, + * { city: 'stockholm', year: 2011, count: 7 }, + * { city: 'bruxelles', year: 2013, count: 8 }, + * ] * ``` * * Script: @@ -16,6 +24,7 @@ import core from './core'; * plugin = analytics * * [pluck] + * path = year * * ``` * @@ -23,6 +32,14 @@ import core from './core'; * * ```json * [ + * { "id": "year", "value": 2000 }, + * { "id": "year", "value": 2001 }, + * { "id": "year", "value": 2003 }, + * { "id": "year", "value": 2005 }, + * { "id": "year", "value": 2007 }, + * { "id": "year", "value": 2009 }, + * { "id": "year", "value": 2011 }, + * { "id": "year", "value": 2013 } * ] * ``` * diff --git a/packages/analytics/src/slice.js b/packages/analytics/src/slice.js index 9d7b89ad..e3a005bb 100644 --- a/packages/analytics/src/slice.js +++ b/packages/analytics/src/slice.js @@ -4,6 +4,14 @@ * * ```json * [{ + * { id: 2000, value: 1 }, + * { id: 2001, value: 2 }, + * { id: 2003, value: 3 }, + * { id: 2005, value: 4 }, + * { id: 2007, value: 5 }, + * { id: 2009, value: 6 }, + * { id: 2011, value: 7 }, + * { id: 2013, value: 8 }, * }] * ``` * @@ -21,6 +29,8 @@ * * ```json * [ + * { "id": 2001, "value": 2 }, + * { "id": 2003, "value": 3 }, * ] * ``` * diff --git a/packages/analytics/src/sort.js b/packages/analytics/src/sort.js index a3ffbb6d..a049ecca 100644 --- a/packages/analytics/src/sort.js +++ b/packages/analytics/src/sort.js @@ -15,6 +15,14 @@ const sorting = (arr, reverse = false) => { * * ```json * [{ + * { id: 2000, value: 1 }, + * { id: 2001, value: 2 }, + * { id: 2003, value: 3 }, + * { id: 2005, value: 4 }, + * { id: 2007, value: 5 }, + * { id: 2009, value: 6 }, + * { id: 2011, value: 7 }, + * { id: 2013, value: 8 }, * }] * ``` * @@ -25,6 +33,8 @@ const sorting = (arr, reverse = false) => { * plugin = analytics * * [sort] + * path = value + * reverse = true * * ``` * @@ -32,11 +42,20 @@ const sorting = (arr, reverse = false) => { * * ```json * [ + * { "id": 2013, "value": 8 }, + * { "id": 2011, "value": 7 }, + * { "id": 2009, "value": 6 }, + * { "id": 2007, "value": 5 }, + * { "id": 2005, "value": 4 }, + * { "id": 2003, "value": 3 }, + * { "id": 2001, "value": 2 }, + * { "id": 2000, "value": 1 } * ] * ``` * * @name sort * @param {String} [path=id] path to use for id + * @param {boolean} [reverse=false] reverser order * @returns {Object} */ export default async function sort(data, feed) { diff --git a/packages/analytics/src/summing.js b/packages/analytics/src/summing.js index ada6f08d..01c46de2 100644 --- a/packages/analytics/src/summing.js +++ b/packages/analytics/src/summing.js @@ -5,8 +5,11 @@ import core from './core'; * `value`s * * ```json - * [{ - * }] + * [ + * { "id": "A", "value": [1, 1, 1] }, + * { "id": "B", "value": [1] }, + * { "id": "C", "value": [1, 1, 1, 1] }, + * ] * ``` * * Script: @@ -22,8 +25,17 @@ import core from './core'; * Output: * * ```json - * [ - * ] + * [{ + * "id": "A", "value": 3 + * }, + * { + * "id": "B", + * "value": 1 + * }, + * { + * "id": "C", + * "value": 4 + * }] * ``` * * @name summing diff --git a/packages/analytics/src/value.js b/packages/analytics/src/value.js index 32b2c17f..0b109d5e 100644 --- a/packages/analytics/src/value.js +++ b/packages/analytics/src/value.js @@ -4,8 +4,16 @@ import get from 'lodash.get'; * Take `Object` object and getting the value field * * ```json - * [{ - * }] + * [ + * { id: 2000, value: 1 }, + * { id: 2001, value: 2 }, + * { id: 2003, value: 3 }, + * { id: 2005, value: 4 }, + * { id: 2007, value: 5 }, + * { id: 2009, value: 6 }, + * { id: 2011, value: 7 }, + * { id: 2013, value: 8 }, + * ] * ``` * * Script: @@ -15,6 +23,7 @@ import get from 'lodash.get'; * plugin = analytics * * [value] + * path = id * * ``` * @@ -22,6 +31,14 @@ import get from 'lodash.get'; * * ```json * [ + * 2000, + * 2001, + * 2003, + * 2005, + * 2007, + * 2009, + * 2011, + * 2013 * ] * ``` * diff --git a/packages/core/src/settings.js b/packages/core/src/settings.js index ce521dd6..34ff7788 100644 --- a/packages/core/src/settings.js +++ b/packages/core/src/settings.js @@ -1,15 +1,16 @@ import os from 'os'; +import autocast from 'autocast'; const cpus = os.cpus().length; const concurrency = Number(process.env.EZS_CONCURRENCY || cpus); const encoding = String(process.env.EZS_ENCODING || 'gzip'); const port = Number(process.env.EZS_PORT || 31976); -const cacheEnable = Boolean(process.env.EZS_CACHE || true); +const cacheEnable = Boolean(autocast(process.env.EZS_CACHE) || true); const nShards = Number(process.env.EZS_NSHARDS || 16); const settings = { highWaterMark: { - object: Number(process.env.EZS_HIGHWATERMARK_OBJECT || nShards), - bytes: Number(process.env.EZS_HIGHWATERMARK_BYTES || (nShards * 1024)), + object: nShards, + bytes: (nShards * 1024), }, concurrency, encoding, @@ -17,10 +18,10 @@ const settings = { server: process.env.EZS_SERVER ? String(process.env.EZS_SERVER).split(',').map((h) => h.trim()) : null, cacheEnable, cache: { - max: nShards, + max: (nShards * 256), }, queue: { - concurrency, + concurrency: nShards, }, delegate: String(process.env.EZS_DELEGATE || 'delegate'), };