~patrickhaussmann/weather.app.5ls.de

a507a3ef179131e61fa6afcbcd384f1e68b40bc7 — patrickhaussmann 2 years ago d168e81
improve text on 1h tile
1 files changed, 43 insertions(+), 12 deletions(-)

M show.js
M show.js => show.js +43 -12
@@ 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));