From 94d54f68472cbc3ae614a75dc3f2069c1ed88f07 Mon Sep 17 00:00:00 2001 From: Laurent Bossavit Date: Fri, 13 Apr 2018 18:41:45 +0200 Subject: [PATCH] =?UTF-8?q?Transforme=20la=20p=C3=A9nalit=C3=A9=20conditio?= =?UTF-8?q?nnelle=20en=20un=20bonus=20de=20d=C3=A9partage=20tr=C3=A8s=20pe?= =?UTF-8?q?tit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/engine/evaluation.js | 1 + source/engine/mecanisms.js | 9 +++++---- source/engine/traverse.js | 8 ++++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/source/engine/evaluation.js b/source/engine/evaluation.js index 12a6df492..bf8beaeed 100644 --- a/source/engine/evaluation.js +++ b/source/engine/evaluation.js @@ -25,6 +25,7 @@ export let makeJsx = node => export let collectNodeMissing = node => node.missingVariables || {} +export let bonus = (missings, hasCondition=true) => hasCondition ? map(x=>x+.0001, missings || {}) : missings export let mergeAllMissing = missings => reduce(mergeWith(add),{},map(collectNodeMissing,missings)) export let mergeMissing = (left, right) => mergeWith(add, left || {}, right || {}) diff --git a/source/engine/mecanisms.js b/source/engine/mecanisms.js index cbbd68f6d..9aef8d437 100644 --- a/source/engine/mecanisms.js +++ b/source/engine/mecanisms.js @@ -47,7 +47,8 @@ import { parseObject, collectNodeMissing, mergeAllMissing, - mergeMissing + mergeMissing, + bonus } from './evaluation' import { findRuleByName, @@ -160,8 +161,8 @@ let devariate = (recurse, k, v) => { : mergeAllMissing(pluck('condition', explanation)), rightMissing = choice === false ? {} - : map(x=>x-1, mergeAllMissing(satisfied)), - missingVariables = mergeMissing(leftMissing, rightMissing) + : mergeAllMissing(satisfied), + missingVariables = mergeMissing(bonus(leftMissing), rightMissing) return rewriteNode(node, nodeValue, explanation, missingVariables) } @@ -318,7 +319,7 @@ export let mecanismNumericalSwitch = (recurse, k, v) => { rightMissing = investigate ? explanation.consequence.missingVariables : {}, - missingVariables = mergeMissing(leftMissing, rightMissing) + missingVariables = mergeMissing(bonus(leftMissing), rightMissing) return { ...node, diff --git a/source/engine/traverse.js b/source/engine/traverse.js index b5cb31233..a7bdd3d0c 100644 --- a/source/engine/traverse.js +++ b/source/engine/traverse.js @@ -60,7 +60,8 @@ import { rewriteNode, makeJsx, mergeMissing, - mergeAllMissing + mergeAllMissing, + bonus } from './evaluation' import { anyNull, @@ -492,7 +493,10 @@ export let treatRuleRoot = (rules, rule) => { ), collectInFormule = isApplicable !== false, formMissing = (collectInFormule && formule.missingVariables) || {}, - missingVariables = mergeMissing(condMissing, formMissing) + // On veut abaisser le score des conséquences par rapport aux conditions, + // mais seulement dans le cas où une condition est effectivement présente + hasCondition = keys(condMissing).length > 0, + missingVariables = mergeMissing(bonus(condMissing,hasCondition), formMissing) cache.parseLevel-- // if (keys(condMissing).length) console.log("".padStart(cache.parseLevel-1),{conditions:condMissing, formule:formMissing})