Simplification du mécanisme sélection

pull/266/head
Mael 2018-06-25 16:58:00 +00:00
parent 010dc5ec53
commit 9bbe251f56
3 changed files with 12 additions and 22 deletions

View File

@ -975,27 +975,17 @@ export let mecanismSelection = (recurse, k, v) => {
dataSource = findRuleByName(parsedRules, dataSourceName),
data = dataSource ? dataSource['data'] : null,
dataKey = explanation.nodeValue,
dataItems =
found =
data && dataKey && dataSearchField
? filter(item => item[dataSearchField] == dataKey, data)
? find(item => item[dataSearchField] == dataKey, data)
: null,
dataItemValues =
dataItems && !isEmpty(dataItems) ? values(dataItems) : null,
// TODO - over-specific! transform the JSON instead
dataItemSubValues =
dataItemValues && dataItemValues[0][dataTargetName]
? dataItemValues[0][dataTargetName]['taux']
: null,
sortedSubValues = dataItemSubValues
? sortBy(pair => pair[0], toPairs(dataItemSubValues))
: null,
// return 0 if we found a match for the lookup but not for the specific field,
// so that component sums don't sum to null
nodeValue = dataItems
? sortedSubValues
? Number.parseFloat(last(sortedSubValues)[1]) / 100
: 0
: null,
nodeValue =
(found &&
found[dataTargetName] &&
Number.parseFloat(found[dataTargetName]) / 100) ||
0,
missingVariables = explanation.missingVariables
return rewriteNode(node, nodeValue, explanation, missingVariables)

View File

@ -87,9 +87,9 @@ fs.writeFile(
JSON.stringify(trimmed),
function(err) {
if (err) {
return console.log(err)
return console.log(err) //eslint-disable-line no-console
}
console.log("C'est tout bon !")
console.log("C'est tout bon !") //eslint-disable-line no-console
}
)

View File

@ -440,8 +440,8 @@ describe('analyse with mecanisms', function() {
let stateSelector = name => ({ 'top . code postal': '2' }[name])
let data = {
taux_versement_transport: [
{ codePostal: 1, aot: { taux: { '2019': '1.0' } } },
{ codePostal: 2, smt: { taux: { '2019': '2.0' } } }
{ codePostal: 1, aot: '2.5' },
{ codePostal: 2, smt: '1.5' }
]
}
let rawRules = [
@ -463,7 +463,7 @@ describe('analyse with mecanisms', function() {
rules = parseAll(rawRules.map(rule => enrichRule(rule, data)))
expect(
analyse(rules, 'startHere')(stateSelector).targets[0]
).to.have.property('nodeValue', 0.02)
).to.have.property('nodeValue', 0.015)
})
it('should handle failed selections', function() {