diff options
| author | Danilo M. <danix@danix.xyz> | 2026-09-17 08:53:43 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-09-17 08:53:43 +0200 |
| commit | a249039f2de33d8cc8126d6dd62fbc1004193536 (patch) | |
| tree | e2f5d93c3dcc91d3513174548143826da369c73c /lib | |
| parent | 6832a816f9965e273c104f7641c662d6d5d57ced (diff) | |
| download | conky-theme-udt-a249039f2de33d8cc8126d6dd62fbc1004193536.tar.gz conky-theme-udt-a249039f2de33d8cc8126d6dd62fbc1004193536.zip | |
feat: add wind conversion, Beaufort and compass tables
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/weather.lua | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/weather.lua b/lib/weather.lua index 0b4b1b7..6e2741a 100644 --- a/lib/weather.lua +++ b/lib/weather.lua @@ -63,4 +63,45 @@ function M.icon(id, now, sunrise, sunset) return M.ICON.unknown end +-- OWM's metric units report wind in m/s. The card shows km/h. +function M.kmh(ms) + if type(ms) ~= 'number' then return nil end + return ms * 3.6 +end + +-- Beaufort force from km/h. Upper bounds carried over from the polybar +-- script; a value equal to a bound stays in the lower force. +local BEAUFORT = { 1, 5, 11, 19, 28, 38, 49, 61, 74, 88, 102, 117 } + +function M.beaufort(kmh) + if type(kmh) ~= 'number' then return nil end + for force, bound in ipairs(BEAUFORT) do + if kmh <= bound then return force - 1 end + end + return 12 +end + +-- Eight compass points. The half-step offset is what makes north straddle +-- zero: without it, 350 degrees would land in NW and 10 in NE, leaving north +-- with only half its arc. +local POINTS = { 'N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW' } + +function M.compass(deg) + if type(deg) ~= 'number' then return nil end + local i = math.floor(((deg % 360) + 22.5) / 45) % 8 + return POINTS[i + 1] +end + +-- Arrow glyphs, in the same order as POINTS but rotated half a turn: OWM +-- reports the direction the wind comes FROM, and an arrow reads as the +-- direction it goes TO. +local ARROWS = { '\u{2193}', '\u{2199}', '\u{2190}', '\u{2196}', + '\u{2191}', '\u{2197}', '\u{2192}', '\u{2198}' } + +function M.arrow(deg) + if type(deg) ~= 'number' then return '' end + local i = math.floor(((deg % 360) + 22.5) / 45) % 8 + return ARROWS[i + 1] +end + return M |
