Skip to content

Commit

Permalink
🔥 Supprime les variables temporelles
Browse files Browse the repository at this point in the history
  • Loading branch information
mquandalle committed May 21, 2021
1 parent 49a7ae2 commit f43f02e
Show file tree
Hide file tree
Showing 13 changed files with 10 additions and 806 deletions.
16 changes: 0 additions & 16 deletions publicodes/core/source/AST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,6 @@ export const traverseASTNode: TraverseFunction<NodeKind> = (fn, node) => {
return traverseUnitéNode(fn, node)
case 'variations':
return traverseVariationNode(fn, node)
case 'variable temporelle':
return traverseVariableTemporelle(fn, node)
case 'replacementRule':
return traverseReplacementNode(fn, node)
default:
Expand Down Expand Up @@ -382,17 +380,3 @@ const traverseVariationNode: TraverseFunction<'variations'> = (fn, node) => ({
consequence: fn(consequence),
})),
})

const traverseVariableTemporelle: TraverseFunction<'variable temporelle'> = (
fn,
node
) => ({
...node,
explanation: {
period: {
end: node.explanation.period.end && fn(node.explanation.period.end),
start: node.explanation.period.start && fn(node.explanation.period.start),
},
value: fn(node.explanation.value),
},
})
5 changes: 0 additions & 5 deletions publicodes/core/source/AST/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ import { SommeNode } from '../mecanisms/sum'
import { SynchronisationNode } from '../mecanisms/synchronisation'
import { TauxProgressifNode } from '../mecanisms/tauxProgressif'
import { UnitéNode } from '../mecanisms/unité'
import { VariableTemporelleNode } from '../mecanisms/variableTemporelle'
import { VariationNode } from '../mecanisms/variations'
import { ReferenceNode } from '../reference'
import { ReplacementRule } from '../replacement'
import { RuleNode } from '../rule'
import { Temporal } from '../temporal'

export type ConstantNode = {
type: 'boolean' | 'objet' | 'number' | 'string'
Expand Down Expand Up @@ -64,7 +62,6 @@ export type ASTNode = (
| SynchronisationNode
| TauxProgressifNode
| UnitéNode
| VariableTemporelleNode
| VariationNode
| ConstantNode
| ReplacementRule
Expand Down Expand Up @@ -109,12 +106,10 @@ export type Unit = {
}

// Idée : une évaluation est un n-uple : (value, unit, missingVariable, isApplicable)
// Une temporalEvaluation est une liste d'evaluation sur chaque période. : [(Evaluation, Period)]
type EvaluationDecoration<T extends Types> = {
nodeValue: Evaluation<T>
missingVariables: Record<string, number>
unit?: Unit
temporalValue?: Temporal<Evaluation>
}
export type Types = number | boolean | string | Record<string, unknown>
export type Evaluation<T extends Types = Types> = T | false | null
Expand Down
8 changes: 1 addition & 7 deletions publicodes/core/source/grammar.ne
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

@{%
const {
string, date, variable, temporalNumericValue, binaryOperation,
unaryOperation, boolean, number, numberWithUnit, JSONObject
string, date, variable, binaryOperation, unaryOperation, boolean, number, numberWithUnit, JSONObject
} = require('./grammarFunctions')

const moo = require("moo");
Expand Down Expand Up @@ -61,11 +60,6 @@ main ->
NumericValue ->
AdditionSubstraction {% id %}
| Negation {% id %}
| TemporalNumericValue {% id %}

TemporalNumericValue ->
NumericValue %space %periodWord %space %date {% ([value,,word,,dateString]) => temporalNumericValue(value, word, date([dateString])) %}
| NumericValue %space %periodWord %colon Date {% ([value,,word,,date]) => temporalNumericValue(value, word, date) %}

NumericTerminal ->
Variable {% id %}
Expand Down
8 changes: 0 additions & 8 deletions publicodes/core/source/grammarFunctions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* Those are postprocessor functions for the Nearley grammar.ne.
The advantage of putting them here is to get prettier's JS formatting, since Nealrey doesn't support it https://github.com/kach/nearley/issues/310 */
import { normalizeDateString } from './date'
import { parsePeriod } from './temporal'

export let binaryOperation = (operationType) => ([A, , operator, , B]) => ({
[operator]: {
Expand All @@ -17,13 +16,6 @@ export let unaryOperation = (operationType) => ([operator, , A]) => ({
},
})

export let temporalNumericValue = (variable, word, date) => ({
temporalValue: {
explanation: variable,
period: parsePeriod(word.value.slice(2), date),
},
})

export let variable = ([firstFragment, nextFragment], _, reject) => {
const fragments = [firstFragment, ...nextFragment].map(({ value }) => value)
if (!nextFragment.length && ['oui', 'non'].includes(firstFragment)) {
Expand Down
10 changes: 8 additions & 2 deletions publicodes/core/source/mecanisms/product.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { EvaluationFunction } from '..'
import { ASTNode } from '../AST/types'
import { warning } from '../error'
import { defaultNode, parseObject } from '../evaluation'
import { defaultNode, mergeAllMissing, parseObject } from '../evaluation'
import { registerEvaluationFunction } from '../evaluationFunctions'
import { convertNodeToUnit, simplifyNodeUnit } from '../nodeUnits'
import { areUnitConvertible, convertUnit, inferUnit } from '../units'
Expand Down Expand Up @@ -72,11 +72,17 @@ const evaluateProduit: EvaluationFunction<'produit'> = function (node) {
nodeValue = convertUnit(unit, assiette.unit, nodeValue)
unit = assiette.unit
}

return simplifyNodeUnit({
...node,
missingVariables: mergeAllMissing([assiette, taux, facteur, plafond]),
nodeValue,
unit,

explanation: {
assiette,
taux,
facteur,
plafond,
plafondActif: (assiette.nodeValue as any) > (plafond as any).nodeValue,
},
})
Expand Down
69 changes: 0 additions & 69 deletions publicodes/core/source/mecanisms/variableTemporelle.ts

This file was deleted.

2 changes: 0 additions & 2 deletions publicodes/core/source/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import { mecanismSum } from './mecanisms/sum'
import { mecanismSynchronisation } from './mecanisms/synchronisation'
import tauxProgressif from './mecanisms/tauxProgressif'
import unité from './mecanisms/unité'
import variableTemporelle from './mecanisms/variableTemporelle'
import variations, { devariate } from './mecanisms/variations'
import { Context } from './parsePublicodes'
import parseReference from './reference'
Expand Down Expand Up @@ -190,7 +189,6 @@ const parseFunctions = {
somme: mecanismSum,
multiplication: mecanismProduct,
produit: mecanismProduct,
temporalValue: variableTemporelle,
barème,
grille,
'taux progressif': tauxProgressif,
Expand Down
Loading

0 comments on commit f43f02e

Please sign in to comment.