about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorana <ana@ana.st>2021-08-08 19:17:02 +0200
committerana <ana@ana.st>2021-08-08 19:17:02 +0200
commite74892159c53d29281fc24cf01dd87528d223dc9 (patch)
tree4a92fb8fd6f14cb42565b1b7d54f5c55415f91e5
parentcc0ef3e4f905f5c3c6441069bdb3bf8a78ac1314 (diff)
downloadeureka-marks-e74892159c53d29281fc24cf01dd87528d223dc9.tar.gz
fix: account for d/n when predicting future stuff
-rw-r--r--src/App.svelte14
-rw-r--r--src/bestiary.js11
2 files changed, 10 insertions, 15 deletions
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);
+}