diff --git a/__tests__/traverse.test.js b/__tests__/traverse.test.js
index 2b84500a7..cf02c39c1 100644
--- a/__tests__/traverse.test.js
+++ b/__tests__/traverse.test.js
@@ -90,4 +90,11 @@ describe('analyseSituation with mecanisms', function() {
expect(analyseSituation(rules,"startHere")(stateSelector)).to.have.property('nodeValue',11)
});
+ it('should handle percentages', function() {
+ let rawRules = [
+ {nom: "startHere", formule: {taux: "35%"}, espace: "top"}],
+ rules = rawRules.map(enrichRule)
+ expect(analyseSituation(rules,"startHere")(stateSelector)).to.have.property('nodeValue',0.35)
+ });
+
});
diff --git a/source/engine/traverse.js b/source/engine/traverse.js
index 320ef6158..7d973485d 100644
--- a/source/engine/traverse.js
+++ b/source/engine/traverse.js
@@ -379,6 +379,49 @@ let treat = (situationGate, rules, rule) => rawNode => {
/>
})
))(v),
+ mecanismTaux = (k,v) => {
+ let reg = /^(\d+(\.\d+)?)\%$/
+ if (R.test(reg)(v))
+ return {
+ category: 'percentage',
+ type: 'numeric',
+ percentage: v,
+ nodeValue: R.match(reg)(v)[1]/100,
+ explanation: null,
+ jsx:
+
+ {v}
+
+ }
+ // Si c'est une liste historisée de pourcentages
+ // TODO revoir le test avant le bug de l'an 2100
+ else if ( R.is(Array)(v) && R.all(R.test(/(19|20)\d\d(-\d\d)?(-\d\d)?/))(R.keys(v)) ) {
+ //TODO sélectionner la date de la simulation en cours
+ let lazySelection = R.first(R.values(v))
+ return {
+ category: 'percentage',
+ type: 'numeric',
+ percentage: lazySelection,
+ nodeValue: transformPercentage(lazySelection),
+ explanation: null,
+ jsx:
+
+ {lazySelection}
+
+ }
+ }
+ else {
+ let node = reTreat(v)
+ return {
+ type: 'numeric',
+ category: 'percentage',
+ percentage: node.nodeValue,
+ nodeValue: node.nodeValue,
+ explanation: node,
+ jsx: node.jsx
+ }
+ }
+ },
treatObject = rawNode => {
let mecanisms = R.intersection(R.keys(rawNode), R.keys(knownMecanisms))
@@ -393,50 +436,7 @@ let treat = (situationGate, rules, rule) => rawNode => {
if (k === 'une de ces conditions') return mecanismOneOf(k,v)
if (k === 'toutes ces conditions') return mecanismAllOf(k,v)
if (k === 'logique numérique') return mecanismNumericalLogic(k,v)
-
- if (k === 'taux') {
- let reg = /^(\d+(\.\d+)?)\%$/
- if (R.test(reg)(v))
- return {
- category: 'percentage',
- type: 'numeric',
- percentage: v,
- nodeValue: R.match(reg)(v)[1]/100,
- explanation: null,
- jsx:
-
- {v}
-
- }
- // Si c'est une liste historisée de pourcentages
- // TODO revoir le test avant le bug de l'an 2100
- else if ( R.is(Array)(v) && R.all(R.test(/(19|20)\d\d(-\d\d)?(-\d\d)?/))(R.keys(v)) ) {
- //TODO sélectionner la date de la simulation en cours
- let lazySelection = R.first(R.values(v))
- return {
- category: 'percentage',
- type: 'numeric',
- percentage: lazySelection,
- nodeValue: transformPercentage(lazySelection),
- explanation: null,
- jsx:
-
- {lazySelection}
-
- }
- }
- else {
- let node = reTreat(v)
- return {
- type: 'numeric',
- category: 'percentage',
- percentage: node.nodeValue,
- nodeValue: node.nodeValue,
- explanation: node,
- jsx: node.jsx
- }
- }
- }
+ if (k === 'taux') return mecanismTaux(k,v)
// Une simple somme de variables
if (k === 'somme') {