Skip to content

Commit

Permalink
Merge pull request #413 from Inist-CNRS/conditor/update-rnsr-to-2023
Browse files Browse the repository at this point in the history
Conditor: update rnsr to 2023
  • Loading branch information
parmentf authored May 30, 2024
2 parents 4846625 + 0eb82ae commit 16a729f
Show file tree
Hide file tree
Showing 11 changed files with 125 additions and 136 deletions.
40 changes: 3 additions & 37 deletions docs/plugin-conditor.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ Sachant qu'on appauvrit (casse, accents, tiret, apostrophe) tous les champs.
- [compareRnsr](#comparernsr)
- [conditorScroll](#conditorscroll)
- [CORHALFetch](#corhalfetch)
- [CORHALFetch](#corhalfetch-1)
- [getRnsr](#getrnsr)
- [getRnsrInfo](#getrnsrinfo)
- [WOSFetch](#wosfetch)
Expand Down Expand Up @@ -107,7 +106,7 @@ Output:

#### Parameters

- `year` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Year of the RNSR to use instead of the last one (optional, default `2021`)
- `year` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Year of the RNSR to use instead of the last one (optional, default `2023`)

### compareRnsr

Expand Down Expand Up @@ -227,39 +226,6 @@ Output:

Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**

### CORHALFetch

Take `String` as URL, throw each chunk from the result

Input:

```json
[
{ q: "toto" },
]
```

Script:

```ini
[CORHALFetch]
url = https://corhal-api.inist.fr
```

Output:

```json
[{...}, {"a": "b"}, {"a": "c" }]
```

#### Parameters

- `url` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** corhal api url
- `timeout` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Timeout in milliseconds (optional, default `1000`)
- `retries` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** The maximum amount of times to retry the connection (optional, default `5`)

Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**

### getRnsr

Find the RNSR identifier(s) matching the `address` and the publication `year`
Expand Down Expand Up @@ -292,7 +258,7 @@ Output:

#### Parameters

- `year` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Year of the RNSR to use instead of the last one (optional, default `2021`)
- `year` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Year of the RNSR to use instead of the last one (optional, default `2023`)

### getRnsrInfo

Expand Down Expand Up @@ -368,7 +334,7 @@ Output:

#### Parameters

- `year` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Year of the RNSR to use instead of the last one (optional, default `2021`)
- `year` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Year of the RNSR to use instead of the last one (optional, default `2023`)

### WOSFetch

Expand Down
35 changes: 7 additions & 28 deletions docs/plugin-core.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ npm install @ezs/core

Plusieurs instructions permettent de créer des sous flux (sub pipeline), à partir d'un fichier d’instructions ou d'instructions imbriquées. Si elles s'utilisent toutes de la même manière (avec les mêmes paramètres) centaines peuvent apparaître comme similaires mais leur fonctionnement est différent :

- [delegate] : 1 sous flux pour tous les éléments
- [swing] : 1 sous flux pour tous les éléments filtrés selon une condition
- [spaw] : 1 sous flux par élément
- [loop] : 1 sous flux par élément
- [expand] : 1 sous flux pour N éléments (N = size), seul le champ sélectionné est envoyé dans le pipeline
- [combine] : 1 sous flux pour tous les éléments, seul le champ sélectionné est comparé avec le résultat du sous flux
- [singleton] : 1 sous flux pour le premier élément
- [delegate] : 1 sous flux pour tous les éléments
- [swing] : 1 sous flux pour tous les éléments filtrés selon une condition
- [spaw] : 1 sous flux par élément
- [loop] : 1 sous flux par élément
- [expand] : 1 sous flux pour N éléments (N = size), seul le champ sélectionné est envoyé dans le pipeline
- [combine] : 1 sous flux pour tous les éléments, seul le champ sélectionné est comparé avec le résultat du sous flux
- [singleton] : 1 sous flux pour le premier élément

## usage

Expand Down Expand Up @@ -64,7 +64,6 @@ Plusieurs instructions permettent de créer des sous flux (sub pipeline), à par
- [truncate](#truncate)
- [ungroup](#ungroup)
- [unpack](#unpack)
- [use](#use)
- [validate](#validate)

### assign
Expand Down Expand Up @@ -1306,26 +1305,6 @@ Take `String`s or `Buffer`s and throw `Object` builded by JSON.parse on each lin
Returns **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
### use
Take all `String`, concat them and throw just one.
Script:
```ini
[use]
plugin = basics
plugin = analytics
```
#### Parameters
- `beginWith` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Add value at the begin
- `joinWith` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** use value to join 2 chunk
- `endWith` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Add value at the end
Returns **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
### validate
From an `Object`, throw the same object if all rules pass
Expand Down
40 changes: 3 additions & 37 deletions packages/conditor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ Sachant qu'on appauvrit (casse, accents, tiret, apostrophe) tous les champs.
- [compareRnsr](#comparernsr)
- [conditorScroll](#conditorscroll)
- [CORHALFetch](#corhalfetch)
- [CORHALFetch](#corhalfetch-1)
- [getRnsr](#getrnsr)
- [getRnsrInfo](#getrnsrinfo)
- [WOSFetch](#wosfetch)
Expand Down Expand Up @@ -107,7 +106,7 @@ Output:

#### Parameters

- `year` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Year of the RNSR to use instead of the last one (optional, default `2021`)
- `year` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Year of the RNSR to use instead of the last one (optional, default `2023`)

### compareRnsr

Expand Down Expand Up @@ -227,39 +226,6 @@ Output:

Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**

### CORHALFetch

Take `String` as URL, throw each chunk from the result

Input:

```json
[
{ q: "toto" },
]
```

Script:

```ini
[CORHALFetch]
url = https://corhal-api.inist.fr
```

Output:

```json
[{...}, {"a": "b"}, {"a": "c" }]
```

#### Parameters

- `url` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** corhal api url
- `timeout` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Timeout in milliseconds (optional, default `1000`)
- `retries` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** The maximum amount of times to retry the connection (optional, default `5`)

Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**

### getRnsr

Find the RNSR identifier(s) matching the `address` and the publication `year`
Expand Down Expand Up @@ -292,7 +258,7 @@ Output:

#### Parameters

- `year` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Year of the RNSR to use instead of the last one (optional, default `2021`)
- `year` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Year of the RNSR to use instead of the last one (optional, default `2023`)

### getRnsrInfo

Expand Down Expand Up @@ -368,7 +334,7 @@ Output:

#### Parameters

- `year` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Year of the RNSR to use instead of the last one (optional, default `2021`)
- `year` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Year of the RNSR to use instead of the last one (optional, default `2023`)

### WOSFetch

Expand Down
1 change: 1 addition & 0 deletions packages/conditor/data/RNSR-2023.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions packages/conditor/src/affAlign.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ const getYear = pipe(slice(0, 4), Number);
* ```
*
* @export
* @param {number} [year=2021] Year of the RNSR to use instead of the last one
* @param {number} [year=2023] Year of the RNSR to use instead of the last one
* @name affAlign
*/
export default async function affAlign(data, feed) {
if (this.isFirst()) {
const rnsrYear = this.getParam('year', 2021);
const rnsrYear = this.getParam('year', 2023);
RNSR = await getRnsrYear(rnsrYear);
}
if (this.isLast()) {
Expand Down
4 changes: 2 additions & 2 deletions packages/conditor/src/getRnsr.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ import { depleteString } from './strings';
* ```
*
* @export
* @param {number} [year=2021] Year of the RNSR to use instead of the last one
* @param {number} [year=2023] Year of the RNSR to use instead of the last one
* @name getRnsr
*/
export default async function getRnsr(data, feed) {
if (this.isFirst()) {
const rnsrYear = this.getParam('year', 2021);
const rnsrYear = this.getParam('year', 2023);
this.RNSR = await getRnsrYear(rnsrYear);
}
if (this.isLast()) {
Expand Down
4 changes: 2 additions & 2 deletions packages/conditor/src/getRnsrInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ import { depleteString } from './strings';
* ```
*
* @export
* @param {number} [year=2021] Year of the RNSR to use instead of the last one
* @param {number} [year=2023] Year of the RNSR to use instead of the last one
* @name getRnsrInfo
*/
export default async function getRnsrInfo(data, feed) {
if (this.isFirst()) {
const rnsrYear = this.getParam('year', 2021);
const rnsrYear = this.getParam('year', 2023);
this.RNSR = await getRnsrYear(rnsrYear);
}
if (this.isLast()) {
Expand Down
26 changes: 26 additions & 0 deletions packages/conditor/test/getRnsr.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,4 +354,30 @@ describe('getRnsr', () => {
done();
});
});

it('should return all correct identifier(s) - using RNSR 2023', (done) => {
let res = [];
const input = examples
.map((ex, i) => ({ id: i, value: { year: ex[2], address: ex[0] } }))
.filter((ex) => [1, 2, 3, 12, 15, 17, 18, 21].includes(ex.id)); // keep correct cases

const expected = examples.map((ex, i) => ({
id: i,
value: ex[1].split(','),
}));
from(input)
.pipe(ezs('getRnsr', { year: 2023 }))
.on('data', (data) => {
res = [...res, data];
})
.on('end', () => {
expect(res.length).toBe(input.length);
res.forEach((r) => {
expect(r.value).toEqual(
expect.arrayContaining(expected[r.id].value),
);
});
done();
});
});
});
60 changes: 60 additions & 0 deletions packages/conditor/test/getRnsrInfo.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,4 +289,64 @@ describe('getRnsrInfo', () => {
done();
});
});

it('should return all correct identifier(s) - using RNSR 2023', (done) => {
let res = [];
const input = examples
.map((ex, i) => ({ id: i, value: { year: ex[2], address: ex[0] } }))
.filter((ex) => ex.id === 1); // choose correct case

from(input)
.pipe(ezs('getRnsrInfo', { year: 2023 }))
.on('data', (data) => {
res = [...res, data];
})
.on('end', () => {
expect(res.length).toBe(1);
expect(res[0].value).toEqual([{
an_fermeture: 0,
annee_creation: 2010,
code_postal: 91191,
etabAssoc: [{
etab: {
libelle: 'Centre national de la recherche scientifique',
libelleAppauvri: 'centre national de la recherche scientifique',
sigle: 'CNRS',
sigleAppauvri: 'cnrs',
},
label: 'UMR',
labelAppauvri: 'umr',
numero: 8212,
}, {
etab: {
libelle: 'Université Versailles Saint-Quentin-en-Yvelines',
libelleAppauvri: 'universite versailles saint quentin en yvelines',
sigle: 'VERSAILLES',
sigleAppauvri: 'versailles',
},
label: 'UMR',
labelAppauvri: 'umr',
numero: 8212,
}, {
etab: {
libelle: "Commissariat à l'énergie atomique et aux énergies alternatives",
libelleAppauvri: 'commissariat a l energie atomique et aux energies alternatives',
sigle: 'CEA',
sigleAppauvri: 'cea',
},
label: 'UMR',
labelAppauvri: 'umr',
numero: 8212,
}],
intitule: "Laboratoire des Sciences du Climat et de l'Environnement UMR 8212",
intituleAppauvri: 'laboratoire des sciences du climat et de l environnement umr 8212',
num_nat_struct: '200611689J',
sigle: 'LSCE',
sigleAppauvri: 'lsce',
ville_postale: 'GIF SUR YVETTE CEDEX',
ville_postale_appauvrie: 'gif sur yvette cedex',
}]);
done();
});
});
});
12 changes: 12 additions & 0 deletions packages/conditor/test/rnsr.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,18 @@ describe('existedInYear', () => {
expect(result).toBe(true);
});

it('should exist when an_fermeture is 0', () => {
const structure = {
annee_creation: '2000',
an_fermeture: 0,
};
const year = 2021;

const result = existedInYear(year)(structure);

expect(result).toBe(true);
});

it('should exist when no year given', () => {
const structure = {
annee_creation: '2000',
Expand Down
Loading

0 comments on commit 16a729f

Please sign in to comment.