2019-04-11 13:23:46 +00:00
|
|
|
import { dropLast, isEmpty, last } from 'ramda'
|
2020-03-26 15:03:19 +00:00
|
|
|
import { joinName, splitName } from './ruleUtils'
|
2017-03-16 18:30:30 +00:00
|
|
|
|
2017-04-24 18:03:38 +00:00
|
|
|
let evaluateBottomUp = situationGate => startingFragments => {
|
2018-01-03 15:54:19 +00:00
|
|
|
let rec = (parentFragments, childFragments = []) =>
|
|
|
|
parentFragments.length == 0
|
|
|
|
? null
|
2019-09-11 08:04:19 +00:00
|
|
|
: (function() {
|
2018-01-03 15:54:19 +00:00
|
|
|
let query = joinName(parentFragments),
|
2018-01-08 15:07:26 +00:00
|
|
|
expectedResult = isEmpty(childFragments)
|
2018-01-03 15:54:19 +00:00
|
|
|
? 'oui'
|
|
|
|
: joinName(childFragments)
|
2017-04-24 18:03:38 +00:00
|
|
|
|
2019-09-11 08:04:19 +00:00
|
|
|
return situationGate(query) == null
|
2018-01-08 15:07:26 +00:00
|
|
|
? rec(dropLast(1)(parentFragments), [
|
|
|
|
last(parentFragments),
|
2018-01-03 15:54:19 +00:00
|
|
|
...childFragments
|
2018-05-22 17:12:13 +00:00
|
|
|
])
|
2018-01-03 15:54:19 +00:00
|
|
|
: situationGate(query) == expectedResult
|
2019-09-11 08:04:19 +00:00
|
|
|
})()
|
2018-09-04 19:14:56 +00:00
|
|
|
|
2017-04-24 18:03:38 +00:00
|
|
|
return rec(startingFragments)
|
|
|
|
}
|
2018-09-07 15:30:50 +00:00
|
|
|
export let getSituationValue = (situationGate, variableName, rule) => {
|
|
|
|
// get the current situation value
|
|
|
|
// it's the user input or test input, possibly with default values
|
2017-03-16 18:30:30 +00:00
|
|
|
let value = situationGate(variableName)
|
2017-05-10 14:09:36 +00:00
|
|
|
|
2018-09-04 19:14:56 +00:00
|
|
|
if (rule.formule && rule.formule['une possibilité'])
|
|
|
|
return evaluateBottomUp(situationGate)(splitName(variableName))
|
|
|
|
|
|
|
|
return value
|
2017-03-16 18:30:30 +00:00
|
|
|
}
|