lmarzen / esp32-weather-epd

A low-power E-Paper weather display powered by an ESP32 microcontroller. Utilizes the OpenWeatherMap API.
GNU General Public License v3.0
2.33k stars 179 forks source link

When calculating max precipitation values, use first index too #65

Closed cwitting closed 7 months ago

cwitting commented 7 months ago

Noticed that if the first index of rain values where larger than the rest, the bound calculation would be off, as the loop below starts from 1. I am not sure I understand why the first index does not need to be used for the temperature calculation though.

lmarzen commented 7 months ago

Good catch.

Can you clarify what you mean that the first index is not used for the temperature calculation?

cwitting commented 7 months ago

I mean that i do not fully understand why the loop needs to start at 1. In the second loop below the temperature are accessed using "i - 1" as index, where as rain/pop is accessed using just "i".

lmarzen commented 7 months ago

The first loop identifies the range for max/min temperature and max rainfall (lower bound for rain fall is always 0). The first loop starts at 1 since on iteration 0 for temperature, we need to initialize both the max and min temperature to the first hourly for temperature. For rain we wouldn't need to do this since we could use max(0,hourly.rain[i]).

For the second loop, the reason temperature accesses i-1 is because it must draw a line from the previous hour to the current hour. However, this is not necessary for rain/pop since it just draws a bar for each hour and is independent of the pop of any other hour.