@sailingrotevista/rotevista-dash 6.1.1 → 6.1.2

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 (3) hide show
  1. package/app.js +33 -15
  2. package/index.js +10 -8
  3. package/package.json +1 -1
package/app.js CHANGED
@@ -128,6 +128,7 @@ function safeSetText(el, text) {
128
128
 
129
129
  /**
130
130
  * Inserimento sicuro nel buffer con trigonometria precaricata e pruning automatico
131
+ * Mantiene sempre almeno 60 minuti di memoria locale per il calcolo della bussola meteo.
131
132
  */
132
133
  function safePush(buffer, val, time) {
133
134
  if (val === null || val === undefined || isNaN(val)) return;
@@ -139,7 +140,11 @@ function safePush(buffer, val, time) {
139
140
  cos: Math.cos(val)
140
141
  });
141
142
 
142
- const maxHistoryMs = (CONFIG.graphs.historyMinutes * 60000 * 2) + 60000;
143
+ // Se stiamo spingendo nel buffer TWD, conserviamo sempre almeno 60 minuti in memoria locale
144
+ const isTwdBuffer = (buffer === store.longBuf.twd);
145
+ const limitMinutes = isTwdBuffer ? 60 : CONFIG.graphs.historyMinutes;
146
+ const maxHistoryMs = (limitMinutes * 60000 * 2) + 60000;
147
+
143
148
  while (buffer.length > 0 && (time - buffer[0].time) > maxHistoryMs) {
144
149
  buffer.shift();
145
150
  }
@@ -436,16 +441,20 @@ function processIncomingData(path, val, source, timeMs) {
436
441
 
437
442
  // ==========================================================================
438
443
  // 6. TREND VENTO (Tattico 2s vs 10s | Strategico 1m vs 10m)
444
+ // Sincronizzato sul tempo reale dei sensori per eliminare i conflitti di orologio.
439
445
  // ==========================================================================
440
446
  function updateWindTrend() {
441
- const now = Date.now();
442
-
443
- // --- 6.1 TREND TATTICO (AWA/TWA) ---
444
- const twaNow = getCircularAverageFromBuffer(store.longBuf.twa, 2000, true);
445
- const twaRef = getCircularAverageFromBuffer(store.longBuf.twa, 10000, true);
447
+ // --- RISOLUZIONE CLOCK DRIFT SUI PALLINI METEO ---
448
+ // Usiamo il tempo del sensore (l'ultimo dato del TWD in memoria) invece dell'orologio del tablet
449
+ const latestTwdPoint = store.longBuf.twd.length > 0 ? store.longBuf.twd[store.longBuf.twd.length - 1] : null;
450
+ const now = latestTwdPoint ? latestTwdPoint.time : Date.now();
451
+
452
+ // --- 6.1 TREND TATTICO (AWA/TWA Sintonizzato) ---
453
+ const twaNow = getCircularAverageFromBuffer(store.longBuf.twa, 2000, true, now);
454
+ const twaRef = getCircularAverageFromBuffer(store.longBuf.twa, 10000, true, now);
446
455
  const gaugeDots = { cw: document.getElementById('trend-gauge-cw'), ccw: document.getElementById('trend-gauge-ccw') };
447
456
 
448
- // --- 6.2 ALLARME STRAMBATA CON ISTERESI (MACCHINA A STATI ANTI-BRANDEGGIO) ---
457
+ // --- 6.2 ALLARME STRAMBATA CON ISTERESI (MACCHINA A STATI ANTI-BRANDEGGIO Sintonizzato) ---
449
458
  const instTwaRad = store.raw["environment.wind.angleTrueWater"];
450
459
  let smoothedTwaDeg = null;
451
460
 
@@ -530,11 +539,15 @@ function updateWindTrend() {
530
539
  }
531
540
  }
532
541
 
533
- // --- 6.3 TREND METEO STRATEGICO (TWD) ---
534
- const twdNow = getCircularAverageFromBuffer(store.longBuf.twd, 60000, false);
535
- const multiplier = isNavigating ? 1 : 2;
536
- const strategicWindowMs = CONFIG.graphs.historyMinutes * 60000 * multiplier;
537
- const twdRef = getCircularAverageFromBuffer(store.longBuf.twd, strategicWindowMs, false);
542
+ // --- 6.3 TREND METEO STRATEGICO (TWD PARAMETRIZZATO E SINTONIZZATO) ---
543
+ const twdNow = getCircularAverageFromBuffer(store.longBuf.twd, 60000, false, now); // 1 minuto fisso
544
+
545
+ // Parametrizzazione rigida nel codice: 15 minuti in navigazione, 60 minuti all'ancora
546
+ const fixedTwdMinutes = isNavigating ? 15 : 60;
547
+ const strategicWindowMs = fixedTwdMinutes * 60000;
548
+
549
+ const twdRef = getCircularAverageFromBuffer(store.longBuf.twd, strategicWindowMs, false, now);
550
+
538
551
  const compassDots = { cw: document.getElementById('trend-dot-cw'), ccw: document.getElementById('trend-dot-ccw') };
539
552
 
540
553
  if (twdNow && twdRef) {
@@ -894,11 +907,16 @@ async function fetchServerHistory() {
894
907
  }
895
908
  }
896
909
  // --- SILLABAZIONE STRATEGICA DELLA BUSSOLA METEO (TWD) ---
897
- // Se il server ci invia lo storico del TWD, lo inseriamo direttamente nella memoria a lungo termine
910
+ // Se il server ci invia lo storico del TWD, lo inseriamo calcolando i seni e coseni per i vettori
898
911
  if (data.twd && data.twd.length > 0) {
899
- store.longBuf.twd = data.twd;
912
+ store.longBuf.twd = data.twd.map(p => ({
913
+ val: p.val,
914
+ time: p.time,
915
+ sin: Math.sin(p.val),
916
+ cos: Math.cos(p.val)
917
+ }));
900
918
  console.log(`📈 Memoria strategica TWD sincronizzata dal server (${data.twd.length} punti).`);
901
- }
919
+ }
902
920
  console.log("📈 Storico dei grafici pre-popolato caricato dal server.");
903
921
  }
