@open3cl/engine 1.0.3 → 1.0.5

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/4_ventilation.js CHANGED
@@ -1,4 +1,3 @@
1
- import enums from './enums.js';
2
1
  import { tv, requestInputID, requestInput, bug_for_bug_compat } from './utils.js';
3
2
  import calc_pvent from './5_conso_ventilation.js';
4
3
 
@@ -21,15 +20,31 @@ function tv_debits_ventilation(di, de, du) {
21
20
  function tv_q4pa_conv(di, de, cg, mur_list, ph_list, porte_list, bv_list) {
22
21
  const surfaces = mur_list.concat(ph_list);
23
22
  const surface_isolee = surfaces.reduce((acc, s) => {
24
- const type_isolation = enums.type_isolation[s.donnee_entree.enum_type_isolation_id];
25
23
  if (s.donnee_intermediaire.b === 0) return acc;
26
- if (['non isolé', 'inconnu'].includes(type_isolation)) return acc;
24
+
25
+ const typeIsolation = parseInt(s.donnee_entree.enum_type_isolation_id);
26
+
27
+ // Si le type isolation est inconnu mais avec que la période d'isolation est connue et > 1974 alors on considère la surface isolée
28
+ if (typeIsolation === 1 && parseInt(s.donnee_entree.enum_periode_isolation_id) >= 3) {
29
+ return acc + s.donnee_entree.surface_paroi_opaque;
30
+ }
31
+
32
+ // Si type d'isolation "1 - inconnu" ou "2 - non isolé"
33
+ if ([1, 2].includes(typeIsolation)) return acc;
27
34
  else return acc + s.donnee_entree.surface_paroi_opaque;
28
35
  }, 0);
29
36
  const surface_non_isolee = surfaces.reduce((acc, s) => {
30
- const type_isolation = enums.type_isolation[s.donnee_entree.enum_type_isolation_id];
31
37
  if (s.donnee_intermediaire.b === 0) return acc;
32
- if (['non isolé', 'inconnu'].includes(type_isolation)) {
38
+
39
+ const typeIsolation = parseInt(s.donnee_entree.enum_type_isolation_id);
40
+
41
+ // Si le type isolation est inconnu mais avec que la période d'isolation est connue et > 1974 alors on considère la surface isolée
42
+ if (typeIsolation === 1 && parseInt(s.donnee_entree.enum_periode_isolation_id) >= 3) {
43
+ return acc;
44
+ }
45
+
46
+ // Si type d'isolation "1 - inconnu" ou "2 - non isolé"
47
+ if ([1, 2].includes(typeIsolation)) {
33
48
  return acc + s.donnee_entree.surface_paroi_opaque;
34
49
  } else return acc;
35
50
  }, 0);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open3cl/engine",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Open Source 3CL-DPE engine",
5
5
  "main": "index.js",
6
6
  "directories": {
package/utils.js CHANGED
@@ -7,6 +7,11 @@ export function set_bug_for_bug_compat() {
7
7
  bug_for_bug_compat = true;
8
8
  }
9
9
 
10
+ export let use_enum_as_string = false;
11
+ export function set_use_enum_as_string() {
12
+ use_enum_as_string = true;
13
+ }
14
+
10
15
  export let tv_match_new_version = false;
11
16
  export function set_tv_match_optimized_version() {
12
17
  tv_match_new_version = true;
@@ -279,6 +284,22 @@ export function removeKeyFromJSON(jsonObj, keyToRemove, skipKeys) {
279
284
  }
280
285
  }
281
286
 
287
+ export function useEnumAsString(jsonObj) {
288
+ for (const key in jsonObj) {
289
+ if (jsonObj.hasOwnProperty(key)) {
290
+ if (key === 'donnee_entree') {
291
+ for (const kde in jsonObj[key]) {
292
+ if (kde.startsWith('enum_')) {
293
+ jsonObj[key][kde] = jsonObj[key][kde].toString();
294
+ }
295
+ }
296
+ } else if (typeof jsonObj[key] === 'object') {
297
+ useEnumAsString(jsonObj[key]);
298
+ }
299
+ }
300
+ }
301
+ }
302
+
282
303
  export function clean_dpe(dpe_in) {
283
304
  // skip generateur_[ecs|chauffage] because some input data is contained in donnee_intermediaire (e.g. pn, qp0, ...)
284
305
  removeKeyFromJSON(dpe_in, 'donnee_intermediaire', ['generateur_ecs', 'generateur_chauffage']);
@@ -300,6 +321,9 @@ export function sanitize_dpe(dpe_in) {
300
321
  _.set(dpe_in, path, []);
301
322
  }
302
323
  }
324
+ if (use_enum_as_string) {
325
+ useEnumAsString(dpe_in);
326
+ }
303
327
  }
304
328
 
305
329
  /**