@sailingrotevista/rotevista-dash 4.0.14 → 4.0.15
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/app.js +27 -48
- package/package.json +1 -1
package/app.js
CHANGED
|
@@ -12,36 +12,23 @@
|
|
|
12
12
|
// 1. CONFIGURAZIONE E DEFAULT
|
|
13
13
|
// ==========================================================================
|
|
14
14
|
let CONFIG = {
|
|
15
|
-
alarms: {
|
|
16
|
-
depthDanger: 2.5,
|
|
17
|
-
depthWarning: 5.0
|
|
18
|
-
},
|
|
19
|
-
// Gestione parametri di stabilità e medie
|
|
15
|
+
alarms: { depthDanger: 2.5, depthWarning: 5.0 },
|
|
20
16
|
averaging: {
|
|
21
|
-
smoothWindow: 2000,
|
|
22
|
-
longWindow: 30000,
|
|
23
|
-
stabilityTolerance: 2000,
|
|
24
|
-
stabilityThreshold: 0.85,
|
|
25
|
-
minSpeed: 0,
|
|
17
|
+
smoothWindow: 2000,
|
|
18
|
+
longWindow: 30000,
|
|
19
|
+
stabilityTolerance: 2000,
|
|
20
|
+
stabilityThreshold: 0.85,
|
|
21
|
+
minSpeed: 0.5,
|
|
26
22
|
stabilityBreakout: 15
|
|
27
23
|
},
|
|
28
|
-
|
|
29
|
-
graphs: {
|
|
30
|
-
reef1: 15.0, // Soglia primo reef (Orange)
|
|
31
|
-
reef2: 20.0, // Soglia secondo reef (Red)
|
|
32
|
-
historyMinutes: 5, // Finestra temporale visualizzata
|
|
33
|
-
samples: 60 // Numero di punti di campionamento
|
|
34
|
-
},
|
|
35
|
-
// Configurazioni scale automatiche
|
|
24
|
+
graphs: { reef1: 15.0, reef2: 20.0, historyMinutes: 5, samples: 60 },
|
|
36
25
|
scales: {
|
|
37
26
|
stw: { stdMax: 12, hercSpan: 4, step: 2 },
|
|
38
27
|
sog: { stdMax: 12, hercSpan: 4, step: 2 },
|
|
39
28
|
tws: { stdMax: 25, hercSpan: 10, step: 5 },
|
|
40
29
|
depth: { stdMax: 20, hercSpan: 10, step: 10 }
|
|
41
30
|
},
|
|
42
|
-
server: {
|
|
43
|
-
fallbackIp: "192.168.111.240:3000"
|
|
44
|
-
}
|
|
31
|
+
server: { fallbackIp: "192.168.111.240:3000" }
|
|
45
32
|
};
|
|
46
33
|
|
|
47
34
|
const RENDER_INTERVAL_MS = 1000;
|
|
@@ -560,18 +547,15 @@ function startDisplayLoop() {
|
|
|
560
547
|
// 8. CONFIGURAZIONE E GRAFICI UTILS
|
|
561
548
|
// ==========================================================================
|
|
562
549
|
/**
|
|
563
|
-
* Recupera la configurazione
|
|
550
|
+
* Recupera la configurazione e forza la sovrascrittura di ogni parametro.
|
|
564
551
|
*/
|
|
565
552
|
async function fetchServerConfig() {
|
|
566
553
|
try {
|
|
567
554
|
const response = await fetch('/rotevista-config');
|
|
568
|
-
if (!response.ok) throw new Error(`
|
|
569
|
-
|
|
555
|
+
if (!response.ok) throw new Error(`Server offline o rotta non trovata`);
|
|
570
556
|
const data = await response.json();
|
|
571
|
-
|
|
572
|
-
// DEBUG 1: Visualizza i dati esattamente come arrivano dal server
|
|
573
|
-
console.log("📥 [DEBUG] Dati grezzi ricevuti dal server:", data);
|
|
574
557
|
|
|
558
|
+
// 1. Funzione di pulizia: trasforma stringhe in numeri
|
|
575
559
|
const parse = (obj) => {
|
|
576
560
|
for (let k in obj) {
|
|
577
561
|
if (typeof obj[k] === 'object' && obj[k] !== null) parse(obj[k]);
|
|
@@ -580,36 +564,31 @@ async function fetchServerConfig() {
|
|
|
580
564
|
}
|
|
581
565
|
return obj;
|
|
582
566
|
};
|
|
567
|
+
const actual = parse(data);
|
|
583
568
|
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
// DEBUG 2: Visualizza i dati dopo la conversione numerica
|
|
587
|
-
console.log("⚙️ [DEBUG] Dati convertiti (numeric):", actual);
|
|
588
|
-
|
|
589
|
-
// ASSEGNAZIONE E FUSIONE (Mappatura dei blocchi)
|
|
569
|
+
// 2. Mappatura Forzata (Deep Merge)
|
|
590
570
|
if (actual.alarms) Object.assign(CONFIG.alarms, actual.alarms);
|
|
591
|
-
if (actual.graphs) Object.assign(CONFIG.graphs, actual.graphs);
|
|
592
571
|
|
|
593
|
-
|
|
572
|
+
if (actual.graphs) {
|
|
573
|
+
Object.assign(CONFIG.graphs, actual.graphs);
|
|
574
|
+
console.log(`📈 GRAFICI: Durata ${CONFIG.graphs.historyMinutes}m | Reef1: ${CONFIG.graphs.reef1}kts | Reef2: ${CONFIG.graphs.reef2}kts`);
|
|
575
|
+
}
|
|
576
|
+
|
|
594
577
|
if (actual.averaging) {
|
|
595
578
|
Object.assign(CONFIG.averaging, actual.averaging);
|
|
596
|
-
|
|
597
|
-
console.table({
|
|
598
|
-
"Parametro": ["longWindow", "minSpeed", "stabilityThreshold", "stabilityBreakout"],
|
|
599
|
-
"Valore Attuale": [
|
|
600
|
-
CONFIG.averaging.longWindow,
|
|
601
|
-
CONFIG.averaging.minSpeed,
|
|
602
|
-
CONFIG.averaging.stabilityThreshold,
|
|
603
|
-
CONFIG.averaging.stabilityBreakout
|
|
604
|
-
]
|
|
605
|
-
});
|
|
579
|
+
console.log(`⏱️ STABILITÀ: MinSpeed ${CONFIG.averaging.minSpeed}kts | Breakout: ${CONFIG.averaging.stabilityBreakout}°`);
|
|
606
580
|
}
|
|
607
581
|
|
|
608
|
-
if (actual.scales)
|
|
582
|
+
if (actual.scales) {
|
|
583
|
+
// Per le scale facciamo un merge profondo per ogni box
|
|
584
|
+
for (let key in actual.scales) {
|
|
585
|
+
if (CONFIG.scales[key]) Object.assign(CONFIG.scales[key], actual.scales[key]);
|
|
586
|
+
}
|
|
587
|
+
}
|
|
609
588
|
|
|
610
|
-
console.log("✅
|
|
589
|
+
console.log("✅ Configurazione sincronizzata con successo.");
|
|
611
590
|
} catch (err) {
|
|
612
|
-
console.warn("⚠️
|
|
591
|
+
console.warn("⚠️ Utilizzo default locali. Motivo:", err.message);
|
|
613
592
|
}
|
|
614
593
|
}
|
|
615
594
|
|