Skip to content

Commit

Permalink
Merge pull request #83 from betagouv/bug-paliers-revenu
Browse files Browse the repository at this point in the history
bug paliers revenu
  • Loading branch information
laem authored Apr 3, 2024
2 parents 1530c7b + e0a2501 commit 8599506
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 20 deletions.
24 changes: 12 additions & 12 deletions app/personas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
DPE . actuel: 6
projet . DPE visé: 2
projet . travaux: 70140 / (1.055)
ménage . code région: 27 # Doubs
ménage . code région: "'27'" # Doubs
valeurs attendues:
# d'après https://www.ecologie.gouv.fr/sites/default/files/DP_MPR2024.pdf#page=8
MPR . accompagnée: 59835
Expand All @@ -20,7 +20,7 @@
DPE . actuel: 7
projet . DPE visé: 4
projet . travaux: 53200 / (1.055)
ménage . code région: 24 # Cher
ménage . code région: "'24'" # Cher
valeurs attendues:
# d'après https://www.ecologie.gouv.fr/sites/default/files/DP_MPR2024.pdf#page=9
MPR . accompagnée: 30256
Expand All @@ -34,7 +34,7 @@
DPE . actuel: 4
projet . DPE visé: 1
projet . travaux: 49300
ménage . code région: 53
ménage . code région: "'53'"
- description: |
Couple aisé., passoire, 4 sauts, ~ 70k € de travaux
situation:
Expand All @@ -43,7 +43,7 @@
ménage . revenu: 70000
DPE . actuel: 6
projet . DPE visé: 2
ménage . code région: 52
ménage . code région: "'52'"
- description: |
Couple modeste, presque passoire, 1 saut.
situation:
Expand All @@ -52,7 +52,7 @@
ménage . revenu: 20000
DPE . actuel: 5
projet . DPE visé: 4
ménage . code région: 52
ménage . code région: '"52"'
- description: |
Individu aisé, presque passoire, 3 saut.
situation:
Expand All @@ -61,7 +61,7 @@
ménage . revenu: 80000
DPE . actuel: 5
projet . DPE visé: 2
ménage . code région: 52
ménage . code région: "'52'"
- description: |
Propriétaire élligible, mais pas d'autres infos
situation:
Expand All @@ -75,7 +75,7 @@
DPE . actuel: 4
projet . DPE visé: 1
projet . travaux: 49000
ménage . code région: 53
ménage . code région: "'53'"
- description: |
Couple moyen, revenu 35k, enveloppe 49k mais en IdF.
situation:
Expand All @@ -85,31 +85,31 @@
DPE . actuel: 4
projet . DPE visé: 1
projet . travaux: 49000
ménage . code région: 11
ménage . code région: "'11'"
- description: |
Éligible aux deux parcours.
situation:
conditions communes: oui
ménage . personnes: 2
ménage . revenu: 25000
DPE . actuel: 4
ménage . code région: 53
ménage . code région: "'53'"
- description: |
Éligible seulement au parcours accompagné.
situation:
conditions communes: oui
ménage . personnes: 2
ménage . revenu: 80000
DPE . actuel: 7
ménage . code région: 53
ménage . code région: "'53'"
- description: |
Éligible seulement au parcours par gestes.
situation:
conditions communes: oui
ménage . personnes: 2
ménage . revenu: 35000
DPE . actuel: 2
ménage . code région: 53
ménage . code région: "'53'"
- description: |
1 saut, aisé.
situation:
Expand All @@ -118,7 +118,7 @@
ménage . revenu: 85000
DPE . actuel: 3
projet . DPE visé: 2
ménage . code région: 53
ménage . code région: "'53'"
- description: |
DPE C, revenu aisé -> 1 seul scénario MPR accompagné.
situation:
Expand Down
12 changes: 7 additions & 5 deletions app/règles/index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,16 @@ ménage:

ménage . code région:
formule: commune # Juste pour appeler cette question, qui lui donnera sa valeur via l'UI
par défaut: 53 # La Bretagne, comme toute autre région non francilienne, ouvre l'éligibilité aux aides
par défaut: '"53"' # La Bretagne, comme toute autre région non francilienne, ouvre l'éligibilité aux aides
suggestions:
Bretagne: 53
Pays de la Loire: 52
IdF: 11
Bretagne: '"53"'
Pays de la Loire: '"52"'
IdF: "'11'"

ménage . commune:
titre: Votre commune
question: Dans quelle commune habitez-vous ?
par défaut: "'29200'"
description: |
Attention, il s'agit ici de renseigner la commune de *votre ménage*.
Expand All @@ -201,7 +202,8 @@ ménage . id ban:
titre: Identifiant base nationale des adresses (BAN)

ménage . région:
ménage . région . IdF: code région = 11

ménage . région . IdF: code région = "11"

DPE:
titre: Diagnostic de Performance Énergétique.
Expand Down
1 change: 1 addition & 0 deletions app/simulation/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export default function Form({ searchParams, rules }) {
answeredQuestions.includes(k),
),
)

const evaluation = engine.setSituation(validatedSituation).evaluate(target),
nextQuestions = getNextQuestions(
evaluation,
Expand Down
16 changes: 14 additions & 2 deletions components/SmartInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,26 @@ export default function Input({ situation, onChange, value, rule, engine }) {

const idf = engine.evaluate('ménage . région . IdF')
const evaluation = engine.evaluate(targets[idf.nodeValue ? 0 : 1])
console.log('smart eval', evaluation)
const activeBarème =
evaluation.explanation.valeur.explanation.alors.explanation.find(
(el) => el.condition.nodeValue,
)
console.log('smart eval list', activeBarème.consequence.explanation)
const list = activeBarème.consequence.explanation
.map((el) => el.condition[1]?.constant?.nodeValue)
.map((el) => {
if (el.condition.isDefault) return false
console.log('smart eval condition', el.condition)
const conditionRightValue = engine.evaluate(
el.condition.explanation[1],
).nodeValue
if (conditionRightValue != null) return conditionRightValue

throw new Error(
'Impossible de calculer les bornes de revenu intelligentes.',
)
})
.filter(Boolean)

console.log('smart eval list', list)

console.log('smart revenu', revenu)
Expand Down
4 changes: 3 additions & 1 deletion components/publicodes/situationUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ export const getSituation = (searchParams, rules) =>
.map(([k, v, rule]) => {
const stringValue = v.endsWith(validValueMark) ? v.slice(0, -1) : v

// Remove trailing zeros for numeric values
// TODO this is brittle : some values can be numeric without an explicité yaml unit, it can be defined on the go in the value itself like blabla: 23 dogs
const value =
rule.unité && stringValue.match(/^0+\d+?/g)
(rule.unité || typeof rule['par défaut'] === 'number') &&
stringValue.match(/^0+\d+?/g)
? stringValue.replace(/^0+/g, '')
: stringValue

Expand Down

0 comments on commit 8599506

Please sign in to comment.