904
922
  } catch (err) {
package/index.js CHANGED
@@ -219,16 +219,18 @@ module.exports = function (app) {
219
219
  if (!isFinite(finalValue)) return;
220
220
  finalValue = Math.max(0, finalValue);
221
221
 
222
- // Salvataggio nel ring buffer dello storico principale
223
- histories[type].push({ val: finalValue, time: now });
222
+ // Salvataggio nel ring buffer dello storico principale
223
+ histories[type].push({ val: finalValue, time: now });
224
224
 
225
- // Pruning automatico basato sulle impostazioni di timeline
226
- const maxViewportMinutes = historyMinutes * 2;
227
- const maxHistoryMs = (maxViewportMinutes * 60000) + 60000;
225
+ // Pruning automatico basato sulle impostazioni di timeline
226
+ // (Forziamo il server a conservare sempre almeno 60 minuti per il TWD!)
227
+ const limitMinutes = (type === 'twd') ? 60 : historyMinutes;
228
+ const maxViewportMinutes = limitMinutes * 2;
229
+ const maxHistoryMs = (maxViewportMinutes * 60000) + 60000;
228
230
 
229
- while (histories[type].length > 0 && (now - histories[type][0].time) > maxHistoryMs) {
230
- histories[type].shift();
231
- }
231
+ while (histories[type].length > 0 && (now - histories[type][0].time) > maxHistoryMs) {
232
+ histories[type].shift();
233
+ }
232
234
 
233
235
  graphTempBuf[type] = [];
234
236
  // Spostiamo il timer esattamente al confine del secchiello assoluto appena concluso
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sailingrotevista/rotevista-dash",
3
- "version": "6.1.1",
3
+ "version": "6.1.2",
4
4
  "description": "Wind Dashboard with navigation and course aids",
5
5
  "main": "index.js",
6
6
  "publishConfig": {