From 857b00dbea5a63811b55d2a1f370e64acd8f7172 Mon Sep 17 00:00:00 2001 From: Mael Date: Mon, 25 Mar 2019 19:14:27 +0100 Subject: [PATCH] :gear: Mise en valeur du plafond actif --- source/engine/mecanismViews/Product.js | 10 ++- source/engine/mecanisms.js | 105 ++++++++++++++++++------- 2 files changed, 86 insertions(+), 29 deletions(-) diff --git a/source/engine/mecanismViews/Product.js b/source/engine/mecanismViews/Product.js index 65350e62c..b8f74395d 100644 --- a/source/engine/mecanismViews/Product.js +++ b/source/engine/mecanismViews/Product.js @@ -29,7 +29,15 @@ export default function ProductView(nodeValue, explanation) { alignItems: 'baseline', flexWrap: 'wrap' }}> - Plafonnée à : {makeJsx(explanation.plafond)} + + Plafonnée à :  + {makeJsx(explanation.plafond)} + )} diff --git a/source/engine/mecanisms.js b/source/engine/mecanisms.js index e14c91301..4f8b85d97 100644 --- a/source/engine/mecanisms.js +++ b/source/engine/mecanisms.js @@ -1,23 +1,68 @@ -import { desugarScale } from 'Engine/mecanisms/barème'; -import { decompose, devariateExplanation } from 'Engine/mecanisms/utils'; -import { add, any, aperture, curry, equals, evolve, filter, find, head, is, isEmpty, isNil, keys, last, map, max, mergeWith, min, path, pipe, pluck, prop, propEq, reduce, reduced, reject, sort, subtract, toPairs } from 'ramda'; -import React from 'react'; -import { Trans } from 'react-i18next'; -import 'react-virtualized/styles.css'; -import { bonus, collectNodeMissing, defaultNode, evaluateArray, evaluateNode, evaluateObject, makeJsx, mergeAllMissing, mergeMissing, parseObject, rewriteNode } from './evaluation'; -import Allègement from './mecanismViews/Allègement'; -import Barème from './mecanismViews/Barème'; -import BarèmeContinu from './mecanismViews/BarèmeContinu'; -import { Node, SimpleRuleLink } from './mecanismViews/common'; -import InversionNumérique from './mecanismViews/InversionNumérique'; -import Product from './mecanismViews/Product'; -import buildSelectionView from './mecanismViews/Selection'; -import Somme from './mecanismViews/Somme'; -import Variations from './mecanismViews/Variations'; -import { disambiguateRuleReference, findRuleByDottedName, findRuleByName } from './rules'; -import { anyNull, val } from './traverse-common-functions'; -import uniroot from './uniroot'; - +import { desugarScale } from 'Engine/mecanisms/barème' +import { decompose, devariateExplanation } from 'Engine/mecanisms/utils' +import { + add, + any, + aperture, + curry, + equals, + evolve, + filter, + find, + head, + is, + isEmpty, + isNil, + keys, + last, + map, + max, + mergeWith, + min, + path, + pipe, + pluck, + prop, + propEq, + reduce, + reduced, + reject, + sort, + subtract, + toPairs +} from 'ramda' +import React from 'react' +import { Trans } from 'react-i18next' +import 'react-virtualized/styles.css' +import { + bonus, + collectNodeMissing, + defaultNode, + evaluateArray, + evaluateNode, + evaluateObject, + makeJsx, + mergeAllMissing, + mergeMissing, + parseObject, + rewriteNode +} from './evaluation' +import Allègement from './mecanismViews/Allègement' +import Barème from './mecanismViews/Barème' +import BarèmeContinu from './mecanismViews/BarèmeContinu' +import { Node, SimpleRuleLink } from './mecanismViews/common' +import InversionNumérique from './mecanismViews/InversionNumérique' +import Product from './mecanismViews/Product' +import buildSelectionView from './mecanismViews/Selection' +import Somme from './mecanismViews/Somme' +import Variations from './mecanismViews/Variations' +import { + disambiguateRuleReference, + findRuleByDottedName, + findRuleByName +} from './rules' +import { anyNull, val } from './traverse-common-functions' +import uniroot from './uniroot' /* @devariate = true => This function will produce variations of a same mecanism (e.g. product) that share some common properties */ export let mecanismVariations = (recurse, k, v, devariate) => { @@ -557,14 +602,18 @@ export let mecanismProduct = (recurse, k, v) => { let effect = ({ assiette, taux, facteur, plafond }) => { let mult = (base, rate, facteur, plafond) => Math.min(base, plafond) * rate * facteur - return val(taux) === 0 || - val(taux) === false || - val(assiette) === 0 || - val(facteur) === 0 - ? 0 - : anyNull([taux, assiette, facteur, plafond]) - ? null - : mult(val(assiette), val(taux), val(facteur), val(plafond)) + return { + nodeValue: + val(taux) === 0 || + val(taux) === false || + val(assiette) === 0 || + val(facteur) === 0 + ? 0 + : anyNull([taux, assiette, facteur, plafond]) + ? null + : mult(val(assiette), val(taux), val(facteur), val(plafond)), + additionalExplanation: { plafondActif: val(assiette) > val(plafond) } + } } let explanation = parseObject(recurse, objectShape, v),