From e74892159c53d29281fc24cf01dd87528d223dc9 Mon Sep 17 00:00:00 2001 From: ana Date: Sun, 8 Aug 2021 19:17:02 +0200 Subject: fix: account for d/n when predicting future stuff --- src/App.svelte | 14 -------------- src/bestiary.js | 11 ++++++++++- 2 files changed, 10 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/App.svelte b/src/App.svelte index 4cc445f..502f465 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -28,20 +28,6 @@ }, 10000); // 10 seconds $: currentEzTime = formatUtc(date); - function formatWeathers(weathers) { - if (weathers.length === 1) { - return ew.getWeatherName(weathers[0]); - } - return weathers - .map((w, i) => { - if (i + 1 === weathers.length) { - return `and ${ew.getWeatherName(w)}`; - } - return `${ew.getWeatherName(w)}, `; - }) - .join(""); - } - function newForecasts() { anemosForecast = ew.forecast(ew.ANEMOS_WEATHER, "anemos"); pagosForecast = ew.forecast(ew.PAGOS_WEATHER, "pagos"); diff --git a/src/bestiary.js b/src/bestiary.js index b09a613..6eac997 100644 --- a/src/bestiary.js +++ b/src/bestiary.js @@ -46,7 +46,7 @@ function findForecastMatch(forecast, conditions) { isUp: forecastMatches(forecast, conditions[dn], 0), weathers: conditions[dn], futureUptime: [1, 2, 3, 4].map((i) => { - return forecastMatches(forecast, conditions[dn], i); + return futureForecastMatches(forecast, conditions, i); }), }; } @@ -55,3 +55,12 @@ function forecastMatches(forecast, condition, index) { const currWeather = forecast[index].currWeather; return condition.some((c) => c === currWeather); } + +function futureForecastMatches(forecast, conditions, index) { + const fc = forecast[index]; + const fcTime = day((fc.date.getTime() * 1440) / 70); + const dn = day(fcTime).isBetween(fcTime.hour(8), fcTime.hour(18)) + ? "day" + : "night"; + return conditions[dn].some((c) => c === fc.currWeather); +} -- cgit 1.4.1-2-gfad0