summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstreetturtle <streetturtle@users.noreply.github.com>2018-04-01 18:01:23 -0400
committerGitHub <noreply@github.com>2018-04-01 18:01:23 -0400
commit7eafdb21a8cc5053e6e82d2ac20d4ce8e5ac1efb (patch)
tree88a6bcf387e8e18bf4d22d13d3478034e0560a5f
parentd46954629f14a9d4cebd18ac7b25046282487f97 (diff)
parentc5181829f518abffb789d7c83c84569c096fe115 (diff)
Merge pull request #40 from webknjaz/bugfix/wind-dir-calc
Reimplement wind direction detection properly
-rw-r--r--weather-widget/weather.lua45
1 files changed, 21 insertions, 24 deletions
diff --git a/weather-widget/weather.lua b/weather-widget/weather.lua
index 43ce974..08883b9 100644
--- a/weather-widget/weather.lua
+++ b/weather-widget/weather.lua
@@ -67,33 +67,30 @@ end
-- Return wind direction as a string.
function to_direction(degrees)
- local directions = {
- { "N", 348.75, 360 },
- { "N", 0, 11.25 },
- { "NNE", 11.25, 33.75 },
- { "NE", 33.75, 56.25 },
- { "ENE", 56.25, 78.75 },
- { "E", 78.75, 101.25 },
- { "ESE", 101.25, 123.75 },
- { "SE", 123.75, 146.25 },
- { "SSE", 146.25, 168.75 },
- { "S", 168.75, 191.25 },
- { "SSW", 191.25, 213.75 },
- { "SW", 213.75, 236.25 },
- { "WSW", 236.25, 258.75 },
- { "W", 258.75, 281.25 },
- { "WNW", 281.25, 303.75 },
- { "NW", 303.75, 326.25 },
- { "NNW", 326.25, 348.75 },
- }
+ -- Ref: https://www.campbellsci.eu/blog/convert-wind-directions
if degrees == nil then
return "Unknown dir"
end
- for i, dir in ipairs(directions) do
- if degrees > dir[2] and degrees < dir[3] then
- return dir[1]
- end
- end
+ local directions = {
+ "N",
+ "NNE",
+ "NE",
+ "ENE",
+ "E",
+ "ESE",
+ "SE",
+ "SSE",
+ "S",
+ "SSW",
+ "SW",
+ "WSW",
+ "W",
+ "WNW",
+ "NW",
+ "NNW",
+ "N",
+ }
+ return directions[math.floor((degrees % 360) / 22.5) + 1]
end
local weather_timer = timer({ timeout = 60 })