myio-js-library 0.1.40 → 0.1.41

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/dist/index.cjs CHANGED
@@ -6947,7 +6947,7 @@ var AllReportModal = class {
6947
6947
  return maybe || null;
6948
6948
  }
6949
6949
  // Helper: pick a numeric consumption from an API item
6950
- pickNumericConsumption(item) {
6950
+ pickConsumption(item) {
6951
6951
  const fields = ["total_value", "totalValue", "consumption", "value", "total", "energy", "kwh"];
6952
6952
  for (const f of fields) {
6953
6953
  if (item?.[f] !== void 0 && item?.[f] !== null) {
@@ -7431,37 +7431,54 @@ var AllReportModal = class {
7431
7431
  console.log("[AllReportModal] Customer totals response:", data);
7432
7432
  return data;
7433
7433
  }
7434
- // Replace this whole method
7435
7434
  mapCustomerTotalsResponse(apiResponse) {
7436
- const dataArray = Array.isArray(apiResponse?.data) ? apiResponse.data : Array.isArray(apiResponse) ? apiResponse : [];
7437
- if (!dataArray.length) {
7435
+ const apiArray = Array.isArray(apiResponse?.data) ? apiResponse.data : Array.isArray(apiResponse) ? apiResponse : [];
7436
+ if (!apiArray.length) {
7438
7437
  console.warn("[AllReportModal] Empty/invalid API response:", apiResponse);
7439
7438
  return [];
7440
7439
  }
7441
- const sumById = /* @__PURE__ */ new Map();
7442
- for (const it of dataArray) {
7443
- const key = String(it?.id || "");
7444
- if (!key) continue;
7445
- const val = this.parseConsumptionValue(it);
7446
- sumById.set(key, (sumById.get(key) || 0) + val);
7447
- }
7448
- let matched = 0;
7449
- const rows = this.params.itemsList.map((storeItem) => {
7450
- const c = sumById.get(storeItem.id) ?? 0;
7451
- if (c > 0) matched++;
7440
+ const sumByApiId = /* @__PURE__ */ new Map();
7441
+ let apiItemsWithoutId = 0;
7442
+ for (const item of apiArray) {
7443
+ const consumption = this.pickConsumption(item);
7444
+ if (item?.id) {
7445
+ const id = String(item.id);
7446
+ sumByApiId.set(id, (sumByApiId.get(id) || 0) + consumption);
7447
+ } else {
7448
+ apiItemsWithoutId++;
7449
+ }
7450
+ }
7451
+ let matchedById = 0, matchedBySubstring = 0;
7452
+ const rows = this.params.itemsList.map((listItem) => {
7453
+ let consumption = sumByApiId.get(listItem.id) ?? 0;
7454
+ if (consumption > 0) {
7455
+ matchedById++;
7456
+ } else {
7457
+ for (const apiItem of apiArray) {
7458
+ const assetName = apiItem?.assetName || "";
7459
+ const name = apiItem?.name || "";
7460
+ if (assetName.includes(listItem.identifier) || name.includes(listItem.identifier)) {
7461
+ consumption += this.pickConsumption(apiItem);
7462
+ }
7463
+ }
7464
+ if (consumption > 0) {
7465
+ matchedBySubstring++;
7466
+ }
7467
+ }
7452
7468
  return {
7453
- identifier: storeItem.identifier,
7454
- // keep original code shown in the table
7455
- name: storeItem.label,
7456
- // friendly name from itemsList
7457
- consumption: Math.round(c * 100) / 100
7469
+ identifier: listItem.identifier,
7470
+ name: listItem.label,
7471
+ consumption: Math.round(consumption * 100) / 100
7458
7472
  };
7459
7473
  });
7460
- console.log("[AllReportModal] Mapping by id stats:", {
7461
- apiItems: dataArray.length,
7462
- uniqueIdsInApi: sumById.size,
7474
+ console.log("[AllReportModal] Mapping stats:", {
7475
+ apiItems: apiArray.length,
7476
+ uniqueApiIds: sumByApiId.size,
7463
7477
  itemsInList: this.params.itemsList.length,
7464
- matched
7478
+ matchedById,
7479
+ matchedBySubstring,
7480
+ unmatched: this.params.itemsList.length - matchedById - matchedBySubstring,
7481
+ apiItemsWithoutId
7465
7482
  });
7466
7483
  return rows;
7467
7484
  }
package/dist/index.js CHANGED
@@ -6880,7 +6880,7 @@ var AllReportModal = class {
6880
6880
  return maybe || null;
6881
6881
  }
6882
6882
  // Helper: pick a numeric consumption from an API item
6883
- pickNumericConsumption(item) {
6883
+ pickConsumption(item) {
6884
6884
  const fields = ["total_value", "totalValue", "consumption", "value", "total", "energy", "kwh"];
6885
6885
  for (const f of fields) {
6886
6886
  if (item?.[f] !== void 0 && item?.[f] !== null) {
@@ -7364,37 +7364,54 @@ var AllReportModal = class {
7364
7364
  console.log("[AllReportModal] Customer totals response:", data);
7365
7365
  return data;
7366
7366
  }
7367
- // Replace this whole method
7368
7367
  mapCustomerTotalsResponse(apiResponse) {
7369
- const dataArray = Array.isArray(apiResponse?.data) ? apiResponse.data : Array.isArray(apiResponse) ? apiResponse : [];
7370
- if (!dataArray.length) {
7368
+ const apiArray = Array.isArray(apiResponse?.data) ? apiResponse.data : Array.isArray(apiResponse) ? apiResponse : [];
7369
+ if (!apiArray.length) {
7371
7370
  console.warn("[AllReportModal] Empty/invalid API response:", apiResponse);
7372
7371
  return [];
7373
7372
  }
7374
- const sumById = /* @__PURE__ */ new Map();
7375
- for (const it of dataArray) {
7376
- const key = String(it?.id || "");
7377
- if (!key) continue;
7378
- const val = this.parseConsumptionValue(it);
7379
- sumById.set(key, (sumById.get(key) || 0) + val);
7380
- }
7381
- let matched = 0;
7382
- const rows = this.params.itemsList.map((storeItem) => {
7383
- const c = sumById.get(storeItem.id) ?? 0;
7384
- if (c > 0) matched++;
7373
+ const sumByApiId = /* @__PURE__ */ new Map();
7374
+ let apiItemsWithoutId = 0;
7375
+ for (const item of apiArray) {
7376
+ const consumption = this.pickConsumption(item);
7377
+ if (item?.id) {
7378
+ const id = String(item.id);
7379
+ sumByApiId.set(id, (sumByApiId.get(id) || 0) + consumption);
7380
+ } else {
7381
+ apiItemsWithoutId++;
7382
+ }
7383
+ }
7384
+ let matchedById = 0, matchedBySubstring = 0;
7385
+ const rows = this.params.itemsList.map((listItem) => {
7386
+ let consumption = sumByApiId.get(listItem.id) ?? 0;
7387
+ if (consumption > 0) {
7388
+ matchedById++;
7389
+ } else {
7390
+ for (const apiItem of apiArray) {
7391
+ const assetName = apiItem?.assetName || "";
7392
+ const name = apiItem?.name || "";
7393
+ if (assetName.includes(listItem.identifier) || name.includes(listItem.identifier)) {
7394
+ consumption += this.pickConsumption(apiItem);
7395
+ }
7396
+ }
7397
+ if (consumption > 0) {
7398
+ matchedBySubstring++;
7399
+ }
7400
+ }
7385
7401
  return {
7386
- identifier: storeItem.identifier,
7387
- // keep original code shown in the table
7388
- name: storeItem.label,
7389
- // friendly name from itemsList
7390
- consumption: Math.round(c * 100) / 100
7402
+ identifier: listItem.identifier,
7403
+ name: listItem.label,
7404
+ consumption: Math.round(consumption * 100) / 100
7391
7405
  };
7392
7406
  });
7393
- console.log("[AllReportModal] Mapping by id stats:", {
7394
- apiItems: dataArray.length,
7395
- uniqueIdsInApi: sumById.size,
7407
+ console.log("[AllReportModal] Mapping stats:", {
7408
+ apiItems: apiArray.length,
7409
+ uniqueApiIds: sumByApiId.size,
7396
7410
  itemsInList: this.params.itemsList.length,
7397
- matched
7411
+ matchedById,
7412
+ matchedBySubstring,
7413
+ unmatched: this.params.itemsList.length - matchedById - matchedBySubstring,
7414
+ apiItemsWithoutId
7398
7415
  });
7399
7416
  return rows;
7400
7417
  }
@@ -6869,7 +6869,7 @@
6869
6869
  return maybe || null;
6870
6870
  }
6871
6871
  // Helper: pick a numeric consumption from an API item
6872
- pickNumericConsumption(item) {
6872
+ pickConsumption(item) {
6873
6873
  const fields = ["total_value", "totalValue", "consumption", "value", "total", "energy", "kwh"];
6874
6874
  for (const f of fields) {
6875
6875
  if (item?.[f] !== void 0 && item?.[f] !== null) {
@@ -7353,37 +7353,54 @@
7353
7353
  console.log("[AllReportModal] Customer totals response:", data);
7354
7354
  return data;
7355
7355
  }
7356
- // Replace this whole method
7357
7356
  mapCustomerTotalsResponse(apiResponse) {
7358
- const dataArray = Array.isArray(apiResponse?.data) ? apiResponse.data : Array.isArray(apiResponse) ? apiResponse : [];
7359
- if (!dataArray.length) {
7357
+ const apiArray = Array.isArray(apiResponse?.data) ? apiResponse.data : Array.isArray(apiResponse) ? apiResponse : [];
7358
+ if (!apiArray.length) {
7360
7359
  console.warn("[AllReportModal] Empty/invalid API response:", apiResponse);
7361
7360
  return [];
7362
7361
  }
7363
- const sumById = /* @__PURE__ */ new Map();
7364
- for (const it of dataArray) {
7365
- const key = String(it?.id || "");
7366
- if (!key) continue;
7367
- const val = this.parseConsumptionValue(it);
7368
- sumById.set(key, (sumById.get(key) || 0) + val);
7369
- }
7370
- let matched = 0;
7371
- const rows = this.params.itemsList.map((storeItem) => {
7372
- const c = sumById.get(storeItem.id) ?? 0;
7373
- if (c > 0) matched++;
7362
+ const sumByApiId = /* @__PURE__ */ new Map();
7363
+ let apiItemsWithoutId = 0;
7364
+ for (const item of apiArray) {
7365
+ const consumption = this.pickConsumption(item);
7366
+ if (item?.id) {
7367
+ const id = String(item.id);
7368
+ sumByApiId.set(id, (sumByApiId.get(id) || 0) + consumption);
7369
+ } else {
7370
+ apiItemsWithoutId++;
7371
+ }
7372
+ }
7373
+ let matchedById = 0, matchedBySubstring = 0;
7374
+ const rows = this.params.itemsList.map((listItem) => {
7375
+ let consumption = sumByApiId.get(listItem.id) ?? 0;
7376
+ if (consumption > 0) {
7377
+ matchedById++;
7378
+ } else {
7379
+ for (const apiItem of apiArray) {
7380
+ const assetName = apiItem?.assetName || "";
7381
+ const name = apiItem?.name || "";
7382
+ if (assetName.includes(listItem.identifier) || name.includes(listItem.identifier)) {
7383
+ consumption += this.pickConsumption(apiItem);
7384
+ }
7385
+ }
7386
+ if (consumption > 0) {
7387
+ matchedBySubstring++;
7388
+ }
7389
+ }
7374
7390
  return {
7375
- identifier: storeItem.identifier,
7376
- // keep original code shown in the table
7377
- name: storeItem.label,
7378
- // friendly name from itemsList
7379
- consumption: Math.round(c * 100) / 100
7391
+ identifier: listItem.identifier,
7392
+ name: listItem.label,
7393
+ consumption: Math.round(consumption * 100) / 100
7380
7394
  };
7381
7395
  });
7382
- console.log("[AllReportModal] Mapping by id stats:", {
7383
- apiItems: dataArray.length,
7384
- uniqueIdsInApi: sumById.size,
7396
+ console.log("[AllReportModal] Mapping stats:", {
7397
+ apiItems: apiArray.length,
7398
+ uniqueApiIds: sumByApiId.size,
7385
7399
  itemsInList: this.params.itemsList.length,
7386
- matched
7400
+ matchedById,
7401
+ matchedBySubstring,
7402
+ unmatched: this.params.itemsList.length - matchedById - matchedBySubstring,
7403
+ apiItemsWithoutId
7387
7404
  });
7388
7405
  return rows;
7389
7406
  }