⚙️ Prise en compte des composantes dans sélection
parent
58e935e791
commit
4169ebedd9
|
@ -3,6 +3,7 @@ import React from 'react'
|
|||
import {anyNull, val} from './traverse-common-functions'
|
||||
import {Node, Leaf} from './traverse-common-jsx'
|
||||
import {makeJsx, evaluateNode, rewriteNode, evaluateArray, evaluateArrayWithFilter, evaluateObject, parseObject, collectNodeMissing} from './evaluation'
|
||||
import {findRuleByName} from './rules'
|
||||
|
||||
let constantNode = constant => ({nodeValue: constant, jsx: nodeValue => <span className="value">{nodeValue}</span>})
|
||||
|
||||
|
@ -609,6 +610,49 @@ export let mecanismComplement = (recurse,k,v) => {
|
|||
}
|
||||
}
|
||||
|
||||
export let mecanismSelection = (recurse,k,v) => {
|
||||
if (v.composantes) { //mécanisme de composantes. Voir known-mecanisms.md/composantes
|
||||
return decompose(recurse,k,v)
|
||||
}
|
||||
|
||||
let dataSourceName = v['données']
|
||||
let dataSearchField = v['dans']
|
||||
let dataTargetName = v['renvoie']
|
||||
let explanation = recurse(v['cherche'])
|
||||
|
||||
let evaluate = (situationGate, parsedRules, node) => {
|
||||
let collectMissing = node => collectNodeMissing(node.explanation),
|
||||
explanation = evaluateNode(situationGate, parsedRules, node.explanation),
|
||||
dataSource = findRuleByName(parsedRules, dataSourceName),
|
||||
data = dataSource ? dataSource['data'] : null,
|
||||
dataKey = explanation.nodeValue,
|
||||
dataItems = (data && dataKey && dataSearchField) ? R.filter(item => item[dataSearchField] == dataKey, data) : null,
|
||||
dataItemValues = dataItems ? R.values(dataItems) : null,
|
||||
// TODO - over-specific! transform the JSON instead
|
||||
dataItemSubValues = dataItemValues && dataItemValues[0][dataTargetName] ? dataItemValues[0][dataTargetName]["taux"] : null,
|
||||
sortedSubValues = dataItemSubValues ? R.sortBy(pair => pair[0], R.toPairs(dataItemSubValues)) : null,
|
||||
nodeValue = sortedSubValues ? Number.parseFloat(R.last(sortedSubValues)[1]) : null
|
||||
return rewriteNode(node,nodeValue,explanation,collectMissing)
|
||||
}
|
||||
|
||||
let jsx = (nodeValue, explanation) =>
|
||||
<Node
|
||||
classes="mecanism"
|
||||
name="sélection"
|
||||
value={nodeValue}
|
||||
child={
|
||||
explanation.category === 'variable' ? <div className="node">{makeJsx(explanation)}</div>
|
||||
: makeJsx(explanation)
|
||||
}
|
||||
/>
|
||||
|
||||
return {
|
||||
evaluate,
|
||||
explanation,
|
||||
jsx
|
||||
}
|
||||
}
|
||||
|
||||
export let mecanismError = (recurse,k,v) => {
|
||||
throw "Le mécanisme '"+k+"' est inconnu !"+v
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ export let disambiguateRuleReference = (allRules, {ns, name}, partialName) => {
|
|||
}
|
||||
|
||||
// On enrichit la base de règles avec des propriétés dérivées de celles du YAML
|
||||
export let rules = rawRules.map(enrichRule, {taux_versement_transport})
|
||||
export let rules = rawRules.map(rule => enrichRule(rule, {taux_versement_transport}))
|
||||
|
||||
|
||||
/****************************************
|
||||
|
|
|
@ -8,7 +8,8 @@ import Grammar from './grammar.ne'
|
|||
import {Node, Leaf} from './traverse-common-jsx'
|
||||
import {
|
||||
mecanismOneOf,mecanismAllOf,mecanismNumericalSwitch,mecanismSum,mecanismProduct,
|
||||
mecanismScale,mecanismMax,mecanismMin, mecanismError, mecanismComplement
|
||||
mecanismScale,mecanismMax,mecanismMin, mecanismError, mecanismComplement,
|
||||
mecanismSelection
|
||||
} from "./mecanisms"
|
||||
import {evaluateNode, rewriteNode, collectNodeMissing, makeJsx} from './evaluation'
|
||||
|
||||
|
@ -330,45 +331,6 @@ let treat = (rules, rule) => rawNode => {
|
|||
{...parsedNode, evaluate: defaultEvaluate}
|
||||
}
|
||||
|
||||
let mecanismSelection = (recurse,k,v) => {
|
||||
let dataSourceName = v['données']
|
||||
let dataSearchField = v['dans']
|
||||
let dataTargetName = v['renvoie']
|
||||
let explanation = recurse(v['cherche'])
|
||||
|
||||
let evaluate = (situationGate, parsedRules, node) => {
|
||||
let collectMissing = node => collectNodeMissing(node.explanation),
|
||||
explanation = evaluateNode(situationGate, parsedRules, node.explanation),
|
||||
dataSource = findRuleByName(parsedRules, dataSourceName),
|
||||
data = dataSource ? dataSource['data'] : null,
|
||||
dataKey = explanation.nodeValue,
|
||||
dataItems = (data && dataKey && dataSearchField) ? R.filter(item => item[dataSearchField] == dataKey, data) : null,
|
||||
dataItemValues = dataItems ? R.values(dataItems) : null,
|
||||
// TODO - over-specific! transform the JSON instead
|
||||
dataItemSubValues = dataItemValues ? dataItemValues[0][dataTargetName]["taux"] : null,
|
||||
sortedSubValues = dataItemSubValues ? R.sortBy(pair => pair[0], R.toPairs(dataItemSubValues)) : null,
|
||||
nodeValue = sortedSubValues ? Number.parseFloat(R.last(sortedSubValues)[1]) : null
|
||||
return rewriteNode(node,nodeValue,explanation,collectMissing)
|
||||
}
|
||||
|
||||
let jsx = (nodeValue, explanation) =>
|
||||
<Node
|
||||
classes="mecanism"
|
||||
name="sélection"
|
||||
value={nodeValue}
|
||||
child={
|
||||
explanation.category === 'variable' ? <div className="node">{makeJsx(explanation)}</div>
|
||||
: makeJsx(explanation)
|
||||
}
|
||||
/>
|
||||
|
||||
return {
|
||||
evaluate,
|
||||
explanation,
|
||||
jsx
|
||||
}
|
||||
}
|
||||
|
||||
//TODO c'est moche :
|
||||
export let computeRuleValue = (formuleValue, condValue) =>
|
||||
condValue === undefined
|
||||
|
|
Loading…
Reference in New Issue