From a507a3ef179131e61fa6afcbcd384f1e68b40bc7 Mon Sep 17 00:00:00 2001 From: patrickhaussmann Date: Fri, 19 Aug 2022 14:32:26 +0200 Subject: [PATCH] improve text on 1h tile --- show.js | 55 +++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 43 insertions(+), 12 deletions(-) diff --git a/show.js b/show.js index adc9c35..d5096a1 100644 --- a/show.js +++ b/show.js @@ -630,24 +630,55 @@ function tile1h() { return; } + const indexChangeMinute = data.minutely + .map(({ precipitation }) => precipitation > 0.01) + .map((value, i, arr) => value != arr[0]) + .findIndex((value) => value); + const indexChangeHour = data.hourly + .map(({ pop }) => pop > 0.2) + .slice(0, 24) + .map((value, i, arr) => value != arr[0]) + .findIndex((value) => value); + let text = ""; if (data.minutely[0].precipitation > 0) { - const indexChange = data.minutely.findIndex( - ({ precipitation }) => precipitation == 0 - ); - if (indexChange == -1) { - text = "rain more that ~1h"; + // rain now + if (indexChangeMinute == -1) { + // rain >60min + + if (indexChangeHour == -1) { + // rain >24h + text = "rain more than ~24h"; + } else { + // rain <24h + text = "rain ends in ~" + (indexChangeHour + 1) + "h"; + } } else { - text = "rain ends in ~" + (indexChange + 1) + "min"; + // rain <60min + text = "rain ends in ~" + (indexChangeMinute + 1) + "min"; } } else { - const indexChange = data.minutely.findIndex( - ({ precipitation }) => precipitation > 0 - ); - if (indexChange == -1) { - text = "no rain"; + // no rain now + + if (indexChangeMinute == -1) { + // no rain >60min + + if (data.hourly[0].pop > 0) { + // minutely and hourly disagree -> trust minutely + text = "no rain in next 60 min"; + } else { + // minutely and hourly agree + + if (indexChangeHour == -1) { + // no rain >24h + text = "no rain in next 24 hour"; + } else { + // no rain <24h + text = "rain ends in ~" + (indexChangeHour + 1) + "h"; + } + } } else { - text = "rain starts in ~" + (indexChange + 1) + "min"; + text = "rain starts in ~" + (indexChangeMinute + 1) + "min"; } } dom(rainText, dom.textNode(text)); -- 2.45.2