Skip to content

Commit

Permalink
fix: correctly use estimated values for alternatives
Browse files Browse the repository at this point in the history
  • Loading branch information
EmileRolley committed Aug 27, 2024
1 parent 3d0acde commit 3a0be38
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 33 deletions.
15 changes: 13 additions & 2 deletions rules/cout.publicodes
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,23 @@ coût . voiture:
unité: €/an
contexte:
futureco . trajet . voyageurs: 1
futureco . voiture . consommation thermique: voiture . thermique . consommation
futureco . voiture . consommation thermique:
valeur:
# TODO: factoriser avec empreinte
# Permet de forcer l'utilisation de la consommation estimée lors des
# recalculs pour les alternatives.
#
# Par défaut, si la personne n'a pas renseigné le prix d'achat, on avec
# le mécansime `plancher`, la règle `prix d'achat` est évaluée à 1.
variations:
- si: voiture . thermique . consommation > 1
alors: voiture . thermique . consommation
- sinon: voiture . thermique . consommation . consommation estimée
futureco . voiture . km annuels . par défaut: usage . km annuels
futureco . voiture . prix d'achat:
valeur:
# Permet de forcer l'utilisation du prix d'achat estimé lors des
# recalculs pour les combinaisons.
# recalculs pour les alternatives.
#
# Par défaut, si la personne n'a pas renseigné le prix d'achat, on avec
# le mécansime `plancher`, la règle `prix d'achat` est évaluée à 1.
Expand Down
12 changes: 11 additions & 1 deletion rules/empreinte.publicodes
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ empreinte . voiture:
ngc . transport . voiture . motorisation: voiture . motorisation
ngc . transport . voiture . thermique . carburant: voiture . thermique . carburant
ngc . transport . voiture . km: usage . km annuels
ngc . transport . voiture . thermique . consommation aux 100: voiture . thermique . consommation
ngc . transport . voiture . thermique . consommation aux 100:
valeur:
# Permet de forcer l'utilisation de la consommation estimée lors des
# recalculs pour les alternatives.
#
# Par défaut, si la personne n'a pas renseigné le prix d'achat, on avec
# le mécansime `plancher`, la règle `prix d'achat` est évaluée à 1.
variations:
- si: voiture . thermique . consommation > 1
alors: voiture . thermique . consommation
- sinon: voiture . thermique . consommation . consommation estimée
ngc . transport . voiture . voyageurs: 1
unité: kgCO2e/an
3 changes: 2 additions & 1 deletion rules/voiture-cible.publicodes
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ voiture . cible . gabarit:
- berline
- SUV
- VUL
par défaut: "'moyenne'"
# NOTE: est-ce que l'on a envie de pousser vers un gabarit plus petit ?
par défaut: voiture . gabarit
avec:
petite:
titre: Citadine
Expand Down
11 changes: 1 addition & 10 deletions rules/voiture.publicodes
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@ voiture . thermique . consommation . consommation estimée:
unité: l/100km
contexte:
ngc . transport . voiture . utilisateur: "'propriétaire'"
# NOTE: il faut seulement que distance soit supérieur à 0 pour que la règle
ngc . transport . voiture . km: usage . km annuels
ngc . transport . voiture . gabarit: voiture . gabarit
ngc . transport . voiture . motorisation: voiture . motorisation
ngc . transport . voiture . thermique . carburant: voiture . thermique . carburant
Expand Down Expand Up @@ -254,17 +252,10 @@ voiture . gabarit:
- berline
- SUV
- VUL
par défaut: "'moyenne'"
par défaut: "'berline'"
description: |
Si vous ne savez pas quel gabarit choisir, vous pouvez penser à la taille
comme (petite, moyenne, grande, 4x4 urbain, camionnette).
# description: |
# - Citadine : petite voiture, type Zoé, Fiat 500
# - Monospace : modèle au dessus de la petite citadine, type Mégane, Golf
# - Berline : une voiture longue, type 308, Tesla Model 3, Audi A3
# - SUV : "Sport utility vehicle", type 4x4 urbain
# - VUL : camionette de type Kangoo ou Partner jusqu'au Trafic et Vito
note: |
Nous considérons que la voiture par défaut est une "Berline", en témoigne
[une étude menée par AAA
Expand Down
30 changes: 11 additions & 19 deletions scripts/generate-alternatives.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,13 @@ export default function generateAlternatives(rules) {
for (const gabarit of gabarits) {
const gabaritTitle =
rules[`voiture . gabarit . ${gabarit}`]?.titre ?? gabarit
const contexteBaseEmission = {
"ngc . transport . voiture . utilisateur": "'propriétaire'",
"ngc . transport . voiture . gabarit": `'${gabarit}'`,
"ngc . transport . voiture . motorisation": `'${motorisation}'`,
"ngc . transport . voiture . km": "usage . km annuels",
"ngc . transport . voiture . voyageurs": 1,
"ngc . transport . voiture . thermique . consommation aux 100":
"voiture . thermique . consommation",
}

const contexteBaseCost = {
const baseContexte = {
"voiture . gabarit": `'${gabarit}'`,
"voiture . motorisation": `'${motorisation}'`,
// We need to disable the rule to use the 'voiture . prix d'achat . estimé' instead
// Needed to force the use of the 'voiture . prix d'achat . estimé'
"voiture . prix d'achat": "non",
// Needed to force the use of the 'voiture . thermique . consommation . estimée'
"voiture . thermique . consommation": "non",
}

if (motorisation !== "électrique") {
Expand All @@ -74,18 +66,18 @@ export default function generateAlternatives(rules) {
rules[`empreinte . ${motorisation} . ${gabarit} . ${carburant}`] = {
titre: `${gabaritTitle} ${motorisation} (${carburantTitle})`,
unité: "kgCO2eq/an",
valeur: "ngc . transport . voiture",
valeur: "empreinte . voiture",
contexte: {
...contexteBaseEmission,
"ngc . transport . voiture . thermique . carburant": `'${carburant}'`,
...baseContexte,
"voiture . thermique . carburant": `'${carburant}'`,
},
}
rules[`coût . ${motorisation} . ${gabarit} . ${carburant}`] = {
titre: `${gabaritTitle} ${motorisation} (${carburantTitle})`,
unité: "€/an",
valeur: "coût . voiture",
contexte: {
...contexteBaseCost,
...baseContexte,
"voiture . thermique . carburant": `'${carburant}'`,
},
}
Expand All @@ -94,14 +86,14 @@ export default function generateAlternatives(rules) {
rules[`empreinte . ${motorisation} . ${gabarit}`] = {
titre: `${gabaritTitle} ${motorisation}`,
unité: "kgCO2eq/an",
valeur: "ngc . transport . voiture",
contexte: contexteBaseEmission,
valeur: "empreinte . voiture",
contexte: baseContexte,
}
rules[`coût . ${motorisation} . ${gabarit}`] = {
titre: `${gabaritTitle} ${motorisation}`,
unité: "€/an",
valeur: "coût . voiture",
contexte: contexteBaseCost,
contexte: baseContexte,
}
}
}
Expand Down

0 comments on commit 3a0be38

Please sign in to comment.