@open3cl/engine 1.8.16 → 1.8.18

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/11_ecs.js CHANGED
@@ -149,7 +149,8 @@ export default function calc_ecs(
149
149
  surfaceImmeuble,
150
150
  nombreAppartements,
151
151
  isImmeubleSystemEcsIndividuels,
152
- becsParMois
152
+ becsParMois,
153
+ isImmeubleMultiEcs = false
153
154
  ) {
154
155
  const de = ecs.donnee_entree;
155
156
  const di = {};
@@ -157,7 +158,18 @@ export default function calc_ecs(
157
158
 
158
159
  // La conso de chaque générateur ECS doit être ramenée au prorata de la surface du logement
159
160
  di.ratio_besoin_ecs = 1;
160
- if (virtualisationECS) {
161
+ if (isImmeubleMultiEcs) {
162
+ /**
163
+ * Immeuble avec plusieurs installations ECS (collectives ou mixtes) : ratio de besoin =
164
+ * surface habitable desservie par l'installation / surface habitable de l'immeuble,
165
+ * sans normalisation ni plafonnement. Le besoin est exprimé par unité dimensionnée (/ rdim),
166
+ * la consommation étant remultipliée par rdim lors de l'agrégation (conso.js, cle_repartition_ecs).
167
+ * @see Methode_de_calcul_3CL_DPE_2021-338.pdf - §11.4
168
+ * @see Moteur_DPE.dll Calcul_batiment.Calcul_Cecs() et Calcul_Cecs_installation_2()
169
+ */
170
+ di.ratio_besoin_ecs =
171
+ Number(de.surface_habitable) / Number(surfaceImmeuble) / (Number(de.rdim) || 1);
172
+ } else if (virtualisationECS) {
161
173
  di.ratio_besoin_ecs = de.cle_repartition_ecs || 1;
162
174
  } else if (isImmeubleSystemEcsIndividuels) {
163
175
  if (nombreAppartements) {
package/11_ecs.spec.js CHANGED
@@ -148,6 +148,104 @@ describe('calc_ecs - ratio de besoin ECS', () => {
148
148
  });
149
149
  });
150
150
 
151
+ /**
152
+ * Immeuble à plusieurs installations ECS collectives ou mixtes (#232) :
153
+ * ratio = Sh_ecs / Sh immeuble / (rdim || 1), prorata brut sans normalisation ni plafond.
154
+ * @see Methode_de_calcul_3CL_DPE_2021-338.pdf - §11.4
155
+ * @see Moteur_DPE.dll Calcul_batiment.Calcul_Cecs() (l.579-593)
156
+ */
157
+ describe('calc_ecs - immeuble à plusieurs installations ECS (prorata des surfaces)', () => {
158
+ /** Calcule le ratio d'une installation dans le cas immeuble multi-ECS. */
159
+ function calcImmeuble(de, surfaceImmeuble, options = {}) {
160
+ const ecs = makeEcs({ tv_rendement_distribution_ecs_id: '5', ...de });
161
+ calc_ecs(
162
+ {},
163
+ ecs,
164
+ 1000,
165
+ 1500,
166
+ 1,
167
+ 'ca1',
168
+ 'h1a',
169
+ 'immeuble',
170
+ options.virtualisation ?? false,
171
+ surfaceImmeuble,
172
+ options.nombreAppartements ?? null,
173
+ options.individuels ?? false,
174
+ {},
175
+ options.multiEcs ?? true
176
+ );
177
+ return ecs.donnee_intermediaire;
178
+ }
179
+
180
+ test('autotest IC1-0-2 : 2 installations collectives 20 et 155 m² sur 175 m²', () => {
181
+ const di1 = calcImmeuble({ enum_type_installation_id: '2', surface_habitable: 20 }, 175);
182
+ const di2 = calcImmeuble({ enum_type_installation_id: '2', surface_habitable: 155 }, 175);
183
+
184
+ expect(di1.ratio_besoin_ecs).toBeCloseTo(20 / 175, 9); // 0,1143
185
+ expect(di2.ratio_besoin_ecs).toBeCloseTo(155 / 175, 9); // 0,8857
186
+ expect(di1.ratio_besoin_ecs + di2.ratio_besoin_ecs).toBeCloseTo(1, 9);
187
+ expect(di1.besoin_ecs).toBeCloseTo((1000 * 20) / 175, 9);
188
+ });
189
+
190
+ test('somme des surfaces < Sh immeuble (461 sur 922) : prorata brut 0,5 sans normalisation', () => {
191
+ const di = calcImmeuble({ enum_type_installation_id: '2', surface_habitable: 461 }, 922);
192
+
193
+ expect(di.ratio_besoin_ecs).toBe(0.5);
194
+ expect(di.besoin_ecs).toBe(500);
195
+ });
196
+
197
+ test('somme des surfaces > Sh immeuble : prorata brut sans plafonnement', () => {
198
+ const di = calcImmeuble({ enum_type_installation_id: '2', surface_habitable: 7706 }, 8726);
199
+
200
+ expect(di.ratio_besoin_ecs).toBeCloseTo(7706 / 8726, 9);
201
+ });
202
+
203
+ test('immeuble mixte : installation individuelle 800 m², rdim 13, sur 2400 m² => besoin par unité', () => {
204
+ const di = calcImmeuble(
205
+ { enum_type_installation_id: '1', surface_habitable: 800, rdim: 13 },
206
+ 2400
207
+ );
208
+
209
+ expect(di.ratio_besoin_ecs).toBeCloseTo(800 / 2400 / 13, 9); // 0,02564
210
+ expect(di.ratio_besoin_ecs).toBeCloseTo(0.02564, 5);
211
+ });
212
+
213
+ test('rdim nul ou absent : diviseur 1', () => {
214
+ expect(
215
+ calcImmeuble({ surface_habitable: 50, rdim: 0, enum_type_installation_id: '2' }, 200)
216
+ .ratio_besoin_ecs
217
+ ).toBe(0.25);
218
+ expect(
219
+ calcImmeuble({ surface_habitable: '50', enum_type_installation_id: '2' }, '200')
220
+ .ratio_besoin_ecs
221
+ ).toBe(0.25);
222
+ });
223
+
224
+ test('besoin_ecs_depensier suit le même ratio que besoin_ecs', () => {
225
+ const di = calcImmeuble({ enum_type_installation_id: '2', surface_habitable: 20 }, 175);
226
+
227
+ expect(di.besoin_ecs_depensier).toBeCloseTo((1500 * 20) / 175, 9);
228
+ expect(di.besoin_ecs_depensier / di.besoin_ecs).toBeCloseTo(1.5, 9);
229
+ });
230
+
231
+ test('prioritaire sur la clé de répartition et la branche « tout individuel »', () => {
232
+ const di = calcImmeuble(
233
+ { enum_type_installation_id: '2', surface_habitable: 100, cle_repartition_ecs: 0.9 },
234
+ 200,
235
+ { virtualisation: true, individuels: true, nombreAppartements: 4 }
236
+ );
237
+
238
+ expect(di.ratio_besoin_ecs).toBe(0.5);
239
+ });
240
+
241
+ test('sans indicateur multi-ECS (valeur par défaut) : comportement historique conservé (1 / rdim)', () => {
242
+ const ecs = makeEcs({ tv_rendement_distribution_ecs_id: '5', surface_habitable: 100, rdim: 4 });
243
+ calc_ecs({}, ecs, 1000, 1500, 1, 'ca1', 'h1a', 'immeuble', false, 200, null, false, {});
244
+
245
+ expect(ecs.donnee_intermediaire.ratio_besoin_ecs).toBe(0.25);
246
+ });
247
+ });
248
+
151
249
  describe('calc_ecs - rendement de distribution', () => {
152
250
  test('la ligne forfaitaire alimente rendement_distribution et l’identifiant de table', () => {
153
251
  const de = { tv_rendement_distribution_ecs_id: '5' };
package/15_conso_aux.js CHANGED
@@ -41,7 +41,13 @@ export function conso_aux_gen(di, de, type, besoin, besoin_dep, Sh) {
41
41
  pe = 70000;
42
42
  }
43
43
 
44
- const Paux_g_ch = g + (h * (pe / 1000)) / (de.ratio_virtualisation || 1);
44
+ /**
45
+ * Installation collective virtualisée : Paux_g (W) est celle du générateur de l'immeuble
46
+ * (Pn = pe, puissance immeuble) et Caux_g = Paux_g × Bch_logement / Pn. Le terme G ne doit pas
47
+ * être proratisé par ratio_virtualisation (sinon G × ratio), comme le moteur CSTB (Tribu).
48
+ * @see : Methode_de_calcul_3CL_DPE_2021-338.pdf - §15.1
49
+ */
50
+ const Paux_g_ch = g + h * (pe / 1000);
45
51
 
46
52
  // Pour les installations collectives, la conso des auxiliaires est calculée à partir du besoin de l'appartement
47
53
  let besoinAppart = besoin * (de[`cle_repartition_${type}`] || 1);
@@ -55,10 +61,9 @@ export function conso_aux_gen(di, de, type, besoin, besoin_dep, Sh) {
55
61
  ratio = Sc / Sh;
56
62
  }
57
63
 
58
- di[`conso_auxiliaire_generation_${type}`] =
59
- ((de.ratio_virtualisation || 1) * (Paux_g_ch * besoinAppart * ratio)) / pe || 0;
64
+ di[`conso_auxiliaire_generation_${type}`] = (Paux_g_ch * besoinAppart * ratio) / pe || 0;
60
65
  di[`conso_auxiliaire_generation_${type}_depensier`] =
61
- (Paux_g_ch * besoinAppartDep * ratio) / di.pn || 0;
66
+ (Paux_g_ch * besoinAppartDep * ratio) / (di.pn / (de.ratio_virtualisation || 1)) || 0;
62
67
  }
63
68
 
64
69
  /**
@@ -131,6 +131,49 @@ describe('conso_aux_gen - auxiliaires de génération', () => {
131
131
  expect(diInconnu.conso_auxiliaire_generation_autre).toBe(0);
132
132
  expect(diInconnu.conso_auxiliaire_generation_autre_depensier).toBe(0);
133
133
  });
134
+
135
+ /**
136
+ * Installation collective virtualisée (appartement) : di.pn est la puissance ramenée au logement,
137
+ * pe = di.pn / ratio_virtualisation la puissance du générateur de l'immeuble.
138
+ * Caux_g = (G + H × Pn_immeuble) × Bch_logement / Pn_immeuble : G n'est pas proratisé.
139
+ * Cas des autotests CSTB APP5-0-1 (chaudière fioul collective, Tribu Qaux_ch = 15,9928 kWh).
140
+ */
141
+ test('installation virtualisée : Paux_g calculée sur le générateur immeuble, G non proratisé', () => {
142
+ const diVirt = { pn: 35000 };
143
+ conso_aux_gen(
144
+ diVirt,
145
+ { enum_type_generateur_ch_id: '78', ratio_virtualisation: 0.1 },
146
+ 'ch',
147
+ 1000,
148
+ 1200,
149
+ 100
150
+ );
151
+ // pe = 350 kW => Paux = 20 + 1,6 × 350 = 580 W ; conso = 580 × 1000 / 350000
152
+ expect(diVirt.conso_auxiliaire_generation_ch).toBeCloseTo(580 / 350, 10);
153
+ expect(diVirt.conso_auxiliaire_generation_ch_depensier).toBeCloseTo((580 * 1.2) / 350, 10);
154
+ });
155
+
156
+ test('installation virtualisée : identique au calcul non virtualisé du générateur immeuble', () => {
157
+ const diVirt = { pn: 2000 };
158
+ const diImmeuble = { pn: 20000 };
159
+ conso_aux_gen(
160
+ diVirt,
161
+ { enum_type_generateur_ecs_id: '50', ratio_virtualisation: 0.1 },
162
+ 'ecs',
163
+ 800,
164
+ 1000,
165
+ 100
166
+ );
167
+ conso_aux_gen(diImmeuble, { enum_type_generateur_ecs_id: '50' }, 'ecs', 800, 1000, 100);
168
+ expect(diVirt.conso_auxiliaire_generation_ecs).toBeCloseTo(
169
+ diImmeuble.conso_auxiliaire_generation_ecs,
170
+ 10
171
+ );
172
+ expect(diVirt.conso_auxiliaire_generation_ecs_depensier).toBeCloseTo(
173
+ diImmeuble.conso_auxiliaire_generation_ecs_depensier,
174
+ 10
175
+ );
176
+ });
134
177
  });
135
178
 
136
179
  /**
package/README.md CHANGED
@@ -370,22 +370,22 @@ 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.15`** · branche `main` · généré le 2026-10-02
373
+ > **Version `1.8.17`** · branche `main` · généré le 2026-10-02
374
374
  > Seuil de tolérance **5%**
375
375
 
376
376
  <table>
377
377
  <tr>
378
378
  <td align="center"><strong>9</strong><br/><sub>corpus</sub></td>
379
379
  <td align="center"><strong>89 990</strong><br/><sub>DPE analysés</sub></td>
380
- <td align="center"><strong>60 383</strong><br/><sub>DPE conformes</sub></td>
381
- <td align="center"><strong>67,10 %</strong><br/><sub>réussite globale</sub></td>
380
+ <td align="center"><strong>60 389</strong><br/><sub>DPE conformes</sub></td>
381
+ <td align="center"><strong>67,11 %</strong><br/><sub>réussite globale</sub></td>
382
382
  </tr>
383
383
  </table>
384
384
 
385
385
  | | Corpus | Réussite | | DPE conformes |
386
386
  | :-: | :---------------------------------------------------------------------------------------------------------------------- | ----------: | :--------------------- | -------------: |
387
387
  | 🔴 | **Généraliste**<br/><sub>`corpus_dpe.csv`</sub> | **46,54 %** | `█████████░░░░░░░░░░░` | 4 654 / 10 000 |
388
- | 🟢 | **Appartement · chauffage individuel (2025)**<br/><sub>`dpe_appartement_individuel_chauffage_individuel_2025.csv`</sub> | **92,46 %** | `██████████████████░░` | 9 246 / 10 000 |
388
+ | 🟢 | **Appartement · chauffage individuel (2025)**<br/><sub>`dpe_appartement_individuel_chauffage_individuel_2025.csv`</sub> | **92,52 %** | `███████████████████░` | 9 252 / 10 000 |
389
389
  | 🟢 | **Logement individuel (2025)**<br/><sub>`dpe_logement_individuel_2025.csv`</sub> | **89,46 %** | `██████████████████░░` | 8 939 / 9 992 |
390
390
  | 🟢 | **Maison individuelle (2025)**<br/><sub>`dpe_maison_individuelle_2025.csv`</sub> | **88,56 %** | `██████████████████░░` | 8 856 / 10 000 |
391
391
  | 🟡 | **Immeuble · chauffage individuel**<br/><sub>`dpe_immeuble_chauffage_individuel.csv`</sub> | **75,88 %** | `███████████████░░░░░` | 7 587 / 9 999 |
@@ -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,61 ms</strong><br/><sub>moyenne</sub></td>
407
- <td align="center"><strong>4,83 ms</strong><br/><sub>médiane</sub></td>
408
- <td align="center"><strong>0,13 ms</strong><br/><sub>min</sub></td>
409
- <td align="center"><strong>553,5 ms</strong><br/><sub>max</sub></td>
406
+ <td align="center"><strong>4,88 ms</strong><br/><sub>moyenne</sub></td>
407
+ <td align="center"><strong>4,24 ms</strong><br/><sub>médiane</sub></td>
408
+ <td align="center"><strong>0,12 ms</strong><br/><sub>min</sub></td>
409
+ <td align="center"><strong>799,7 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** | 5,81 ms | 4,80 ms | 0,23 ms | 65,1 ms | 12,7 ms | 21,9 ms |
416
- | **Appartement · chauffage individuel (2025)** | 4,53 ms | 4,10 ms | 1,55 ms | 34,9 ms | 7,91 ms | 11,3 ms |
417
- | **Logement individuel (2025)** | 5,04 ms | 4,40 ms | 1,65 ms | 44,6 ms | 9,54 ms | 13,2 ms |
418
- | **Maison individuelle (2025)** | 5,61 ms | 5,02 ms | 1,84 ms | 42,6 ms | 10,0 ms | 13,8 ms |
419
- | **Immeuble · chauffage individuel** | 6,64 ms | 5,59 ms | 0,13 ms | 124,6 ms | 13,4 ms | 21,2 ms |
420
- | **Appartement · chauffage collectif (2025)** | 5,10 ms | 4,85 ms | 1,58 ms | 39,5 ms | 8,31 ms | 11,3 ms |
421
- | **Immeuble · chauffage collectif** | 5,58 ms | 4,68 ms | 0,13 ms | 127,9 ms | 10,1 ms | 17,8 ms |
422
- | **Immeuble · chauffage mixte** | 6,34 ms | 5,01 ms | 0,18 ms | 553,5 ms | 14,1 ms | 25,2 ms |
423
- | **Individuel généré depuis l'immeuble (2026)** | 5,85 ms | 5,04 ms | 1,57 ms | 49,4 ms | 11,0 ms | 16,7 ms |
415
+ | **Généraliste** | 3,87 ms | 3,49 ms | 0,20 ms | 31,7 ms | 6,99 ms | 9,56 ms |
416
+ | **Appartement · chauffage individuel (2025)** | 3,54 ms | 3,23 ms | 1,45 ms | 29,3 ms | 6,14 ms | 7,86 ms |
417
+ | **Logement individuel (2025)** | 4,86 ms | 4,32 ms | 1,52 ms | 35,5 ms | 9,06 ms | 12,6 ms |
418
+ | **Maison individuelle (2025)** | 5,70 ms | 5,06 ms | 1,82 ms | 54,9 ms | 10,4 ms | 14,0 ms |
419
+ | **Immeuble · chauffage individuel** | 6,10 ms | 5,17 ms | 0,17 ms | 73,6 ms | 12,3 ms | 20,2 ms |
420
+ | **Appartement · chauffage collectif (2025)** | 3,87 ms | 3,50 ms | 1,46 ms | 35,8 ms | 6,37 ms | 8,52 ms |
421
+ | **Immeuble · chauffage collectif** | 5,29 ms | 4,44 ms | 0,12 ms | 89,5 ms | 9,69 ms | 17,0 ms |
422
+ | **Immeuble · chauffage mixte** | 5,20 ms | 4,26 ms | 0,19 ms | 799,7 ms | 10,6 ms | 17,6 ms |
423
+ | **Individuel généré depuis l'immeuble (2026)** | 5,53 ms | 4,72 ms | 1,58 ms | 45,9 ms | 10,6 ms | 15,8 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/engine.js CHANGED
@@ -33,7 +33,7 @@ import getFicheTechnique from './ficheTechnique.js';
33
33
  import { ProductionENR } from './16.2_production_enr.js';
34
34
  import DpeSanitizerService from './dpe-sanitizer.service.js';
35
35
 
36
- const LIB_VERSION = '1.8.16';
36
+ const LIB_VERSION = '1.8.18';
37
37
 
38
38
  const dpeSanitizerService = new DpeSanitizerService();
39
39
 
@@ -323,17 +323,37 @@ export function calcul_3cl(inputDpe, options) {
323
323
  let becs = apport_et_besoin.besoin_ecs;
324
324
  let becs_dep = apport_et_besoin.besoin_ecs_depensier;
325
325
  let isImmeubleSystemEcsIndividuels = false;
326
+ let isImmeubleMultiEcs = false;
326
327
 
327
328
  /**
328
329
  * 11.4 Plusieurs systèmes d’ECS (limité à 2 systèmes différents par logement)
329
330
  * Les besoins en ECS pour chaque générateur sont / 2
331
+ *
332
+ * Immeuble avec plusieurs installations ECS (collectives ou mixtes) : le besoin est réparti
333
+ * au prorata de la surface habitable desservie par chaque installation (Sh_ecs / Sh immeuble),
334
+ * sans normalisation ni plafonnement (cf. calc_ecs).
335
+ * @see Methode_de_calcul_3CL_DPE_2021-338.pdf - §11.4
336
+ * @see Guide Tribu TE-211208 p. 24 ; Moteur_DPE.dll Calcul_batiment.Calcul_Cecs()
330
337
  */
331
338
  if (ecs.length > 1) {
332
339
  // Immeuble avec différents systèmes individuels
333
340
  isImmeubleSystemEcsIndividuels =
334
341
  th === 'immeuble' && ecs.every((e) => e.donnee_entree.enum_type_installation_id === '1');
335
342
 
336
- if (!isImmeubleSystemEcsIndividuels) {
343
+ if (th === 'immeuble' && !isImmeubleSystemEcsIndividuels) {
344
+ isImmeubleMultiEcs =
345
+ Number(cg.surface_habitable_immeuble) > 0 &&
346
+ ecs.every((e) => Number(e.donnee_entree.surface_habitable) > 0);
347
+
348
+ if (!isImmeubleMultiEcs) {
349
+ console.warn(
350
+ `Immeuble avec plusieurs installations ECS : surface habitable de l'immeuble ou d'une installation ECS absente ou nulle.
351
+ Repli sur la division du besoin ECS par 2 (§11.4).`
352
+ );
353
+ }
354
+ }
355
+
356
+ if (!isImmeubleSystemEcsIndividuels && !isImmeubleMultiEcs) {
337
357
  becs /= 2;
338
358
  becs_dep /= 2;
339
359
  }
@@ -438,7 +458,8 @@ export function calcul_3cl(inputDpe, options) {
438
458
  dpe.logement.caracteristique_generale.surface_habitable_immeuble,
439
459
  dpe.logement.caracteristique_generale.nombre_appartement,
440
460
  isImmeubleSystemEcsIndividuels,
441
- apport_et_besoin.besoin_ecs_par_mois || {}
461
+ apport_et_besoin.besoin_ecs_par_mois || {},
462
+ isImmeubleMultiEcs
442
463
  );
443
464
 
444
465
  if (!dpeGenereImmeuble) {
package/engine.spec.js CHANGED
@@ -565,7 +565,7 @@ describe('calcul_3cl - surfaces immeuble / appartement et prorata', () => {
565
565
  expect(conso_aux_distribution_ecs.mock.calls[0][3]).toBe(200);
566
566
  });
567
567
 
568
- test('immeuble : systèmes ECS non tous individuels => besoin divisé par deux', () => {
568
+ test('immeuble : systèmes ECS non tous individuels sans surfaces => repli sur la division par deux', () => {
569
569
  enums.methode_application_dpe_log = { 1: 'dpe immeuble collectif' };
570
570
  const dpe = makeDpe();
571
571
  dpe.logement.installation_ecs_collection.installation_ecs = [
@@ -578,11 +578,86 @@ describe('calcul_3cl - surfaces immeuble / appartement et prorata', () => {
578
578
  generateur_ecs_collection: { generateur_ecs: [] }
579
579
  }
580
580
  ];
581
+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
581
582
 
582
583
  calcul_3cl(dpe, { sanitize: false });
583
584
 
584
585
  expect(calc_ecs.mock.calls[0][11]).toBe(false);
585
586
  expect(calc_ecs.mock.calls[0][2]).toBe(50); // 100 / 2
587
+ expect(calc_ecs.mock.calls[0][13]).toBe(false); // pas de prorata des surfaces
588
+ expect(warn).toHaveBeenCalledWith(expect.stringContaining('Repli sur la division'));
589
+ warn.mockRestore();
590
+ });
591
+
592
+ /**
593
+ * Immeuble à plusieurs installations ECS collectives ou mixtes : répartition au prorata des
594
+ * surfaces (cf. calc_ecs), sans division par 2.
595
+ * @see Methode_de_calcul_3CL_DPE_2021-338.pdf - §11.4
596
+ */
597
+ describe('immeuble à plusieurs installations ECS collectives ou mixtes (#232)', () => {
598
+ function makeImmeubleMultiEcs(surfaces, surfaceImmeuble = 200) {
599
+ enums.methode_application_dpe_log = { 1: 'dpe immeuble collectif' };
600
+ const dpe = makeDpe();
601
+ dpe.logement.caracteristique_generale.surface_habitable_immeuble = surfaceImmeuble;
602
+ dpe.logement.installation_ecs_collection.installation_ecs = surfaces.map((s, i) => ({
603
+ donnee_entree: { enum_type_installation_id: i === 0 ? '1' : '2', surface_habitable: s },
604
+ generateur_ecs_collection: { generateur_ecs: [] }
605
+ }));
606
+ return dpe;
607
+ }
608
+
609
+ test('surfaces renseignées : besoin non divisé et prorata des surfaces signalé à calc_ecs', () => {
610
+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
611
+ calcul_3cl(makeImmeubleMultiEcs([20, 155]), { sanitize: false });
612
+
613
+ expect(calc_ecs).toHaveBeenCalledTimes(2);
614
+ calc_ecs.mock.calls.forEach((call) => {
615
+ expect(call[2]).toBe(100); // besoin_ecs non divisé
616
+ expect(call[3]).toBe(120); // besoin_ecs_depensier non divisé
617
+ expect(call[11]).toBe(false);
618
+ expect(call[13]).toBe(true);
619
+ });
620
+ expect(warn).not.toHaveBeenCalled();
621
+ warn.mockRestore();
622
+ });
623
+
624
+ test.each([
625
+ ['une surface d’installation nulle', [0, 155], 200],
626
+ ['une surface d’installation absente', [undefined, 155], 200],
627
+ ['la surface de l’immeuble nulle', [20, 155], 0]
628
+ ])('%s : repli sur la division par deux avec avertissement', (_, surfaces, sh) => {
629
+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
630
+ calcul_3cl(makeImmeubleMultiEcs(surfaces, sh), { sanitize: false });
631
+
632
+ expect(calc_ecs.mock.calls[0][2]).toBe(50);
633
+ expect(calc_ecs.mock.calls[0][3]).toBe(60);
634
+ expect(calc_ecs.mock.calls[0][13]).toBe(false);
635
+ expect(warn).toHaveBeenCalledWith(expect.stringContaining('Repli sur la division'));
636
+ warn.mockRestore();
637
+ });
638
+
639
+ test('appartement avec deux installations renseignées : division par deux inchangée', () => {
640
+ const dpe = makeImmeubleMultiEcs([40, 40]);
641
+ enums.methode_application_dpe_log = { 1: 'dpe appartement individuel' };
642
+
643
+ calcul_3cl(dpe, { sanitize: false });
644
+
645
+ expect(calc_ecs.mock.calls[0][2]).toBe(50);
646
+ expect(calc_ecs.mock.calls[0][13]).toBe(false);
647
+ });
648
+
649
+ test('immeuble dont toutes les installations sont individuelles : branche existante inchangée', () => {
650
+ const dpe = makeImmeubleMultiEcs([100, 100]);
651
+ dpe.logement.installation_ecs_collection.installation_ecs.forEach(
652
+ (e) => (e.donnee_entree.enum_type_installation_id = '1')
653
+ );
654
+
655
+ calcul_3cl(dpe, { sanitize: false });
656
+
657
+ expect(calc_ecs.mock.calls[0][2]).toBe(100);
658
+ expect(calc_ecs.mock.calls[0][11]).toBe(true);
659
+ expect(calc_ecs.mock.calls[0][13]).toBe(false);
660
+ });
586
661
  });
587
662
 
588
663
  test('maison avec deux systèmes ECS => besoin divisé par deux', () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open3cl/engine",
3
- "version": "1.8.16",
3
+ "version": "1.8.18",
4
4
  "description": "Open Source 3CL-DPE engine",
5
5
  "main": "index.js",
6
6
  "directories": {