myio-js-library 0.1.135 → 0.1.137
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 +134 -21
- package/dist/index.js +134 -21
- package/dist/myio-js-library.umd.js +134 -21
- package/dist/myio-js-library.umd.min.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -7073,15 +7073,23 @@ if (typeof module !== "undefined" && module.exports) {
|
|
|
7073
7073
|
|
|
7074
7074
|
// src/components/RealTimeTelemetryModal.ts
|
|
7075
7075
|
var TELEMETRY_CONFIG = {
|
|
7076
|
-
|
|
7076
|
+
// Voltage phases
|
|
7077
|
+
voltage_a: { label: "Tens\xE3o Fase A", unit: "V", icon: "\u26A1", decimals: 1 },
|
|
7078
|
+
voltage_b: { label: "Tens\xE3o Fase B", unit: "V", icon: "\u26A1", decimals: 1 },
|
|
7079
|
+
voltage_c: { label: "Tens\xE3o Fase C", unit: "V", icon: "\u26A1", decimals: 1 },
|
|
7080
|
+
// Current
|
|
7081
|
+
total_current: { label: "Corrente Total", unit: "A", icon: "\u{1F50C}", decimals: 2 },
|
|
7077
7082
|
current: { label: "Corrente", unit: "A", icon: "\u{1F50C}", decimals: 2 },
|
|
7078
|
-
|
|
7083
|
+
// Power and Energy
|
|
7084
|
+
consumption: { label: "Pot\xEAncia", unit: "W", icon: "\u2699\uFE0F", decimals: 0 },
|
|
7085
|
+
power: { label: "Pot\xEAncia", unit: "W", icon: "\u2699\uFE0F", decimals: 0 },
|
|
7079
7086
|
energy: { label: "Energia", unit: "kWh", icon: "\u{1F4CA}", decimals: 1 },
|
|
7080
|
-
temperature: { label: "Temperatura", unit: "\xB0C", icon: "\u{1F321}\uFE0F", decimals: 1 },
|
|
7081
7087
|
activePower: { label: "Pot\xEAncia Ativa", unit: "kW", icon: "\u2699\uFE0F", decimals: 2 },
|
|
7082
7088
|
reactivePower: { label: "Pot\xEAncia Reativa", unit: "kVAr", icon: "\u{1F504}", decimals: 2 },
|
|
7083
7089
|
apparentPower: { label: "Pot\xEAncia Aparente", unit: "kVA", icon: "\u{1F4C8}", decimals: 2 },
|
|
7084
|
-
powerFactor: { label: "Fator de Pot\xEAncia", unit: "", icon: "\u{1F4D0}", decimals: 3 }
|
|
7090
|
+
powerFactor: { label: "Fator de Pot\xEAncia", unit: "", icon: "\u{1F4D0}", decimals: 3 },
|
|
7091
|
+
// Temperature
|
|
7092
|
+
temperature: { label: "Temperatura", unit: "\xB0C", icon: "\u{1F321}\uFE0F", decimals: 1 }
|
|
7085
7093
|
};
|
|
7086
7094
|
var STRINGS = {
|
|
7087
7095
|
"pt-BR": {
|
|
@@ -7120,7 +7128,7 @@ async function openRealTimeTelemetryModal(params) {
|
|
|
7120
7128
|
token,
|
|
7121
7129
|
deviceId,
|
|
7122
7130
|
deviceLabel = "Dispositivo",
|
|
7123
|
-
telemetryKeys = ["
|
|
7131
|
+
telemetryKeys = ["voltage_a", "voltage_b", "voltage_c", "total_current", "consumption"],
|
|
7124
7132
|
refreshInterval = 8e3,
|
|
7125
7133
|
historyPoints = 50,
|
|
7126
7134
|
onClose,
|
|
@@ -7130,7 +7138,9 @@ async function openRealTimeTelemetryModal(params) {
|
|
|
7130
7138
|
let refreshIntervalId = null;
|
|
7131
7139
|
let isPaused = false;
|
|
7132
7140
|
let telemetryHistory = /* @__PURE__ */ new Map();
|
|
7141
|
+
let lastKnownValues = /* @__PURE__ */ new Map();
|
|
7133
7142
|
let chart = null;
|
|
7143
|
+
let selectedChartKey = "consumption";
|
|
7134
7144
|
const overlay = document.createElement("div");
|
|
7135
7145
|
overlay.className = "myio-realtime-telemetry-overlay";
|
|
7136
7146
|
overlay.innerHTML = `
|
|
@@ -7291,7 +7301,27 @@ async function openRealTimeTelemetryModal(params) {
|
|
|
7291
7301
|
}
|
|
7292
7302
|
|
|
7293
7303
|
.myio-telemetry-chart {
|
|
7294
|
-
height:
|
|
7304
|
+
height: 250px;
|
|
7305
|
+
}
|
|
7306
|
+
|
|
7307
|
+
.myio-telemetry-selector {
|
|
7308
|
+
padding: 8px 12px;
|
|
7309
|
+
border: 1px solid #ddd;
|
|
7310
|
+
border-radius: 6px;
|
|
7311
|
+
font-size: 14px;
|
|
7312
|
+
background: white;
|
|
7313
|
+
cursor: pointer;
|
|
7314
|
+
transition: border-color 0.2s;
|
|
7315
|
+
}
|
|
7316
|
+
|
|
7317
|
+
.myio-telemetry-selector:hover {
|
|
7318
|
+
border-color: #667eea;
|
|
7319
|
+
}
|
|
7320
|
+
|
|
7321
|
+
.myio-telemetry-selector:focus {
|
|
7322
|
+
outline: none;
|
|
7323
|
+
border-color: #667eea;
|
|
7324
|
+
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
|
|
7295
7325
|
}
|
|
7296
7326
|
|
|
7297
7327
|
.myio-realtime-telemetry-footer {
|
|
@@ -7401,7 +7431,16 @@ async function openRealTimeTelemetryModal(params) {
|
|
|
7401
7431
|
<div class="myio-telemetry-cards-grid" id="telemetry-cards"></div>
|
|
7402
7432
|
|
|
7403
7433
|
<div class="myio-telemetry-chart-container" id="chart-container" style="display: none;">
|
|
7404
|
-
<
|
|
7434
|
+
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px;">
|
|
7435
|
+
<h3 class="myio-telemetry-chart-title" id="chart-title" style="margin: 0;">Hist\xF3rico de Telemetria</h3>
|
|
7436
|
+
<select id="chart-key-selector" class="myio-telemetry-selector">
|
|
7437
|
+
<option value="consumption">Pot\xEAncia</option>
|
|
7438
|
+
<option value="total_current">Corrente Total</option>
|
|
7439
|
+
<option value="voltage_a">Tens\xE3o Fase A</option>
|
|
7440
|
+
<option value="voltage_b">Tens\xE3o Fase B</option>
|
|
7441
|
+
<option value="voltage_c">Tens\xE3o Fase C</option>
|
|
7442
|
+
</select>
|
|
7443
|
+
</div>
|
|
7405
7444
|
<canvas class="myio-telemetry-chart" id="telemetry-chart"></canvas>
|
|
7406
7445
|
</div>
|
|
7407
7446
|
</div>
|
|
@@ -7443,6 +7482,7 @@ async function openRealTimeTelemetryModal(params) {
|
|
|
7443
7482
|
const telemetryCards = document.getElementById("telemetry-cards");
|
|
7444
7483
|
const chartContainer = document.getElementById("chart-container");
|
|
7445
7484
|
const chartCanvas = document.getElementById("telemetry-chart");
|
|
7485
|
+
const chartKeySelector = document.getElementById("chart-key-selector");
|
|
7446
7486
|
const statusIndicator = document.getElementById("status-indicator");
|
|
7447
7487
|
const statusText = document.getElementById("status-text");
|
|
7448
7488
|
const lastUpdateText = document.getElementById("last-update-text");
|
|
@@ -7534,16 +7574,42 @@ async function openRealTimeTelemetryModal(params) {
|
|
|
7534
7574
|
}
|
|
7535
7575
|
const history = telemetryHistory.get(tel.key);
|
|
7536
7576
|
history.push({ x: now, y: tel.value });
|
|
7577
|
+
lastKnownValues.set(tel.key, tel.value);
|
|
7537
7578
|
if (history.length > historyPoints) {
|
|
7538
7579
|
history.shift();
|
|
7539
7580
|
}
|
|
7540
7581
|
}
|
|
7541
|
-
|
|
7542
|
-
const
|
|
7543
|
-
|
|
7582
|
+
for (const key of telemetryKeys) {
|
|
7583
|
+
const receivedKeys = values.map((v) => v.key);
|
|
7584
|
+
if (!receivedKeys.includes(key) && lastKnownValues.has(key)) {
|
|
7585
|
+
if (!telemetryHistory.has(key)) {
|
|
7586
|
+
telemetryHistory.set(key, []);
|
|
7587
|
+
}
|
|
7588
|
+
const history = telemetryHistory.get(key);
|
|
7589
|
+
const lastValue = lastKnownValues.get(key);
|
|
7590
|
+
history.push({ x: now, y: lastValue });
|
|
7591
|
+
if (history.length > historyPoints) {
|
|
7592
|
+
history.shift();
|
|
7593
|
+
}
|
|
7594
|
+
}
|
|
7595
|
+
}
|
|
7596
|
+
if (telemetryHistory.has(selectedChartKey) && chart) {
|
|
7597
|
+
const selectedHistory = telemetryHistory.get(selectedChartKey);
|
|
7598
|
+
chart.data.datasets[0].data = selectedHistory;
|
|
7544
7599
|
chart.update("none");
|
|
7545
7600
|
}
|
|
7546
7601
|
}
|
|
7602
|
+
function getFormattedValue(key, value) {
|
|
7603
|
+
const config = TELEMETRY_CONFIG[key];
|
|
7604
|
+
if (!config) return value.toFixed(2);
|
|
7605
|
+
if (key === "consumption" || key === "power") {
|
|
7606
|
+
if (value >= 1e3) {
|
|
7607
|
+
return `${(value / 1e3).toFixed(2)} kW`;
|
|
7608
|
+
}
|
|
7609
|
+
return `${value.toFixed(0)} W`;
|
|
7610
|
+
}
|
|
7611
|
+
return `${value.toFixed(config.decimals)} ${config.unit}`;
|
|
7612
|
+
}
|
|
7547
7613
|
function initializeChart() {
|
|
7548
7614
|
const Chart = window.Chart;
|
|
7549
7615
|
if (!Chart) {
|
|
@@ -7551,23 +7617,26 @@ async function openRealTimeTelemetryModal(params) {
|
|
|
7551
7617
|
return;
|
|
7552
7618
|
}
|
|
7553
7619
|
chartContainer.style.display = "block";
|
|
7620
|
+
const config = TELEMETRY_CONFIG[selectedChartKey] || { label: selectedChartKey, unit: "" };
|
|
7554
7621
|
chart = new Chart(chartCanvas, {
|
|
7555
7622
|
type: "line",
|
|
7556
7623
|
data: {
|
|
7557
7624
|
datasets: [{
|
|
7558
|
-
label:
|
|
7625
|
+
label: config.label,
|
|
7559
7626
|
data: [],
|
|
7560
7627
|
borderColor: "#667eea",
|
|
7561
7628
|
backgroundColor: "rgba(102, 126, 234, 0.1)",
|
|
7562
7629
|
borderWidth: 2,
|
|
7563
7630
|
fill: true,
|
|
7564
7631
|
tension: 0.4,
|
|
7565
|
-
pointRadius:
|
|
7632
|
+
pointRadius: 3,
|
|
7633
|
+
pointHoverRadius: 5
|
|
7566
7634
|
}]
|
|
7567
7635
|
},
|
|
7568
7636
|
options: {
|
|
7569
7637
|
responsive: true,
|
|
7570
7638
|
maintainAspectRatio: false,
|
|
7639
|
+
animation: false,
|
|
7571
7640
|
plugins: {
|
|
7572
7641
|
legend: { display: false },
|
|
7573
7642
|
tooltip: {
|
|
@@ -7575,10 +7644,18 @@ async function openRealTimeTelemetryModal(params) {
|
|
|
7575
7644
|
title: function(context) {
|
|
7576
7645
|
const timestamp = context[0].parsed.x;
|
|
7577
7646
|
const date = new Date(timestamp);
|
|
7578
|
-
return date.
|
|
7647
|
+
return date.toLocaleString(locale, {
|
|
7648
|
+
day: "2-digit",
|
|
7649
|
+
month: "2-digit",
|
|
7650
|
+
year: "numeric",
|
|
7651
|
+
hour: "2-digit",
|
|
7652
|
+
minute: "2-digit",
|
|
7653
|
+
second: "2-digit"
|
|
7654
|
+
});
|
|
7579
7655
|
},
|
|
7580
7656
|
label: function(context) {
|
|
7581
|
-
|
|
7657
|
+
const value = context.parsed.y;
|
|
7658
|
+
return getFormattedValue(selectedChartKey, value);
|
|
7582
7659
|
}
|
|
7583
7660
|
}
|
|
7584
7661
|
}
|
|
@@ -7587,23 +7664,57 @@ async function openRealTimeTelemetryModal(params) {
|
|
|
7587
7664
|
x: {
|
|
7588
7665
|
type: "linear",
|
|
7589
7666
|
ticks: {
|
|
7667
|
+
maxRotation: 45,
|
|
7668
|
+
minRotation: 0,
|
|
7590
7669
|
callback: function(value) {
|
|
7591
7670
|
const date = new Date(value);
|
|
7592
|
-
return date.toLocaleTimeString(locale, {
|
|
7671
|
+
return date.toLocaleTimeString(locale, {
|
|
7672
|
+
hour: "2-digit",
|
|
7673
|
+
minute: "2-digit",
|
|
7674
|
+
second: "2-digit"
|
|
7675
|
+
});
|
|
7593
7676
|
}
|
|
7677
|
+
},
|
|
7678
|
+
title: {
|
|
7679
|
+
display: true,
|
|
7680
|
+
text: "Hora"
|
|
7594
7681
|
}
|
|
7595
7682
|
},
|
|
7596
7683
|
y: {
|
|
7597
7684
|
beginAtZero: true,
|
|
7685
|
+
ticks: {
|
|
7686
|
+
callback: function(value) {
|
|
7687
|
+
if (selectedChartKey === "consumption" || selectedChartKey === "power") {
|
|
7688
|
+
if (value >= 1e3) {
|
|
7689
|
+
return `${(value / 1e3).toFixed(1)} kW`;
|
|
7690
|
+
}
|
|
7691
|
+
return `${value} W`;
|
|
7692
|
+
}
|
|
7693
|
+
return `${value} ${config.unit}`;
|
|
7694
|
+
}
|
|
7695
|
+
},
|
|
7598
7696
|
title: {
|
|
7599
7697
|
display: true,
|
|
7600
|
-
text: "
|
|
7698
|
+
text: selectedChartKey === "consumption" || selectedChartKey === "power" ? "W" : config.unit
|
|
7601
7699
|
}
|
|
7602
7700
|
}
|
|
7603
7701
|
}
|
|
7604
7702
|
}
|
|
7605
7703
|
});
|
|
7606
7704
|
}
|
|
7705
|
+
function updateChartKey(newKey) {
|
|
7706
|
+
selectedChartKey = newKey;
|
|
7707
|
+
if (chart) {
|
|
7708
|
+
chart.destroy();
|
|
7709
|
+
chart = null;
|
|
7710
|
+
}
|
|
7711
|
+
initializeChart();
|
|
7712
|
+
if (telemetryHistory.has(selectedChartKey)) {
|
|
7713
|
+
const selectedHistory = telemetryHistory.get(selectedChartKey);
|
|
7714
|
+
chart.data.datasets[0].data = selectedHistory;
|
|
7715
|
+
chart.update("none");
|
|
7716
|
+
}
|
|
7717
|
+
}
|
|
7607
7718
|
async function refreshData() {
|
|
7608
7719
|
try {
|
|
7609
7720
|
const data = await fetchLatestTelemetry();
|
|
@@ -7615,9 +7726,7 @@ async function openRealTimeTelemetryModal(params) {
|
|
|
7615
7726
|
if (loadingState.style.display !== "none") {
|
|
7616
7727
|
loadingState.style.display = "none";
|
|
7617
7728
|
telemetryContent.style.display = "block";
|
|
7618
|
-
|
|
7619
|
-
initializeChart();
|
|
7620
|
-
}
|
|
7729
|
+
initializeChart();
|
|
7621
7730
|
}
|
|
7622
7731
|
} catch (error) {
|
|
7623
7732
|
console.error("[RealTimeTelemetry] Error fetching data:", error);
|
|
@@ -7685,6 +7794,10 @@ async function openRealTimeTelemetryModal(params) {
|
|
|
7685
7794
|
closeBtn.addEventListener("click", closeModal);
|
|
7686
7795
|
pauseBtn.addEventListener("click", togglePause);
|
|
7687
7796
|
exportBtn.addEventListener("click", exportToCSV2);
|
|
7797
|
+
chartKeySelector.addEventListener("change", (e) => {
|
|
7798
|
+
const newKey = e.target.value;
|
|
7799
|
+
updateChartKey(newKey);
|
|
7800
|
+
});
|
|
7688
7801
|
overlay.addEventListener("click", (e) => {
|
|
7689
7802
|
if (e.target === overlay) {
|
|
7690
7803
|
closeModal();
|
|
@@ -11537,7 +11650,7 @@ var EnergyModalView = class {
|
|
|
11537
11650
|
let startDate;
|
|
11538
11651
|
let endDate;
|
|
11539
11652
|
if (this.dateRangePicker) {
|
|
11540
|
-
const dates = this.dateRangePicker.
|
|
11653
|
+
const dates = this.dateRangePicker.getDates();
|
|
11541
11654
|
startDate = dates.startISO;
|
|
11542
11655
|
endDate = dates.endISO;
|
|
11543
11656
|
} else {
|
|
@@ -11575,7 +11688,7 @@ var EnergyModalView = class {
|
|
|
11575
11688
|
token: jwtToken,
|
|
11576
11689
|
deviceId: this.config.params.deviceId,
|
|
11577
11690
|
deviceLabel: this.config.params.deviceLabel || "Dispositivo",
|
|
11578
|
-
telemetryKeys: ["
|
|
11691
|
+
telemetryKeys: ["voltage_a", "voltage_b", "voltage_c", "total_current", "consumption"],
|
|
11579
11692
|
refreshInterval: 8e3,
|
|
11580
11693
|
// 8 seconds
|
|
11581
11694
|
historyPoints: 50,
|
package/dist/index.js
CHANGED
|
@@ -6977,15 +6977,23 @@ if (typeof module !== "undefined" && module.exports) {
|
|
|
6977
6977
|
|
|
6978
6978
|
// src/components/RealTimeTelemetryModal.ts
|
|
6979
6979
|
var TELEMETRY_CONFIG = {
|
|
6980
|
-
|
|
6980
|
+
// Voltage phases
|
|
6981
|
+
voltage_a: { label: "Tens\xE3o Fase A", unit: "V", icon: "\u26A1", decimals: 1 },
|
|
6982
|
+
voltage_b: { label: "Tens\xE3o Fase B", unit: "V", icon: "\u26A1", decimals: 1 },
|
|
6983
|
+
voltage_c: { label: "Tens\xE3o Fase C", unit: "V", icon: "\u26A1", decimals: 1 },
|
|
6984
|
+
// Current
|
|
6985
|
+
total_current: { label: "Corrente Total", unit: "A", icon: "\u{1F50C}", decimals: 2 },
|
|
6981
6986
|
current: { label: "Corrente", unit: "A", icon: "\u{1F50C}", decimals: 2 },
|
|
6982
|
-
|
|
6987
|
+
// Power and Energy
|
|
6988
|
+
consumption: { label: "Pot\xEAncia", unit: "W", icon: "\u2699\uFE0F", decimals: 0 },
|
|
6989
|
+
power: { label: "Pot\xEAncia", unit: "W", icon: "\u2699\uFE0F", decimals: 0 },
|
|
6983
6990
|
energy: { label: "Energia", unit: "kWh", icon: "\u{1F4CA}", decimals: 1 },
|
|
6984
|
-
temperature: { label: "Temperatura", unit: "\xB0C", icon: "\u{1F321}\uFE0F", decimals: 1 },
|
|
6985
6991
|
activePower: { label: "Pot\xEAncia Ativa", unit: "kW", icon: "\u2699\uFE0F", decimals: 2 },
|
|
6986
6992
|
reactivePower: { label: "Pot\xEAncia Reativa", unit: "kVAr", icon: "\u{1F504}", decimals: 2 },
|
|
6987
6993
|
apparentPower: { label: "Pot\xEAncia Aparente", unit: "kVA", icon: "\u{1F4C8}", decimals: 2 },
|
|
6988
|
-
powerFactor: { label: "Fator de Pot\xEAncia", unit: "", icon: "\u{1F4D0}", decimals: 3 }
|
|
6994
|
+
powerFactor: { label: "Fator de Pot\xEAncia", unit: "", icon: "\u{1F4D0}", decimals: 3 },
|
|
6995
|
+
// Temperature
|
|
6996
|
+
temperature: { label: "Temperatura", unit: "\xB0C", icon: "\u{1F321}\uFE0F", decimals: 1 }
|
|
6989
6997
|
};
|
|
6990
6998
|
var STRINGS = {
|
|
6991
6999
|
"pt-BR": {
|
|
@@ -7024,7 +7032,7 @@ async function openRealTimeTelemetryModal(params) {
|
|
|
7024
7032
|
token,
|
|
7025
7033
|
deviceId,
|
|
7026
7034
|
deviceLabel = "Dispositivo",
|
|
7027
|
-
telemetryKeys = ["
|
|
7035
|
+
telemetryKeys = ["voltage_a", "voltage_b", "voltage_c", "total_current", "consumption"],
|
|
7028
7036
|
refreshInterval = 8e3,
|
|
7029
7037
|
historyPoints = 50,
|
|
7030
7038
|
onClose,
|
|
@@ -7034,7 +7042,9 @@ async function openRealTimeTelemetryModal(params) {
|
|
|
7034
7042
|
let refreshIntervalId = null;
|
|
7035
7043
|
let isPaused = false;
|
|
7036
7044
|
let telemetryHistory = /* @__PURE__ */ new Map();
|
|
7045
|
+
let lastKnownValues = /* @__PURE__ */ new Map();
|
|
7037
7046
|
let chart = null;
|
|
7047
|
+
let selectedChartKey = "consumption";
|
|
7038
7048
|
const overlay = document.createElement("div");
|
|
7039
7049
|
overlay.className = "myio-realtime-telemetry-overlay";
|
|
7040
7050
|
overlay.innerHTML = `
|
|
@@ -7195,7 +7205,27 @@ async function openRealTimeTelemetryModal(params) {
|
|
|
7195
7205
|
}
|
|
7196
7206
|
|
|
7197
7207
|
.myio-telemetry-chart {
|
|
7198
|
-
height:
|
|
7208
|
+
height: 250px;
|
|
7209
|
+
}
|
|
7210
|
+
|
|
7211
|
+
.myio-telemetry-selector {
|
|
7212
|
+
padding: 8px 12px;
|
|
7213
|
+
border: 1px solid #ddd;
|
|
7214
|
+
border-radius: 6px;
|
|
7215
|
+
font-size: 14px;
|
|
7216
|
+
background: white;
|
|
7217
|
+
cursor: pointer;
|
|
7218
|
+
transition: border-color 0.2s;
|
|
7219
|
+
}
|
|
7220
|
+
|
|
7221
|
+
.myio-telemetry-selector:hover {
|
|
7222
|
+
border-color: #667eea;
|
|
7223
|
+
}
|
|
7224
|
+
|
|
7225
|
+
.myio-telemetry-selector:focus {
|
|
7226
|
+
outline: none;
|
|
7227
|
+
border-color: #667eea;
|
|
7228
|
+
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
|
|
7199
7229
|
}
|
|
7200
7230
|
|
|
7201
7231
|
.myio-realtime-telemetry-footer {
|
|
@@ -7305,7 +7335,16 @@ async function openRealTimeTelemetryModal(params) {
|
|
|
7305
7335
|
<div class="myio-telemetry-cards-grid" id="telemetry-cards"></div>
|
|
7306
7336
|
|
|
7307
7337
|
<div class="myio-telemetry-chart-container" id="chart-container" style="display: none;">
|
|
7308
|
-
<
|
|
7338
|
+
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px;">
|
|
7339
|
+
<h3 class="myio-telemetry-chart-title" id="chart-title" style="margin: 0;">Hist\xF3rico de Telemetria</h3>
|
|
7340
|
+
<select id="chart-key-selector" class="myio-telemetry-selector">
|
|
7341
|
+
<option value="consumption">Pot\xEAncia</option>
|
|
7342
|
+
<option value="total_current">Corrente Total</option>
|
|
7343
|
+
<option value="voltage_a">Tens\xE3o Fase A</option>
|
|
7344
|
+
<option value="voltage_b">Tens\xE3o Fase B</option>
|
|
7345
|
+
<option value="voltage_c">Tens\xE3o Fase C</option>
|
|
7346
|
+
</select>
|
|
7347
|
+
</div>
|
|
7309
7348
|
<canvas class="myio-telemetry-chart" id="telemetry-chart"></canvas>
|
|
7310
7349
|
</div>
|
|
7311
7350
|
</div>
|
|
@@ -7347,6 +7386,7 @@ async function openRealTimeTelemetryModal(params) {
|
|
|
7347
7386
|
const telemetryCards = document.getElementById("telemetry-cards");
|
|
7348
7387
|
const chartContainer = document.getElementById("chart-container");
|
|
7349
7388
|
const chartCanvas = document.getElementById("telemetry-chart");
|
|
7389
|
+
const chartKeySelector = document.getElementById("chart-key-selector");
|
|
7350
7390
|
const statusIndicator = document.getElementById("status-indicator");
|
|
7351
7391
|
const statusText = document.getElementById("status-text");
|
|
7352
7392
|
const lastUpdateText = document.getElementById("last-update-text");
|
|
@@ -7438,16 +7478,42 @@ async function openRealTimeTelemetryModal(params) {
|
|
|
7438
7478
|
}
|
|
7439
7479
|
const history = telemetryHistory.get(tel.key);
|
|
7440
7480
|
history.push({ x: now, y: tel.value });
|
|
7481
|
+
lastKnownValues.set(tel.key, tel.value);
|
|
7441
7482
|
if (history.length > historyPoints) {
|
|
7442
7483
|
history.shift();
|
|
7443
7484
|
}
|
|
7444
7485
|
}
|
|
7445
|
-
|
|
7446
|
-
const
|
|
7447
|
-
|
|
7486
|
+
for (const key of telemetryKeys) {
|
|
7487
|
+
const receivedKeys = values.map((v) => v.key);
|
|
7488
|
+
if (!receivedKeys.includes(key) && lastKnownValues.has(key)) {
|
|
7489
|
+
if (!telemetryHistory.has(key)) {
|
|
7490
|
+
telemetryHistory.set(key, []);
|
|
7491
|
+
}
|
|
7492
|
+
const history = telemetryHistory.get(key);
|
|
7493
|
+
const lastValue = lastKnownValues.get(key);
|
|
7494
|
+
history.push({ x: now, y: lastValue });
|
|
7495
|
+
if (history.length > historyPoints) {
|
|
7496
|
+
history.shift();
|
|
7497
|
+
}
|
|
7498
|
+
}
|
|
7499
|
+
}
|
|
7500
|
+
if (telemetryHistory.has(selectedChartKey) && chart) {
|
|
7501
|
+
const selectedHistory = telemetryHistory.get(selectedChartKey);
|
|
7502
|
+
chart.data.datasets[0].data = selectedHistory;
|
|
7448
7503
|
chart.update("none");
|
|
7449
7504
|
}
|
|
7450
7505
|
}
|
|
7506
|
+
function getFormattedValue(key, value) {
|
|
7507
|
+
const config = TELEMETRY_CONFIG[key];
|
|
7508
|
+
if (!config) return value.toFixed(2);
|
|
7509
|
+
if (key === "consumption" || key === "power") {
|
|
7510
|
+
if (value >= 1e3) {
|
|
7511
|
+
return `${(value / 1e3).toFixed(2)} kW`;
|
|
7512
|
+
}
|
|
7513
|
+
return `${value.toFixed(0)} W`;
|
|
7514
|
+
}
|
|
7515
|
+
return `${value.toFixed(config.decimals)} ${config.unit}`;
|
|
7516
|
+
}
|
|
7451
7517
|
function initializeChart() {
|
|
7452
7518
|
const Chart = window.Chart;
|
|
7453
7519
|
if (!Chart) {
|
|
@@ -7455,23 +7521,26 @@ async function openRealTimeTelemetryModal(params) {
|
|
|
7455
7521
|
return;
|
|
7456
7522
|
}
|
|
7457
7523
|
chartContainer.style.display = "block";
|
|
7524
|
+
const config = TELEMETRY_CONFIG[selectedChartKey] || { label: selectedChartKey, unit: "" };
|
|
7458
7525
|
chart = new Chart(chartCanvas, {
|
|
7459
7526
|
type: "line",
|
|
7460
7527
|
data: {
|
|
7461
7528
|
datasets: [{
|
|
7462
|
-
label:
|
|
7529
|
+
label: config.label,
|
|
7463
7530
|
data: [],
|
|
7464
7531
|
borderColor: "#667eea",
|
|
7465
7532
|
backgroundColor: "rgba(102, 126, 234, 0.1)",
|
|
7466
7533
|
borderWidth: 2,
|
|
7467
7534
|
fill: true,
|
|
7468
7535
|
tension: 0.4,
|
|
7469
|
-
pointRadius:
|
|
7536
|
+
pointRadius: 3,
|
|
7537
|
+
pointHoverRadius: 5
|
|
7470
7538
|
}]
|
|
7471
7539
|
},
|
|
7472
7540
|
options: {
|
|
7473
7541
|
responsive: true,
|
|
7474
7542
|
maintainAspectRatio: false,
|
|
7543
|
+
animation: false,
|
|
7475
7544
|
plugins: {
|
|
7476
7545
|
legend: { display: false },
|
|
7477
7546
|
tooltip: {
|
|
@@ -7479,10 +7548,18 @@ async function openRealTimeTelemetryModal(params) {
|
|
|
7479
7548
|
title: function(context) {
|
|
7480
7549
|
const timestamp = context[0].parsed.x;
|
|
7481
7550
|
const date = new Date(timestamp);
|
|
7482
|
-
return date.
|
|
7551
|
+
return date.toLocaleString(locale, {
|
|
7552
|
+
day: "2-digit",
|
|
7553
|
+
month: "2-digit",
|
|
7554
|
+
year: "numeric",
|
|
7555
|
+
hour: "2-digit",
|
|
7556
|
+
minute: "2-digit",
|
|
7557
|
+
second: "2-digit"
|
|
7558
|
+
});
|
|
7483
7559
|
},
|
|
7484
7560
|
label: function(context) {
|
|
7485
|
-
|
|
7561
|
+
const value = context.parsed.y;
|
|
7562
|
+
return getFormattedValue(selectedChartKey, value);
|
|
7486
7563
|
}
|
|
7487
7564
|
}
|
|
7488
7565
|
}
|
|
@@ -7491,23 +7568,57 @@ async function openRealTimeTelemetryModal(params) {
|
|
|
7491
7568
|
x: {
|
|
7492
7569
|
type: "linear",
|
|
7493
7570
|
ticks: {
|
|
7571
|
+
maxRotation: 45,
|
|
7572
|
+
minRotation: 0,
|
|
7494
7573
|
callback: function(value) {
|
|
7495
7574
|
const date = new Date(value);
|
|
7496
|
-
return date.toLocaleTimeString(locale, {
|
|
7575
|
+
return date.toLocaleTimeString(locale, {
|
|
7576
|
+
hour: "2-digit",
|
|
7577
|
+
minute: "2-digit",
|
|
7578
|
+
second: "2-digit"
|
|
7579
|
+
});
|
|
7497
7580
|
}
|
|
7581
|
+
},
|
|
7582
|
+
title: {
|
|
7583
|
+
display: true,
|
|
7584
|
+
text: "Hora"
|
|
7498
7585
|
}
|
|
7499
7586
|
},
|
|
7500
7587
|
y: {
|
|
7501
7588
|
beginAtZero: true,
|
|
7589
|
+
ticks: {
|
|
7590
|
+
callback: function(value) {
|
|
7591
|
+
if (selectedChartKey === "consumption" || selectedChartKey === "power") {
|
|
7592
|
+
if (value >= 1e3) {
|
|
7593
|
+
return `${(value / 1e3).toFixed(1)} kW`;
|
|
7594
|
+
}
|
|
7595
|
+
return `${value} W`;
|
|
7596
|
+
}
|
|
7597
|
+
return `${value} ${config.unit}`;
|
|
7598
|
+
}
|
|
7599
|
+
},
|
|
7502
7600
|
title: {
|
|
7503
7601
|
display: true,
|
|
7504
|
-
text: "
|
|
7602
|
+
text: selectedChartKey === "consumption" || selectedChartKey === "power" ? "W" : config.unit
|
|
7505
7603
|
}
|
|
7506
7604
|
}
|
|
7507
7605
|
}
|
|
7508
7606
|
}
|
|
7509
7607
|
});
|
|
7510
7608
|
}
|
|
7609
|
+
function updateChartKey(newKey) {
|
|
7610
|
+
selectedChartKey = newKey;
|
|
7611
|
+
if (chart) {
|
|
7612
|
+
chart.destroy();
|
|
7613
|
+
chart = null;
|
|
7614
|
+
}
|
|
7615
|
+
initializeChart();
|
|
7616
|
+
if (telemetryHistory.has(selectedChartKey)) {
|
|
7617
|
+
const selectedHistory = telemetryHistory.get(selectedChartKey);
|
|
7618
|
+
chart.data.datasets[0].data = selectedHistory;
|
|
7619
|
+
chart.update("none");
|
|
7620
|
+
}
|
|
7621
|
+
}
|
|
7511
7622
|
async function refreshData() {
|
|
7512
7623
|
try {
|
|
7513
7624
|
const data = await fetchLatestTelemetry();
|
|
@@ -7519,9 +7630,7 @@ async function openRealTimeTelemetryModal(params) {
|
|
|
7519
7630
|
if (loadingState.style.display !== "none") {
|
|
7520
7631
|
loadingState.style.display = "none";
|
|
7521
7632
|
telemetryContent.style.display = "block";
|
|
7522
|
-
|
|
7523
|
-
initializeChart();
|
|
7524
|
-
}
|
|
7633
|
+
initializeChart();
|
|
7525
7634
|
}
|
|
7526
7635
|
} catch (error) {
|
|
7527
7636
|
console.error("[RealTimeTelemetry] Error fetching data:", error);
|
|
@@ -7589,6 +7698,10 @@ async function openRealTimeTelemetryModal(params) {
|
|
|
7589
7698
|
closeBtn.addEventListener("click", closeModal);
|
|
7590
7699
|
pauseBtn.addEventListener("click", togglePause);
|
|
7591
7700
|
exportBtn.addEventListener("click", exportToCSV2);
|
|
7701
|
+
chartKeySelector.addEventListener("change", (e) => {
|
|
7702
|
+
const newKey = e.target.value;
|
|
7703
|
+
updateChartKey(newKey);
|
|
7704
|
+
});
|
|
7592
7705
|
overlay.addEventListener("click", (e) => {
|
|
7593
7706
|
if (e.target === overlay) {
|
|
7594
7707
|
closeModal();
|
|
@@ -11441,7 +11554,7 @@ var EnergyModalView = class {
|
|
|
11441
11554
|
let startDate;
|
|
11442
11555
|
let endDate;
|
|
11443
11556
|
if (this.dateRangePicker) {
|
|
11444
|
-
const dates = this.dateRangePicker.
|
|
11557
|
+
const dates = this.dateRangePicker.getDates();
|
|
11445
11558
|
startDate = dates.startISO;
|
|
11446
11559
|
endDate = dates.endISO;
|
|
11447
11560
|
} else {
|
|
@@ -11479,7 +11592,7 @@ var EnergyModalView = class {
|
|
|
11479
11592
|
token: jwtToken,
|
|
11480
11593
|
deviceId: this.config.params.deviceId,
|
|
11481
11594
|
deviceLabel: this.config.params.deviceLabel || "Dispositivo",
|
|
11482
|
-
telemetryKeys: ["
|
|
11595
|
+
telemetryKeys: ["voltage_a", "voltage_b", "voltage_c", "total_current", "consumption"],
|
|
11483
11596
|
refreshInterval: 8e3,
|
|
11484
11597
|
// 8 seconds
|
|
11485
11598
|
historyPoints: 50,
|