@open3cl/engine 1.8.36 → 1.8.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -13
- package/conso.js +19 -5
- package/conso.spec.js +49 -0
- package/engine.js +16 -4
- package/engine.spec.js +41 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -370,7 +370,7 @@ Ces résultats sont **générés automatiquement** à la fin de `npm run test:co
|
|
|
370
370
|
|
|
371
371
|
<!-- CORPUS:START -->
|
|
372
372
|
|
|
373
|
-
> **Version `1.8.
|
|
373
|
+
> **Version `1.8.36`** · branche `main` · généré le 2026-10-09
|
|
374
374
|
> Seuil de tolérance **5%**
|
|
375
375
|
|
|
376
376
|
<table>
|
|
@@ -403,24 +403,24 @@ Ces résultats sont **générés automatiquement** à la fin de `npm run test:co
|
|
|
403
403
|
|
|
404
404
|
<table>
|
|
405
405
|
<tr>
|
|
406
|
-
<td align="center"><strong>5,
|
|
407
|
-
<td align="center"><strong>4,
|
|
406
|
+
<td align="center"><strong>5,13 ms</strong><br/><sub>moyenne</sub></td>
|
|
407
|
+
<td align="center"><strong>4,48 ms</strong><br/><sub>médiane</sub></td>
|
|
408
408
|
<td align="center"><strong>0,11 ms</strong><br/><sub>min</sub></td>
|
|
409
|
-
<td align="center"><strong>
|
|
409
|
+
<td align="center"><strong>468,0 ms</strong><br/><sub>max</sub></td>
|
|
410
410
|
</tr>
|
|
411
411
|
</table>
|
|
412
412
|
|
|
413
413
|
| Corpus | Moyenne | Médiane | Min | Max | p95 | p99 |
|
|
414
414
|
| :--------------------------------------------- | ------: | ------: | ------: | -------: | ------: | ------: |
|
|
415
|
-
| **Généraliste** | 4,
|
|
416
|
-
| **Appartement · chauffage individuel (2025)** | 3,
|
|
417
|
-
| **Logement individuel (2025)** |
|
|
418
|
-
| **Maison individuelle (2025)** |
|
|
419
|
-
| **Immeuble · chauffage individuel** | 6,
|
|
420
|
-
| **Appartement · chauffage collectif (2025)** |
|
|
421
|
-
| **Immeuble · chauffage collectif** | 5,
|
|
422
|
-
| **Immeuble · chauffage mixte** | 5,
|
|
423
|
-
| **Individuel généré depuis l'immeuble (2026)** |
|
|
415
|
+
| **Généraliste** | 4,50 ms | 4,02 ms | 0,22 ms | 33,8 ms | 8,30 ms | 12,2 ms |
|
|
416
|
+
| **Appartement · chauffage individuel (2025)** | 3,59 ms | 3,26 ms | 1,42 ms | 25,6 ms | 6,19 ms | 7,93 ms |
|
|
417
|
+
| **Logement individuel (2025)** | 5,29 ms | 4,77 ms | 1,61 ms | 35,7 ms | 9,74 ms | 13,2 ms |
|
|
418
|
+
| **Maison individuelle (2025)** | 6,09 ms | 5,50 ms | 1,84 ms | 37,9 ms | 10,9 ms | 14,2 ms |
|
|
419
|
+
| **Immeuble · chauffage individuel** | 6,28 ms | 5,40 ms | 0,12 ms | 85,1 ms | 12,7 ms | 19,8 ms |
|
|
420
|
+
| **Appartement · chauffage collectif (2025)** | 3,96 ms | 3,55 ms | 1,40 ms | 33,4 ms | 6,53 ms | 8,28 ms |
|
|
421
|
+
| **Immeuble · chauffage collectif** | 5,22 ms | 4,41 ms | 0,11 ms | 93,8 ms | 9,69 ms | 16,8 ms |
|
|
422
|
+
| **Immeuble · chauffage mixte** | 5,18 ms | 4,23 ms | 0,22 ms | 468,0 ms | 10,7 ms | 17,7 ms |
|
|
423
|
+
| **Individuel généré depuis l'immeuble (2026)** | 6,07 ms | 5,20 ms | 1,63 ms | 47,3 ms | 11,7 ms | 18,6 ms |
|
|
424
424
|
|
|
425
425
|
<sub>La moyenne est tirée vers le haut par les DPE collectifs, dont le coût atteint plusieurs
|
|
426
426
|
dizaines de fois la médiane : c’est la médiane qui décrit le cas courant, et p95/p99 le cas
|
package/conso.js
CHANGED
|
@@ -212,16 +212,29 @@ export function masqueEnergie(groupe) {
|
|
|
212
212
|
* postes au prorata de leur consommation.
|
|
213
213
|
* Immeuble : consommation des usages individuels rapportée au logement (N × f(C / N)) ;
|
|
214
214
|
* chauffage / ECS des installations collectives tarifés sur leur total (f(C)).
|
|
215
|
+
* Appartement desservi par une installation collective : la tranche est déterminée sur la
|
|
216
|
+
* consommation de l'immeuble extrapolée (C × SH_immeuble / SH_logement) et le coût ramené au
|
|
217
|
+
* logement : f(C × k) / k avec k = SH_immeuble / SH_logement (moteur de référence CSTB :
|
|
218
|
+
* DPE.Core Calcul_cout.cs l.133-136 et l.152-154, appelé avec SH_batiment / SH par
|
|
219
|
+
* Calcul_batiment.cs l.1318). Vérifié sur 927 / 1000 DPE ADEME appartement gaz collectif 2026.
|
|
215
220
|
*
|
|
216
221
|
* @param base {object} barème (prix unitaires et fonctions par tranches)
|
|
217
222
|
* @param consoGroupe {function(masque): {total: number, collectif: number}} consommations EF
|
|
218
223
|
* @param nbLogements {number} nombre de logements (1 hors immeuble)
|
|
219
224
|
* @param genCollectifs {Set} générateurs de chauffage / ECS d'installations collectives
|
|
225
|
+
* @param ratioSurfaceCollectif {number} SH_immeuble / SH_logement pour un appartement (1 sinon)
|
|
220
226
|
* @returns {object}
|
|
221
227
|
*/
|
|
222
|
-
export function coefCoutProrata(
|
|
228
|
+
export function coefCoutProrata(
|
|
229
|
+
base,
|
|
230
|
+
consoGroupe,
|
|
231
|
+
nbLogements,
|
|
232
|
+
genCollectifs,
|
|
233
|
+
ratioSurfaceCollectif = 1
|
|
234
|
+
) {
|
|
223
235
|
const coef = { ...base };
|
|
224
236
|
const coefCollectif = { ...base };
|
|
237
|
+
const k = ratioSurfaceCollectif > 1 ? ratioSurfaceCollectif : 1;
|
|
225
238
|
new Set(Object.values(ENERGIES_A_TRANCHES)).forEach((groupe) => {
|
|
226
239
|
const { total, collectif } = consoGroupe(masqueEnergie(groupe));
|
|
227
240
|
const individuel = total - collectif;
|
|
@@ -230,7 +243,7 @@ export function coefCoutProrata(base, consoGroupe, nbLogements, genCollectifs) {
|
|
|
230
243
|
.forEach((cle) => {
|
|
231
244
|
const f = base[cle];
|
|
232
245
|
const prix = individuel > 0 ? (nbLogements * f(individuel / nbLogements)) / individuel : 0;
|
|
233
|
-
const prixCollectif = collectif > 0 ? f(collectif) / collectif : 0;
|
|
246
|
+
const prixCollectif = collectif > 0 ? f(collectif * k) / (collectif * k) : 0;
|
|
234
247
|
coef[cle] = (c) => prix * c;
|
|
235
248
|
coefCollectif[cle] = (c) => prixCollectif * c;
|
|
236
249
|
});
|
|
@@ -321,7 +334,8 @@ export default function calc_conso(
|
|
|
321
334
|
prorataChauffage,
|
|
322
335
|
dateDpe,
|
|
323
336
|
coeffEp,
|
|
324
|
-
nbLogements = 1
|
|
337
|
+
nbLogements = 1,
|
|
338
|
+
ratioSurfaceCollectif = 1
|
|
325
339
|
) {
|
|
326
340
|
const gen_ch = ch.reduce((acc, ch) => {
|
|
327
341
|
const generateur_chauffage = ch.generateur_chauffage_collection.generateur_chauffage;
|
|
@@ -369,7 +383,7 @@ export default function calc_conso(
|
|
|
369
383
|
const base = getCoefCout(dateDpe);
|
|
370
384
|
if (base === coef_cout) return coef_cout;
|
|
371
385
|
const genCollectifs = new Set();
|
|
372
|
-
if (nbLogements > 1) {
|
|
386
|
+
if (nbLogements > 1 || ratioSurfaceCollectif > 1) {
|
|
373
387
|
gen_ch
|
|
374
388
|
.filter((g) => g.donnee_entree.enum_type_installation_id !== '1')
|
|
375
389
|
.forEach((g) => genCollectifs.add(g));
|
|
@@ -408,7 +422,7 @@ export default function calc_conso(
|
|
|
408
422
|
);
|
|
409
423
|
return { total: tot.c_5_usages, collectif: coll.c_ch + coll.c_ecs };
|
|
410
424
|
};
|
|
411
|
-
return coefCoutProrata(base, consoGroupe, nbLogements, genCollectifs);
|
|
425
|
+
return coefCoutProrata(base, consoGroupe, nbLogements, genCollectifs, ratioSurfaceCollectif);
|
|
412
426
|
};
|
|
413
427
|
|
|
414
428
|
const ret = {
|
package/conso.spec.js
CHANGED
|
@@ -684,4 +684,53 @@ describe('calc_conso - coût avec le barème mis à jour (DPE 2026)', () => {
|
|
|
684
684
|
// Élec totale 4100 kWh / 4 logements => 4 × (158 + 0,18954 × 1025)
|
|
685
685
|
expect(res.cout.cout_5_usages).toBeCloseTo(4 * (158 + 0.18954 * 1025), 9);
|
|
686
686
|
});
|
|
687
|
+
|
|
688
|
+
/**
|
|
689
|
+
* Appartement desservi par une installation collective : tranche déterminée sur la conso de
|
|
690
|
+
* l'immeuble extrapolée (C × k, k = SH_immeuble / SH_logement), coût ramené au logement (÷ k).
|
|
691
|
+
* @see Moteur_DPE.dll (CSTB) Calcul_cout.cs l.133-136 / l.152-154 ; autotests APP5-0-5x, APP3-0-2.
|
|
692
|
+
*/
|
|
693
|
+
test('appartement, chauffage gaz collectif : tranche sur la conso extrapolée à l’immeuble', () => {
|
|
694
|
+
const ch = [
|
|
695
|
+
installCh({ enum_type_installation_id: '2' }, [
|
|
696
|
+
genCh('2', { conso_ch: 4000, conso_ch_depensier: 4000 })
|
|
697
|
+
])
|
|
698
|
+
];
|
|
699
|
+
const res = calc_conso(100, 1, 1, [], ch, [], [], 1, 1, DATE_DPE_2026, coef_ep, 1, 20);
|
|
700
|
+
// 4000 × 20 = 80000 kWh (> 50000) => (288 + 0,09274 × 80000) / 20 = 0,0965 €/kWh × 4000
|
|
701
|
+
expect(res.cout.cout_ch).toBeCloseTo((288 + 0.09274 * 80000) / 20, 9);
|
|
702
|
+
// Sans extrapolation, le logement serait tarifé en 1ʳᵉ tranche (0,1312 × 4000 = 524,8 €).
|
|
703
|
+
expect(res.cout.cout_ch).not.toBeCloseTo(0.1312 * 4000, 0);
|
|
704
|
+
// Éclairage (usage individuel) : tarifé sur la seule conso du logement (100 kWh).
|
|
705
|
+
expect(res.cout.cout_eclairage).toBeCloseTo(0.34721 * 100, 9);
|
|
706
|
+
});
|
|
707
|
+
|
|
708
|
+
test('appartement, ECS électrique collective : tranche élec sur la conso extrapolée', () => {
|
|
709
|
+
const ecs = [
|
|
710
|
+
installEcs({ enum_type_installation_id: '2' }, [
|
|
711
|
+
genEcs('1', { conso_ecs: 1400, conso_ecs_depensier: 1400 })
|
|
712
|
+
])
|
|
713
|
+
];
|
|
714
|
+
const res = calc_conso(100, 1, 1, [], [], ecs, [], 1, 1, DATE_DPE_2026, coef_ep, 1, 10);
|
|
715
|
+
// 1400 × 10 = 14000 kWh => (119 + 0,19726 × 14000) / 10
|
|
716
|
+
expect(res.cout.cout_ecs).toBeCloseTo((119 + 0.19726 * 14000) / 10, 9);
|
|
717
|
+
});
|
|
718
|
+
|
|
719
|
+
test('appartement, installations individuelles : ratio de surface sans effet', () => {
|
|
720
|
+
const ch = [installCh({}, [genCh('2', { conso_ch: 4000, conso_ch_depensier: 4000 })])];
|
|
721
|
+
const res = calc_conso(100, 1, 1, [], ch, [], [], 1, 1, DATE_DPE_2026, coef_ep, 1, 20);
|
|
722
|
+
expect(res.cout.cout_ch).toBeCloseTo(0.1312 * 4000, 9);
|
|
723
|
+
});
|
|
724
|
+
});
|
|
725
|
+
|
|
726
|
+
describe('coefCoutProrata - ratio de surface des installations collectives', () => {
|
|
727
|
+
test('ratio ≤ 1 : neutre (tarif sur la conso collective seule)', () => {
|
|
728
|
+
const base = getCoefCout('2026-01-15');
|
|
729
|
+
const consoGroupe = () => ({ total: 4000, collectif: 4000 });
|
|
730
|
+
[undefined, 1, 0.5].forEach((ratio) => {
|
|
731
|
+
const coef = coefCoutProrata(base, consoGroupe, 1, new Set(['g']), ratio);
|
|
732
|
+
const coll = Object.getOwnPropertySymbols(coef).map((s) => coef[s])[0].coef;
|
|
733
|
+
expect(coll['gaz naturel'](4000)).toBeCloseTo(0.1312 * 4000, 9);
|
|
734
|
+
});
|
|
735
|
+
});
|
|
687
736
|
});
|
package/engine.js
CHANGED
|
@@ -33,7 +33,7 @@ import getFicheTechnique from './ficheTechnique.js';
|
|
|
33
33
|
import { ProductionENR, ratioProrataPvLogement } from './16.2_production_enr.js';
|
|
34
34
|
import DpeSanitizerService from './dpe-sanitizer.service.js';
|
|
35
35
|
|
|
36
|
-
const LIB_VERSION = '1.8.
|
|
36
|
+
const LIB_VERSION = '1.8.37';
|
|
37
37
|
|
|
38
38
|
const dpeSanitizerService = new DpeSanitizerService();
|
|
39
39
|
|
|
@@ -583,6 +583,15 @@ export function calcul_3cl(inputDpe, options) {
|
|
|
583
583
|
prorataChauffage = Sh / ShChauffageAndEcs;
|
|
584
584
|
}
|
|
585
585
|
|
|
586
|
+
/**
|
|
587
|
+
* Appartement : rapport SH_immeuble / SH_logement utilisé pour déterminer la tranche du barème
|
|
588
|
+
* des installations collectives sur la consommation de l'immeuble (voir coefCoutProrata).
|
|
589
|
+
*/
|
|
590
|
+
const ratioSurfaceCoutCollectif =
|
|
591
|
+
th === 'appartement' && Number(cg.surface_habitable_immeuble) > Number(Sh) && Number(Sh) > 0
|
|
592
|
+
? Number(cg.surface_habitable_immeuble) / Number(Sh)
|
|
593
|
+
: 1;
|
|
594
|
+
|
|
586
595
|
const conso = calc_conso(
|
|
587
596
|
Sh,
|
|
588
597
|
zc_id,
|
|
@@ -595,7 +604,8 @@ export function calcul_3cl(inputDpe, options) {
|
|
|
595
604
|
prorataChauffage,
|
|
596
605
|
dateDpe,
|
|
597
606
|
coef_ep,
|
|
598
|
-
th === 'immeuble' ? Nb_lgt : 1
|
|
607
|
+
th === 'immeuble' ? Nb_lgt : 1,
|
|
608
|
+
ratioSurfaceCoutCollectif
|
|
599
609
|
);
|
|
600
610
|
|
|
601
611
|
// Proratisation au logement d'une installation PV d'immeuble (appartement)
|
|
@@ -628,7 +638,8 @@ export function calcul_3cl(inputDpe, options) {
|
|
|
628
638
|
prorataChauffage,
|
|
629
639
|
dateDpe,
|
|
630
640
|
coef_ep_1_7,
|
|
631
|
-
th === 'immeuble' ? Nb_lgt : 1
|
|
641
|
+
th === 'immeuble' ? Nb_lgt : 1,
|
|
642
|
+
ratioSurfaceCoutCollectif
|
|
632
643
|
);
|
|
633
644
|
|
|
634
645
|
productionENR.calculateEnr(
|
|
@@ -653,7 +664,8 @@ export function calcul_3cl(inputDpe, options) {
|
|
|
653
664
|
prorataChauffage,
|
|
654
665
|
dateDpe,
|
|
655
666
|
coef_ep_2_3,
|
|
656
|
-
th === 'immeuble' ? Nb_lgt : 1
|
|
667
|
+
th === 'immeuble' ? Nb_lgt : 1,
|
|
668
|
+
ratioSurfaceCoutCollectif
|
|
657
669
|
);
|
|
658
670
|
|
|
659
671
|
productionENR.calculateEnr(
|
package/engine.spec.js
CHANGED
|
@@ -710,6 +710,47 @@ describe('calcul_3cl - surfaces immeuble / appartement et prorata', () => {
|
|
|
710
710
|
expect(conso_aux_distribution_ecs.mock.calls[0][3]).toBe(80);
|
|
711
711
|
expect(conso_aux_distribution_ecs.mock.calls[0][4]).toBe(200);
|
|
712
712
|
});
|
|
713
|
+
|
|
714
|
+
test('appartement : rapport SH immeuble / SH logement transmis au calcul du coût', () => {
|
|
715
|
+
enums.methode_application_dpe_log = { 2: 'dpe appartement individuel' };
|
|
716
|
+
const dpe = makeDpe();
|
|
717
|
+
dpe.logement.caracteristique_generale.enum_methode_application_dpe_log_id = '2';
|
|
718
|
+
|
|
719
|
+
calcul_3cl(dpe, { sanitize: false });
|
|
720
|
+
|
|
721
|
+
// 3 appels (coef_ep, 1,7, 2,3) : nbLogements = 1 (hors immeuble), ratio = 200 / 80 = 2,5.
|
|
722
|
+
expect(calc_conso).toHaveBeenCalledTimes(3);
|
|
723
|
+
calc_conso.mock.calls.forEach((call) => {
|
|
724
|
+
expect(call[11]).toBe(1);
|
|
725
|
+
expect(call[12]).toBeCloseTo(2.5, 9);
|
|
726
|
+
});
|
|
727
|
+
});
|
|
728
|
+
|
|
729
|
+
test('appartement sans surface immeuble exploitable : ratio neutre (1)', () => {
|
|
730
|
+
enums.methode_application_dpe_log = { 2: 'dpe appartement individuel' };
|
|
731
|
+
const dpe = makeDpe();
|
|
732
|
+
dpe.logement.caracteristique_generale.enum_methode_application_dpe_log_id = '2';
|
|
733
|
+
// Surface immeuble inférieure à celle du logement (saisie incohérente) => pas d'extrapolation.
|
|
734
|
+
dpe.logement.caracteristique_generale.surface_habitable_immeuble = 50;
|
|
735
|
+
|
|
736
|
+
calcul_3cl(dpe, { sanitize: false });
|
|
737
|
+
|
|
738
|
+
expect(calc_conso.mock.calls[0][12]).toBe(1);
|
|
739
|
+
});
|
|
740
|
+
|
|
741
|
+
test('maison et immeuble : ratio de surface du coût neutre (1)', () => {
|
|
742
|
+
const maison = makeDpe();
|
|
743
|
+
calcul_3cl(maison, { sanitize: false });
|
|
744
|
+
expect(calc_conso.mock.calls[0][12]).toBe(1);
|
|
745
|
+
|
|
746
|
+
vi.mocked(calc_conso).mockClear();
|
|
747
|
+
enums.methode_application_dpe_log = { 6: 'dpe immeuble collectif' };
|
|
748
|
+
const immeuble = makeDpe();
|
|
749
|
+
immeuble.logement.caracteristique_generale.enum_methode_application_dpe_log_id = '6';
|
|
750
|
+
calcul_3cl(immeuble, { sanitize: false });
|
|
751
|
+
expect(calc_conso.mock.calls[0][11]).toBe(4);
|
|
752
|
+
expect(calc_conso.mock.calls[0][12]).toBe(1);
|
|
753
|
+
});
|
|
713
754
|
});
|
|
714
755
|
|
|
715
756
|
describe("calcul_3cl - auxiliaires de distribution d'ECS", () => {
|