@sailingrotevista/rotevista-dash 4.0.13 → 4.0.14

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.
Files changed (2) hide show
  1. package/app.js +42 -23
  2. package/package.json +1 -1
package/app.js CHANGED
@@ -17,7 +17,7 @@ let CONFIG = {
17
17
  depthWarning: 5.0
18
18
  },
19
19
  // Gestione parametri di stabilità e medie
20
- averages: {
20
+ averaging: {
21
21
  smoothWindow: 2000, // Smoothing puntatori (2s)
22
22
  longWindow: 30000, // Finestra per i valori MEAN (30s)
23
23
  stabilityTolerance: 2000, // Millisecondi per considerare il buffer "pieno"
@@ -146,7 +146,7 @@ function getCircularAverageFromBuffer(bufferArray, windowMs, signed = false) {
146
146
  let historyDuration = (validData.length > 2) ? (validData[validData.length - 1].time - validData[0].time) : 0;
147
147
 
148
148
  // Un dato è stabile se abbiamo abbastanza storia e la coerenza vettoriale R è alta
149
- let isStable = (historyDuration > 10000) && (R > CONFIG.averages.stabilityThreshold);
149
+ let isStable = (historyDuration > 10000) && (R > CONFIG.averaging.stabilityThreshold);
150
150
  let avgRad = Math.atan2(sSin, sCos);
151
151
 
152
152
  // Calcolo della Deviazione Standard Circolare (±) in gradi
@@ -401,7 +401,7 @@ const upUI = (el, obj, instantRaw, isCompass = false) => {
401
401
 
402
402
  let diff = Math.abs((radToDeg(instantRaw) - radToDeg(obj.val) + 540) % 360 - 180);
403
403
  // Allarme lampeggio solo se in navigazione E (R bassa O deviazione alta O salto istantaneo brusco)
404
- if (isNavigating && (!obj.stable || obj.dev > CONFIG.averages.stabilityBreakout || diff > CONFIG.averages.stabilityBreakout)) el.classList.add('unstable-data');
404
+ if (isNavigating && (!obj.stable || obj.dev > CONFIG.averaging.stabilityBreakout || diff > CONFIG.averaging.stabilityBreakout)) el.classList.add('unstable-data');
405
405
  else el.classList.remove('unstable-data');
406
406
  }
407
407
  };
@@ -420,7 +420,7 @@ function startDisplayLoop() {
420
420
  const sogKts = msToKts(store.raw["navigation.speedOverGround"] || 0);
421
421
 
422
422
  // Verifica stato navigazione basato su soglia impostata
423
- isNavigating = stwKts > CONFIG.averages.minSpeed || sogKts > CONFIG.averages.minSpeed;
423
+ isNavigating = stwKts > CONFIG.averaging.minSpeed || sogKts > CONFIG.averaging.minSpeed;
424
424
 
425
425
  // --- TIER LIVE (1s): CONTROLLO TIMEOUT DATI ---
426
426
  const watch = { "navigation.speedThroughWater": ui.stw, "navigation.speedOverGround": ui.sog, "navigation.headingTrue": ui.hdg, "navigation.courseOverGroundTrue": ui.cog, "environment.wind.speedApparent": ui.awsSvg, "environment.depth.belowTransducer": ui.depth, "environment.wind.speedTrue": ui.tws };
@@ -488,7 +488,7 @@ function startDisplayLoop() {
488
488
  if (store.raw["navigation.courseOverGroundTrue"] !== undefined && store.raw["navigation.headingTrue"] !== undefined) {
489
489
  let driftDeg = radToDeg((store.raw["navigation.courseOverGroundTrue"] - store.raw["navigation.headingTrue"] + Math.PI * 3) % (Math.PI * 2) - Math.PI);
490
490
  // Azzeramento sotto soglia minima impostata
491
- smoothedLeeway = (sogKts < CONFIG.averages.minSpeed) ? 0 : (smoothedLeeway * 0.9) + (driftDeg * 0.1);
491
+ smoothedLeeway = (sogKts < CONFIG.averaging.minSpeed) ? 0 : (smoothedLeeway * 0.9) + (driftDeg * 0.1);
492
492
  curTrackRot = getShortestRotation(curTrackRot, smoothedLeeway); ui.track.setAttribute('transform', `rotate(${curTrackRot}, 200, 200)`);
493
493
  ui.leewayVal.style.color = (Math.abs(sogKts - stwKts) > 0.5 && Math.abs(smoothedLeeway) > 7) ? "#e67e22" : "";
494
494
  updateLeewayDisplay(Math.max(-20, Math.min(20, smoothedLeeway)));
@@ -504,11 +504,11 @@ function startDisplayLoop() {
504
504
 
505
505
  // TIER SLOW (3s) - Medie Lunghe e Calcolo TACK
506
506
  if (lastAvgUIUpdate % 3 === 0) {
507
- let hObj = getCircularAverageFromBuffer(store.longBuf.hdg, CONFIG.averages.longWindow * 2, false);
508
- let cObj = getCircularAverageFromBuffer(store.longBuf.cog, CONFIG.averages.longWindow, false);
509
- let awObj = getCircularAverageFromBuffer(store.longBuf.awa, CONFIG.averages.longWindow, true);
510
- let twObj = getCircularAverageFromBuffer(store.longBuf.twa, CONFIG.averages.longWindow, true);
511
- let twdObj = getCircularAverageFromBuffer(store.longBuf.twd, CONFIG.averages.longWindow, false);
507
+ let hObj = getCircularAverageFromBuffer(store.longBuf.hdg, CONFIG.averaging.longWindow * 2, false);
508
+ let cObj = getCircularAverageFromBuffer(store.longBuf.cog, CONFIG.averaging.longWindow, false);
509
+ let awObj = getCircularAverageFromBuffer(store.longBuf.awa, CONFIG.averaging.longWindow, true);
510
+ let twObj = getCircularAverageFromBuffer(store.longBuf.twa, CONFIG.averaging.longWindow, true);
511
+ let twdObj = getCircularAverageFromBuffer(store.longBuf.twd, CONFIG.averaging.longWindow, false);
512
512
 
513
513
  upUI(ui.hdg, hObj, store.raw["navigation.headingTrue"], true);
514
514
  upUI(ui.cog, cObj, store.raw["navigation.courseOverGroundTrue"], true);
@@ -519,7 +519,7 @@ function startDisplayLoop() {
519
519
  // --- LOGICA TACK STRATEGICA (Riflessione geometrica su TWD) ---
520
520
  if (hObj && twdObj) {
521
521
  const tH = radToDeg((2 * twdObj.val - hObj.val + Math.PI * 2) % (Math.PI * 2));
522
- const unstableH = !hObj.stable || !twdObj.stable || hObj.dev > CONFIG.averages.stabilityBreakout || twdObj.dev > CONFIG.averages.stabilityBreakout;
522
+ const unstableH = !hObj.stable || !twdObj.stable || hObj.dev > CONFIG.averaging.stabilityBreakout || twdObj.dev > CONFIG.averaging.stabilityBreakout;
523
523
 
524
524
  if (!isNavigating) {
525
525
  ui.tackHdg.innerHTML = "---&deg;"; ui.tackHdg.classList.remove('unstable-data');
@@ -532,7 +532,7 @@ function startDisplayLoop() {
532
532
 
533
533
  if (cObj) {
534
534
  const tC = radToDeg((2 * twdObj.val - cObj.val + Math.PI * 2) % (Math.PI * 2));
535
- const unstableC = !cObj.stable || !twdObj.stable || cObj.dev > CONFIG.averages.stabilityBreakout || twdObj.dev > CONFIG.averages.stabilityBreakout;
535
+ const unstableC = !cObj.stable || !twdObj.stable || cObj.dev > CONFIG.averaging.stabilityBreakout || twdObj.dev > CONFIG.averaging.stabilityBreakout;
536
536
 
537
537
  if (!isNavigating) {
538
538
  ui.tackCog.innerHTML = "---&deg;"; ui.tackCog.classList.remove('unstable-data');
@@ -560,37 +560,56 @@ function startDisplayLoop() {
560
560
  // 8. CONFIGURAZIONE E GRAFICI UTILS
561
561
  // ==========================================================================
562
562
  /**
563
- * Recupera la configurazione tramite l'endpoint dedicato /rotevista-config.
564
- * Questo bypassa i blocchi di sicurezza standard di Signal K.
563
+ * Recupera la configurazione dal server con log di debug estesi.
565
564
  */
566
565
  async function fetchServerConfig() {
567
566
  try {
568
567
  const response = await fetch('/rotevista-config');
569
- if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
570
-
568
+ if (!response.ok) throw new Error(`HTTP Error: ${response.status}`);
569
+
571
570
  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);
572
574
 
573
- // Funzione di utilità per garantire che i valori siano numeri (evita bug nei grafici)
574
575
  const parse = (obj) => {
575
576
  for (let k in obj) {
576
- if (typeof obj[k] === 'object') parse(obj[k]);
577
+ if (typeof obj[k] === 'object' && obj[k] !== null) parse(obj[k]);
577
578
  else if (!isNaN(obj[k]) && typeof obj[k] === 'string' && obj[k] !== "")
578
579
  obj[k] = parseFloat(obj[k]);
579
580
  }
580
581
  return obj;
581
582
  };
582
583
 
583
- const actual = parse(data);
584
+ const actual = parse(JSON.parse(JSON.stringify(data))); // Cloniamo per sicurezza
585
+
586
+ // DEBUG 2: Visualizza i dati dopo la conversione numerica
587
+ console.log("⚙️ [DEBUG] Dati convertiti (numeric):", actual);
584
588
 
585
- // Fondiamo i dati del server con il CONFIG locale
589
+ // ASSEGNAZIONE E FUSIONE (Mappatura dei blocchi)
586
590
  if (actual.alarms) Object.assign(CONFIG.alarms, actual.alarms);
587
591
  if (actual.graphs) Object.assign(CONFIG.graphs, actual.graphs);
588
- if (actual.averaging) Object.assign(CONFIG.averages, actual.averaging);
592
+
593
+ // Gestione specifica per averaging (il blocco più critico)
594
+ if (actual.averaging) {
595
+ Object.assign(CONFIG.averaging, actual.averaging);
596
+ // DEBUG 3: Tabella comparativa per verificare minSpeed e soglie
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
+ });
606
+ }
607
+
589
608
  if (actual.scales) Object.assign(CONFIG.scales, actual.scales);
590
609
 
591
- console.log("✅ Configurazione sincronizzata via /rotevista-config");
610
+ console.log("✅ [SUCCESS] Configurazione sincronizzata correttamente.");
592
611
  } catch (err) {
593
- console.warn("⚠️ Utilizzo default locali (Endpoint non ancora attivo o server offline).");
612
+ console.warn("⚠️ [WARNING] Utilizzo default locali. Motivo:", err.message);
594
613
  }
595
614
  }
596
615
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sailingrotevista/rotevista-dash",
3
- "version": "4.0.13",
3
+ "version": "4.0.14",
4
4
  "description": "Public Wind Dashboard with navigation and course aids",
5
5
  "main": "index.js",
6
6
  "publishConfig": {