diff --git a/source/engine/mecanisms.js b/source/engine/mecanisms.js index 2462add4c..e5bfe0ac9 100644 --- a/source/engine/mecanisms.js +++ b/source/engine/mecanisms.js @@ -9,12 +9,32 @@ let transformPercentage = s => +s.replace('%', '') / 100 : +s +let evaluateArray = (reducer, start) => (situationGate, parsedRules, node) => { + let evaluateOne = child => evaluateNode(situationGate, parsedRules, child), + explanation = R.map(evaluateOne, node.explanation), + values = R.pluck("nodeValue",explanation), + nodeValue = R.any(R.equals(null),values) ? null : R.reduce(reducer, start, values) + + let collectMissing = node => R.chain(collectNodeMissing,node.explanation) + + return { + ...node, + nodeValue, + collectMissing, + explanation, + jsx: { + ...node.jsx, + value: nodeValue + } + } +} + export let decompose = (recurse, k, v) => { let subProps = R.dissoc('composantes')(v), filter = val(recurse("sys . filter")), isRelevant = c => !filter || !c.attributs || c.attributs['dû par'] == filter, - composantes = v.composantes.filter(isRelevant).map(c => + explanation = v.composantes.filter(isRelevant).map(c => ({ ... recurse( R.objOf(k, @@ -25,23 +45,20 @@ export let decompose = (recurse, k, v) => { ), composante: c.nom ? {nom: c.nom} : c.attributs }) - ), - nodeValue = anyNull(composantes) ? null - : R.reduce(R.add, 0, composantes.map(val)) + ) return { - nodeValue, + evaluate: evaluateArray(R.add,0), category: 'mecanism', name: 'composantes', type: 'numeric', - explanation: composantes, + explanation, jsx: - { composantes.map((c, i) => + { explanation.map((c, i) => [