myio-js-library 0.1.584 → 0.1.586
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 +68 -55
- package/dist/index.js +68 -55
- package/dist/myio-js-library.umd.js +68 -55
- package/dist/myio-js-library.umd.min.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -989,7 +989,7 @@ module.exports = __toCommonJS(src_exports);
|
|
|
989
989
|
// package.json
|
|
990
990
|
var package_default = {
|
|
991
991
|
name: "myio-js-library",
|
|
992
|
-
version: "0.1.
|
|
992
|
+
version: "0.1.586",
|
|
993
993
|
description: "A clean, standalone JS SDK for MYIO projects",
|
|
994
994
|
license: "MIT",
|
|
995
995
|
repository: "github:gh-myio/myio-js-library",
|
|
@@ -29328,6 +29328,7 @@ function createDateRangePicker($2, input, opts) {
|
|
|
29328
29328
|
} else {
|
|
29329
29329
|
ranges = {
|
|
29330
29330
|
"Hoje": [moment().startOf("day"), moment().endOf("day")],
|
|
29331
|
+
"Ontem": [moment().subtract(1, "day").startOf("day"), moment().subtract(1, "day").endOf("day")],
|
|
29331
29332
|
"\xDAltimos 7 dias": [moment().subtract(6, "days").startOf("day"), moment().endOf("day")],
|
|
29332
29333
|
"\xDAltimos 15 dias": [moment().subtract(14, "days").startOf("day"), moment().endOf("day")],
|
|
29333
29334
|
"\xDAltimos 30 dias": [moment().subtract(29, "days").startOf("day"), moment().endOf("day")],
|
|
@@ -29465,6 +29466,42 @@ var TELEMETRY_CONFIG = {
|
|
|
29465
29466
|
// Temperature
|
|
29466
29467
|
temperature: { label: "Temperatura", unit: "\xB0C", icon: "\u{1F321}\uFE0F", decimals: 1 }
|
|
29467
29468
|
};
|
|
29469
|
+
var CURRENT_KEYS_MA = /* @__PURE__ */ new Set(["total_current", "current", "current_a", "current_b", "current_c"]);
|
|
29470
|
+
var POWER_FACTOR_KEYS_255 = /* @__PURE__ */ new Set(["fp_a", "fp_b", "fp_c", "powerFactor"]);
|
|
29471
|
+
function normalizeTelemetryValue(key, raw) {
|
|
29472
|
+
const v = Number(raw) || 0;
|
|
29473
|
+
if (CURRENT_KEYS_MA.has(key)) return v / 1e3;
|
|
29474
|
+
if (POWER_FACTOR_KEYS_255.has(key)) return v / 255;
|
|
29475
|
+
return v;
|
|
29476
|
+
}
|
|
29477
|
+
function scaleWatts(value, decimals) {
|
|
29478
|
+
const abs = Math.abs(value);
|
|
29479
|
+
if (abs >= 1e6) return `${(value / 1e6).toFixed(decimals)} MW`;
|
|
29480
|
+
if (abs >= 1e3) return `${(value / 1e3).toFixed(decimals)} kW`;
|
|
29481
|
+
return `${value.toFixed(0)} W`;
|
|
29482
|
+
}
|
|
29483
|
+
function formatTelemetryValue(key, value) {
|
|
29484
|
+
const config2 = TELEMETRY_CONFIG[key];
|
|
29485
|
+
if (!config2) return value.toFixed(2);
|
|
29486
|
+
if (config2.unit === "W") return scaleWatts(value, 2);
|
|
29487
|
+
return `${value.toFixed(config2.decimals)} ${config2.unit}`;
|
|
29488
|
+
}
|
|
29489
|
+
function formatAxisTick(unit, value) {
|
|
29490
|
+
if (unit === "W") {
|
|
29491
|
+
const n = Number(value);
|
|
29492
|
+
if (Math.abs(n) >= 1e3) return scaleWatts(n, 1);
|
|
29493
|
+
return `${value} W`;
|
|
29494
|
+
}
|
|
29495
|
+
return `${value}${unit ? " " + unit : ""}`;
|
|
29496
|
+
}
|
|
29497
|
+
function formatPeakValue(key, value) {
|
|
29498
|
+
const cfg = TELEMETRY_CONFIG[key] || { label: key, unit: "", icon: "", decimals: 2 };
|
|
29499
|
+
if (cfg.unit === "W") return formatPower(value, 3);
|
|
29500
|
+
return `${value.toLocaleString("pt-BR", {
|
|
29501
|
+
minimumFractionDigits: cfg.decimals ?? 2,
|
|
29502
|
+
maximumFractionDigits: cfg.decimals ?? 2
|
|
29503
|
+
})} ${cfg.unit}`;
|
|
29504
|
+
}
|
|
29468
29505
|
var PHASE_SHORT_LABEL = {
|
|
29469
29506
|
consumption: "Total",
|
|
29470
29507
|
power: "Total",
|
|
@@ -31638,11 +31675,7 @@ async function openRealTimeTelemetryModal(params) {
|
|
|
31638
31675
|
});
|
|
31639
31676
|
}
|
|
31640
31677
|
function normalizeRealtimeValue(key, raw) {
|
|
31641
|
-
|
|
31642
|
-
return raw / 1e3;
|
|
31643
|
-
}
|
|
31644
|
-
if (key === "fp_a" || key === "fp_b" || key === "fp_c" || key === "powerFactor") return raw / 255;
|
|
31645
|
-
return raw;
|
|
31678
|
+
return normalizeTelemetryValue(key, raw);
|
|
31646
31679
|
}
|
|
31647
31680
|
function fillAggregatedGaps(returned, startTs, endTs, intervalMs, seedY) {
|
|
31648
31681
|
const byBucket = /* @__PURE__ */ new Map();
|
|
@@ -31795,13 +31828,7 @@ async function openRealTimeTelemetryModal(params) {
|
|
|
31795
31828
|
const data = await fetchPeriodTelemetry(periodStartISO, periodEndISO);
|
|
31796
31829
|
periodHistory.clear();
|
|
31797
31830
|
periodLastKnown.clear();
|
|
31798
|
-
const toPeriodY = (key, raw) =>
|
|
31799
|
-
let y = raw ?? 0;
|
|
31800
|
-
if (key === "total_current" || key === "current") y = y / 1e3;
|
|
31801
|
-
if (key === "fp_a" || key === "fp_b" || key === "fp_c" || key === "powerFactor") y = y / 255;
|
|
31802
|
-
if (POWER_KEYS.has(key)) y = y / 1e3;
|
|
31803
|
-
return y;
|
|
31804
|
-
};
|
|
31831
|
+
const toPeriodY = (key, raw) => normalizeTelemetryValue(key, raw);
|
|
31805
31832
|
const fillGaps = selectedAgg !== "NONE";
|
|
31806
31833
|
const periodStartTs = new Date(periodStartISO).getTime();
|
|
31807
31834
|
const periodEndTs = new Date(periodEndISO).getTime();
|
|
@@ -31851,10 +31878,7 @@ async function openRealTimeTelemetryModal(params) {
|
|
|
31851
31878
|
minute: "2-digit"
|
|
31852
31879
|
}
|
|
31853
31880
|
) : "";
|
|
31854
|
-
const formattedValue =
|
|
31855
|
-
minimumFractionDigits: cfg.decimals ?? 2,
|
|
31856
|
-
maximumFractionDigits: cfg.decimals ?? 2
|
|
31857
|
-
})} ${cfg.unit}`;
|
|
31881
|
+
const formattedValue = formatPeakValue(peakKey, peakPoint.y);
|
|
31858
31882
|
peakSummaryEl.textContent = `M\xE1xima: ${formattedValue} (${cfg.label}) em ${when}`;
|
|
31859
31883
|
peakSummaryEl.style.display = "block";
|
|
31860
31884
|
} else {
|
|
@@ -31879,13 +31903,7 @@ async function openRealTimeTelemetryModal(params) {
|
|
|
31879
31903
|
if (!telemetryData || telemetryData.length === 0) continue;
|
|
31880
31904
|
const latest = telemetryData[0];
|
|
31881
31905
|
const config2 = TELEMETRY_CONFIG[key] || { label: key, unit: "", icon: "\u{1F4CA}", decimals: 2 };
|
|
31882
|
-
|
|
31883
|
-
if (key === "total_current" || key === "current" || key === "current_a" || key === "current_b" || key === "current_c") {
|
|
31884
|
-
numValue = numValue / 1e3;
|
|
31885
|
-
}
|
|
31886
|
-
if (key === "fp_a" || key === "fp_b" || key === "fp_c" || key === "powerFactor") {
|
|
31887
|
-
numValue = numValue / 255;
|
|
31888
|
-
}
|
|
31906
|
+
const numValue = normalizeTelemetryValue(key, latest.value);
|
|
31889
31907
|
const formattedNum = numValue.toFixed(config2.decimals);
|
|
31890
31908
|
const displayUnit = config2.unit === "fp" ? "" : config2.unit;
|
|
31891
31909
|
const formatted = displayUnit ? `${formattedNum} ${displayUnit}` : formattedNum;
|
|
@@ -32116,15 +32134,7 @@ async function openRealTimeTelemetryModal(params) {
|
|
|
32116
32134
|
}
|
|
32117
32135
|
}
|
|
32118
32136
|
function getFormattedValue(key, value) {
|
|
32119
|
-
|
|
32120
|
-
if (!config2) return value.toFixed(2);
|
|
32121
|
-
if (key === "consumption" || key === "power") {
|
|
32122
|
-
if (value >= 1e3) {
|
|
32123
|
-
return `${(value / 1e3).toFixed(2)} kW`;
|
|
32124
|
-
}
|
|
32125
|
-
return `${value.toFixed(0)} W`;
|
|
32126
|
-
}
|
|
32127
|
-
return `${value.toFixed(config2.decimals)} ${config2.unit}`;
|
|
32137
|
+
return formatTelemetryValue(key, value);
|
|
32128
32138
|
}
|
|
32129
32139
|
function hexRgba(hex, alpha) {
|
|
32130
32140
|
const r = parseInt(hex.slice(1, 3), 16);
|
|
@@ -32154,11 +32164,7 @@ async function openRealTimeTelemetryModal(params) {
|
|
|
32154
32164
|
const rightAxisColor = rightAxisKey ? KEY_COLORS[rightAxisKey] || "#555" : "#555";
|
|
32155
32165
|
function makeTickCallback(unit) {
|
|
32156
32166
|
return function(value) {
|
|
32157
|
-
|
|
32158
|
-
if (value >= 1e3) return `${(value / 1e3).toFixed(1)} kW`;
|
|
32159
|
-
return `${value} W`;
|
|
32160
|
-
}
|
|
32161
|
-
return `${value}${unit ? " " + unit : ""}`;
|
|
32167
|
+
return formatAxisTick(unit, value);
|
|
32162
32168
|
};
|
|
32163
32169
|
}
|
|
32164
32170
|
const datasets = selectedChartKeys.map((key) => {
|
|
@@ -63617,6 +63623,7 @@ var DeviceProfileTab = class {
|
|
|
63617
63623
|
const slaveIdNum = typeof slaveId === "string" ? parseInt(slaveId, 10) : slaveId;
|
|
63618
63624
|
let page = 1;
|
|
63619
63625
|
let match = null;
|
|
63626
|
+
let fallback = null;
|
|
63620
63627
|
for (; page <= 50 && !match; page++) {
|
|
63621
63628
|
const res = await fetch(
|
|
63622
63629
|
`${INGESTION_API_BASE2}/management/devices?page=${page}&limit=100&customerId=${encodeURIComponent(
|
|
@@ -63628,15 +63635,18 @@ var DeviceProfileTab = class {
|
|
|
63628
63635
|
const json = await res.json();
|
|
63629
63636
|
const list = json?.data || [];
|
|
63630
63637
|
for (const d of list) {
|
|
63631
|
-
|
|
63632
|
-
if (
|
|
63638
|
+
if (d.slaveId !== slaveIdNum) continue;
|
|
63639
|
+
if (d.gateway?.hardwareUuid === centralId) {
|
|
63633
63640
|
match = { id: d.id };
|
|
63634
63641
|
break;
|
|
63635
63642
|
}
|
|
63643
|
+
if (!fallback && (d.gatewayId === centralId || d.gateway?.id === centralId)) fallback = { id: d.id };
|
|
63636
63644
|
}
|
|
63645
|
+
if (match) break;
|
|
63637
63646
|
const totalPages = json?.pagination?.pages || 1;
|
|
63638
63647
|
if (page >= totalPages) break;
|
|
63639
63648
|
}
|
|
63649
|
+
if (!match && fallback) match = fallback;
|
|
63640
63650
|
if (!match) {
|
|
63641
63651
|
return { ok: false, message: `Nenhum device na Ingestion API com centralId=${centralId} e slaveId=${slaveIdNum}.` };
|
|
63642
63652
|
}
|
|
@@ -111480,27 +111490,30 @@ async function fetchIngestionDevicesAllPaged(customerId) {
|
|
|
111480
111490
|
}
|
|
111481
111491
|
function findIngestionDeviceByCentralSlaveId(devices, centralId, slaveId) {
|
|
111482
111492
|
const slaveIdNum = typeof slaveId === "string" ? parseInt(slaveId, 10) : slaveId;
|
|
111483
|
-
|
|
111484
|
-
|
|
111485
|
-
|
|
111486
|
-
|
|
111487
|
-
|
|
111488
|
-
|
|
111489
|
-
|
|
111490
|
-
|
|
111491
|
-
|
|
111492
|
-
|
|
111493
|
-
|
|
111494
|
-
|
|
111495
|
-
|
|
111493
|
+
const bySlave = devices.filter((d) => d.slaveId === slaveIdNum);
|
|
111494
|
+
const match = bySlave.find((d) => d.gateway?.hardwareUuid === centralId) || bySlave.find((d) => d.gatewayId === centralId || d.gateway?.id === centralId);
|
|
111495
|
+
if (match) {
|
|
111496
|
+
console.log(
|
|
111497
|
+
"[UpsellModal] Found matching device:",
|
|
111498
|
+
match.name,
|
|
111499
|
+
"via:",
|
|
111500
|
+
match.gateway?.hardwareUuid === centralId ? "hardwareUuid" : "gatewayId",
|
|
111501
|
+
"centralId:",
|
|
111502
|
+
centralId,
|
|
111503
|
+
"slaveId:",
|
|
111504
|
+
match.slaveId
|
|
111505
|
+
);
|
|
111506
|
+
return match;
|
|
111496
111507
|
}
|
|
111497
111508
|
console.log("[UpsellModal] No match found. Looking for centralId:", centralId, "slaveId:", slaveIdNum);
|
|
111498
111509
|
devices.slice(0, 3).forEach((d, i) => {
|
|
111499
111510
|
console.log(
|
|
111500
111511
|
`[UpsellModal] Sample device ${i}:`,
|
|
111501
111512
|
d.name,
|
|
111502
|
-
"gateway
|
|
111503
|
-
d.gateway?.hardwareUuid
|
|
111513
|
+
"gateway hwUuid / id:",
|
|
111514
|
+
d.gateway?.hardwareUuid,
|
|
111515
|
+
"/",
|
|
111516
|
+
d.gatewayId || d.gateway?.id,
|
|
111504
111517
|
"slaveId:",
|
|
111505
111518
|
d.slaveId
|
|
111506
111519
|
);
|
package/dist/index.js
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
// package.json
|
|
11
11
|
var package_default = {
|
|
12
12
|
name: "myio-js-library",
|
|
13
|
-
version: "0.1.
|
|
13
|
+
version: "0.1.586",
|
|
14
14
|
description: "A clean, standalone JS SDK for MYIO projects",
|
|
15
15
|
license: "MIT",
|
|
16
16
|
repository: "github:gh-myio/myio-js-library",
|
|
@@ -27624,6 +27624,7 @@ function createDateRangePicker($2, input, opts) {
|
|
|
27624
27624
|
} else {
|
|
27625
27625
|
ranges = {
|
|
27626
27626
|
"Hoje": [moment().startOf("day"), moment().endOf("day")],
|
|
27627
|
+
"Ontem": [moment().subtract(1, "day").startOf("day"), moment().subtract(1, "day").endOf("day")],
|
|
27627
27628
|
"\xDAltimos 7 dias": [moment().subtract(6, "days").startOf("day"), moment().endOf("day")],
|
|
27628
27629
|
"\xDAltimos 15 dias": [moment().subtract(14, "days").startOf("day"), moment().endOf("day")],
|
|
27629
27630
|
"\xDAltimos 30 dias": [moment().subtract(29, "days").startOf("day"), moment().endOf("day")],
|
|
@@ -27761,6 +27762,42 @@ var TELEMETRY_CONFIG = {
|
|
|
27761
27762
|
// Temperature
|
|
27762
27763
|
temperature: { label: "Temperatura", unit: "\xB0C", icon: "\u{1F321}\uFE0F", decimals: 1 }
|
|
27763
27764
|
};
|
|
27765
|
+
var CURRENT_KEYS_MA = /* @__PURE__ */ new Set(["total_current", "current", "current_a", "current_b", "current_c"]);
|
|
27766
|
+
var POWER_FACTOR_KEYS_255 = /* @__PURE__ */ new Set(["fp_a", "fp_b", "fp_c", "powerFactor"]);
|
|
27767
|
+
function normalizeTelemetryValue(key, raw) {
|
|
27768
|
+
const v = Number(raw) || 0;
|
|
27769
|
+
if (CURRENT_KEYS_MA.has(key)) return v / 1e3;
|
|
27770
|
+
if (POWER_FACTOR_KEYS_255.has(key)) return v / 255;
|
|
27771
|
+
return v;
|
|
27772
|
+
}
|
|
27773
|
+
function scaleWatts(value, decimals) {
|
|
27774
|
+
const abs = Math.abs(value);
|
|
27775
|
+
if (abs >= 1e6) return `${(value / 1e6).toFixed(decimals)} MW`;
|
|
27776
|
+
if (abs >= 1e3) return `${(value / 1e3).toFixed(decimals)} kW`;
|
|
27777
|
+
return `${value.toFixed(0)} W`;
|
|
27778
|
+
}
|
|
27779
|
+
function formatTelemetryValue(key, value) {
|
|
27780
|
+
const config = TELEMETRY_CONFIG[key];
|
|
27781
|
+
if (!config) return value.toFixed(2);
|
|
27782
|
+
if (config.unit === "W") return scaleWatts(value, 2);
|
|
27783
|
+
return `${value.toFixed(config.decimals)} ${config.unit}`;
|
|
27784
|
+
}
|
|
27785
|
+
function formatAxisTick(unit, value) {
|
|
27786
|
+
if (unit === "W") {
|
|
27787
|
+
const n = Number(value);
|
|
27788
|
+
if (Math.abs(n) >= 1e3) return scaleWatts(n, 1);
|
|
27789
|
+
return `${value} W`;
|
|
27790
|
+
}
|
|
27791
|
+
return `${value}${unit ? " " + unit : ""}`;
|
|
27792
|
+
}
|
|
27793
|
+
function formatPeakValue(key, value) {
|
|
27794
|
+
const cfg = TELEMETRY_CONFIG[key] || { label: key, unit: "", icon: "", decimals: 2 };
|
|
27795
|
+
if (cfg.unit === "W") return formatPower(value, 3);
|
|
27796
|
+
return `${value.toLocaleString("pt-BR", {
|
|
27797
|
+
minimumFractionDigits: cfg.decimals ?? 2,
|
|
27798
|
+
maximumFractionDigits: cfg.decimals ?? 2
|
|
27799
|
+
})} ${cfg.unit}`;
|
|
27800
|
+
}
|
|
27764
27801
|
var PHASE_SHORT_LABEL = {
|
|
27765
27802
|
consumption: "Total",
|
|
27766
27803
|
power: "Total",
|
|
@@ -29934,11 +29971,7 @@ async function openRealTimeTelemetryModal(params) {
|
|
|
29934
29971
|
});
|
|
29935
29972
|
}
|
|
29936
29973
|
function normalizeRealtimeValue(key, raw) {
|
|
29937
|
-
|
|
29938
|
-
return raw / 1e3;
|
|
29939
|
-
}
|
|
29940
|
-
if (key === "fp_a" || key === "fp_b" || key === "fp_c" || key === "powerFactor") return raw / 255;
|
|
29941
|
-
return raw;
|
|
29974
|
+
return normalizeTelemetryValue(key, raw);
|
|
29942
29975
|
}
|
|
29943
29976
|
function fillAggregatedGaps(returned, startTs, endTs, intervalMs, seedY) {
|
|
29944
29977
|
const byBucket = /* @__PURE__ */ new Map();
|
|
@@ -30091,13 +30124,7 @@ async function openRealTimeTelemetryModal(params) {
|
|
|
30091
30124
|
const data = await fetchPeriodTelemetry(periodStartISO, periodEndISO);
|
|
30092
30125
|
periodHistory.clear();
|
|
30093
30126
|
periodLastKnown.clear();
|
|
30094
|
-
const toPeriodY = (key, raw) =>
|
|
30095
|
-
let y = raw ?? 0;
|
|
30096
|
-
if (key === "total_current" || key === "current") y = y / 1e3;
|
|
30097
|
-
if (key === "fp_a" || key === "fp_b" || key === "fp_c" || key === "powerFactor") y = y / 255;
|
|
30098
|
-
if (POWER_KEYS.has(key)) y = y / 1e3;
|
|
30099
|
-
return y;
|
|
30100
|
-
};
|
|
30127
|
+
const toPeriodY = (key, raw) => normalizeTelemetryValue(key, raw);
|
|
30101
30128
|
const fillGaps = selectedAgg !== "NONE";
|
|
30102
30129
|
const periodStartTs = new Date(periodStartISO).getTime();
|
|
30103
30130
|
const periodEndTs = new Date(periodEndISO).getTime();
|
|
@@ -30147,10 +30174,7 @@ async function openRealTimeTelemetryModal(params) {
|
|
|
30147
30174
|
minute: "2-digit"
|
|
30148
30175
|
}
|
|
30149
30176
|
) : "";
|
|
30150
|
-
const formattedValue =
|
|
30151
|
-
minimumFractionDigits: cfg.decimals ?? 2,
|
|
30152
|
-
maximumFractionDigits: cfg.decimals ?? 2
|
|
30153
|
-
})} ${cfg.unit}`;
|
|
30177
|
+
const formattedValue = formatPeakValue(peakKey, peakPoint.y);
|
|
30154
30178
|
peakSummaryEl.textContent = `M\xE1xima: ${formattedValue} (${cfg.label}) em ${when}`;
|
|
30155
30179
|
peakSummaryEl.style.display = "block";
|
|
30156
30180
|
} else {
|
|
@@ -30175,13 +30199,7 @@ async function openRealTimeTelemetryModal(params) {
|
|
|
30175
30199
|
if (!telemetryData || telemetryData.length === 0) continue;
|
|
30176
30200
|
const latest = telemetryData[0];
|
|
30177
30201
|
const config = TELEMETRY_CONFIG[key] || { label: key, unit: "", icon: "\u{1F4CA}", decimals: 2 };
|
|
30178
|
-
|
|
30179
|
-
if (key === "total_current" || key === "current" || key === "current_a" || key === "current_b" || key === "current_c") {
|
|
30180
|
-
numValue = numValue / 1e3;
|
|
30181
|
-
}
|
|
30182
|
-
if (key === "fp_a" || key === "fp_b" || key === "fp_c" || key === "powerFactor") {
|
|
30183
|
-
numValue = numValue / 255;
|
|
30184
|
-
}
|
|
30202
|
+
const numValue = normalizeTelemetryValue(key, latest.value);
|
|
30185
30203
|
const formattedNum = numValue.toFixed(config.decimals);
|
|
30186
30204
|
const displayUnit = config.unit === "fp" ? "" : config.unit;
|
|
30187
30205
|
const formatted = displayUnit ? `${formattedNum} ${displayUnit}` : formattedNum;
|
|
@@ -30412,15 +30430,7 @@ async function openRealTimeTelemetryModal(params) {
|
|
|
30412
30430
|
}
|
|
30413
30431
|
}
|
|
30414
30432
|
function getFormattedValue(key, value) {
|
|
30415
|
-
|
|
30416
|
-
if (!config) return value.toFixed(2);
|
|
30417
|
-
if (key === "consumption" || key === "power") {
|
|
30418
|
-
if (value >= 1e3) {
|
|
30419
|
-
return `${(value / 1e3).toFixed(2)} kW`;
|
|
30420
|
-
}
|
|
30421
|
-
return `${value.toFixed(0)} W`;
|
|
30422
|
-
}
|
|
30423
|
-
return `${value.toFixed(config.decimals)} ${config.unit}`;
|
|
30433
|
+
return formatTelemetryValue(key, value);
|
|
30424
30434
|
}
|
|
30425
30435
|
function hexRgba(hex, alpha) {
|
|
30426
30436
|
const r = parseInt(hex.slice(1, 3), 16);
|
|
@@ -30450,11 +30460,7 @@ async function openRealTimeTelemetryModal(params) {
|
|
|
30450
30460
|
const rightAxisColor = rightAxisKey ? KEY_COLORS[rightAxisKey] || "#555" : "#555";
|
|
30451
30461
|
function makeTickCallback(unit) {
|
|
30452
30462
|
return function(value) {
|
|
30453
|
-
|
|
30454
|
-
if (value >= 1e3) return `${(value / 1e3).toFixed(1)} kW`;
|
|
30455
|
-
return `${value} W`;
|
|
30456
|
-
}
|
|
30457
|
-
return `${value}${unit ? " " + unit : ""}`;
|
|
30463
|
+
return formatAxisTick(unit, value);
|
|
30458
30464
|
};
|
|
30459
30465
|
}
|
|
30460
30466
|
const datasets = selectedChartKeys.map((key) => {
|
|
@@ -61913,6 +61919,7 @@ var DeviceProfileTab = class {
|
|
|
61913
61919
|
const slaveIdNum = typeof slaveId === "string" ? parseInt(slaveId, 10) : slaveId;
|
|
61914
61920
|
let page = 1;
|
|
61915
61921
|
let match = null;
|
|
61922
|
+
let fallback = null;
|
|
61916
61923
|
for (; page <= 50 && !match; page++) {
|
|
61917
61924
|
const res = await fetch(
|
|
61918
61925
|
`${INGESTION_API_BASE2}/management/devices?page=${page}&limit=100&customerId=${encodeURIComponent(
|
|
@@ -61924,15 +61931,18 @@ var DeviceProfileTab = class {
|
|
|
61924
61931
|
const json = await res.json();
|
|
61925
61932
|
const list = json?.data || [];
|
|
61926
61933
|
for (const d of list) {
|
|
61927
|
-
|
|
61928
|
-
if (
|
|
61934
|
+
if (d.slaveId !== slaveIdNum) continue;
|
|
61935
|
+
if (d.gateway?.hardwareUuid === centralId) {
|
|
61929
61936
|
match = { id: d.id };
|
|
61930
61937
|
break;
|
|
61931
61938
|
}
|
|
61939
|
+
if (!fallback && (d.gatewayId === centralId || d.gateway?.id === centralId)) fallback = { id: d.id };
|
|
61932
61940
|
}
|
|
61941
|
+
if (match) break;
|
|
61933
61942
|
const totalPages = json?.pagination?.pages || 1;
|
|
61934
61943
|
if (page >= totalPages) break;
|
|
61935
61944
|
}
|
|
61945
|
+
if (!match && fallback) match = fallback;
|
|
61936
61946
|
if (!match) {
|
|
61937
61947
|
return { ok: false, message: `Nenhum device na Ingestion API com centralId=${centralId} e slaveId=${slaveIdNum}.` };
|
|
61938
61948
|
}
|
|
@@ -108508,27 +108518,30 @@ async function fetchIngestionDevicesAllPaged(customerId) {
|
|
|
108508
108518
|
}
|
|
108509
108519
|
function findIngestionDeviceByCentralSlaveId(devices, centralId, slaveId) {
|
|
108510
108520
|
const slaveIdNum = typeof slaveId === "string" ? parseInt(slaveId, 10) : slaveId;
|
|
108511
|
-
|
|
108512
|
-
|
|
108513
|
-
|
|
108514
|
-
|
|
108515
|
-
|
|
108516
|
-
|
|
108517
|
-
|
|
108518
|
-
|
|
108519
|
-
|
|
108520
|
-
|
|
108521
|
-
|
|
108522
|
-
|
|
108523
|
-
|
|
108521
|
+
const bySlave = devices.filter((d) => d.slaveId === slaveIdNum);
|
|
108522
|
+
const match = bySlave.find((d) => d.gateway?.hardwareUuid === centralId) || bySlave.find((d) => d.gatewayId === centralId || d.gateway?.id === centralId);
|
|
108523
|
+
if (match) {
|
|
108524
|
+
console.log(
|
|
108525
|
+
"[UpsellModal] Found matching device:",
|
|
108526
|
+
match.name,
|
|
108527
|
+
"via:",
|
|
108528
|
+
match.gateway?.hardwareUuid === centralId ? "hardwareUuid" : "gatewayId",
|
|
108529
|
+
"centralId:",
|
|
108530
|
+
centralId,
|
|
108531
|
+
"slaveId:",
|
|
108532
|
+
match.slaveId
|
|
108533
|
+
);
|
|
108534
|
+
return match;
|
|
108524
108535
|
}
|
|
108525
108536
|
console.log("[UpsellModal] No match found. Looking for centralId:", centralId, "slaveId:", slaveIdNum);
|
|
108526
108537
|
devices.slice(0, 3).forEach((d, i) => {
|
|
108527
108538
|
console.log(
|
|
108528
108539
|
`[UpsellModal] Sample device ${i}:`,
|
|
108529
108540
|
d.name,
|
|
108530
|
-
"gateway
|
|
108531
|
-
d.gateway?.hardwareUuid
|
|
108541
|
+
"gateway hwUuid / id:",
|
|
108542
|
+
d.gateway?.hardwareUuid,
|
|
108543
|
+
"/",
|
|
108544
|
+
d.gatewayId || d.gateway?.id,
|
|
108532
108545
|
"slaveId:",
|
|
108533
108546
|
d.slaveId
|
|
108534
108547
|
);
|
|
@@ -5524,7 +5524,7 @@
|
|
|
5524
5524
|
|
|
5525
5525
|
// package.json
|
|
5526
5526
|
var package_default = {
|
|
5527
|
-
version: "0.1.
|
|
5527
|
+
version: "0.1.586"};
|
|
5528
5528
|
|
|
5529
5529
|
// src/utils/format/energy.ts
|
|
5530
5530
|
function formatPower(value, decimals = 2) {
|
|
@@ -33019,6 +33019,7 @@
|
|
|
33019
33019
|
} else {
|
|
33020
33020
|
ranges = {
|
|
33021
33021
|
"Hoje": [moment().startOf("day"), moment().endOf("day")],
|
|
33022
|
+
"Ontem": [moment().subtract(1, "day").startOf("day"), moment().subtract(1, "day").endOf("day")],
|
|
33022
33023
|
"\xDAltimos 7 dias": [moment().subtract(6, "days").startOf("day"), moment().endOf("day")],
|
|
33023
33024
|
"\xDAltimos 15 dias": [moment().subtract(14, "days").startOf("day"), moment().endOf("day")],
|
|
33024
33025
|
"\xDAltimos 30 dias": [moment().subtract(29, "days").startOf("day"), moment().endOf("day")],
|
|
@@ -33156,6 +33157,42 @@
|
|
|
33156
33157
|
// Temperature
|
|
33157
33158
|
temperature: { label: "Temperatura", unit: "\xB0C", icon: "\u{1F321}\uFE0F", decimals: 1 }
|
|
33158
33159
|
};
|
|
33160
|
+
var CURRENT_KEYS_MA = /* @__PURE__ */ new Set(["total_current", "current", "current_a", "current_b", "current_c"]);
|
|
33161
|
+
var POWER_FACTOR_KEYS_255 = /* @__PURE__ */ new Set(["fp_a", "fp_b", "fp_c", "powerFactor"]);
|
|
33162
|
+
function normalizeTelemetryValue(key, raw) {
|
|
33163
|
+
const v = Number(raw) || 0;
|
|
33164
|
+
if (CURRENT_KEYS_MA.has(key)) return v / 1e3;
|
|
33165
|
+
if (POWER_FACTOR_KEYS_255.has(key)) return v / 255;
|
|
33166
|
+
return v;
|
|
33167
|
+
}
|
|
33168
|
+
function scaleWatts(value, decimals) {
|
|
33169
|
+
const abs = Math.abs(value);
|
|
33170
|
+
if (abs >= 1e6) return `${(value / 1e6).toFixed(decimals)} MW`;
|
|
33171
|
+
if (abs >= 1e3) return `${(value / 1e3).toFixed(decimals)} kW`;
|
|
33172
|
+
return `${value.toFixed(0)} W`;
|
|
33173
|
+
}
|
|
33174
|
+
function formatTelemetryValue(key, value) {
|
|
33175
|
+
const config = TELEMETRY_CONFIG[key];
|
|
33176
|
+
if (!config) return value.toFixed(2);
|
|
33177
|
+
if (config.unit === "W") return scaleWatts(value, 2);
|
|
33178
|
+
return `${value.toFixed(config.decimals)} ${config.unit}`;
|
|
33179
|
+
}
|
|
33180
|
+
function formatAxisTick(unit, value) {
|
|
33181
|
+
if (unit === "W") {
|
|
33182
|
+
const n = Number(value);
|
|
33183
|
+
if (Math.abs(n) >= 1e3) return scaleWatts(n, 1);
|
|
33184
|
+
return `${value} W`;
|
|
33185
|
+
}
|
|
33186
|
+
return `${value}${unit ? " " + unit : ""}`;
|
|
33187
|
+
}
|
|
33188
|
+
function formatPeakValue(key, value) {
|
|
33189
|
+
const cfg = TELEMETRY_CONFIG[key] || { unit: "", decimals: 2 };
|
|
33190
|
+
if (cfg.unit === "W") return formatPower(value, 3);
|
|
33191
|
+
return `${value.toLocaleString("pt-BR", {
|
|
33192
|
+
minimumFractionDigits: cfg.decimals ?? 2,
|
|
33193
|
+
maximumFractionDigits: cfg.decimals ?? 2
|
|
33194
|
+
})} ${cfg.unit}`;
|
|
33195
|
+
}
|
|
33159
33196
|
var PHASE_SHORT_LABEL = {
|
|
33160
33197
|
consumption: "Total",
|
|
33161
33198
|
power: "Total",
|
|
@@ -35329,11 +35366,7 @@
|
|
|
35329
35366
|
});
|
|
35330
35367
|
}
|
|
35331
35368
|
function normalizeRealtimeValue(key, raw) {
|
|
35332
|
-
|
|
35333
|
-
return raw / 1e3;
|
|
35334
|
-
}
|
|
35335
|
-
if (key === "fp_a" || key === "fp_b" || key === "fp_c" || key === "powerFactor") return raw / 255;
|
|
35336
|
-
return raw;
|
|
35369
|
+
return normalizeTelemetryValue(key, raw);
|
|
35337
35370
|
}
|
|
35338
35371
|
function fillAggregatedGaps(returned, startTs, endTs, intervalMs, seedY) {
|
|
35339
35372
|
const byBucket = /* @__PURE__ */ new Map();
|
|
@@ -35486,13 +35519,7 @@
|
|
|
35486
35519
|
const data = await fetchPeriodTelemetry(periodStartISO, periodEndISO);
|
|
35487
35520
|
periodHistory.clear();
|
|
35488
35521
|
periodLastKnown.clear();
|
|
35489
|
-
const toPeriodY = (key, raw) =>
|
|
35490
|
-
let y = raw ?? 0;
|
|
35491
|
-
if (key === "total_current" || key === "current") y = y / 1e3;
|
|
35492
|
-
if (key === "fp_a" || key === "fp_b" || key === "fp_c" || key === "powerFactor") y = y / 255;
|
|
35493
|
-
if (POWER_KEYS.has(key)) y = y / 1e3;
|
|
35494
|
-
return y;
|
|
35495
|
-
};
|
|
35522
|
+
const toPeriodY = (key, raw) => normalizeTelemetryValue(key, raw);
|
|
35496
35523
|
const fillGaps = selectedAgg !== "NONE";
|
|
35497
35524
|
const periodStartTs = new Date(periodStartISO).getTime();
|
|
35498
35525
|
const periodEndTs = new Date(periodEndISO).getTime();
|
|
@@ -35542,10 +35569,7 @@
|
|
|
35542
35569
|
minute: "2-digit"
|
|
35543
35570
|
}
|
|
35544
35571
|
) : "";
|
|
35545
|
-
const formattedValue =
|
|
35546
|
-
minimumFractionDigits: cfg.decimals ?? 2,
|
|
35547
|
-
maximumFractionDigits: cfg.decimals ?? 2
|
|
35548
|
-
})} ${cfg.unit}`;
|
|
35572
|
+
const formattedValue = formatPeakValue(peakKey, peakPoint.y);
|
|
35549
35573
|
peakSummaryEl.textContent = `M\xE1xima: ${formattedValue} (${cfg.label}) em ${when}`;
|
|
35550
35574
|
peakSummaryEl.style.display = "block";
|
|
35551
35575
|
} else {
|
|
@@ -35570,13 +35594,7 @@
|
|
|
35570
35594
|
if (!telemetryData || telemetryData.length === 0) continue;
|
|
35571
35595
|
const latest = telemetryData[0];
|
|
35572
35596
|
const config = TELEMETRY_CONFIG[key] || { label: key, unit: "", icon: "\u{1F4CA}", decimals: 2 };
|
|
35573
|
-
|
|
35574
|
-
if (key === "total_current" || key === "current" || key === "current_a" || key === "current_b" || key === "current_c") {
|
|
35575
|
-
numValue = numValue / 1e3;
|
|
35576
|
-
}
|
|
35577
|
-
if (key === "fp_a" || key === "fp_b" || key === "fp_c" || key === "powerFactor") {
|
|
35578
|
-
numValue = numValue / 255;
|
|
35579
|
-
}
|
|
35597
|
+
const numValue = normalizeTelemetryValue(key, latest.value);
|
|
35580
35598
|
const formattedNum = numValue.toFixed(config.decimals);
|
|
35581
35599
|
const displayUnit = config.unit === "fp" ? "" : config.unit;
|
|
35582
35600
|
const formatted = displayUnit ? `${formattedNum} ${displayUnit}` : formattedNum;
|
|
@@ -35807,15 +35825,7 @@
|
|
|
35807
35825
|
}
|
|
35808
35826
|
}
|
|
35809
35827
|
function getFormattedValue(key, value) {
|
|
35810
|
-
|
|
35811
|
-
if (!config) return value.toFixed(2);
|
|
35812
|
-
if (key === "consumption" || key === "power") {
|
|
35813
|
-
if (value >= 1e3) {
|
|
35814
|
-
return `${(value / 1e3).toFixed(2)} kW`;
|
|
35815
|
-
}
|
|
35816
|
-
return `${value.toFixed(0)} W`;
|
|
35817
|
-
}
|
|
35818
|
-
return `${value.toFixed(config.decimals)} ${config.unit}`;
|
|
35828
|
+
return formatTelemetryValue(key, value);
|
|
35819
35829
|
}
|
|
35820
35830
|
function hexRgba(hex, alpha) {
|
|
35821
35831
|
const r = parseInt(hex.slice(1, 3), 16);
|
|
@@ -35845,11 +35855,7 @@
|
|
|
35845
35855
|
const rightAxisColor = rightAxisKey ? KEY_COLORS[rightAxisKey] || "#555" : "#555";
|
|
35846
35856
|
function makeTickCallback(unit) {
|
|
35847
35857
|
return function(value) {
|
|
35848
|
-
|
|
35849
|
-
if (value >= 1e3) return `${(value / 1e3).toFixed(1)} kW`;
|
|
35850
|
-
return `${value} W`;
|
|
35851
|
-
}
|
|
35852
|
-
return `${value}${unit ? " " + unit : ""}`;
|
|
35858
|
+
return formatAxisTick(unit, value);
|
|
35853
35859
|
};
|
|
35854
35860
|
}
|
|
35855
35861
|
const datasets = selectedChartKeys.map((key) => {
|
|
@@ -67271,6 +67277,7 @@ ${kpiRows}` : ""}
|
|
|
67271
67277
|
const slaveIdNum = typeof slaveId === "string" ? parseInt(slaveId, 10) : slaveId;
|
|
67272
67278
|
let page = 1;
|
|
67273
67279
|
let match = null;
|
|
67280
|
+
let fallback = null;
|
|
67274
67281
|
for (; page <= 50 && !match; page++) {
|
|
67275
67282
|
const res = await fetch(
|
|
67276
67283
|
`${INGESTION_API_BASE2}/management/devices?page=${page}&limit=100&customerId=${encodeURIComponent(
|
|
@@ -67282,15 +67289,18 @@ ${kpiRows}` : ""}
|
|
|
67282
67289
|
const json = await res.json();
|
|
67283
67290
|
const list = json?.data || [];
|
|
67284
67291
|
for (const d of list) {
|
|
67285
|
-
|
|
67286
|
-
if (
|
|
67292
|
+
if (d.slaveId !== slaveIdNum) continue;
|
|
67293
|
+
if (d.gateway?.hardwareUuid === centralId) {
|
|
67287
67294
|
match = { id: d.id };
|
|
67288
67295
|
break;
|
|
67289
67296
|
}
|
|
67297
|
+
if (!fallback && (d.gatewayId === centralId || d.gateway?.id === centralId)) fallback = { id: d.id };
|
|
67290
67298
|
}
|
|
67299
|
+
if (match) break;
|
|
67291
67300
|
const totalPages = json?.pagination?.pages || 1;
|
|
67292
67301
|
if (page >= totalPages) break;
|
|
67293
67302
|
}
|
|
67303
|
+
if (!match && fallback) match = fallback;
|
|
67294
67304
|
if (!match) {
|
|
67295
67305
|
return { ok: false, message: `Nenhum device na Ingestion API com centralId=${centralId} e slaveId=${slaveIdNum}.` };
|
|
67296
67306
|
}
|
|
@@ -113723,27 +113733,30 @@ ${state5.year}-03-15T08,15`)}">${esc7(state5.csv)}</textarea>
|
|
|
113723
113733
|
}
|
|
113724
113734
|
function findIngestionDeviceByCentralSlaveId(devices, centralId, slaveId) {
|
|
113725
113735
|
const slaveIdNum = typeof slaveId === "string" ? parseInt(slaveId, 10) : slaveId;
|
|
113726
|
-
|
|
113727
|
-
|
|
113728
|
-
|
|
113729
|
-
|
|
113730
|
-
|
|
113731
|
-
|
|
113732
|
-
|
|
113733
|
-
|
|
113734
|
-
|
|
113735
|
-
|
|
113736
|
-
|
|
113737
|
-
|
|
113738
|
-
|
|
113736
|
+
const bySlave = devices.filter((d) => d.slaveId === slaveIdNum);
|
|
113737
|
+
const match = bySlave.find((d) => d.gateway?.hardwareUuid === centralId) || bySlave.find((d) => d.gatewayId === centralId || d.gateway?.id === centralId);
|
|
113738
|
+
if (match) {
|
|
113739
|
+
console.log(
|
|
113740
|
+
"[UpsellModal] Found matching device:",
|
|
113741
|
+
match.name,
|
|
113742
|
+
"via:",
|
|
113743
|
+
match.gateway?.hardwareUuid === centralId ? "hardwareUuid" : "gatewayId",
|
|
113744
|
+
"centralId:",
|
|
113745
|
+
centralId,
|
|
113746
|
+
"slaveId:",
|
|
113747
|
+
match.slaveId
|
|
113748
|
+
);
|
|
113749
|
+
return match;
|
|
113739
113750
|
}
|
|
113740
113751
|
console.log("[UpsellModal] No match found. Looking for centralId:", centralId, "slaveId:", slaveIdNum);
|
|
113741
113752
|
devices.slice(0, 3).forEach((d, i) => {
|
|
113742
113753
|
console.log(
|
|
113743
113754
|
`[UpsellModal] Sample device ${i}:`,
|
|
113744
113755
|
d.name,
|
|
113745
|
-
"gateway
|
|
113746
|
-
d.gateway?.hardwareUuid
|
|
113756
|
+
"gateway hwUuid / id:",
|
|
113757
|
+
d.gateway?.hardwareUuid,
|
|
113758
|
+
"/",
|
|
113759
|
+
d.gatewayId || d.gateway?.id,
|
|
113747
113760
|
"slaveId:",
|
|
113748
113761
|
d.slaveId
|
|
113749
113762
|
);
|