🐛 Transformation temporelle avant les filtres

co2
Mael 2018-10-01 10:56:18 +00:00
parent 33060ebd62
commit 94d002e18d
3 changed files with 26 additions and 8 deletions

View File

@ -27,7 +27,8 @@ import { Node } from './mecanismViews/common'
import {
treatVariable,
treatNegatedVariable,
treatFilteredVariable
treatFilteredVariable,
treatPeriodTransform
} from './treatVariable'
import { treat } from './traverse'
import knownMecanisms from './known-mecanisms.yaml'
@ -90,9 +91,13 @@ export let treatString = (rules, rule) => rawNode => {
)
if (parseResult.category == 'variable')
return treatVariable(rules, rule)(parseResult)
return treatPeriodTransform(rules, rule)(
treatVariable(rules, rule)(parseResult)
)
if (parseResult.category == 'filteredVariable')
return treatFilteredVariable(rules, rule)
return treatPeriodTransform(rules, rule)(
treatFilteredVariable(rules, rule)(parseResult)
)
if (parseResult.category == 'negatedVariable')
return treatNegatedVariable(
treatVariable(rules, rule)(parseResult.variable)
@ -154,10 +159,19 @@ export let treatString = (rules, rule) => rawNode => {
let explanation = parseResult.explanation.map(
cond([
[propEq('category', 'variable'), treatVariable(rules, rule)],
[
propEq('category', 'variable'),
parseResult =>
treatPeriodTransform(rules, rule)(
treatVariable(rules, rule)(parseResult)
)
],
[
propEq('category', 'filteredVariable'),
treatFilteredVariable(rules, rule)
parseResult =>
treatPeriodTransform(rules, rule)(
treatFilteredVariable(rules, rule)(parseResult)
)
],
[
propEq('category', 'value'),

View File

@ -5,8 +5,9 @@ import { evaluateNode, rewriteNode, makeJsx } from './evaluation'
import { getSituationValue } from './variables'
import { Trans } from 'react-i18next'
export let treatVariable = (rules, rule, filter) => parseResult => {
let variable = treatVariableTimeless(rules, rule, filter)(parseResult)
// This function is a wrapper that can apply temporal transformations to the value of the variable.
// See the période.yaml test suite for details
export let treatPeriodTransform = (rules, rule) => variable => {
let evaluate = (cache, situation, parsedRules, node) => {
let explanation = evaluateNode(
cache,
@ -55,7 +56,7 @@ export let treatVariable = (rules, rule, filter) => parseResult => {
}
}
export let treatVariableTimeless = (rules, rule, filter) => parseResult => {
export let treatVariable = (rules, rule, filter) => parseResult => {
let evaluate = (cache, situation, parsedRules, node) => {
let dottedName = node.dottedName,
// On va vérifier dans le cache courant, dict, si la variable n'a pas été déjà évaluée

View File

@ -123,8 +123,11 @@ const analysisToCotisations = (
'contrat salarié . cotisations patronales'
]
.map(name => analysis.cache[name])
// the last 'explanation' is because variables are wrapped in a period transform node
.map(pathOr([], ['explanation', 'formule', 'explanation', 'explanation']))
.reduce(concat, [])
.map(prop('explanation'))
const cotisations = pipe(
groupBy(prop('dottedName')),
values,