diff --git a/docs/plugin-analytics.md b/docs/plugin-analytics.md
index 1cf8d07c..d741b757 100644
--- a/docs/plugin-analytics.md
+++ b/docs/plugin-analytics.md
@@ -996,587 +996,814 @@ Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/G
### output
-Format the output with data a meta
+Create an output string containing all incoming elements in a `data` array.
+with given `meta` extracted into an object called `meta`.
-#### Parameters
-
-- `indent` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** indent or not (optional, default `false`)
-- `meta` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>?** fields to be considered as metadata
- object
+Créer une sortie en chain de caratere avec les element entrent mise dans un tableau nommé `data`
+eyent les donnée `meta` extrais et mises dans un objet appelé `meta`.
-#### Examples
+##### Script / Scénario
-Input
+###### ini
+```ini
+; Import analytics plugin required to use "output"
+; Importation du plugin analytique nécessaire pour utiliser "output"
+[use]
+plugin = analytics
-```javascript
-[
- { _id: 1, value: 2, total: 2 },
- { _id: 2, value: 4, total: 2 }
-]
+; Using "output" with 'indent' as true and 'meta' as total
+; Utilisation de "output" avec 'indent' à vrai et total comme paramètres de 'meta'
+[output]
+indent = true
+meta = total
```
-Script
-
+##### Input / Entrée
-```javascript
-.pipe(ezs('output', { meta: 'total' }))
+```json
+ [
+ { "_id": 1, "value": 2, "total": 2 },
+ { "_id": 2, "value": 4, "total": 2 }
+ ]
```
-Output
+##### Output / Sortie
+!!! Attention: This is an output function that can only be used at the end of an EZS script. !!!
+!!! The output is a string and can't be used with other EZS functions. !!!
-```javascript
-{
- data: [
- { _id: 1, value: 2 },
- { _id: 2, value: 4 }
- ],
- meta: {
- total: 2
- }
-}
+!!! Attention : Ceci est une fonction de sortie, Elle peut uniquement etre utilisé à la fin d'un script ezs !!!
+!!! Cette sortie est une chaine de carater et ne peut pas etre utilisé avec d'autre fonction ezs !!!
+
+```json
+ {
+ "data": [
+ { "_id": 1, "value": 2 },
+ { "_id": 2, "value": 4 }
+ ],
+ "meta": {
+ "total": 2
+ }
+ }
```
-Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
+#### Parameters
+
+- `indent` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**
+ indenté le json de sortie (optional, default `false`)
+- `meta` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** element from the input to put it in the `meta` object
+ élément a extraire de l'entrée et a mettre dans l'objet `meta`
+
+Returns **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
### pair
-Take `Object` object getting some fields with json path, and
-throw all pair of value from two fields
+Create a pair with 'id' containing a pair of the given 'path's and 'value' set to 1.
-```json
-[
- { departure: ['tokyo', 'nancy'], arrival: 'toul' },
- { departure: ['paris', 'nancy'], arrival: 'toul' },
- { departure: ['london', 'berlin'], arrival: 'toul' },
-]
-```
+Créer un couple 'id' contenent un couple des 'path's donnée et 'value' mise à 1.
-Script:
+##### Script / Scénario
```ini
+; Import analytics plugin required to use "pair"
+; Importation du plugin analytique nécessaire pour utiliser "pair"
[use]
plugin = analytics
+; Using "pair" with 'departure' and 'arrival' as paths setttings
+; Utilisation de "pair" avec 'departure' et 'arrival' comme paramètres de paths
[pair]
path = departure
path = arrival
```
-Output:
+##### Input / Entrée
```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 }
-]
+ [
+ { "departure": ["tokyo", "nancy"], "arrival": "toul" },
+ { "departure": ["paris", "nancy"], "arrival": "toul" },
+ { "departure": ["london", "berlin"], "arrival": "toul" }
+ ]
+```
+
+##### Output / Sortie
+
+```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)**
+- `null` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path of the element who will be use to create the pair
+ chemin de l'élément qui vas etre utilisé pour créer le couple
-Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
+Returns **{id: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>, value: `1`}**
### pluck
-Take `Object` object getting value of fields (with json `path`) and throws an
-object for each value
+Extract the value of a given `path` and create a pair with the `path` as the `id`
+and `path` value as the `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 },
-]
-```
+Extrais la valeur d'un `path` donnée et créer un couple avec pour identifient le `path`
+et comme `value` la valeur du `path`.
-Script:
+#### Example / Exemple
+
+##### Script / Scénario
```ini
+; Import analytics plugin required to use "pluck"
+; Importation du plugin analytique nécessaire pour utiliser "pluck"
[use]
plugin = analytics
+; Using "pluck" with 'year' as path setttings instead of 'id' how is the default value
+; Utilisation de "pluck" avec 'year' comme paramètres de path au lieux de la valeur par defaut qui et 'id'
[pluck]
path = year
```
-Output:
+##### Input / Entrée
```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 }
-]
+ [
+ { "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 }
+ ]
+```
+
+##### Output / Sortie
+
+```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
-- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use form group by (optional, default `id`)
+- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path of the element who need to be extrated
+ chemin de l'élément qui doit être extrais (optional, default `id`)
-Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
+Returns **{id: [String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), value: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)}**
### reducing
-Take `Object` group value of `{ id, value }` objectpath
+Merges the `id`, `value` pairs into a new pair, associating the identifier with the values.
-```json
-[{
- { id: 'x', value: 2 },
- { id: 't', value: 2 },
- { id: 'x', value: 3 },
- { id: 'x', value: 5 },
-}]
-```
+Fusionne les couple `id`, `value`, en un nouveau couple associent l'identifient au valeurs.
-Script:
+#### Example / Exemple
+
+##### Script / Scénario
```ini
+; Import analytics plugin required to use "reducing"
+; Importation du plugin analytique nécessaire pour utiliser "reducing"
[use]
plugin = analytics
+; Using "reducing" with default settings
+; Utilisation de "reducing" avec les paramètres par défaut
[reducing]
+; id = id
+; value = value
```
-Output:
+##### Input / Entrée
```json
-[
- { id: 'x', value: [2, 3, 5] },
- { id: 't', value: [2] },
-]
+ [
+ { "id": "x", "value": 2 },
+ { "id": "t", "value": 2 },
+ { "id": "x", "value": 3 },
+ { "id": "x", "value": 5 }
+ ]
+```
+
+##### Output / Sortie
+
+```json
+ [
+ { "id": "x", "value": [2, 3, 5] },
+ { "id": "t", "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 of the element who will be use as the key
+ chemin de l'élément qui vas être utilisé comme clé (optional, default `id`)
+- `value` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path of the element who will be merge into an array
+ chemin de l'élément qui vas être fussioné en un tableau (optional, default `value`)
-Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
+Returns **{id: [String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), value: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)>}**
### segment
-Take `Object` object getting some fields with json path, and throw segment of
-value. Ex: get `[a,b,c]` and throw `[a,b], [b,c]`
+Returns an object containing a segmentation of the input.
-```json
-[{
- {
- id: 'doc#1',
- value: [
- 1,
- 2,
- 3,
- 4,
- ],
- },
- {
- id: 'doc#2',
- value: [
- 4,
- 5,
- 6,
- ],
- },
- {
- id: 'doc#3',
- value: [
- 6,
- 7,
- ]
- },
- {
- id: 'doc#4',
- value: [
- 1,
- 2,
- 3,
- 4,
- 5,
- 6,
- 7,
- ]
- }
-}]
-```
+- `[a,b,c]` will be returned as `[a,b], [b,c]`
-Script:
+Renvoie un objet contenant une segmentation de l'entrée.
+
+- `[a,b,c]` sera retourné sous la forme `[a,b], [b,c]`
+
+#### Example / Exemple
+
+##### Script / Scénario
```ini
+; Import analytics plugin required to use "segment"
+; Importation du plugin analytique nécessaire pour utiliser "segment"
[use]
plugin = analytics
+; Using "segment" with default settings
+; Utilisation de "segment" avec les paramètres par défaut
[segment]
-path = value
+; aggregate = true
+; identifier = false
+; path = value
```
-Output:
+##### Input / Entrée
```json
-[
- { id: [ 1, 2 ], value: 1 }
- { id: [ 2, 3 ], value: 1 }
- { id: [ 3, 4 ], value: 1 }
- { id: [ 4, 5 ], value: 1 }
- { id: [ 5, 6 ], value: 1 }
- { id: [ 6, 7 ], value: 1 }
- { id: [ 1, 2 ], value: 1 }
- { id: [ 2, 3 ], value: 1 }
- { id: [ 3, 4 ], value: 1 }
- { id: [ 4, 5 ], value: 1 }
- { id: [ 5, 6 ], value: 1 }
- { id: [ 6, 7 ], value: 1 }
-]
+ [
+ {
+ "id": "doc#1",
+ "value": [
+ 1,
+ 2,
+ 3,
+ 4
+ ]
+ },
+ {
+ "id": "doc#2",
+ "value": [
+ 4,
+ 5,
+ 6
+ ]
+ },
+ {
+ "id": "doc#3",
+ "value": [
+ 6,
+ 7
+ ]
+ },
+ {
+ "id": "doc#4",
+ "value": [
+ 1,
+ 2,
+ 3,
+ 4,
+ 5,
+ 6,
+ 7
+ ]
+ }
+ ]
+```
+
+##### Output / Sortie
+
+```json
+ [
+ { "id": [ 1, 2 ], "value": 1 },
+ { "id": [ 2, 3 ], "value": 1 },
+ { "id": [ 3, 4 ], "value": 1 },
+ { "id": [ 4, 5 ], "value": 1 },
+ { "id": [ 5, 6 ], "value": 1 },
+ { "id": [ 6, 7 ], "value": 1 },
+ { "id": [ 1, 2 ], "value": 1 },
+ { "id": [ 2, 3 ], "value": 1 },
+ { "id": [ 3, 4 ], "value": 1 },
+ { "id": [ 4, 5 ], "value": 1 },
+ { "id": [ 5, 6 ], "value": 1 },
+ { "id": [ 6, 7 ], "value": 1 }
+ ]
```
#### Parameters
-- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path (optional, default `value`)
-- `aggregate` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** aggregate all values for all paths (or not) (optional, default `true`)
-- `identifier` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use to set value result field (if not set or not exists, 1 is use as a default value) (optional, default `false`)
+- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path of the element who need to be segmented
+ chemin de l'élément qui doit être segmentés (optional, default `value`)
+- `aggregate` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** aggregate all values for all paths (or not) aggregate all segmented value in one element (work if you have multiple path)
+ agréger toutes les valeurs segmentées en un seul élément (fonctionne si vous avez plusieurs chemins) (optional, default `true`)
+- `identifier` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path of the element who will be put in value field (if not set, fallback to `1`)
+ chemin de l'élément qui sera mis dans le champ valeur (si non défini, fallback à `1`) (optional, default `false`)
-Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
+Returns **{id: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)>, value: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)}**
### slice
-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
+Returns a copy of a section of a stream.
-```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 },
-}]
-```
+Renvoie une copie d'une section d'un flux.
-Script:
+#### Example / Exemple
+
+##### Script / Scénario
```ini
+; Import analytics plugin required to use "slice"
+; Importation du plugin analytique nécessaire pour utiliser "slice"
[use]
plugin = analytics
-[drop]
+; Using "slice" with default settings
+; Utilisation de "slice" avec les paramètres par défaut
+[slice]
+; start = 1
+; size = 10
```
-Output:
+##### Input / Entrée
```json
-[
-{ "id": 2001, "value": 2 },
-{ "id": 2003, "value": 3 },
-]
+ [
+ { "id": 2023, "value": 12 },
+ { "id": 2021, "value": 11 },
+ { "id": 2019, "value": 10 },
+ { "id": 2017, "value": 9 },
+ { "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 }
+ ]
+```
+
+##### Output / Sortie
+
+```json
+ [
+ { "id": 2023, "value": 12 },
+ { "id": 2021, "value": 11 },
+ { "id": 2019, "value": 10 },
+ { "id": 2017, "value": 9 },
+ { "id": 2013, "value": 8 },
+ { "id": 2011, "value": 7 },
+ { "id": 2009, "value": 6 },
+ { "id": 2007, "value": 5 },
+ { "id": 2005, "value": 4 },
+ { "id": 2003, "value": 3 }
+ ]
```
#### 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`)
+- `start` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** the beginning index of the specified portion of the stream
+ l'indice de début de la partie spécifiée du flux (optional, default `1`)
+- `size` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** the size of the specified portion of the stream
+ la taille de début de la partie spécifiée du flux (optional, default `10`)
Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
### sort
-Take all `Object` and sort them with dedicated key
+Sort incomming objects based on the value of the given path.
-```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 },
-}]
-```
+Trie les objets entrants en fonction de la valeur du champ donné par `path`.
-Script:
+#### Example / Exemple
+
+##### Script / Scénario
```ini
+; Import analytics plugin required to use "sort"
+; Importation du plugin analytique nécessaire pour utiliser "sort"
[use]
plugin = analytics
+; Using "sort" with default settings
+; Utilisation de "sort" avec les paramètres par défaut
[sort]
-path = value
-reverse = true
+; path = id
+; reverse = false
```
-Output:
+##### Input / Entrée
```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 }
-]
+ [
+ { "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 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)**
-
-### statistics
+##### Output / Sortie
-Compute some statistics from one or more fields
+```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 }
+ ]
+```
#### Parameters
-- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path of the value field (optional, default `value`)
-- `target` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path of statistics in output object (optional, default `_statistics`)
+- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path of the element used to as reference for the sort
+ chemin de l'élément utilisé comme référence pour le tri (optional, default `id`)
+- `reverse` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** sort in ascending or descending order
+ trier par ordre croissant ou décroissant (optional, default `false`)
-#### Examples
+Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
-Input
+### statistics
+Analyse and create statistics from given fields.
-````javascript
-```json
-[
- { a: 1, },
- { a: 1, },
- { a: 2, },
- { a: 3, },
- { a: 3, },
- { a: 3, },
-]
-```
-````
+Analyse et crée des statistiques à partir des champs donnés.
-Script
+#### Example / Exemple
+##### Script / Scénario
-````javascript
```ini
+; Import analytics plugin required to use "statistics"
+; Importation du plugin analytique nécessaire pour utiliser "statistics"
[use]
plugin = analytics
+; Using "statistics" with default settings
+; Utilisation de "statistics" avec les paramètres par défaut
[statistics]
-path = a
-
+; path = value
+; target = _statistics
```
-````
-Output
+##### Input / Entrée
+```json
+ [
+ { "value": 1 },
+ { "value": 1 },
+ { "value": 2 },
+ { "value": 3 },
+ { "value": 3 },
+ { "value": 3 }
+ ]
+```
+
+##### Output / Sortie
-````javascript
```json
-[{
- "a": 1,
- "stats": {
- "a": {
- "sample": 2,
- "frequency": 1,
- "percentage": 25,
- "sum": 4,
- "count": 3,
- "min": 1,
- "max": 2,
- "mean": 1.3333333333333333,
- "range": 1,
- "midrange": 0.5,
- "variance": 0.2222222222222222,
- "deviation": 0.4714045207910317,
- "population": 2
- }
- }
-},
-{
- "a": 1,
- "stats": {
- "a": {
- "sample": 2,
- "frequency": 1,
- "percentage": 25,
- "sum": 4,
- "count": 3,
- "min": 1,
- "max": 2,
- "mean": 1.3333333333333333,
- "range": 1,
- "midrange": 0.5,
- "variance": 0.2222222222222222,
- "deviation": 0.4714045207910317,
- "population": 2
- }
- }
-},
-{
- "a": 2,
- "stats": {
- "a": {
- "sample": 1,
- "frequency": 0.5,
- "percentage": 50,
- "sum": 4,
- "count": 3,
- "min": 1,
- "max": 2,
- "mean": 1.3333333333333333,
- "range": 1,
- "midrange": 0.5,
- "variance": 0.2222222222222222,
- "deviation": 0.4714045207910317,
- "population": 2
+ [
+ {
+ "value": 1,
+ "_statistics": {
+ "value": {
+ "sample": 2,
+ "frequency": 1,
+ "percentage": 25,
+ "sum": 4,
+ "count": 3,
+ "min": 1,
+ "max": 2,
+ "mean": 1.3333333333333333,
+ "range": 1,
+ "midrange": 0.5,
+ "variance": 0.2222222222222222,
+ "deviation": 0.4714045207910317,
+ "population": 2
+ }
+ }
+ },
+ {
+ "value": 1,
+ "_statistics": {
+ "value": {
+ "sample": 2,
+ "frequency": 1,
+ "percentage": 25,
+ "sum": 4,
+ "count": 3,
+ "min": 1,
+ "max": 2,
+ "mean": 1.3333333333333333,
+ "range": 1,
+ "midrange": 0.5,
+ "variance": 0.2222222222222222,
+ "deviation": 0.4714045207910317,
+ "population": 2
+ }
+ }
+ },
+ {
+ "value": 2,
+ "_statistics": {
+ "value": {
+ "sample": 1,
+ "frequency": 0.5,
+ "percentage": 50,
+ "sum": 4,
+ "count": 3,
+ "min": 1,
+ "max": 2,
+ "mean": 1.3333333333333333,
+ "range": 1,
+ "midrange": 0.5,
+ "variance": 0.2222222222222222,
+ "deviation": 0.4714045207910317,
+ "population": 2
+ }
+ }
}
- }
-}]
+ ]
```
-````
+
+#### Parameters
+
+- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path of the element used to create the statistics
+ chemin de l'élément utilisé pour créer les statistiques (optional, default `value`)
+- `target` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path of the statistics in the returned object
+ chemin des stastistiques dans l'objet retourné (optional, default `_statistics`)
Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
### summing
-Take special `Object` like `{id, value}` and replace `value` with the sum of
-`value`s
+Create an `id`, `value` pair from two given paths and apply a sum to the value.
-```json
-[
- { "id": "A", "value": [1, 1, 1] },
- { "id": "B", "value": [1] },
- { "id": "C", "value": [1, 1, 1, 1] },
-]
-```
+Créer un couple `id`, `value` à partir de chemins et applique une somme sur `value`.
-Script:
+#### Example / Exemple
+
+##### Script / Scénario
```ini
+; Import analytics plugin required to use "summing"
+; Importation du plugin analytique nécessaire pour utiliser "summing"
[use]
plugin = analytics
+; Using "summing" with default settings
+; Utilisation de "summing" avec les paramètres par défaut
[summing]
+; id = id
+; value = value
```
-Output:
+##### Input / Entrée
```json
-[{
- "id": "A", "value": 3
-},
-{
- "id": "B",
- "value": 1
-},
-{
- "id": "C",
- "value": 4
-}]
+ [
+ {
+ "id": 1,
+ "value": [1, 1, 1],
+ "hello": "world"
+ },
+ {
+ "id": 2,
+ "value": [2, 2, 2],
+ "hello": "world"
+ }
+ ]
+```
+
+##### Output / Sortie
+
+```json
+[
+ {
+ "id": 1,
+ "value": 3
+ },
+ {
+ "id": 2,
+ "value": 6
+ }
+]
```
#### 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 of the element used to create the new identifier
+ chemin de l'élément utilisé pour créer le nouvel identifiant (optional, default `id`)
+- `value` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path of the element to be summed
+ chemin de l'élément qui doit être sommé (optional, default `value`)
-Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
+Returns **{id: [String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), value: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)}**
### tune
-Take all `Object` and sort them with selected field
+Create and replace the id with a unified id that can be used with [sort](#sort).
-```json
-[{
-}]
-```
+Créer et remplacer l'identifiant par un identifiant unifié qui peut être utilisé avec [sort](#sort).
-Script:
+#### Example / Exemple
+
+##### Script / Scénario
```ini
+; Import analytics plugin required to use "tune"
+; Importation du plugin analytique nécessaire pour utiliser "tune"
[use]
plugin = analytics
+; Using "tune" with default settings
+; Utilisation de "tune" avec les paramètres par défaut
[tune]
+; path = id
+; method = natural
```
-Output:
+##### Input / Entrée
```json
-[
-]
+ [
+ {
+ "id": 1,
+ "value": 1
+ },
+ {
+ "id": 2,
+ "value": 2
+ }
+ ]
+```
+
+##### Output / Sortie
+
+```json
+ [
+ {
+ "id": "0000000000000000001.00000000000000000000",
+ "value": {
+ "id": 1,
+ "value": 1,
+ "label": "static value"
+ }
+ },
+ {
+ "id": "0000000000000000002.00000000000000000000",
+ "value": {
+ "id": 2,
+ "value": 2,
+ "label": "static value"
+ }
+ }
+ ]
```
#### Parameters
-- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for the sort key (optional, default `id`)
+- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path of the element used to create the unified identifier
+ chemin de l'élément utilisé pour créer l'identifiant unifié (optional, default `id`)
+- `method` **(`"natural"` \| `"levenshtein"` \| `"numerical"`)** method used to create the unified identifier
+ natural - Create a normalised identifier that is set to a fixed length
+ levenshtein - Create an identifier based on the Levenshtein algorithm
+ numerical - Create an identifier based on a numeric value
+ méthode utilisée pour créer l'identifiant unifié
+ natural - Crée un identifiant normalisé de longueur fixe
+ levenshtein - Crée un identifiant basé sur l'algorithme de Levenshtein
+ numerical - Crée un identifiant basé sur une valeur numérique (optional, default `natural`)
-Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
+Returns **{id: [String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), value: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)}**
### value
-Take `Object` object and getting the value field
+Create a new object from the value of the given `path`.
-```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 },
-]
-```
+Créer un nouvel objet à partir du chemin donné dans `path`.
-Script:
+#### Example / Exemple
+
+##### Script / Scénario
```ini
+; Import analytics plugin required to use "value"
+; Importation du plugin analytique nécessaire pour utiliser "value"
[use]
plugin = analytics
+; Using "value" with default settings
+; Utilisation de "tune" avec les paramètres par défaut
[value]
-path = id
+; path = value
```
-Output:
+##### Input / Entrée
+
+###### Dataset 1 / Jeu de données 1
```json
-[
-2000,
-2001,
-2003,
-2005,
-2007,
-2009,
-2011,
-2013
-]
+ [
+ { "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 }
+ ]
+```
+
+###### Dataset 2 / Jeu de données 2
+
+```json
+ [
+ {
+ "id": 1,
+ "value": {
+ "hello": "world"
+ }
+ },
+ {
+ "id": 2,
+ "value": {
+ "hello": "ezs"
+ }
+ },
+ {
+ "id": 3,
+ "value": {
+ "hello": "lodex"
+ }
+ }
+ ]
+```
+
+##### Output / Sortie
+
+###### Dataset 1 / Jeu de données 1
+
+```json
+ [
+ 1,
+ 2,
+ 3,
+ 4,
+ 5,
+ 6,
+ 7,
+ 8
+ ]
+```
+
+###### Dataset 2 / Jeu de données 2
+
+```json
+ [
+ {
+ "hello": "world"
+ },
+ {
+ "hello": "ezs"
+ },
+ {
+ "hello": "lodex"
+ }
+ ]
```
#### Parameters
-- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the pah of the value field (optional, default `value`)
+- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path of the element used to create the new object
+ chemin de l'élément utilisé pour créer le nouvel objet (optional, default `value`)
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 1cf8d07c..d741b757 100644
--- a/packages/analytics/README.md
+++ b/packages/analytics/README.md
@@ -996,587 +996,814 @@ Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/G
### output
-Format the output with data a meta
+Create an output string containing all incoming elements in a `data` array.
+with given `meta` extracted into an object called `meta`.
-#### Parameters
-
-- `indent` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** indent or not (optional, default `false`)
-- `meta` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>?** fields to be considered as metadata
- object
+Créer une sortie en chain de caratere avec les element entrent mise dans un tableau nommé `data`
+eyent les donnée `meta` extrais et mises dans un objet appelé `meta`.
-#### Examples
+##### Script / Scénario
-Input
+###### ini
+```ini
+; Import analytics plugin required to use "output"
+; Importation du plugin analytique nécessaire pour utiliser "output"
+[use]
+plugin = analytics
-```javascript
-[
- { _id: 1, value: 2, total: 2 },
- { _id: 2, value: 4, total: 2 }
-]
+; Using "output" with 'indent' as true and 'meta' as total
+; Utilisation de "output" avec 'indent' à vrai et total comme paramètres de 'meta'
+[output]
+indent = true
+meta = total
```
-Script
-
+##### Input / Entrée
-```javascript
-.pipe(ezs('output', { meta: 'total' }))
+```json
+ [
+ { "_id": 1, "value": 2, "total": 2 },
+ { "_id": 2, "value": 4, "total": 2 }
+ ]
```
-Output
+##### Output / Sortie
+!!! Attention: This is an output function that can only be used at the end of an EZS script. !!!
+!!! The output is a string and can't be used with other EZS functions. !!!
-```javascript
-{
- data: [
- { _id: 1, value: 2 },
- { _id: 2, value: 4 }
- ],
- meta: {
- total: 2
- }
-}
+!!! Attention : Ceci est une fonction de sortie, Elle peut uniquement etre utilisé à la fin d'un script ezs !!!
+!!! Cette sortie est une chaine de carater et ne peut pas etre utilisé avec d'autre fonction ezs !!!
+
+```json
+ {
+ "data": [
+ { "_id": 1, "value": 2 },
+ { "_id": 2, "value": 4 }
+ ],
+ "meta": {
+ "total": 2
+ }
+ }
```
-Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
+#### Parameters
+
+- `indent` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**
+ indenté le json de sortie (optional, default `false`)
+- `meta` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** element from the input to put it in the `meta` object
+ élément a extraire de l'entrée et a mettre dans l'objet `meta`
+
+Returns **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
### pair
-Take `Object` object getting some fields with json path, and
-throw all pair of value from two fields
+Create a pair with 'id' containing a pair of the given 'path's and 'value' set to 1.
-```json
-[
- { departure: ['tokyo', 'nancy'], arrival: 'toul' },
- { departure: ['paris', 'nancy'], arrival: 'toul' },
- { departure: ['london', 'berlin'], arrival: 'toul' },
-]
-```
+Créer un couple 'id' contenent un couple des 'path's donnée et 'value' mise à 1.
-Script:
+##### Script / Scénario
```ini
+; Import analytics plugin required to use "pair"
+; Importation du plugin analytique nécessaire pour utiliser "pair"
[use]
plugin = analytics
+; Using "pair" with 'departure' and 'arrival' as paths setttings
+; Utilisation de "pair" avec 'departure' et 'arrival' comme paramètres de paths
[pair]
path = departure
path = arrival
```
-Output:
+##### Input / Entrée
```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 }
-]
+ [
+ { "departure": ["tokyo", "nancy"], "arrival": "toul" },
+ { "departure": ["paris", "nancy"], "arrival": "toul" },
+ { "departure": ["london", "berlin"], "arrival": "toul" }
+ ]
+```
+
+##### Output / Sortie
+
+```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)**
+- `null` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path of the element who will be use to create the pair
+ chemin de l'élément qui vas etre utilisé pour créer le couple
-Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
+Returns **{id: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>, value: `1`}**
### pluck
-Take `Object` object getting value of fields (with json `path`) and throws an
-object for each value
+Extract the value of a given `path` and create a pair with the `path` as the `id`
+and `path` value as the `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 },
-]
-```
+Extrais la valeur d'un `path` donnée et créer un couple avec pour identifient le `path`
+et comme `value` la valeur du `path`.
-Script:
+#### Example / Exemple
+
+##### Script / Scénario
```ini
+; Import analytics plugin required to use "pluck"
+; Importation du plugin analytique nécessaire pour utiliser "pluck"
[use]
plugin = analytics
+; Using "pluck" with 'year' as path setttings instead of 'id' how is the default value
+; Utilisation de "pluck" avec 'year' comme paramètres de path au lieux de la valeur par defaut qui et 'id'
[pluck]
path = year
```
-Output:
+##### Input / Entrée
```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 }
-]
+ [
+ { "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 }
+ ]
+```
+
+##### Output / Sortie
+
+```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
-- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use form group by (optional, default `id`)
+- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path of the element who need to be extrated
+ chemin de l'élément qui doit être extrais (optional, default `id`)
-Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
+Returns **{id: [String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), value: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)}**
### reducing
-Take `Object` group value of `{ id, value }` objectpath
+Merges the `id`, `value` pairs into a new pair, associating the identifier with the values.
-```json
-[{
- { id: 'x', value: 2 },
- { id: 't', value: 2 },
- { id: 'x', value: 3 },
- { id: 'x', value: 5 },
-}]
-```
+Fusionne les couple `id`, `value`, en un nouveau couple associent l'identifient au valeurs.
-Script:
+#### Example / Exemple
+
+##### Script / Scénario
```ini
+; Import analytics plugin required to use "reducing"
+; Importation du plugin analytique nécessaire pour utiliser "reducing"
[use]
plugin = analytics
+; Using "reducing" with default settings
+; Utilisation de "reducing" avec les paramètres par défaut
[reducing]
+; id = id
+; value = value
```
-Output:
+##### Input / Entrée
```json
-[
- { id: 'x', value: [2, 3, 5] },
- { id: 't', value: [2] },
-]
+ [
+ { "id": "x", "value": 2 },
+ { "id": "t", "value": 2 },
+ { "id": "x", "value": 3 },
+ { "id": "x", "value": 5 }
+ ]
+```
+
+##### Output / Sortie
+
+```json
+ [
+ { "id": "x", "value": [2, 3, 5] },
+ { "id": "t", "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 of the element who will be use as the key
+ chemin de l'élément qui vas être utilisé comme clé (optional, default `id`)
+- `value` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path of the element who will be merge into an array
+ chemin de l'élément qui vas être fussioné en un tableau (optional, default `value`)
-Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
+Returns **{id: [String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), value: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)>}**
### segment
-Take `Object` object getting some fields with json path, and throw segment of
-value. Ex: get `[a,b,c]` and throw `[a,b], [b,c]`
+Returns an object containing a segmentation of the input.
-```json
-[{
- {
- id: 'doc#1',
- value: [
- 1,
- 2,
- 3,
- 4,
- ],
- },
- {
- id: 'doc#2',
- value: [
- 4,
- 5,
- 6,
- ],
- },
- {
- id: 'doc#3',
- value: [
- 6,
- 7,
- ]
- },
- {
- id: 'doc#4',
- value: [
- 1,
- 2,
- 3,
- 4,
- 5,
- 6,
- 7,
- ]
- }
-}]
-```
+- `[a,b,c]` will be returned as `[a,b], [b,c]`
-Script:
+Renvoie un objet contenant une segmentation de l'entrée.
+
+- `[a,b,c]` sera retourné sous la forme `[a,b], [b,c]`
+
+#### Example / Exemple
+
+##### Script / Scénario
```ini
+; Import analytics plugin required to use "segment"
+; Importation du plugin analytique nécessaire pour utiliser "segment"
[use]
plugin = analytics
+; Using "segment" with default settings
+; Utilisation de "segment" avec les paramètres par défaut
[segment]
-path = value
+; aggregate = true
+; identifier = false
+; path = value
```
-Output:
+##### Input / Entrée
```json
-[
- { id: [ 1, 2 ], value: 1 }
- { id: [ 2, 3 ], value: 1 }
- { id: [ 3, 4 ], value: 1 }
- { id: [ 4, 5 ], value: 1 }
- { id: [ 5, 6 ], value: 1 }
- { id: [ 6, 7 ], value: 1 }
- { id: [ 1, 2 ], value: 1 }
- { id: [ 2, 3 ], value: 1 }
- { id: [ 3, 4 ], value: 1 }
- { id: [ 4, 5 ], value: 1 }
- { id: [ 5, 6 ], value: 1 }
- { id: [ 6, 7 ], value: 1 }
-]
+ [
+ {
+ "id": "doc#1",
+ "value": [
+ 1,
+ 2,
+ 3,
+ 4
+ ]
+ },
+ {
+ "id": "doc#2",
+ "value": [
+ 4,
+ 5,
+ 6
+ ]
+ },
+ {
+ "id": "doc#3",
+ "value": [
+ 6,
+ 7
+ ]
+ },
+ {
+ "id": "doc#4",
+ "value": [
+ 1,
+ 2,
+ 3,
+ 4,
+ 5,
+ 6,
+ 7
+ ]
+ }
+ ]
+```
+
+##### Output / Sortie
+
+```json
+ [
+ { "id": [ 1, 2 ], "value": 1 },
+ { "id": [ 2, 3 ], "value": 1 },
+ { "id": [ 3, 4 ], "value": 1 },
+ { "id": [ 4, 5 ], "value": 1 },
+ { "id": [ 5, 6 ], "value": 1 },
+ { "id": [ 6, 7 ], "value": 1 },
+ { "id": [ 1, 2 ], "value": 1 },
+ { "id": [ 2, 3 ], "value": 1 },
+ { "id": [ 3, 4 ], "value": 1 },
+ { "id": [ 4, 5 ], "value": 1 },
+ { "id": [ 5, 6 ], "value": 1 },
+ { "id": [ 6, 7 ], "value": 1 }
+ ]
```
#### Parameters
-- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path (optional, default `value`)
-- `aggregate` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** aggregate all values for all paths (or not) (optional, default `true`)
-- `identifier` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use to set value result field (if not set or not exists, 1 is use as a default value) (optional, default `false`)
+- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path of the element who need to be segmented
+ chemin de l'élément qui doit être segmentés (optional, default `value`)
+- `aggregate` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** aggregate all values for all paths (or not) aggregate all segmented value in one element (work if you have multiple path)
+ agréger toutes les valeurs segmentées en un seul élément (fonctionne si vous avez plusieurs chemins) (optional, default `true`)
+- `identifier` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path of the element who will be put in value field (if not set, fallback to `1`)
+ chemin de l'élément qui sera mis dans le champ valeur (si non défini, fallback à `1`) (optional, default `false`)
-Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
+Returns **{id: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)>, value: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)}**
### slice
-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
+Returns a copy of a section of a stream.
-```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 },
-}]
-```
+Renvoie une copie d'une section d'un flux.
-Script:
+#### Example / Exemple
+
+##### Script / Scénario
```ini
+; Import analytics plugin required to use "slice"
+; Importation du plugin analytique nécessaire pour utiliser "slice"
[use]
plugin = analytics
-[drop]
+; Using "slice" with default settings
+; Utilisation de "slice" avec les paramètres par défaut
+[slice]
+; start = 1
+; size = 10
```
-Output:
+##### Input / Entrée
```json
-[
-{ "id": 2001, "value": 2 },
-{ "id": 2003, "value": 3 },
-]
+ [
+ { "id": 2023, "value": 12 },
+ { "id": 2021, "value": 11 },
+ { "id": 2019, "value": 10 },
+ { "id": 2017, "value": 9 },
+ { "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 }
+ ]
+```
+
+##### Output / Sortie
+
+```json
+ [
+ { "id": 2023, "value": 12 },
+ { "id": 2021, "value": 11 },
+ { "id": 2019, "value": 10 },
+ { "id": 2017, "value": 9 },
+ { "id": 2013, "value": 8 },
+ { "id": 2011, "value": 7 },
+ { "id": 2009, "value": 6 },
+ { "id": 2007, "value": 5 },
+ { "id": 2005, "value": 4 },
+ { "id": 2003, "value": 3 }
+ ]
```
#### 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`)
+- `start` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** the beginning index of the specified portion of the stream
+ l'indice de début de la partie spécifiée du flux (optional, default `1`)
+- `size` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** the size of the specified portion of the stream
+ la taille de début de la partie spécifiée du flux (optional, default `10`)
Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
### sort
-Take all `Object` and sort them with dedicated key
+Sort incomming objects based on the value of the given path.
-```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 },
-}]
-```
+Trie les objets entrants en fonction de la valeur du champ donné par `path`.
-Script:
+#### Example / Exemple
+
+##### Script / Scénario
```ini
+; Import analytics plugin required to use "sort"
+; Importation du plugin analytique nécessaire pour utiliser "sort"
[use]
plugin = analytics
+; Using "sort" with default settings
+; Utilisation de "sort" avec les paramètres par défaut
[sort]
-path = value
-reverse = true
+; path = id
+; reverse = false
```
-Output:
+##### Input / Entrée
```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 }
-]
+ [
+ { "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 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)**
-
-### statistics
+##### Output / Sortie
-Compute some statistics from one or more fields
+```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 }
+ ]
+```
#### Parameters
-- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path of the value field (optional, default `value`)
-- `target` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path of statistics in output object (optional, default `_statistics`)
+- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path of the element used to as reference for the sort
+ chemin de l'élément utilisé comme référence pour le tri (optional, default `id`)
+- `reverse` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** sort in ascending or descending order
+ trier par ordre croissant ou décroissant (optional, default `false`)
-#### Examples
+Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
-Input
+### statistics
+Analyse and create statistics from given fields.
-````javascript
-```json
-[
- { a: 1, },
- { a: 1, },
- { a: 2, },
- { a: 3, },
- { a: 3, },
- { a: 3, },
-]
-```
-````
+Analyse et crée des statistiques à partir des champs donnés.
-Script
+#### Example / Exemple
+##### Script / Scénario
-````javascript
```ini
+; Import analytics plugin required to use "statistics"
+; Importation du plugin analytique nécessaire pour utiliser "statistics"
[use]
plugin = analytics
+; Using "statistics" with default settings
+; Utilisation de "statistics" avec les paramètres par défaut
[statistics]
-path = a
-
+; path = value
+; target = _statistics
```
-````
-Output
+##### Input / Entrée
+```json
+ [
+ { "value": 1 },
+ { "value": 1 },
+ { "value": 2 },
+ { "value": 3 },
+ { "value": 3 },
+ { "value": 3 }
+ ]
+```
+
+##### Output / Sortie
-````javascript
```json
-[{
- "a": 1,
- "stats": {
- "a": {
- "sample": 2,
- "frequency": 1,
- "percentage": 25,
- "sum": 4,
- "count": 3,
- "min": 1,
- "max": 2,
- "mean": 1.3333333333333333,
- "range": 1,
- "midrange": 0.5,
- "variance": 0.2222222222222222,
- "deviation": 0.4714045207910317,
- "population": 2
- }
- }
-},
-{
- "a": 1,
- "stats": {
- "a": {
- "sample": 2,
- "frequency": 1,
- "percentage": 25,
- "sum": 4,
- "count": 3,
- "min": 1,
- "max": 2,
- "mean": 1.3333333333333333,
- "range": 1,
- "midrange": 0.5,
- "variance": 0.2222222222222222,
- "deviation": 0.4714045207910317,
- "population": 2
- }
- }
-},
-{
- "a": 2,
- "stats": {
- "a": {
- "sample": 1,
- "frequency": 0.5,
- "percentage": 50,
- "sum": 4,
- "count": 3,
- "min": 1,
- "max": 2,
- "mean": 1.3333333333333333,
- "range": 1,
- "midrange": 0.5,
- "variance": 0.2222222222222222,
- "deviation": 0.4714045207910317,
- "population": 2
+ [
+ {
+ "value": 1,
+ "_statistics": {
+ "value": {
+ "sample": 2,
+ "frequency": 1,
+ "percentage": 25,
+ "sum": 4,
+ "count": 3,
+ "min": 1,
+ "max": 2,
+ "mean": 1.3333333333333333,
+ "range": 1,
+ "midrange": 0.5,
+ "variance": 0.2222222222222222,
+ "deviation": 0.4714045207910317,
+ "population": 2
+ }
+ }
+ },
+ {
+ "value": 1,
+ "_statistics": {
+ "value": {
+ "sample": 2,
+ "frequency": 1,
+ "percentage": 25,
+ "sum": 4,
+ "count": 3,
+ "min": 1,
+ "max": 2,
+ "mean": 1.3333333333333333,
+ "range": 1,
+ "midrange": 0.5,
+ "variance": 0.2222222222222222,
+ "deviation": 0.4714045207910317,
+ "population": 2
+ }
+ }
+ },
+ {
+ "value": 2,
+ "_statistics": {
+ "value": {
+ "sample": 1,
+ "frequency": 0.5,
+ "percentage": 50,
+ "sum": 4,
+ "count": 3,
+ "min": 1,
+ "max": 2,
+ "mean": 1.3333333333333333,
+ "range": 1,
+ "midrange": 0.5,
+ "variance": 0.2222222222222222,
+ "deviation": 0.4714045207910317,
+ "population": 2
+ }
+ }
}
- }
-}]
+ ]
```
-````
+
+#### Parameters
+
+- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path of the element used to create the statistics
+ chemin de l'élément utilisé pour créer les statistiques (optional, default `value`)
+- `target` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path of the statistics in the returned object
+ chemin des stastistiques dans l'objet retourné (optional, default `_statistics`)
Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
### summing
-Take special `Object` like `{id, value}` and replace `value` with the sum of
-`value`s
+Create an `id`, `value` pair from two given paths and apply a sum to the value.
-```json
-[
- { "id": "A", "value": [1, 1, 1] },
- { "id": "B", "value": [1] },
- { "id": "C", "value": [1, 1, 1, 1] },
-]
-```
+Créer un couple `id`, `value` à partir de chemins et applique une somme sur `value`.
-Script:
+#### Example / Exemple
+
+##### Script / Scénario
```ini
+; Import analytics plugin required to use "summing"
+; Importation du plugin analytique nécessaire pour utiliser "summing"
[use]
plugin = analytics
+; Using "summing" with default settings
+; Utilisation de "summing" avec les paramètres par défaut
[summing]
+; id = id
+; value = value
```
-Output:
+##### Input / Entrée
```json
-[{
- "id": "A", "value": 3
-},
-{
- "id": "B",
- "value": 1
-},
-{
- "id": "C",
- "value": 4
-}]
+ [
+ {
+ "id": 1,
+ "value": [1, 1, 1],
+ "hello": "world"
+ },
+ {
+ "id": 2,
+ "value": [2, 2, 2],
+ "hello": "world"
+ }
+ ]
+```
+
+##### Output / Sortie
+
+```json
+[
+ {
+ "id": 1,
+ "value": 3
+ },
+ {
+ "id": 2,
+ "value": 6
+ }
+]
```
#### 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 of the element used to create the new identifier
+ chemin de l'élément utilisé pour créer le nouvel identifiant (optional, default `id`)
+- `value` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path of the element to be summed
+ chemin de l'élément qui doit être sommé (optional, default `value`)
-Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
+Returns **{id: [String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), value: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)}**
### tune
-Take all `Object` and sort them with selected field
+Create and replace the id with a unified id that can be used with [sort](#sort).
-```json
-[{
-}]
-```
+Créer et remplacer l'identifiant par un identifiant unifié qui peut être utilisé avec [sort](#sort).
-Script:
+#### Example / Exemple
+
+##### Script / Scénario
```ini
+; Import analytics plugin required to use "tune"
+; Importation du plugin analytique nécessaire pour utiliser "tune"
[use]
plugin = analytics
+; Using "tune" with default settings
+; Utilisation de "tune" avec les paramètres par défaut
[tune]
+; path = id
+; method = natural
```
-Output:
+##### Input / Entrée
```json
-[
-]
+ [
+ {
+ "id": 1,
+ "value": 1
+ },
+ {
+ "id": 2,
+ "value": 2
+ }
+ ]
+```
+
+##### Output / Sortie
+
+```json
+ [
+ {
+ "id": "0000000000000000001.00000000000000000000",
+ "value": {
+ "id": 1,
+ "value": 1,
+ "label": "static value"
+ }
+ },
+ {
+ "id": "0000000000000000002.00000000000000000000",
+ "value": {
+ "id": 2,
+ "value": 2,
+ "label": "static value"
+ }
+ }
+ ]
```
#### Parameters
-- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for the sort key (optional, default `id`)
+- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path of the element used to create the unified identifier
+ chemin de l'élément utilisé pour créer l'identifiant unifié (optional, default `id`)
+- `method` **(`"natural"` \| `"levenshtein"` \| `"numerical"`)** method used to create the unified identifier
+ natural - Create a normalised identifier that is set to a fixed length
+ levenshtein - Create an identifier based on the Levenshtein algorithm
+ numerical - Create an identifier based on a numeric value
+ méthode utilisée pour créer l'identifiant unifié
+ natural - Crée un identifiant normalisé de longueur fixe
+ levenshtein - Crée un identifiant basé sur l'algorithme de Levenshtein
+ numerical - Crée un identifiant basé sur une valeur numérique (optional, default `natural`)
-Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
+Returns **{id: [String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), value: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)}**
### value
-Take `Object` object and getting the value field
+Create a new object from the value of the given `path`.
-```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 },
-]
-```
+Créer un nouvel objet à partir du chemin donné dans `path`.
-Script:
+#### Example / Exemple
+
+##### Script / Scénario
```ini
+; Import analytics plugin required to use "value"
+; Importation du plugin analytique nécessaire pour utiliser "value"
[use]
plugin = analytics
+; Using "value" with default settings
+; Utilisation de "tune" avec les paramètres par défaut
[value]
-path = id
+; path = value
```
-Output:
+##### Input / Entrée
+
+###### Dataset 1 / Jeu de données 1
```json
-[
-2000,
-2001,
-2003,
-2005,
-2007,
-2009,
-2011,
-2013
-]
+ [
+ { "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 }
+ ]
+```
+
+###### Dataset 2 / Jeu de données 2
+
+```json
+ [
+ {
+ "id": 1,
+ "value": {
+ "hello": "world"
+ }
+ },
+ {
+ "id": 2,
+ "value": {
+ "hello": "ezs"
+ }
+ },
+ {
+ "id": 3,
+ "value": {
+ "hello": "lodex"
+ }
+ }
+ ]
+```
+
+##### Output / Sortie
+
+###### Dataset 1 / Jeu de données 1
+
+```json
+ [
+ 1,
+ 2,
+ 3,
+ 4,
+ 5,
+ 6,
+ 7,
+ 8
+ ]
+```
+
+###### Dataset 2 / Jeu de données 2
+
+```json
+ [
+ {
+ "hello": "world"
+ },
+ {
+ "hello": "ezs"
+ },
+ {
+ "hello": "lodex"
+ }
+ ]
```
#### Parameters
-- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the pah of the value field (optional, default `value`)
+- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path of the element used to create the new object
+ chemin de l'élément utilisé pour créer le nouvel objet (optional, default `value`)
Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
diff --git a/packages/analytics/src/output.js b/packages/analytics/src/output.js
index a5b85d3c..2e3de1ce 100644
--- a/packages/analytics/src/output.js
+++ b/packages/analytics/src/output.js
@@ -1,47 +1,26 @@
import { get, unset } from 'lodash';
/**
- * Format the output with data a meta
- *
- * @example Input
- * [
- * { _id: 1, value: 2, total: 2 },
- * { _id: 2, value: 4, total: 2 }
- * ]
- *
- * @example Script
- * .pipe(ezs('output', { meta: 'total' }))
- *
- * @example Output
- * {
- * data: [
- * { _id: 1, value: 2 },
- * { _id: 2, value: 4 }
- * ],
- * meta: {
- * total: 2
- * }
- * }
- *
- * @name output
- * @param {boolean} [indent=false] indent or not
- * @param {string[]} [meta] fields to be considered as metadata
- * object
- * @returns {string}
+ * Pair function see documentation at the end.
+ * This part of the doc is used for jsdoc typing
+ * @private
+ * @param data {unknown}
+ * @param feed {Feed}
+ * @param ctx {import('../../core/src/engine').EngineScope}
*/
-function output(data, feed) {
- const indent = this.getParam('indent', false);
- const extract = this.getParam('meta');
+const output = (data, feed, ctx) => {
+ const indent = ctx.getParam('indent', false);
+ const extract = ctx.getParam('meta');
const extracts = Array.isArray(extract) ? extract : [extract];
const keys = extracts.filter((x) => x);
const cr = indent ? '\n ' : '';
const json = (d) => JSON.stringify(d, null, indent ? ' ' : null);
- if (this.isLast()) {
+ if (ctx.isLast()) {
feed.write(`]}${cr}`);
return feed.close();
}
- if (this.isFirst() && !this.isLast()) {
+ if (ctx.isFirst() && !ctx.isLast()) {
const values = keys.map((p) => get(data, p));
feed.write(`{${cr}"meta":{${cr}`);
if (keys.length > 0) {
@@ -63,7 +42,71 @@ function output(data, feed) {
keys.forEach((p) => unset(data, p));
feed.write(json(data));
return feed.end();
-}
+};
+
+/**
+ * Create an output string containing all incoming elements in a `data` array.
+ * with given `meta` extracted into an object called `meta`.
+ *
+ * Créer une sortie en chain de caratere avec les element entrent mise dans un tableau nommé `data`
+ * eyent les donnée `meta` extrais et mises dans un objet appelé `meta`.
+ *
+ * #### Script / Scénario
+ *
+ * ##### ini
+ *
+ * ```ini
+ * ; Import analytics plugin required to use "output"
+ * ; Importation du plugin analytique nécessaire pour utiliser "output"
+ * [use]
+ * plugin = analytics
+ *
+ * ; Using "output" with 'indent' as true and 'meta' as total
+ * ; Utilisation de "output" avec 'indent' à vrai et total comme paramètres de 'meta'
+ * [output]
+ * indent = true
+ * meta = total
+ *
+ * ```
+ *
+ * #### Input / Entrée
+ *
+ * ```json
+ * [
+ * { "_id": 1, "value": 2, "total": 2 },
+ * { "_id": 2, "value": 4, "total": 2 }
+ * ]
+ * ```
+ *
+ * #### Output / Sortie
+ *
+ * !!! Attention: This is an output function that can only be used at the end of an EZS script. !!!
+ * !!! The output is a string and can't be used with other EZS functions. !!!
+ *
+ * !!! Attention : Ceci est une fonction de sortie, Elle peut uniquement etre utilisé à la fin d'un script ezs !!!
+ * !!! Cette sortie est une chaine de carater et ne peut pas etre utilisé avec d'autre fonction ezs !!!
+ *
+ * ```json
+ * {
+ * "data": [
+ * { "_id": 1, "value": 2 },
+ * { "_id": 2, "value": 4 }
+ * ],
+ * "meta": {
+ * "total": 2
+ * }
+ * }
+ * ```
+ *
+ * @name output
+ * @param {Boolean} [indent=false]
+ *
+ * indenté le json de sortie
+ * @param {String} [meta]
+ * element from the input to put it in the `meta` object
+ * élément a extraire de l'entrée et a mettre dans l'objet `meta`
+ * @returns {String}
+ */
export default {
output,
};
diff --git a/packages/analytics/src/pair.js b/packages/analytics/src/pair.js
index 28d0cc94..1f30a71f 100644
--- a/packages/analytics/src/pair.js
+++ b/packages/analytics/src/pair.js
@@ -2,52 +2,19 @@ import { get } from 'lodash';
import core from './core';
/**
- * 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:
- *
- * ```ini
- * [use]
- * plugin = analytics
- *
- * [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 }
- * ]
- * ```
- *
- * @name pair
- * @param {String} path
- * @returns {Object}
+ * Pair function see documentation at the end.
+ * This part of the doc is used for jsdoc typing
+ * @private
+ * @param data {unknown}
+ * @param feed {Feed}
+ * @param ctx {import('../../core/src/engine').EngineScope}
*/
-export default function pair(data, feed) {
- if (this.isLast()) {
+const pair = (data, feed, ctx) => {
+ if (ctx.isLast()) {
feed.close();
return;
}
- let fields = this.getParam('path', []);
+ let fields = ctx.getParam('path', []);
if (!Array.isArray(fields)) {
fields = [fields];
}
@@ -68,4 +35,59 @@ export default function pair(data, feed) {
});
feed.end();
-}
+};
+
+/**
+ * Create a pair with 'id' containing a pair of the given 'path's and 'value' set to 1.
+ *
+ * Créer un couple 'id' contenent un couple des 'path's donnée et 'value' mise à 1.
+ *
+ * #### Script / Scénario
+ *
+ * ```ini
+ * ; Import analytics plugin required to use "pair"
+ * ; Importation du plugin analytique nécessaire pour utiliser "pair"
+ * [use]
+ * plugin = analytics
+ *
+ * ; Using "pair" with 'departure' and 'arrival' as paths setttings
+ * ; Utilisation de "pair" avec 'departure' et 'arrival' comme paramètres de paths
+ * [pair]
+ * path = departure
+ * path = arrival
+ *
+ * ```
+ *
+ * #### Input / Entrée
+ *
+ * ```json
+ * [
+ * { "departure": ["tokyo", "nancy"], "arrival": "toul" },
+ * { "departure": ["paris", "nancy"], "arrival": "toul" },
+ * { "departure": ["london", "berlin"], "arrival": "toul" }
+ * ]
+ * ```
+ *
+ * #### Output / Sortie
+ *
+ * ```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 }
+ * ]
+ * ```
+ *
+ * @name pair
+ * @param {String}
+ * path of the element who will be use to create the pair
+ * chemin de l'élément qui vas etre utilisé pour créer le couple
+ * @returns {{
+ * id: Array,
+ * value: 1
+ * }}
+ */
+export default pair;
diff --git a/packages/analytics/src/pluck.js b/packages/analytics/src/pluck.js
index 7efe21e5..19884614 100644
--- a/packages/analytics/src/pluck.js
+++ b/packages/analytics/src/pluck.js
@@ -1,68 +1,95 @@
import { get } from 'lodash';
import core from './core';
+
/**
- * Take `Object` object getting value of fields (with json `path`) and throws an
- * object for each value
+ * Pluck function see documentation at the end.
+ * This part of the doc is used for jsdoc typing
+ * @private
+ * @param data {unknown}
+ * @param feed {Feed}
+ * @param ctx {import('../../core/src/engine').EngineScope}
+ */
+const pluck = (data, feed, ctx) => {
+ if (ctx.isLast()) {
+ feed.close();
+ return;
+ }
+ let fields = ctx.getParam('path', 'id');
+ if (!Array.isArray(fields)) {
+ fields = [fields];
+ }
+
+ fields
+ .filter((k) => typeof k === 'string')
+ .map((key) => [key, get(data, key)])
+ .filter((x) => x[1])
+ .map((item) => ([item[0], (item[1] instanceof Array ? item[1] : [item[1]])]))
+ .reduce((prev, cur) => prev.concat(cur[1].map((x) => ([cur[0], x]))), [])
+ .forEach((item) => feed.write(core(item[0], item[1])));
+ feed.end();
+};
+
+/**
+ * Extract the value of a given `path` and create a pair with the `path` as the `id`
+ * and `path` value as the `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 },
- * ]
- * ```
+ * Extrais la valeur d'un `path` donnée et créer un couple avec pour identifient le `path`
+ * et comme `value` la valeur du `path`.
*
- * Script:
+ * ### Example / Exemple
+ *
+ * #### Script / Scénario
*
* ```ini
+ * ; Import analytics plugin required to use "pluck"
+ * ; Importation du plugin analytique nécessaire pour utiliser "pluck"
* [use]
* plugin = analytics
*
+ * ; Using "pluck" with 'year' as path setttings instead of 'id' how is the default value
+ * ; Utilisation de "pluck" avec 'year' comme paramètres de path au lieux de la valeur par defaut qui et 'id'
* [pluck]
* path = year
*
* ```
*
- * Output:
+ * #### Input / Entrée
+ *
+ * ```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 }
+ * ]
+ * ```
+ *
+ * #### Output / Sortie
*
* ```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 }
- * ]
+ * [
+ * { "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 }
+ * ]
* ```
*
* @name pluck
- * @param {String} [path=id] path to use form group by
- * @returns {Object}
+ * @param {String} [path=id]
+ * path of the element who need to be extrated
+ * chemin de l'élément qui doit être extrais
+ * @returns {{
+ * id: String,
+ * value: Object
+ * }}
*/
-export default function pluck(data, feed) {
- if (this.isLast()) {
- feed.close();
- return;
- }
- let fields = this.getParam('path', 'id');
- if (!Array.isArray(fields)) {
- fields = [fields];
- }
-
- fields
- .filter((k) => typeof k === 'string')
- .map((key) => [key, get(data, key)])
- .filter((x) => x[1])
- .map((item) => ([item[0], (item[1] instanceof Array ? item[1] : [item[1]])]))
- .reduce((prev, cur) => prev.concat(cur[1].map((x) => ([cur[0], x]))), [])
- .forEach((item) => feed.write(core(item[0], item[1])));
- feed.end();
-}
+export default pluck;
diff --git a/packages/analytics/src/reducing.js b/packages/analytics/src/reducing.js
index e0f22efd..d18728cb 100644
--- a/packages/analytics/src/reducing.js
+++ b/packages/analytics/src/reducing.js
@@ -2,58 +2,86 @@ import { get } from 'lodash';
import { createStore } from '@ezs/store';
/**
- * Take `Object` group value of `{ id, value }` objectpath
+ * Reducing function see documentation at the end.
+ * This part of the doc is used for jsdoc typing
+ * @private
+ * @param data {unknown}
+ * @param feed {Feed}
+ * @param ctx {import('../../core/src/engine').EngineScope}
+ */
+const reducing = async (data, feed, ctx) => {
+ if (!ctx.store) {
+ const location = ctx.getParam('location');
+ ctx.store = createStore(ctx.ezs, 'reducing', location);
+ }
+ if (ctx.isLast()) {
+ const stream = await ctx.store.empty();
+ stream
+ .on('data', (item) => feed.write(item))
+ .on('end', async () => {
+ await ctx.store.close();
+ feed.close();
+ });
+ } else {
+ const id = get(data, ctx.getParam('id', 'id')) || ctx.getIndex();
+ const value = get(data, ctx.getParam('value', 'value'));
+ await ctx.store.add(id, value);
+ feed.end();
+ }
+};
+
+/**
+ * Merges the `id`, `value` pairs into a new pair, associating the identifier with the values.
*
- * ```json
- * [{
- * { id: 'x', value: 2 },
- * { id: 't', value: 2 },
- * { id: 'x', value: 3 },
- * { id: 'x', value: 5 },
- * }]
- * ```
+ * Fusionne les couple `id`, `value`, en un nouveau couple associent l'identifient au valeurs.
*
- * Script:
+ * ### Example / Exemple
+ *
+ * #### Script / Scénario
*
* ```ini
+ * ; Import analytics plugin required to use "reducing"
+ * ; Importation du plugin analytique nécessaire pour utiliser "reducing"
* [use]
* plugin = analytics
*
+ * ; Using "reducing" with default settings
+ * ; Utilisation de "reducing" avec les paramètres par défaut
* [reducing]
+ * ; id = id
+ * ; value = value
*
* ```
*
- * Output:
+ * #### Input / Entrée
+ *
+ * ```json
+ * [
+ * { "id": "x", "value": 2 },
+ * { "id": "t", "value": 2 },
+ * { "id": "x", "value": 3 },
+ * { "id": "x", "value": 5 }
+ * ]
+ * ```
+ * #### Output / Sortie
*
* ```json
- * [
- * { id: 'x', value: [2, 3, 5] },
- * { id: 't', value: [2] },
- * ]
+ * [
+ * { "id": "x", "value": [2, 3, 5] },
+ * { "id": "t", "value": [2] }
+ * ]
* ```
*
* @name reducing
- * @param {String} [id=id] path to use for id
- * @param {String} [value=value] path to use for value
- * @returns {Object}
+ * @param {String} [id=id]
+ * path of the element who will be use as the key
+ * chemin de l'élément qui vas être utilisé comme clé
+ * @param {String} [value=value]
+ * path of the element who will be merge into an array
+ * chemin de l'élément qui vas être fussioné en un tableau
+ * @returns {{
+ * id: String,
+ * value: Array
+ * }}
*/
-export default async function reducing(data, feed) {
- if (!this.store) {
- const location = this.getParam('location');
- this.store = createStore(this.ezs, 'reducing', location);
- }
- if (this.isLast()) {
- const stream = await this.store.empty();
- stream
- .on('data', (item) => feed.write(item))
- .on('end', async () => {
- await this.store.close();
- feed.close();
- });
- } else {
- const id = get(data, this.getParam('id', 'id')) || this.getIndex();
- const value = get(data, this.getParam('value', 'value'));
- await this.store.add(id, value)
- feed.end();
- }
-}
+export default reducing;
diff --git a/packages/analytics/src/segment.js b/packages/analytics/src/segment.js
index a9c9743a..c04f413c 100644
--- a/packages/analytics/src/segment.js
+++ b/packages/analytics/src/segment.js
@@ -2,94 +2,21 @@ import { get, flatten } from 'lodash';
import core from './core';
/**
- * Take `Object` object getting some fields with json path, and throw segment of
- * value. Ex: get `[a,b,c]` and throw `[a,b], [b,c]`
- *
- * ```json
- * [{
- * {
- * id: 'doc#1',
- * value: [
- * 1,
- * 2,
- * 3,
- * 4,
- * ],
- * },
- * {
- * id: 'doc#2',
- * value: [
- * 4,
- * 5,
- * 6,
- * ],
- * },
- * {
- * id: 'doc#3',
- * value: [
- * 6,
- * 7,
- * ]
- * },
- * {
- * id: 'doc#4',
- * value: [
- * 1,
- * 2,
- * 3,
- * 4,
- * 5,
- * 6,
- * 7,
- * ]
- * }
- * }]
- * ```
- *
- * Script:
- *
- * ```ini
- * [use]
- * plugin = analytics
- *
- * [segment]
- * path = value
- *
- * ```
- *
- * Output:
- *
- * ```json
- * [
- * { id: [ 1, 2 ], value: 1 }
- * { id: [ 2, 3 ], value: 1 }
- * { id: [ 3, 4 ], value: 1 }
- * { id: [ 4, 5 ], value: 1 }
- * { id: [ 5, 6 ], value: 1 }
- * { id: [ 6, 7 ], value: 1 }
- * { id: [ 1, 2 ], value: 1 }
- * { id: [ 2, 3 ], value: 1 }
- * { id: [ 3, 4 ], value: 1 }
- * { id: [ 4, 5 ], value: 1 }
- * { id: [ 5, 6 ], value: 1 }
- * { id: [ 6, 7 ], value: 1 }
- * ]
- * ```
- *
- * @name segment
- * @param {String} [path=value] path
- * @param {Boolean} [aggregate=true] aggregate all values for all paths (or not)
- * @param {String} [identifier=false] path to use to set value result field (if not set or not exists, 1 is use as a default value)
- * @returns {Object}
+ * Segment function see documentation at the end.
+ * This part of the doc is used for jsdoc typing
+ * @private
+ * @param data {unknown}
+ * @param feed {Feed}
+ * @param ctx {import('../../core/src/engine').EngineScope}
*/
-export default function segment(data, feed) {
- if (this.isLast()) {
+const segment = (data, feed, ctx) => {
+ if (ctx.isLast()) {
feed.close();
return;
}
- const aggr = this.getParam('aggregate', true);
- const idt = this.getParam('identifier', false);
- const path = this.getParam('path', 'value');
+ const aggr = ctx.getParam('aggregate', true);
+ const idt = ctx.getParam('identifier', false);
+ const path = ctx.getParam('path', 'value');
const fields = Array.isArray(path) ? path : [path];
const valuesOrig = fields
@@ -119,4 +46,109 @@ export default function segment(data, feed) {
}
feed.end();
-}
+};
+
+/**
+ * Returns an object containing a segmentation of the input.
+ * - `[a,b,c]` will be returned as `[a,b], [b,c]`
+ *
+ * Renvoie un objet contenant une segmentation de l'entrée.
+ * - `[a,b,c]` sera retourné sous la forme `[a,b], [b,c]`
+ *
+ * ### Example / Exemple
+ *
+ * #### Script / Scénario
+ *
+ * ```ini
+ * ; Import analytics plugin required to use "segment"
+ * ; Importation du plugin analytique nécessaire pour utiliser "segment"
+ * [use]
+ * plugin = analytics
+ *
+ * ; Using "segment" with default settings
+ * ; Utilisation de "segment" avec les paramètres par défaut
+ * [segment]
+ * ; aggregate = true
+ * ; identifier = false
+ * ; path = value
+ *
+ * ```
+ *
+ * #### Input / Entrée
+ *
+ * ```json
+ * [
+ * {
+ * "id": "doc#1",
+ * "value": [
+ * 1,
+ * 2,
+ * 3,
+ * 4
+ * ]
+ * },
+ * {
+ * "id": "doc#2",
+ * "value": [
+ * 4,
+ * 5,
+ * 6
+ * ]
+ * },
+ * {
+ * "id": "doc#3",
+ * "value": [
+ * 6,
+ * 7
+ * ]
+ * },
+ * {
+ * "id": "doc#4",
+ * "value": [
+ * 1,
+ * 2,
+ * 3,
+ * 4,
+ * 5,
+ * 6,
+ * 7
+ * ]
+ * }
+ * ]
+ * ```
+ *
+ * #### Output / Sortie
+ *
+ * ```json
+ * [
+ * { "id": [ 1, 2 ], "value": 1 },
+ * { "id": [ 2, 3 ], "value": 1 },
+ * { "id": [ 3, 4 ], "value": 1 },
+ * { "id": [ 4, 5 ], "value": 1 },
+ * { "id": [ 5, 6 ], "value": 1 },
+ * { "id": [ 6, 7 ], "value": 1 },
+ * { "id": [ 1, 2 ], "value": 1 },
+ * { "id": [ 2, 3 ], "value": 1 },
+ * { "id": [ 3, 4 ], "value": 1 },
+ * { "id": [ 4, 5 ], "value": 1 },
+ * { "id": [ 5, 6 ], "value": 1 },
+ * { "id": [ 6, 7 ], "value": 1 }
+ * ]
+ * ```
+ *
+ * @name segment
+ * @param {String} [path=value]
+ * path of the element who need to be segmented
+ * chemin de l'élément qui doit être segmentés
+ * @param {Boolean} [aggregate=true] aggregate all values for all paths (or not)
+ * aggregate all segmented value in one element (work if you have multiple path)
+ * agréger toutes les valeurs segmentées en un seul élément (fonctionne si vous avez plusieurs chemins)
+ * @param {String} [identifier=false]
+ * path of the element who will be put in value field (if not set, fallback to `1`)
+ * chemin de l'élément qui sera mis dans le champ valeur (si non défini, fallback à `1`)
+ * @returns {{
+ * id: Array,
+ * value: Object,
+ * }}
+ */
+export default segment;
diff --git a/packages/analytics/src/slice.js b/packages/analytics/src/slice.js
index e3a005bb..da387b33 100644
--- a/packages/analytics/src/slice.js
+++ b/packages/analytics/src/slice.js
@@ -1,60 +1,98 @@
+
/**
- * 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
+ * Slice function see documentation at the end.
+ * This part of the doc is used for jsdoc typing
+ * @private
+ * @param data {unknown}
+ * @param feed {Feed}
+ * @param ctx {import('../../core/src/engine').EngineScope}
+ */
+const slice = (data, feed, ctx) => {
+ if (ctx.isLast()) {
+ feed.close();
+ return;
+ }
+ const start = Number(ctx.getParam('start')) || 1;
+ const size = Number(ctx.getParam('size')) || 10;
+ const stop = start + size;
+ const index = Number(ctx.getIndex());
+
+ if (index >= stop) {
+ feed.close();
+ } else {
+ if (index >= start) {
+ feed.write(data);
+ }
+ feed.end();
+ }
+};
+
+/**
+ * Returns a copy of a section of a stream.
*
- * ```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 },
- * }]
- * ```
+ * Renvoie une copie d'une section d'un flux.
*
- * Script:
+ * ### Example / Exemple
+ *
+ * #### Script / Scénario
*
* ```ini
+ * ; Import analytics plugin required to use "slice"
+ * ; Importation du plugin analytique nécessaire pour utiliser "slice"
* [use]
* plugin = analytics
*
- * [drop]
+ * ; Using "slice" with default settings
+ * ; Utilisation de "slice" avec les paramètres par défaut
+ * [slice]
+ * ; start = 1
+ * ; size = 10
+ *
+ * ```
*
+ * #### Input / Entrée
+ *
+ * ```json
+ * [
+ * { "id": 2023, "value": 12 },
+ * { "id": 2021, "value": 11 },
+ * { "id": 2019, "value": 10 },
+ * { "id": 2017, "value": 9 },
+ * { "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 }
+ * ]
* ```
*
- * Output:
+ * #### Output / Sortie
*
* ```json
- * [
- * { "id": 2001, "value": 2 },
- * { "id": 2003, "value": 3 },
- * ]
+ * [
+ * { "id": 2023, "value": 12 },
+ * { "id": 2021, "value": 11 },
+ * { "id": 2019, "value": 10 },
+ * { "id": 2017, "value": 9 },
+ * { "id": 2013, "value": 8 },
+ * { "id": 2011, "value": 7 },
+ * { "id": 2009, "value": 6 },
+ * { "id": 2007, "value": 5 },
+ * { "id": 2005, "value": 4 },
+ * { "id": 2003, "value": 3 }
+ * ]
* ```
*
* @name slice
- * @param {Number} [start=0] start of the slice
- * @param {Number} [size=10] size of the slice
+ * @param {Number} [start=1]
+ * the beginning index of the specified portion of the stream
+ * l'indice de début de la partie spécifiée du flux
+ * @param {Number} [size=10]
+ * the size of the specified portion of the stream
+ * la taille de début de la partie spécifiée du flux
* @returns {Object}
*/
-export default function slice(data, feed) {
- if (this.isLast()) {
- feed.close();
- return;
- }
- const start = Number(this.getParam('start')) || 1;
- const size = Number(this.getParam('size')) || 10;
- const stop = start + size;
- const index = Number(this.getIndex());
-
- if (index >= stop) {
- feed.close();
- } else {
- if (index >= start) {
- feed.write(data);
- }
- feed.end();
- }
-}
+export default slice;
diff --git a/packages/analytics/src/sort.js b/packages/analytics/src/sort.js
index d867f622..4580e95b 100644
--- a/packages/analytics/src/sort.js
+++ b/packages/analytics/src/sort.js
@@ -10,83 +10,114 @@ const sorting = (arr, reverse = false) => {
}
return fastsort(arr).desc();
};
+
+/**
+ * Sort function see documentation at the end.
+ * This part of the doc is used for jsdoc typing
+ * @private
+ * @param data {unknown}
+ * @param feed {Feed}
+ * @param ctx {import('../../core/src/engine').EngineScope}
+ */
+const sort = async (data, feed, ctx) => {
+ if (!ctx.store) {
+ const location = ctx.getParam('location');
+ ctx.store = createStore(ctx.ezs, 'sort', location);
+ ctx.table = [];
+ }
+ if (ctx.isLast()) {
+ const reverse = ctx.getParam('reverse', false);
+ const sorted = sorting(ctx.table, reverse);
+ await sorted.reduce(
+ async (previousPromise, cur) => {
+ await previousPromise;
+ return ctx.store.cut(cur)
+ .then((val) => feed.write(val));
+ },
+ Promise.resolve(),
+ );
+ await ctx.store.close();
+ feed.close();
+ } else {
+ const path = ctx.getParam('path', 'id');
+ const fields = Array.isArray(path) ? path : [path];
+ const keys = fields
+ .filter((k) => typeof k === 'string')
+ .map((key) => get(data, key));
+ const key = keys.length > 1 ? keys.join(',') : keys[0];
+ const idx = ctx.getIndex()
+ .toString()
+ .padStart(20, '0');
+ const hash = normalize(key)
+ .concat('~')
+ .concat(idx)
+ .replace(/\s/g, '~');
+ ctx.table.push(hash);
+ await ctx.store.put(hash, data);
+ feed.end();
+ }
+};
+
/**
- * Take all `Object` and sort them with dedicated key
+ * Sort incomming objects based on the value of the given path.
*
- * ```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 },
- * }]
- * ```
+ * Trie les objets entrants en fonction de la valeur du champ donné par `path`.
+ *
+ * ### Example / Exemple
*
- * Script:
+ * #### Script / Scénario
*
* ```ini
+ * ; Import analytics plugin required to use "sort"
+ * ; Importation du plugin analytique nécessaire pour utiliser "sort"
* [use]
* plugin = analytics
*
+ * ; Using "sort" with default settings
+ * ; Utilisation de "sort" avec les paramètres par défaut
* [sort]
- * path = value
- * reverse = true
+ * ; path = id
+ * ; reverse = false
+ *
+ * ```
+ *
+ * #### Input / Entrée
*
+ * ```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 }
+ * ]
* ```
*
- * Output:
+ * #### Output / Sortie
*
* ```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 }
- * ]
+ * [
+ * { "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 }
+ * ]
* ```
*
* @name sort
- * @param {String} [path=id] path to use for id
- * @param {boolean} [reverse=false] reverser order
+ * @param {String} [path=id]
+ * path of the element used to as reference for the sort
+ * chemin de l'élément utilisé comme référence pour le tri
+ * @param {boolean} [reverse=false]
+ * sort in ascending or descending order
+ * trier par ordre croissant ou décroissant
* @returns {Object}
*/
-export default async function sort(data, feed) {
- if (!this.store) {
- const location = this.getParam('location');
- this.store = createStore(this.ezs, 'sort', location);
- this.table = [];
- }
- if (this.isLast()) {
- const reverse = this.getParam('reverse', false);
- const sorted = sorting(this.table, reverse);
- await sorted.reduce(
- async (previousPromise, cur) => {
- await previousPromise;
- return this.store.cut(cur).then((val) => feed.write(val));
- },
- Promise.resolve(),
- );
- await this.store.close();
- feed.close();
- } else {
- const path = this.getParam('path', 'id');
- const fields = Array.isArray(path) ? path : [path];
- const keys = fields
- .filter((k) => typeof k === 'string')
- .map((key) => get(data, key));
- const key = keys.length > 1 ? keys.join(',') : keys[0];
- const idx = this.getIndex().toString().padStart(20, '0');
- const hash = normalize(key).concat('~').concat(idx).replace(/\s/g, '~');
- this.table.push(hash);
- await this.store.put(hash, data);
- feed.end();
- }
-}
+export default sort;
diff --git a/packages/analytics/src/statistics.js b/packages/analytics/src/statistics.js
index 67dd4d29..6e2e589b 100644
--- a/packages/analytics/src/statistics.js
+++ b/packages/analytics/src/statistics.js
@@ -28,115 +28,28 @@ const calculating = (values) => {
};
/**
- * Compute some statistics from one or more fields
- *
- * @example Input
- * ```json
- * [
- * { a: 1, },
- * { a: 1, },
- * { a: 2, },
- * { a: 3, },
- * { a: 3, },
- * { a: 3, },
- * ]
- * ```
- *
- * @example Script
- * ```ini
- * [use]
- * plugin = analytics
- *
- * [statistics]
- * path = a
- *
- * ```
- *
- * @example Output
- * ```json
- * [{
- * "a": 1,
- * "stats": {
- * "a": {
- * "sample": 2,
- * "frequency": 1,
- * "percentage": 25,
- * "sum": 4,
- * "count": 3,
- * "min": 1,
- * "max": 2,
- * "mean": 1.3333333333333333,
- * "range": 1,
- * "midrange": 0.5,
- * "variance": 0.2222222222222222,
- * "deviation": 0.4714045207910317,
- * "population": 2
- * }
- * }
- * },
- * {
- * "a": 1,
- * "stats": {
- * "a": {
- * "sample": 2,
- * "frequency": 1,
- * "percentage": 25,
- * "sum": 4,
- * "count": 3,
- * "min": 1,
- * "max": 2,
- * "mean": 1.3333333333333333,
- * "range": 1,
- * "midrange": 0.5,
- * "variance": 0.2222222222222222,
- * "deviation": 0.4714045207910317,
- * "population": 2
- * }
- * }
- * },
- * {
- * "a": 2,
- * "stats": {
- * "a": {
- * "sample": 1,
- * "frequency": 0.5,
- * "percentage": 50,
- * "sum": 4,
- * "count": 3,
- * "min": 1,
- * "max": 2,
- * "mean": 1.3333333333333333,
- * "range": 1,
- * "midrange": 0.5,
- * "variance": 0.2222222222222222,
- * "deviation": 0.4714045207910317,
- * "population": 2
- * }
- * }
- * }]
- * ```
- *
- * @export
- * @name statistics
- * @param {String} [path=value] path of the value field
- * @param {String} [target=_statistics] path of statistics in output object
- * @returns {Object}
+ * Statistics function see documentation at the end.
+ * This part of the doc is used for jsdoc typing
+ * @private
+ * @param data {unknown}
+ * @param feed {Feed}
+ * @param ctx {import('../../core/src/engine').EngineScope}
*/
-export default async function statistics(data, feed) {
- const path = this.getParam('path', 'value');
- const target = this.getParam('target', '_statistics');
+const statistics = async (data, feed, ctx) => {
+ const path = ctx.getParam('path', 'value');
+ const target = ctx.getParam('target', '_statistics');
const fields = Array.isArray(path) ? path : [path];
const keys = fields.filter((k) => typeof k === 'string');
- if (this.isFirst()) {
- const location = this.getParam('location');
- this.store = createStore(this.ezs, 'statistics', location);
- this.store.reset();
- this.stack = {};
+ if (ctx.isFirst()) {
+ const location = ctx.getParam('location');
+ ctx.store = createStore(ctx.ezs, 'statistics', location);
+ ctx.store.reset();
+ ctx.stack = {};
}
- if (this.isLast()) {
- const values = keys.filter((key) => this.stack[key]).reduce((obj, key) => {
- const result = calculating(this.stack[key].stat);
+ if (ctx.isLast()) {
+ const values = keys.filter((key) => ctx.stack[key]).reduce((obj, key) => {
+ const result = calculating(ctx.stack[key].stat);
const range = result.max - result.min;
const midrange = range / 2;
const variance = result.diff / result.count;
@@ -150,16 +63,16 @@ export default async function statistics(data, feed) {
midrange,
variance,
deviation: Math.sqrt(variance),
- population: Object.keys(this.stack[key].hash).length,
+ population: Object.keys(ctx.stack[key].hash).length,
};
return obj;
}, {});
- const stream = await this.store.empty();
+ const stream = await ctx.store.empty();
stream
.on('data', ({ value }) => {
const localValues = value.hashValues.reduce((obj, item) => {
- const sample = this.stack[item.key].hash[item.hashValue];
- const percentage = (100 * this.stack[item.key].vals[item.hashValue]) / values[item.key].sum;
+ const sample = ctx.stack[item.key].hash[item.hashValue];
+ const percentage = (100 * ctx.stack[item.key].vals[item.hashValue]) / values[item.key].sum;
const frequency = sample / values[item.key].population;
obj[item.key] = {
sample,
@@ -173,7 +86,7 @@ export default async function statistics(data, feed) {
feed.write(value.data);
})
.on('end', async () => {
- await this.store.close();
+ await ctx.store.close();
feed.close();
});
return;
@@ -181,11 +94,11 @@ export default async function statistics(data, feed) {
const hashValues = keys.map((key) => {
const rawValue = get(data, key);
if (!rawValue) return;
- if (!this.stack[key]) {
- this.stack[key] = { stat: [], hash: {}, vals: {} };
+ if (!ctx.stack[key]) {
+ ctx.stack[key] = { stat: [], hash: {}, vals: {} };
}
const numValue = Number(rawValue);
- this.stack[key].stat.push({
+ ctx.stack[key].stat.push({
sum: numValue || 0,
min: numValue || 0,
max: numValue || 0,
@@ -193,14 +106,126 @@ export default async function statistics(data, feed) {
diff: 0,
});
const hashValue = hashCoerce.hash(rawValue);
- if (this.stack[key].hash[hashValue]) {
- this.stack[key].hash[hashValue] += 1;
+ if (ctx.stack[key].hash[hashValue]) {
+ ctx.stack[key].hash[hashValue] += 1;
} else {
- this.stack[key].hash[hashValue] = 1;
+ ctx.stack[key].hash[hashValue] = 1;
}
- this.stack[key].vals[hashValue] = numValue;
+ ctx.stack[key].vals[hashValue] = numValue;
return { key, hashValue };
}).filter(Boolean);
- const uri = 'uid:'.concat(this.getIndex().toString().padStart(10, '0'));
- this.store.put(uri, { data, hashValues }).then(() => feed.end());
-}
+ const uri = 'uid:'.concat(ctx.getIndex().toString().padStart(10, '0'));
+ ctx.store.put(uri, { data, hashValues }).then(() => feed.end());
+};
+
+/**
+ * Analyse and create statistics from given fields.
+ *
+ * Analyse et crée des statistiques à partir des champs donnés.
+ *
+ * ### Example / Exemple
+ *
+ * #### Script / Scénario
+ * ```ini
+ * ; Import analytics plugin required to use "statistics"
+ * ; Importation du plugin analytique nécessaire pour utiliser "statistics"
+ * [use]
+ * plugin = analytics
+ *
+ * ; Using "statistics" with default settings
+ * ; Utilisation de "statistics" avec les paramètres par défaut
+ * [statistics]
+ * ; path = value
+ * ; target = _statistics
+ *
+ * ```
+ *
+ * #### Input / Entrée
+ * ```json
+ * [
+ * { "value": 1 },
+ * { "value": 1 },
+ * { "value": 2 },
+ * { "value": 3 },
+ * { "value": 3 },
+ * { "value": 3 }
+ * ]
+ * ```
+ *
+ * #### Output / Sortie
+ *
+ * ```json
+ * [
+ * {
+ * "value": 1,
+ * "_statistics": {
+ * "value": {
+ * "sample": 2,
+ * "frequency": 1,
+ * "percentage": 25,
+ * "sum": 4,
+ * "count": 3,
+ * "min": 1,
+ * "max": 2,
+ * "mean": 1.3333333333333333,
+ * "range": 1,
+ * "midrange": 0.5,
+ * "variance": 0.2222222222222222,
+ * "deviation": 0.4714045207910317,
+ * "population": 2
+ * }
+ * }
+ * },
+ * {
+ * "value": 1,
+ * "_statistics": {
+ * "value": {
+ * "sample": 2,
+ * "frequency": 1,
+ * "percentage": 25,
+ * "sum": 4,
+ * "count": 3,
+ * "min": 1,
+ * "max": 2,
+ * "mean": 1.3333333333333333,
+ * "range": 1,
+ * "midrange": 0.5,
+ * "variance": 0.2222222222222222,
+ * "deviation": 0.4714045207910317,
+ * "population": 2
+ * }
+ * }
+ * },
+ * {
+ * "value": 2,
+ * "_statistics": {
+ * "value": {
+ * "sample": 1,
+ * "frequency": 0.5,
+ * "percentage": 50,
+ * "sum": 4,
+ * "count": 3,
+ * "min": 1,
+ * "max": 2,
+ * "mean": 1.3333333333333333,
+ * "range": 1,
+ * "midrange": 0.5,
+ * "variance": 0.2222222222222222,
+ * "deviation": 0.4714045207910317,
+ * "population": 2
+ * }
+ * }
+ * }
+ * ]
+ * ```
+ *
+ * @name statistics
+ * @param {String} [path=value]
+ * path of the element used to create the statistics
+ * chemin de l'élément utilisé pour créer les statistiques
+ * @param {String} [target=_statistics]
+ * path of the statistics in the returned object
+ * chemin des stastistiques dans l'objet retourné
+ * @returns {Object}
+ */
+export default statistics;
\ No newline at end of file
diff --git a/packages/analytics/src/summing.js b/packages/analytics/src/summing.js
index d1d7f232..9fca015c 100644
--- a/packages/analytics/src/summing.js
+++ b/packages/analytics/src/summing.js
@@ -1,58 +1,97 @@
import { get } from 'lodash';
import core from './core';
+
/**
- * Take special `Object` like `{id, value}` and replace `value` with the sum of
- * `value`s
+ * Summing function see documentation at the end.
+ * This part of the doc is used for jsdoc typing
+ * @private
+ * @param data {unknown}
+ * @param feed {Feed}
+ * @param ctx {import('../../core/src/engine').EngineScope}
+ */
+const summing = (data, feed, ctx) => {
+ if (ctx.isLast()) {
+ feed.close();
+ return;
+ }
+
+ const id = get(data, ctx.getParam('id', 'id')) || ctx.getIndex();
+ const value = get(data, ctx.getParam('value', 'value'));
+
+ const values = Array.isArray(value) ? value : [value];
+
+ if (id && value) {
+ feed.write(core(id, values.reduce((sum, x) => sum + Number(x), 0)));
+ }
+
+ feed.end();
+};
+
+/**
+ * Create an `id`, `value` pair from two given paths and apply a sum to the value.
*
- * ```json
- * [
- * { "id": "A", "value": [1, 1, 1] },
- * { "id": "B", "value": [1] },
- * { "id": "C", "value": [1, 1, 1, 1] },
- * ]
- * ```
+ * Créer un couple `id`, `value` à partir de chemins et applique une somme sur `value`.
*
- * Script:
+ * ### Example / Exemple
+ *
+ * #### Script / Scénario
*
* ```ini
+ * ; Import analytics plugin required to use "summing"
+ * ; Importation du plugin analytique nécessaire pour utiliser "summing"
* [use]
* plugin = analytics
*
+ * ; Using "summing" with default settings
+ * ; Utilisation de "summing" avec les paramètres par défaut
* [summing]
+ * ; id = id
+ * ; value = value
*
* ```
*
- * Output:
+ * #### Input / Entrée
*
* ```json
- * [{
- * "id": "A", "value": 3
- * },
- * {
- * "id": "B",
- * "value": 1
- * },
- * {
- * "id": "C",
- * "value": 4
- * }]
- * ```
+ * [
+ * {
+ * "id": 1,
+ * "value": [1, 1, 1],
+ * "hello": "world"
+ * },
+ * {
+ * "id": 2,
+ * "value": [2, 2, 2],
+ * "hello": "world"
+ * }
+ * ]
+ * ```
+ *
+ * #### Output / Sortie
+ *
+ * ```json
+ * [
+ * {
+ * "id": 1,
+ * "value": 3
+ * },
+ * {
+ * "id": 2,
+ * "value": 6
+ * }
+ * ]
+ * ```
*
* @name summing
- * @param {String} [id=id] path to use for id
- * @param {String} [value=value] path to use for value
- * @returns {Object}
+ * @param {String} [id=id]
+ * path of the element used to create the new identifier
+ * chemin de l'élément utilisé pour créer le nouvel identifiant
+ * @param {String} [value=value]
+ * path of the element to be summed
+ * chemin de l'élément qui doit être sommé
+ * @returns {{
+ * id: String,
+ * value: Object
+ * }}
*/
-export default function summing(data, feed) {
- if (this.isLast()) {
- feed.close();
- return;
- }
- const id = get(data, this.getParam('id', 'id')) || this.getIndex();
- const value = get(data, this.getParam('value', 'value'));
- const values = Array.isArray(value) ? value : [value];
- if (id && value) {
- feed.write(core(id, values.reduce((sum, x) => sum + Number(x), 0)));
- }
- feed.end();
-}
+export default summing;
diff --git a/packages/analytics/src/tune.js b/packages/analytics/src/tune.js
index 2899b48c..3c687676 100644
--- a/packages/analytics/src/tune.js
+++ b/packages/analytics/src/tune.js
@@ -2,6 +2,11 @@ import { get, clone } from 'lodash';
import { levenshteinDistance } from './algorithms';
import core from './core';
+/**
+ * @private
+ * @param s {string | number | unknown}
+ * @returns {string}
+ */
export const normalize = (s) => {
if (typeof s === 'string') {
return String(s).normalize('NFD').replace(/[\u0300-\u036f]/g, '').padEnd(40, '~');
@@ -12,7 +17,20 @@ export const normalize = (s) => {
return String(s);
};
+/**
+ * @private
+ * @param x {string | number | unknown}
+ * @param y {string | number | unknown}
+ * @returns {*}
+ */
const levenshtein = (x, y) => levenshteinDistance(normalize(x), normalize(y));
+
+/**
+ * @private
+ * @param x {number}
+ * @param y {number}
+ * @returns {number}
+ */
const numerical = (x, y) => (x + 1) / (y + 1);
const methods = {
@@ -22,41 +40,20 @@ const methods = {
const allMethods = Object.keys(methods).join(',');
/**
- * Take all `Object` and sort them with selected field
- *
- * ```json
- * [{
- * }]
- * ```
- *
- * Script:
- *
- * ```ini
- * [use]
- * plugin = analytics
- *
- * [tune]
- *
- * ```
- *
- * Output:
- *
- * ```json
- * [
- * ]
- * ```
- *
- * @name tune
- * @param {String} [path=id] path to use for the sort key
- * @returns {Object}
+ * Tune function see documentation at the end.
+ * This part of the doc is used for jsdoc typing
+ * @private
+ * @param data {unknown}
+ * @param feed {Feed}
+ * @param ctx {import('../../core/src/engine').EngineScope}
*/
-export default function tune(data, feed) {
- if (this.isLast()) {
+const tune = (data, feed, ctx) => {
+ if (ctx.isLast()) {
feed.close();
return;
}
- const path = this.getParam('path', 'id');
- const method = this.getParam('method', 'natural');
+ const path = ctx.getParam('path', 'id');
+ const method = ctx.getParam('method', 'natural');
const fields = Array.isArray(path) ? path : [path];
const currentValue = fields
.filter((k) => typeof k === 'string')
@@ -72,21 +69,102 @@ export default function tune(data, feed) {
return;
}
- if (!this.previousValue) {
- this.previousValue = currentValue;
- this.previousDistance = 1;
+ if (!ctx.previousValue) {
+ ctx.previousValue = currentValue;
+ ctx.previousDistance = 1;
feed.send(core(1, data));
return;
}
- const similarity = methods[method](this.previousValue, currentValue);
- const score = similarity === 0 ? Math.max(this.previousValue.length, currentValue.length) : similarity;
- const currentDistance = this.previousDistance / score;
+ const similarity = methods[method](ctx.previousValue, currentValue);
+ const score = similarity === 0 ? Math.max(ctx.previousValue.length, currentValue.length) : similarity;
+ const currentDistance = ctx.previousDistance / score;
- this.previousValue = clone(currentValue);
- this.previousDistance = clone(currentDistance);
+ ctx.previousValue = clone(currentValue);
+ ctx.previousDistance = clone(currentDistance);
feed.send(core(currentDistance, data));
-}
+};
+
+/**
+ * Create and replace the id with a unified id that can be used with [sort](#sort).
+ *
+ * Créer et remplacer l'identifiant par un identifiant unifié qui peut être utilisé avec [sort](#sort).
+ *
+ * ### Example / Exemple
+ *
+ * #### Script / Scénario
+ *
+ * ```ini
+ * ; Import analytics plugin required to use "tune"
+ * ; Importation du plugin analytique nécessaire pour utiliser "tune"
+ * [use]
+ * plugin = analytics
+ *
+ * ; Using "tune" with default settings
+ * ; Utilisation de "tune" avec les paramètres par défaut
+ * [tune]
+ * ; path = id
+ * ; method = natural
+ *
+ * ```
+ *
+ * #### Input / Entrée
+ *
+ * ```json
+ * [
+ * {
+ * "id": 1,
+ * "value": 1
+ * },
+ * {
+ * "id": 2,
+ * "value": 2
+ * }
+ * ]
+ * ```
+ *
+ * #### Output / Sortie
+ *
+ * ```json
+ * [
+ * {
+ * "id": "0000000000000000001.00000000000000000000",
+ * "value": {
+ * "id": 1,
+ * "value": 1,
+ * "label": "static value"
+ * }
+ * },
+ * {
+ * "id": "0000000000000000002.00000000000000000000",
+ * "value": {
+ * "id": 2,
+ * "value": 2,
+ * "label": "static value"
+ * }
+ * }
+ * ]
+ * ```
+ *
+ * @name tune
+ * @param {String} [path=id]
+ * path of the element used to create the unified identifier
+ * chemin de l'élément utilisé pour créer l'identifiant unifié
+ * @param {'natural' | 'levenshtein' | 'numerical'} [method=natural]
+ * method used to create the unified identifier
+ * natural - Create a normalised identifier that is set to a fixed length
+ * levenshtein - Create an identifier based on the Levenshtein algorithm
+ * numerical - Create an identifier based on a numeric value
+ * méthode utilisée pour créer l'identifiant unifié
+ * natural - Crée un identifiant normalisé de longueur fixe
+ * levenshtein - Crée un identifiant basé sur l'algorithme de Levenshtein
+ * numerical - Crée un identifiant basé sur une valeur numérique
+ * @returns {{
+ * id: String,
+ * value: Object
+ * }}
+ */
+export default tune;
/*
diff --git a/packages/analytics/src/value.js b/packages/analytics/src/value.js
index 54864815..44ac843b 100644
--- a/packages/analytics/src/value.js
+++ b/packages/analytics/src/value.js
@@ -1,64 +1,131 @@
import { get } from 'lodash';
/**
- * Take `Object` object and getting the value field
+ * Value function see documentation at the end.
+ * This part of the doc is used for jsdoc typing
+ * @private
+ * @param data {unknown}
+ * @param feed {Feed}
+ * @param ctx {import('../../core/src/engine').EngineScope}
+ */
+const value = (data, feed, ctx) => {
+ if (ctx.isLast()) {
+ feed.close();
+ return;
+ }
+ const path = ctx.getParam('path', 'value');
+ const fields = Array.isArray(path) ? path : [path];
+
+ const val = fields
+ .filter((k) => typeof k === 'string')
+ .map((key) => get(data, key))
+ .filter((x) => x !== undefined)
+ .filter((x) => x !== null)[0];
+
+ feed.send(val);
+};
+
+/**
+ * Create a new object from the value of the given `path`.
*
- * ```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 },
- * ]
- * ```
+ * Créer un nouvel objet à partir du chemin donné dans `path`.
*
- * Script:
+ * ### Example / Exemple
+ *
+ * #### Script / Scénario
*
* ```ini
+ * ; Import analytics plugin required to use "value"
+ * ; Importation du plugin analytique nécessaire pour utiliser "value"
* [use]
* plugin = analytics
*
+ * ; Using "value" with default settings
+ * ; Utilisation de "tune" avec les paramètres par défaut
* [value]
- * path = id
+ * ; path = value
+ *
+ * ```
+ *
+ * #### Input / Entrée
+ *
+ * ##### Dataset 1 / Jeu de données 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 }
+ * ]
+ * ```
+ *
+ * ##### Dataset 2 / Jeu de données 2
+ *
+ * ```json
+ * [
+ * {
+ * "id": 1,
+ * "value": {
+ * "hello": "world"
+ * }
+ * },
+ * {
+ * "id": 2,
+ * "value": {
+ * "hello": "ezs"
+ * }
+ * },
+ * {
+ * "id": 3,
+ * "value": {
+ * "hello": "lodex"
+ * }
+ * }
+ * ]
* ```
*
- * Output:
+ * #### Output / Sortie
+ *
+ * ##### Dataset 1 / Jeu de données 1
*
* ```json
- * [
- * 2000,
- * 2001,
- * 2003,
- * 2005,
- * 2007,
- * 2009,
- * 2011,
- * 2013
- * ]
+ * [
+ * 1,
+ * 2,
+ * 3,
+ * 4,
+ * 5,
+ * 6,
+ * 7,
+ * 8
+ * ]
+ * ```
+ *
+ * ##### Dataset 2 / Jeu de données 2
+ *
+ * ```json
+ * [
+ * {
+ * "hello": "world"
+ * },
+ * {
+ * "hello": "ezs"
+ * },
+ * {
+ * "hello": "lodex"
+ * }
+ * ]
* ```
*
* @name value
- * @param {String} [path=value] the pah of the value field
+ * @param {String} [path=value]
+ * path of the element used to create the new object
+ * chemin de l'élément utilisé pour créer le nouvel objet
* @returns {Object}
*/
-export default function value(data, feed) {
- if (this.isLast()) {
- feed.close();
- return;
- }
- const path = this.getParam('path', 'value');
- const fields = Array.isArray(path) ? path : [path];
-
- const val = fields
- .filter((k) => typeof k === 'string')
- .map((key) => get(data, key))
- .filter((x) => x !== undefined)
- .filter((x) => x !== null)[0];
-
- feed.send(val);
-}
+export default value;
diff --git a/packages/analytics/test-utils/runEzs.js b/packages/analytics/test-utils/runEzs.js
new file mode 100644
index 00000000..4c55cebb
--- /dev/null
+++ b/packages/analytics/test-utils/runEzs.js
@@ -0,0 +1,23 @@
+import from from 'from';
+
+/**
+ * Helper function used to call ezs in each test
+ * @param ezsRuntime {(name: string, options: any, environment?: unknown) => NodeJS.WritableStream}
+ * @param dataSet {Array}
+ * @param functionName {string}
+ * @param [options] {any}
+ * @returns {Promise>}
+ */
+const runEzs = (ezsRuntime, dataSet, functionName, options) => new Promise((resolve) => {
+ const result = [];
+ from(dataSet)
+ .pipe(ezsRuntime(functionName, options))
+ .on('data', (chunk) => {
+ result.push(chunk);
+ })
+ .on('end', () => {
+ resolve(result);
+ });
+});
+
+export default runEzs;
\ No newline at end of file
diff --git a/packages/analytics/test/summing.spec.js b/packages/analytics/test/summing.spec.js
new file mode 100644
index 00000000..a6f76177
--- /dev/null
+++ b/packages/analytics/test/summing.spec.js
@@ -0,0 +1,170 @@
+import ezs from '../../core/src';
+import summing from '../src/summing';
+import runEzs from '../test-utils/runEzs';
+
+ezs.addPath(__dirname);
+
+describe('summing', () => {
+
+ beforeAll(() => {
+ ezs.use({ summing });
+ });
+
+ describe('wrong data', () => {
+ const undefinedData = [
+ undefined,
+ undefined,
+ undefined,
+ undefined
+ ];
+
+ const nullData = [
+ null,
+ null,
+ null,
+ null
+ ];
+
+ const undefinedNullData = [
+ undefined,
+ null,
+ undefined,
+ null
+ ];
+
+ const wrongKeyData = [
+ {
+ 'hello': 'world',
+ },
+ {
+ 'hello': 'world',
+ }
+ ];
+
+ it('should return no result when input contains only undefined', async () => {
+ const result = await runEzs(ezs, undefinedData, 'summing');
+
+ expect(result).toHaveLength(0);
+ });
+
+ it.skip('should return no result when input contains only null', async () => {
+ const result = await runEzs(ezs, nullData, 'summing');
+
+ expect(result).toHaveLength(0);
+ });
+
+ it.skip('should return no result when input contains undefined and null', async () => {
+ const result = await runEzs(ezs, undefinedNullData, 'summing');
+
+ expect(result).toHaveLength(0);
+ });
+
+ it('should return no result when input contains wrong key', async () => {
+ const result = await runEzs(ezs, wrongKeyData, 'summing');
+
+ expect(result).toHaveLength(0);
+ });
+ });
+
+ describe('summing, simple object', () => {
+ const simpleData = [
+ {
+ 'id': 1,
+ 'value': [1, 1, 1]
+ },
+ {
+ 'id': 2,
+ 'value': [2, 2, 2]
+ }
+ ];
+
+ it('should sum value (id = id, value = value)', async () => {
+ const result = await runEzs(ezs, simpleData, 'summing');
+
+ expect(result).not.toBeNull();
+
+ expect(result).toHaveLength(2);
+
+ expect(result[0]).not.toBeNull();
+ expect(result[0].id).toStrictEqual(1);
+ expect(result[0].value).toStrictEqual(3);
+
+ expect(result[1]).not.toBeNull();
+ expect(result[1].id).toStrictEqual(2);
+ expect(result[1].value).toStrictEqual(6);
+ });
+
+ it('should not sum id (id = value, value = id)', async () => {
+ const result = await runEzs(ezs, simpleData, 'summing', {
+ id : 'value',
+ value: 'id',
+ });
+
+ expect(result).not.toBeNull();
+
+ expect(result).toHaveLength(2);
+
+ expect(result[0]).not.toBeNull();
+ expect(result[0].id).toStrictEqual([1, 1, 1]);
+ expect(result[0].value).toStrictEqual(1);
+
+ expect(result[1]).not.toBeNull();
+ expect(result[1].id).toStrictEqual([2, 2, 2]);
+ expect(result[1].value).toStrictEqual(2);
+ });
+ });
+
+ describe('summing, noisy object', () => {
+ const noisyData = [
+ {
+ 'id': 2,
+ 'value': [10, 10, 10],
+ 'hello': 'world'
+ },
+ {
+ 'id': 4,
+ 'value': [20, 20, 20],
+ 'hello': 'world'
+ }
+ ];
+
+ it('should sum value and remove noise (id = id, value = value)', async () => {
+ const result = await runEzs(ezs, noisyData, 'summing');
+
+ expect(result).not.toBeNull();
+
+ expect(result).toHaveLength(2);
+
+ expect(result[0]).not.toBeNull();
+ expect(result[0].id).toStrictEqual(2);
+ expect(result[0].value).toStrictEqual(30);
+ expect(result[0]).not.toHaveProperty('hello');
+
+ expect(result[1]).not.toBeNull();
+ expect(result[1].id).toStrictEqual(4);
+ expect(result[1].value).toStrictEqual(60);
+ expect(result[1]).not.toHaveProperty('hello');
+ });
+
+ it('should not sum id and remove noise (id = value, value = id)', async () => {
+ const result = await runEzs(ezs, noisyData, 'summing', {
+ id : 'value',
+ value: 'id',
+ });
+
+ expect(result).not.toBeNull();
+
+ expect(result).toHaveLength(2);
+
+ expect(result[0]).not.toBeNull();
+ expect(result[0].id).toStrictEqual([10, 10, 10]);
+ expect(result[0].value).toStrictEqual(2);
+ expect(result[0]).not.toHaveProperty('hello');
+
+ expect(result[1]).not.toBeNull();
+ expect(result[1].id).toStrictEqual([20, 20, 20]);
+ expect(result[1].value).toStrictEqual(4);
+ expect(result[1]).not.toHaveProperty('hello');
+ });
+ });
+});
\ No newline at end of file
diff --git a/packages/analytics/test/tune.spec.js b/packages/analytics/test/tune.spec.js
new file mode 100644
index 00000000..f4788a56
--- /dev/null
+++ b/packages/analytics/test/tune.spec.js
@@ -0,0 +1,158 @@
+import ezs from '../../core/src';
+import tune from '../src/tune';
+import runEzs from '../test-utils/runEzs';
+
+ezs.addPath(__dirname);
+
+describe('tune', () => {
+
+ beforeAll(() => {
+ ezs.use({ tune });
+ });
+
+ describe('wrong data', () => {
+ const undefinedData = [
+ undefined,
+ undefined,
+ undefined,
+ undefined
+ ];
+
+ const nullData = [
+ null,
+ null,
+ null,
+ null
+ ];
+
+ const undefinedNullData = [
+ undefined,
+ null,
+ undefined,
+ null
+ ];
+
+ const wrongKeyData = [
+ {
+ 'hello': 'world',
+ },
+ {
+ 'hello': 'world',
+ }
+ ];
+
+ it.skip('should return no result when input contains only undefined', async () => {
+ const result = await runEzs(ezs, undefinedData, 'tune');
+
+ expect(result).toHaveLength(0);
+ });
+
+ it.skip('should return no result when input contains only null', async () => {
+ const result = await runEzs(ezs, nullData, 'tune');
+
+ expect(result).toHaveLength(0);
+ });
+
+ it.skip('should return no result when input contains undefined and null', async () => {
+ const result = await runEzs(ezs, undefinedNullData, 'tune');
+
+ expect(result).toHaveLength(0);
+ });
+
+ it('should return no result when input contains wrong key', async () => {
+ const result = await runEzs(ezs, wrongKeyData, 'tune');
+
+ expect(result).toHaveLength(2);
+
+ expect(result[0]).not.toBeNull();
+ expect(result[0].id).toStrictEqual('undefined');
+ expect(result[0].value).toStrictEqual({
+ 'hello': 'world',
+ });
+
+ expect(result[1]).not.toBeNull();
+ expect(result[1].id).toStrictEqual('undefined');
+ expect(result[1].value).toStrictEqual({
+ 'hello': 'world',
+ });
+ });
+ });
+
+ describe('normalize, simple object', () => {
+ const simpleData = [
+ {
+ 'id': 1,
+ 'value': 3
+ },
+ {
+ 'id': 2,
+ 'value': 4
+ }
+ ];
+
+ it('should normalize (path = id)', async () => {
+ const result = await runEzs(ezs, simpleData, 'tune');
+
+ expect(result[0]).not.toBeNull();
+ expect(result[1]).not.toBeNull();
+
+ expect(result[0].id).toStrictEqual('0000000000000000001.00000000000000000000');
+ expect(result[1].id).toStrictEqual('0000000000000000002.00000000000000000000');
+
+ expect(result[0].value).toStrictEqual(simpleData[0]);
+ expect(result[1].value).toStrictEqual(simpleData[1]);
+ });
+
+ it('should normalize (path = value)', async () => {
+ const result = await runEzs(ezs, simpleData, 'tune', { path: 'value' });
+
+ expect(result[0]).not.toBeNull();
+ expect(result[1]).not.toBeNull();
+
+ expect(result[0].id).toStrictEqual('0000000000000000003.00000000000000000000');
+ expect(result[1].id).toStrictEqual('0000000000000000004.00000000000000000000');
+
+ expect(result[0].value).toStrictEqual(simpleData[0]);
+ expect(result[1].value).toStrictEqual(simpleData[1]);
+ });
+ });
+
+ describe('normalize, array object', () => {
+ const arrayData = [
+ {
+ 'id': 1,
+ 'value': [3, 4]
+ },
+ {
+ 'id': 2,
+ 'value': [5, 6]
+ }
+ ];
+
+ it('should normalize (path = id)', async () => {
+ const result = await runEzs(ezs, arrayData, 'tune');
+
+ expect(result[0]).not.toBeNull();
+ expect(result[1]).not.toBeNull();
+
+ expect(result[0].id).toStrictEqual('0000000000000000001.00000000000000000000');
+ expect(result[1].id).toStrictEqual('0000000000000000002.00000000000000000000');
+
+ expect(result[0].value).toStrictEqual(arrayData[0]);
+ expect(result[1].value).toStrictEqual(arrayData[1]);
+ });
+
+ it('should normalize (path = value)', async () => {
+ const result = await runEzs(ezs, arrayData, 'tune', { path: 'value' });
+
+ expect(result[0]).not.toBeNull();
+ expect(result[1]).not.toBeNull();
+
+ expect(result[0].id).toStrictEqual('3,4');
+ expect(result[1].id).toStrictEqual('5,6');
+
+ expect(result[0].value).toStrictEqual(arrayData[0]);
+ expect(result[1].value).toStrictEqual(arrayData[1]);
+ });
+ });
+});
\ No newline at end of file
diff --git a/packages/analytics/test/value.spec.js b/packages/analytics/test/value.spec.js
index 75d6bb71..43ca2dae 100644
--- a/packages/analytics/test/value.spec.js
+++ b/packages/analytics/test/value.spec.js
@@ -1,27 +1,69 @@
-import from from 'from';
import ezs from '../../core/src';
import value from '../src/value';
+import runEzs from '../test-utils/runEzs';
ezs.addPath(__dirname);
describe('value', () => {
- /**
- * Helper function use to call ezs in each tests
- * @param ezsRuntime {(name: string, options: any, environment?: unknown) => NodeJS.WritableStream}
- * @param dataSet {Array}
- * @param path {string | undefined}
- * @returns {Promise>}
- */
- const runEzs = (ezsRuntime, dataSet, path) => new Promise((resolve) => {
- const result = [];
- from(dataSet)
- .pipe(ezsRuntime('value', { path }))
- .on('data', (chunk) => {
- result.push(chunk);
- })
- .on('end', () => {
- resolve(result);
- });
+
+ beforeAll(() => {
+ ezs.use({ value });
+ });
+
+ describe('wrong data', () => {
+ const undefinedData = [
+ undefined,
+ undefined,
+ undefined,
+ undefined
+ ];
+
+ const nullData = [
+ null,
+ null,
+ null,
+ null
+ ];
+
+ const undefinedNullData = [
+ undefined,
+ null,
+ undefined,
+ null
+ ];
+
+ const wrongKeyData = [
+ {
+ 'hello': 'world',
+ },
+ {
+ 'hello': 'world',
+ }
+ ];
+
+ it('should return no result when input contains undefined', async () => {
+ const result = await runEzs(ezs, undefinedData, 'value');
+
+ expect(result).toHaveLength(0);
+ });
+
+ it.skip('should return no result when input contains null', async () => {
+ const result = await runEzs(ezs, nullData, 'value');
+
+ expect(result).toHaveLength(0);
+ });
+
+ it.skip('should return no result when input contains undefined and null', async () => {
+ const result = await runEzs(ezs, undefinedNullData, 'value');
+
+ expect(result).toHaveLength(0);
+ });
+
+ it('should return no result when input contains wrong key', async () => {
+ const result = await runEzs(ezs, wrongKeyData, 'value');
+
+ expect(result).toHaveLength(0);
+ });
});
describe('simple data', () => {
@@ -37,8 +79,7 @@ describe('value', () => {
];
it('should extract the id (path = id)', async () => {
- ezs.use({ value });
- const result = await runEzs(ezs, simpleData, 'id');
+ const result = await runEzs(ezs, simpleData, 'value', { path: 'id' });
expect(result).toHaveLength(2);
@@ -47,8 +88,7 @@ describe('value', () => {
});
it('should extract the value (path = value)', async () => {
- ezs.use({ value });
- const result = await runEzs(ezs, simpleData, 'value');
+ const result = await runEzs(ezs, simpleData, 'value', { path: 'value' });
expect(result).toHaveLength(2);
@@ -57,8 +97,7 @@ describe('value', () => {
});
it('should extract the value (path = undefined)', async () => {
- ezs.use({ value });
- const result = await runEzs(ezs, simpleData);
+ const result = await runEzs(ezs, simpleData, 'value');
expect(result).toHaveLength(2);
@@ -80,8 +119,7 @@ describe('value', () => {
];
it('should extract the id (path = id)', async () => {
- ezs.use({ value });
- const result = await runEzs(ezs, arrayData, 'id');
+ const result = await runEzs(ezs, arrayData, 'value', { path: 'id' });
expect(result).toHaveLength(2);
@@ -90,8 +128,7 @@ describe('value', () => {
});
it('should extract the value (path = value)', async () => {
- ezs.use({ value });
- const result = await runEzs(ezs, arrayData, 'value');
+ const result = await runEzs(ezs, arrayData, 'value', { path: 'value' });
expect(result).toHaveLength(2);
@@ -117,8 +154,7 @@ describe('value', () => {
];
it('should extract the id (path = id)', async () => {
- ezs.use({ value });
- const result = await runEzs(ezs, objectData, 'id');
+ const result = await runEzs(ezs, objectData, 'value', { path: 'id' });
expect(result).toHaveLength(2);
@@ -127,8 +163,7 @@ describe('value', () => {
});
it('should extract the value (path = value)', async () => {
- ezs.use({ value });
- const result = await runEzs(ezs, objectData, 'value');
+ const result = await runEzs(ezs, objectData, 'value', { path: 'value' });
expect(result).toHaveLength(2);
@@ -174,8 +209,7 @@ describe('value', () => {
];
it('should extract the id (path = id)', async () => {
- ezs.use({ value });
- const result = await runEzs(ezs, deepObjectData, 'id');
+ const result = await runEzs(ezs, deepObjectData, 'value', { path: 'id' });
expect(result).toHaveLength(2);
@@ -184,8 +218,7 @@ describe('value', () => {
});
it('should extract the value (path = value)', async () => {
- ezs.use({ value });
- const result = await runEzs(ezs, deepObjectData, 'value');
+ const result = await runEzs(ezs, deepObjectData, 'value', { path: 'value' });
expect(result).toHaveLength(2);
@@ -266,8 +299,7 @@ describe('value', () => {
];
it('should extract the id (path = id)', async () => {
- ezs.use({ value });
- const result = await runEzs(ezs, animalia100Data, 'id');
+ const result = await runEzs(ezs, animalia100Data, 'value', { path: 'id' });
expect(result).toHaveLength(5);
@@ -279,8 +311,7 @@ describe('value', () => {
});
it('should extract the value (path = value)', async () => {
- ezs.use({ value });
- const result = await runEzs(ezs, animalia100Data, 'value');
+ const result = await runEzs(ezs, animalia100Data, 'value', { path: 'value' });
expect(result).toHaveLength(5);
@@ -328,8 +359,7 @@ describe('value', () => {
});
it('should extract the id (path = id)', async () => {
- ezs.use({ value });
- const result = await runEzs(ezs, genratedData, 'id');
+ const result = await runEzs(ezs, genratedData, 'value', { path: 'id' });
expect(result).toHaveLength(LENGTH);
@@ -339,8 +369,7 @@ describe('value', () => {
});
it('should extract the value (path = value)', async () => {
- ezs.use({ value });
- const result = await runEzs(ezs, genratedData, 'value');
+ const result = await runEzs(ezs, genratedData, 'value', { path: 'value' });
expect(result).toHaveLength(LENGTH);
diff --git a/packages/core/src/engine.js b/packages/core/src/engine.js
index 2b4e6b29..3b743ef5 100644
--- a/packages/core/src/engine.js
+++ b/packages/core/src/engine.js
@@ -9,6 +9,23 @@ import Shell from './shell';
import SafeTransform from './SafeTransform';
+/**
+ * Engine scope object type
+ * @private
+ * @typedef {Object} EngineScope
+ *
+ * @property {Engine} ezs
+ * @property {(d: unknown, c: unknown) => void} emit
+ * @property {() => any} getParams
+ * @property {() => boolean} isFirst
+ * @property {() => number} getIndex
+ * @property {() => boolean} isLast
+ * @property {() => string} getCumulativeTime
+ * @property {() => number} getCumulativeTimeMS
+ * @property {() => number} getCounter
+ * @property {(name: string, defval?: string | string[], chunk?: unknown) => string | string[] | undefined} getParam
+ */
+
const nanoZero = () => BigInt(0);
const nano2sec = (ns) => {
@@ -72,6 +89,10 @@ export default class Engine extends SafeTransform {
eos(this, decreaseCounter);
this.shell = new Shell(ezs, this.environment);
this.chunk = {};
+ /**
+ * @private
+ * @type {EngineScope}
+ */
this.scope = {};
this.scope.getEnv = (name) => (name === undefined ? this.environment : this.environment[name]);
this.scope.ezs = this.ezs;