From 3f886e2ff04da5303ebc2264192b6755ab668079 Mon Sep 17 00:00:00 2001 From: Austin Rooks Date: Thu, 14 Nov 2024 09:33:35 -0600 Subject: [PATCH] increase forecast parsing fallback wait time --- assets/static/index.min.js | 2 +- client/index.js | 2 +- templates/base.html | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/assets/static/index.min.js b/assets/static/index.min.js index 7ed3dba..6c22b69 100644 --- a/assets/static/index.min.js +++ b/assets/static/index.min.js @@ -1 +1 @@ -!function(){"use strict";function e(e){if(null==e)throw"item is null or undefined";return e}function t(e){if(null==e)throw"item is null or undefined";if(e instanceof HTMLButtonElement)return e;throw"item is not a button"}function n(e,t){e instanceof Array?e.forEach((e=>a(e,t))):a(e,t)}function a(t,n){e(document.getElementById(t)).innerText=n}function i(e,t,n){document.getElementById(e)?.setAttribute(t,n)}function o(e,t){e instanceof Array?e.forEach((e=>{i(e,"style",t)})):i(e,"style",t)}function r(e){document.querySelectorAll(e).forEach((e=>e.remove()))}function l(e){document.getElementById(e)?.remove()}function s(e,t){document.getElementById(e)?.classList.remove(t)}function c(e){s(e,"hidden")}function d(e){document.getElementById(e).innerHTML+=''}function u(e){o(e,"background-color: #facc15; color: #000; display: flex; align-items: center; flex-direction: row-reverse; gap: 8px"),e instanceof Array?e.forEach((e=>{d(e)})):d(e)}const g="#a8a29e",p={"#0bd674":"Good","#ffcd1e":"Fair to Good","#ff9500":"Poor","#f4496d":"Very Poor","#a8a29e":"Flat"};let m,f,w,v,y,h,x,b,_,E,A,I;function q(e){const a=new Date(e.starting_at).getHours();let i=new Date(e.starting_at).getHours();if(a>20){let t=24-a;const n=e.wave_height_labels.length-(e.wave_height_labels.length-t)%24;i=0,f=e.wave_height_labels.slice(t,n),m=e.quality.slice(t,n),w=e.wave_height.slice(t,n),v=e.wind_speed.slice(t,n),y=e.wind_direction.slice(t,n),h=e.wind_gust.slice(t,n),x=e.wave_period.slice(t,n),b=e.temperature.slice(t,n),_=e.dewpoint.slice(t,n),E=e.cloud_cover.slice(t,n),A=e.probability_of_precipitation.slice(t,n),I=e.probability_of_thunder.slice(t,n)}else{const t=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"][new Date(e.starting_at).getDay()],n=[];for(let e=0;e=10&&e<12&&n.push(`${t} ${e} AM`),12===e&&n.push(`${t} ${e} PM`),e>12&&n.push(`${t} 0${e-12} PM`)):n.push(`${t} 12 AM`);const i=e.wave_height_labels.length+a-(e.wave_height_labels.length+a)%24;f=n.concat(e.wave_height_labels).slice(0,i),m=new Array(a).fill("#a8a29e").concat(e.quality).slice(0,i),w=new Array(a).fill(0).concat(e.wave_height).slice(0,i),v=new Array(a).fill(0).concat(e.wind_speed).slice(0,i),y=new Array(a).fill(0).concat(e.wind_direction).slice(0,i),h=new Array(a).fill(0).concat(e.wind_gust).slice(0,i),x=new Array(a).fill(0).concat(e.wave_period).slice(0,i),b=new Array(a).fill(0).concat(e.temperature).slice(0,i),_=new Array(a).fill(0).concat(e.dewpoint).slice(0,i),E=new Array(a).fill(0).concat(e.cloud_cover).slice(0,i),A=new Array(a).fill(0).concat(e.probability_of_precipitation).slice(0,i),I=new Array(a).fill(0).concat(e.probability_of_thunder).slice(0,i)}let d=(new Date).getHours();const q=document.getElementById("current-wave-height");""===q?.innerText&&(q.innerText=e.current_wave_height,"0"==e.current_wave_height&&(o("wave-quality",`background-color: ${g}`),n("wave-quality-text",p[g]),o("wave-quality-text",`color: ${g}`),r(".wave-quality-loader")),o("wave-icon",`transform: rotate(${e.current_wave_direction}deg);`),r(".wavey"));const k=document.getElementById("current-wave-period");""===k?.innerText&&(k.innerText=e.current_wave_period,l("wavey-period-loader")),n("legend-label",f[d]),n("legend-quality",p[m[d]]),n("legend-wave-height",w[d]),n("legend-wind-speed",v[d]),o("legend-wind-icon",`transform: rotate(${y[d]+180}deg);`),n("legend-wave-period",x[d]),n("legend-wind-gust",h[d]),n("forecast-as-of",`Updated ${e.as_of}`),n("forecast-as-of-2",`Updated ${e.as_of}`);new Date(e.as_of){e.corsair={x:0,y:0}},afterDraw:(e,t,n)=>{if(e.tooltip?._active?.length){let t=e.tooltip._active[0].element.x,a=e.scales.y,i=e.ctx;i.save(),i.beginPath(),i.moveTo(t,a.top),i.lineTo(t,a.bottom),i.lineWidth=1,i.setLineDash(n.dash),i.strokeStyle="#fff",i.stroke(),i.restore()}if(d-i>C){const t=e.ctx,n=e.scales.x.getPixelForValue(d-i);t.save(),t.strokeStyle="#5b5b58",t.lineWidth=1,t.beginPath(),t.moveTo(n,0),t.lineTo(n,e.height),t.stroke(),t.fillStyle="#5b5b58",t.font="bold 1rem ui-sans-serif, system-ui, sans-serif",t.fillText("Now",d>14&&24===D?n-45:n+5,15),t.restore()}}};function $(e){let t;t=0===C?e:e>=f.length-a?f.length-a-1:e;T(t+(0===C?i:C))}function T(e){const t=m[e];o("legend",`background-color: ${t}`),n("legend-label",f[e]),n("legend-quality",p[t]),n("legend-wave-height",w[e]),n("legend-wind-speed",v[e]),o("legend-wind-icon",`transform: rotate(${y[e]+180}deg);`),n("legend-wave-period",x[e]),n("legend-wind-gust",h[e]),n("temperature-legend-label",f[e]),n("temperature-legend-temperature",b[e]),n("temperature-legend-dewpoint",_[e]),n("precipitation-legend-label",f[e]),n("precipitation-legend-precipitation",A[e]),n("precipitation-legend-thunder",I[e]),n("precipitation-legend-cloud-cover",E[e])}const M=(e,t,n)=>{const a=Chart.helpers.getRelativePosition(e,n),i=function(e){return 24===D||48===D?e&&e>0?e>=w.length-C?w.length-C-1:e:0:e&&e>0?e>=w.length?w.length-1:e:0}(n.scales.x.getValueForPixel(a.x));$(i)},L=(e,t)=>{const n=0===C?i:C;return 24===D?t%6==0?f[t+n]:null:48===D?t%8==0?f[t+n]:null:t%24==0?f[t+n]:null};const S=()=>window.innerWidth<768?24:window.innerWidth<1024?48:w.length;let D=S(),C=0,F=C+D;const H={size:24===D?14:18,weight:"semi-bold"},P=e=>({aspectRatio:1.75,onHover:M,borderRadius:5,maintainAspectRatio:!1,plugins:{legend:{display:!1},tooltip:{enabled:!1}},responsive:!0,interaction:{intersect:!1,axis:"x"},scales:{x:{ticks:{callback:L}},y:{grid:{color:"#1B1B1B"},beginAtZero:!0,max:e??10,ticks:{callback:function(e){return e%2!=0?"":e},font:H}}}}),N=new Chart(document.getElementById("forecast"),{type:"bar",plugins:[B],data:{labels:0===C?f.slice(i,F):f.slice(C,F),datasets:[{label:"wave height (feet)",data:0===C?w.slice(i,F):w.slice(C,F),pointStyle:!1,minBarLength:.1}]},options:{...P(void 0),elements:{bar:{backgroundColor:e=>(e=>0===C?m[e.dataIndex+i]:m[e.dataIndex+C])(e)||"#4ade80"}}}});function O(e){n("forecast-range",e)}function W(){if(0===C){let e=a>20&&(new Date).getHours()>20;O(24===D?e?"Tomorrow":"Today":e?`Tomorrow - ${f[C+25].split(" ")[0]}`:"Today - Tomorrow")}else if(24===D)O(f[C].split(" ")[0]);else{const e=f[F-1]??f[f.length-1];O(`${f[C].split(" ")[0]} - ${e.split(" ")[0]}`)}}function J(){const e=0===C?i:C;let t=f.slice(e,F);N.data.labels=t,N.data.datasets[0].data=w.slice(e,F),N.update(),V.data.labels=t,V.data.datasets[0].data=b.slice(e,F),V.update(),j.data.labels=t,j.data.datasets[0].data=A.slice(e,F),j.update()}W(),window.addEventListener("resize",(()=>{D=S(),C+D>f.length?(F=f.length,C=f.length-D):F=C+D,J(),$(0),0===C&&(t(document.getElementById("forecast-backward")).disabled=!0),C+D=w.length&&(t(document.getElementById("forecast-foreward")).disabled=!0),C>0&&(t(document.getElementById("forecast-backward")).disabled=!1),W()})),document.getElementById("forecast-backward")?.addEventListener("click",(()=>{C-D<0?(C=0,F=D):(F-=D,C-=D),J(),0===C?T(d):$(0),0===C&&(t(document.getElementById("forecast-backward")).disabled=!0),C+D{F+D>f.length?(F=f.length,C=F-D):(C+=D,F+=D),J(),$(0),C+D>=w.length&&(t(document.getElementById("forecast-foreward")).disabled=!0),C>0&&(t(document.getElementById("forecast-backward")).disabled=!1),W()}));const R=(e,t,n)=>({type:"bar",plugins:[B],data:{labels:0===C?f.slice(i,F):f.slice(C,F),datasets:[{label:n,data:e,pointStyle:!1,minBarLength:.1}]},options:{...P(100),elements:{bar:t?{backgroundColor:t,borderColor:t}:{}}}}),U=document.getElementById("temperature-forecast"),V=new Chart(U,R(0===C?b.slice(i,F):b.slice(C,F),"pink","F")),Z=document.getElementById("precipitation-forecast"),j=new Chart(Z,R(0===C?A.slice(i,F):A.slice(C,F),null,"%"));function z(e){const t=N.getElementsAtEventForMode(e,"nearest",{axis:"x",intersect:!1},!0);if(t[0]){const e=t[0].datasetIndex,n=t[0].index;V.tooltip.setActiveElements([{datasetIndex:e,index:n}]),V.setActiveElements([{datasetIndex:e,index:n}]),V.update(),j.tooltip.setActiveElements([{datasetIndex:e,index:n}]),j.setActiveElements([{datasetIndex:e,index:n}]),j.update()}else V.tooltip.setActiveElements([],{x:0,y:0}),V.setActiveElements([],{x:0,y:0}),V.update(),j.tooltip.setActiveElements([],{x:0,y:0}),j.setActiveElements([],{x:0,y:0}),j.update()}function G(e){const t=V.getElementsAtEventForMode(e,"nearest",{axis:"x",intersect:!1},!0);if(t[0]){const e=t[0].datasetIndex,n=t[0].index;N.tooltip.setActiveElements([{datasetIndex:e,index:n}]),N.setActiveElements([{datasetIndex:e,index:n}]),N.update(),j.tooltip.setActiveElements([{datasetIndex:e,index:n}]),j.setActiveElements([{datasetIndex:e,index:n}]),j.update()}else N.tooltip.setActiveElements([],{x:0,y:0}),N.setActiveElements([],{x:0,y:0}),N.update(),j.tooltip.setActiveElements([],{x:0,y:0}),j.setActiveElements([],{x:0,y:0}),j.update()}function K(e){const t=j.getElementsAtEventForMode(e,"nearest",{axis:"x",intersect:!1},!0);if(t[0]){const e=t[0].datasetIndex,n=t[0].index;V.tooltip.setActiveElements([{datasetIndex:e,index:n}]),V.setActiveElements([{datasetIndex:e,index:n}]),V.update(),N.tooltip.setActiveElements([{datasetIndex:e,index:n}]),N.setActiveElements([{datasetIndex:e,index:n}]),N.update()}else V.tooltip.setActiveElements([],{x:0,y:0}),V.setActiveElements([],{x:0,y:0}),V.update(),N.tooltip.setActiveElements([],{x:0,y:0}),N.setActiveElements([],{x:0,y:0}),N.update()}N.canvas.onmousemove=z,V.canvas.onmousemove=G,j.canvas.onmousemove=K,N.canvas.ontouchmove=z,V.canvas.ontouchmove=G,j.canvas.ontouchmove=K}function k(t){t.wave_height&&(n("current-wave-height",t.wave_height),o("wave-icon",`transform: rotate(${t.wave_direction}deg);`),r(".wavey")),t.wave_period&&(n("current-wave-period",t.wave_period),l("wavey-period-loader")),(""===e(document.getElementById("wave-quality-text")).innerText||t.wave_height||parseFloat(e(document.getElementById("current-wave-height")).innerText??"0")>=1)&&(o("wave-quality",`background-color: ${t.quality_color};`),n("wave-quality-text",t.quality_text),o("wave-quality-text",`color: ${t.quality_color}`),r(".wave-quality-loader")),n("current-water-temp",t.water_temp),n("current-air-temp",t.air_temp),n("current-air-temp-2",t.air_temp),n("wind",B(t)),n("as-of",`As of ${t.as_of}`),o("wind-icon",`transform: rotate(${t.wind_direction+180}deg);`),r(".latest-loader"),c("wind-icon-container"),c("wave-icon-container"),s("as-of-container","animate-pulse"),c("wave-quality"),t.loaded_from_fallback&&c("wave-fallback-icon");let a=new Date(t.as_of)e.wind_speed===e.gusts||"0"===e.gusts?e.wind_speed:`${e.wind_speed}-${e.gusts}`;function $(t){var n,a;l("forecast-container"),n="forecast-error",a=`\n
\n

\n Error loading forecast data - please refresh the page or try again later.\n

\n

${t}

\n
\n `,e(document.getElementById(n)).innerHTML=a}const T=e(document.querySelector("body"));async function M(e){try{q(JSON.parse(e.target.innerText))}catch{await(t=500,new Promise((e=>setTimeout(e,t))));try{q(JSON.parse(e.target.innerText))}catch(e){$(e)}}var t}new MutationObserver((async e=>{for(const a of e)a.target instanceof HTMLElement&&("realtime-data"===a.target.id&&k(JSON.parse(a.target.innerText)),"water-quality-data"===a.target.id&&(t=JSON.parse(a.target.innerText),r(".water-quality-loader"),c("current-water-quality"),n("current-water-quality-title","Closed for season"===t.water_quality?"-----":t.water_quality.toUpperCase()),n("current-water-quality-status-text",t.water_quality_text),"Advisory"===t.water_quality&&o("current-water-quality-title","color: #facc15;"),"Closed"===t.water_quality&&o("current-water-quality-title","color: #ef4444;")),"forecast-data"===a.target.id&&await M(a));var t})).observe(T,{attributes:!0,childList:!0,subtree:!0})}(); +!function(){"use strict";function e(e){if(null==e)throw"item is null or undefined";return e}function t(e){if(null==e)throw"item is null or undefined";if(e instanceof HTMLButtonElement)return e;throw"item is not a button"}function n(e,t){e instanceof Array?e.forEach((e=>a(e,t))):a(e,t)}function a(t,n){e(document.getElementById(t)).innerText=n}function i(e,t,n){document.getElementById(e)?.setAttribute(t,n)}function o(e,t){e instanceof Array?e.forEach((e=>{i(e,"style",t)})):i(e,"style",t)}function r(e){document.querySelectorAll(e).forEach((e=>e.remove()))}function l(e){document.getElementById(e)?.remove()}function s(e,t){document.getElementById(e)?.classList.remove(t)}function c(e){s(e,"hidden")}function d(e){document.getElementById(e).innerHTML+=''}function u(e){o(e,"background-color: #facc15; color: #000; display: flex; align-items: center; flex-direction: row-reverse; gap: 8px"),e instanceof Array?e.forEach((e=>{d(e)})):d(e)}const g="#a8a29e",p={"#0bd674":"Good","#ffcd1e":"Fair to Good","#ff9500":"Poor","#f4496d":"Very Poor","#a8a29e":"Flat"};let m,f,w,v,y,h,x,b,_,E,A,I;function q(e){const a=new Date(e.starting_at).getHours();let i=new Date(e.starting_at).getHours();if(a>20){let t=24-a;const n=e.wave_height_labels.length-(e.wave_height_labels.length-t)%24;i=0,f=e.wave_height_labels.slice(t,n),m=e.quality.slice(t,n),w=e.wave_height.slice(t,n),v=e.wind_speed.slice(t,n),y=e.wind_direction.slice(t,n),h=e.wind_gust.slice(t,n),x=e.wave_period.slice(t,n),b=e.temperature.slice(t,n),_=e.dewpoint.slice(t,n),E=e.cloud_cover.slice(t,n),A=e.probability_of_precipitation.slice(t,n),I=e.probability_of_thunder.slice(t,n)}else{const t=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"][new Date(e.starting_at).getDay()],n=[];for(let e=0;e=10&&e<12&&n.push(`${t} ${e} AM`),12===e&&n.push(`${t} ${e} PM`),e>12&&n.push(`${t} 0${e-12} PM`)):n.push(`${t} 12 AM`);const i=e.wave_height_labels.length+a-(e.wave_height_labels.length+a)%24;f=n.concat(e.wave_height_labels).slice(0,i),m=new Array(a).fill("#a8a29e").concat(e.quality).slice(0,i),w=new Array(a).fill(0).concat(e.wave_height).slice(0,i),v=new Array(a).fill(0).concat(e.wind_speed).slice(0,i),y=new Array(a).fill(0).concat(e.wind_direction).slice(0,i),h=new Array(a).fill(0).concat(e.wind_gust).slice(0,i),x=new Array(a).fill(0).concat(e.wave_period).slice(0,i),b=new Array(a).fill(0).concat(e.temperature).slice(0,i),_=new Array(a).fill(0).concat(e.dewpoint).slice(0,i),E=new Array(a).fill(0).concat(e.cloud_cover).slice(0,i),A=new Array(a).fill(0).concat(e.probability_of_precipitation).slice(0,i),I=new Array(a).fill(0).concat(e.probability_of_thunder).slice(0,i)}let d=(new Date).getHours();const q=document.getElementById("current-wave-height");""===q?.innerText&&(q.innerText=e.current_wave_height,"0"==e.current_wave_height&&(o("wave-quality",`background-color: ${g}`),n("wave-quality-text",p[g]),o("wave-quality-text",`color: ${g}`),r(".wave-quality-loader")),o("wave-icon",`transform: rotate(${e.current_wave_direction}deg);`),r(".wavey"));const k=document.getElementById("current-wave-period");""===k?.innerText&&(k.innerText=e.current_wave_period,l("wavey-period-loader")),n("legend-label",f[d]),n("legend-quality",p[m[d]]),n("legend-wave-height",w[d]),n("legend-wind-speed",v[d]),o("legend-wind-icon",`transform: rotate(${y[d]+180}deg);`),n("legend-wave-period",x[d]),n("legend-wind-gust",h[d]),n("forecast-as-of",`Updated ${e.as_of}`),n("forecast-as-of-2",`Updated ${e.as_of}`);new Date(e.as_of){e.corsair={x:0,y:0}},afterDraw:(e,t,n)=>{if(e.tooltip?._active?.length){let t=e.tooltip._active[0].element.x,a=e.scales.y,i=e.ctx;i.save(),i.beginPath(),i.moveTo(t,a.top),i.lineTo(t,a.bottom),i.lineWidth=1,i.setLineDash(n.dash),i.strokeStyle="#fff",i.stroke(),i.restore()}if(d-i>C){const t=e.ctx,n=e.scales.x.getPixelForValue(d-i);t.save(),t.strokeStyle="#5b5b58",t.lineWidth=1,t.beginPath(),t.moveTo(n,0),t.lineTo(n,e.height),t.stroke(),t.fillStyle="#5b5b58",t.font="bold 1rem ui-sans-serif, system-ui, sans-serif",t.fillText("Now",d>14&&24===D?n-45:n+5,15),t.restore()}}};function $(e){let t;t=0===C?e:e>=f.length-a?f.length-a-1:e;T(t+(0===C?i:C))}function T(e){const t=m[e];o("legend",`background-color: ${t}`),n("legend-label",f[e]),n("legend-quality",p[t]),n("legend-wave-height",w[e]),n("legend-wind-speed",v[e]),o("legend-wind-icon",`transform: rotate(${y[e]+180}deg);`),n("legend-wave-period",x[e]),n("legend-wind-gust",h[e]),n("temperature-legend-label",f[e]),n("temperature-legend-temperature",b[e]),n("temperature-legend-dewpoint",_[e]),n("precipitation-legend-label",f[e]),n("precipitation-legend-precipitation",A[e]),n("precipitation-legend-thunder",I[e]),n("precipitation-legend-cloud-cover",E[e])}const M=(e,t,n)=>{const a=Chart.helpers.getRelativePosition(e,n),i=function(e){return 24===D||48===D?e&&e>0?e>=w.length-C?w.length-C-1:e:0:e&&e>0?e>=w.length?w.length-1:e:0}(n.scales.x.getValueForPixel(a.x));$(i)},L=(e,t)=>{const n=0===C?i:C;return 24===D?t%6==0?f[t+n]:null:48===D?t%8==0?f[t+n]:null:t%24==0?f[t+n]:null};const S=()=>window.innerWidth<768?24:window.innerWidth<1024?48:w.length;let D=S(),C=0,F=C+D;const H={size:24===D?14:18,weight:"semi-bold"},P=e=>({aspectRatio:1.75,onHover:M,borderRadius:5,maintainAspectRatio:!1,plugins:{legend:{display:!1},tooltip:{enabled:!1}},responsive:!0,interaction:{intersect:!1,axis:"x"},scales:{x:{ticks:{callback:L}},y:{grid:{color:"#1B1B1B"},beginAtZero:!0,max:e??10,ticks:{callback:function(e){return e%2!=0?"":e},font:H}}}}),N=new Chart(document.getElementById("forecast"),{type:"bar",plugins:[B],data:{labels:0===C?f.slice(i,F):f.slice(C,F),datasets:[{label:"wave height (feet)",data:0===C?w.slice(i,F):w.slice(C,F),pointStyle:!1,minBarLength:.1}]},options:{...P(void 0),elements:{bar:{backgroundColor:e=>(e=>0===C?m[e.dataIndex+i]:m[e.dataIndex+C])(e)||"#4ade80"}}}});function O(e){n("forecast-range",e)}function W(){if(0===C){let e=a>20&&(new Date).getHours()>20;O(24===D?e?"Tomorrow":"Today":e?`Tomorrow - ${f[C+25].split(" ")[0]}`:"Today - Tomorrow")}else if(24===D)O(f[C].split(" ")[0]);else{const e=f[F-1]??f[f.length-1];O(`${f[C].split(" ")[0]} - ${e.split(" ")[0]}`)}}function J(){const e=0===C?i:C;let t=f.slice(e,F);N.data.labels=t,N.data.datasets[0].data=w.slice(e,F),N.update(),V.data.labels=t,V.data.datasets[0].data=b.slice(e,F),V.update(),j.data.labels=t,j.data.datasets[0].data=A.slice(e,F),j.update()}W(),window.addEventListener("resize",(()=>{D=S(),C+D>f.length?(F=f.length,C=f.length-D):F=C+D,J(),$(0),0===C&&(t(document.getElementById("forecast-backward")).disabled=!0),C+D=w.length&&(t(document.getElementById("forecast-foreward")).disabled=!0),C>0&&(t(document.getElementById("forecast-backward")).disabled=!1),W()})),document.getElementById("forecast-backward")?.addEventListener("click",(()=>{C-D<0?(C=0,F=D):(F-=D,C-=D),J(),0===C?T(d):$(0),0===C&&(t(document.getElementById("forecast-backward")).disabled=!0),C+D{F+D>f.length?(F=f.length,C=F-D):(C+=D,F+=D),J(),$(0),C+D>=w.length&&(t(document.getElementById("forecast-foreward")).disabled=!0),C>0&&(t(document.getElementById("forecast-backward")).disabled=!1),W()}));const R=(e,t,n)=>({type:"bar",plugins:[B],data:{labels:0===C?f.slice(i,F):f.slice(C,F),datasets:[{label:n,data:e,pointStyle:!1,minBarLength:.1}]},options:{...P(100),elements:{bar:t?{backgroundColor:t,borderColor:t}:{}}}}),U=document.getElementById("temperature-forecast"),V=new Chart(U,R(0===C?b.slice(i,F):b.slice(C,F),"pink","F")),Z=document.getElementById("precipitation-forecast"),j=new Chart(Z,R(0===C?A.slice(i,F):A.slice(C,F),null,"%"));function z(e){const t=N.getElementsAtEventForMode(e,"nearest",{axis:"x",intersect:!1},!0);if(t[0]){const e=t[0].datasetIndex,n=t[0].index;V.tooltip.setActiveElements([{datasetIndex:e,index:n}]),V.setActiveElements([{datasetIndex:e,index:n}]),V.update(),j.tooltip.setActiveElements([{datasetIndex:e,index:n}]),j.setActiveElements([{datasetIndex:e,index:n}]),j.update()}else V.tooltip.setActiveElements([],{x:0,y:0}),V.setActiveElements([],{x:0,y:0}),V.update(),j.tooltip.setActiveElements([],{x:0,y:0}),j.setActiveElements([],{x:0,y:0}),j.update()}function G(e){const t=V.getElementsAtEventForMode(e,"nearest",{axis:"x",intersect:!1},!0);if(t[0]){const e=t[0].datasetIndex,n=t[0].index;N.tooltip.setActiveElements([{datasetIndex:e,index:n}]),N.setActiveElements([{datasetIndex:e,index:n}]),N.update(),j.tooltip.setActiveElements([{datasetIndex:e,index:n}]),j.setActiveElements([{datasetIndex:e,index:n}]),j.update()}else N.tooltip.setActiveElements([],{x:0,y:0}),N.setActiveElements([],{x:0,y:0}),N.update(),j.tooltip.setActiveElements([],{x:0,y:0}),j.setActiveElements([],{x:0,y:0}),j.update()}function K(e){const t=j.getElementsAtEventForMode(e,"nearest",{axis:"x",intersect:!1},!0);if(t[0]){const e=t[0].datasetIndex,n=t[0].index;V.tooltip.setActiveElements([{datasetIndex:e,index:n}]),V.setActiveElements([{datasetIndex:e,index:n}]),V.update(),N.tooltip.setActiveElements([{datasetIndex:e,index:n}]),N.setActiveElements([{datasetIndex:e,index:n}]),N.update()}else V.tooltip.setActiveElements([],{x:0,y:0}),V.setActiveElements([],{x:0,y:0}),V.update(),N.tooltip.setActiveElements([],{x:0,y:0}),N.setActiveElements([],{x:0,y:0}),N.update()}N.canvas.onmousemove=z,V.canvas.onmousemove=G,j.canvas.onmousemove=K,N.canvas.ontouchmove=z,V.canvas.ontouchmove=G,j.canvas.ontouchmove=K}function k(t){t.wave_height&&(n("current-wave-height",t.wave_height),o("wave-icon",`transform: rotate(${t.wave_direction}deg);`),r(".wavey")),t.wave_period&&(n("current-wave-period",t.wave_period),l("wavey-period-loader")),(""===e(document.getElementById("wave-quality-text")).innerText||t.wave_height||parseFloat(e(document.getElementById("current-wave-height")).innerText??"0")>=1)&&(o("wave-quality",`background-color: ${t.quality_color};`),n("wave-quality-text",t.quality_text),o("wave-quality-text",`color: ${t.quality_color}`),r(".wave-quality-loader")),n("current-water-temp",t.water_temp),n("current-air-temp",t.air_temp),n("current-air-temp-2",t.air_temp),n("wind",B(t)),n("as-of",`As of ${t.as_of}`),o("wind-icon",`transform: rotate(${t.wind_direction+180}deg);`),r(".latest-loader"),c("wind-icon-container"),c("wave-icon-container"),s("as-of-container","animate-pulse"),c("wave-quality"),t.loaded_from_fallback&&c("wave-fallback-icon");let a=new Date(t.as_of)e.wind_speed===e.gusts||"0"===e.gusts?e.wind_speed:`${e.wind_speed}-${e.gusts}`;function $(t){var n,a;l("forecast-container"),n="forecast-error",a=`\n
\n

\n Error loading forecast data - please refresh the page or try again later.\n

\n

${t}

\n
\n `,e(document.getElementById(n)).innerHTML=a}const T=e(document.querySelector("body"));async function M(e){try{q(JSON.parse(e.target.innerText))}catch{await(t=1e3,new Promise((e=>setTimeout(e,t))));try{q(JSON.parse(e.target.innerText))}catch(e){$(e)}}var t}new MutationObserver((async e=>{for(const a of e)a.target instanceof HTMLElement&&("realtime-data"===a.target.id&&k(JSON.parse(a.target.innerText)),"water-quality-data"===a.target.id&&(t=JSON.parse(a.target.innerText),r(".water-quality-loader"),c("current-water-quality"),n("current-water-quality-title","Closed for season"===t.water_quality?"-----":t.water_quality.toUpperCase()),n("current-water-quality-status-text",t.water_quality_text),"Advisory"===t.water_quality&&o("current-water-quality-title","color: #facc15;"),"Closed"===t.water_quality&&o("current-water-quality-title","color: #ef4444;")),"forecast-data"===a.target.id&&await M(a));var t})).observe(T,{attributes:!0,childList:!0,subtree:!0})}(); diff --git a/client/index.js b/client/index.js index d45c345..0c7ff88 100644 --- a/client/index.js +++ b/client/index.js @@ -42,7 +42,7 @@ async function parseForecastData(mutation) { try { parseForecast(JSON.parse(mutation.target.innerText)); } catch { - await wait(500); + await wait(1000); try { parseForecast(JSON.parse(mutation.target.innerText)); } catch (e) { diff --git a/templates/base.html b/templates/base.html index f7b5bdf..c189bb3 100644 --- a/templates/base.html +++ b/templates/base.html @@ -37,7 +37,7 @@ rel="stylesheet" /> - + @@ -66,7 +66,7 @@ @keyup.escape="showLiveFeed = false; showNav = false;" :class="{ 'overflow-hidden': showNav || showLiveFeed }" > - + {% block body %} {% endblock %} {% include "includes/footer.html" %} {% if live_reload %}