From 23aa6876b069f05b7f2c4791bb4b344a3a7387b2 Mon Sep 17 00:00:00 2001 From: Michael Knabe Date: Wed, 9 Dec 2015 19:41:16 +0100 Subject: Add template variables for wind speed in m/s and km/h to weather plugin --- readme.md | 2 +- src/Plugins/Monitors/Weather.hs | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/readme.md b/readme.md index e94caeb..7b9d3f1 100644 --- a/readme.md +++ b/readme.md @@ -742,7 +742,7 @@ something like: - Args: default monitor arguments - Variables that can be used with the `-t`/`--template` argument: `station`, `stationState`, `year`, `month`, `day`, `hour`, - `windCardinal`, `windAzimuth`, `windMph`, `windKnots`, + `windCardinal`, `windAzimuth`, `windMph`, `windKnots`, `windMs`, `windKmh` `visibility`, `skyCondition`, `tempC`, `tempF`, `dewPointC`, `dewPointF`, `rh`, `pressure` - Default template: `: C, rh % ()` diff --git a/src/Plugins/Monitors/Weather.hs b/src/Plugins/Monitors/Weather.hs index d458279..b2520a9 100644 --- a/src/Plugins/Monitors/Weather.hs +++ b/src/Plugins/Monitors/Weather.hs @@ -43,6 +43,8 @@ weatherConfig = mkMConfig , "windAzimuth" , "windMph" , "windKnots" + , "windKmh" + , "windMs" , "visibility" , "skyCondition" , "tempC" @@ -59,6 +61,8 @@ data WindInfo = , windAzimuth :: String -- azimuth direction , windMph :: String -- speed (MPH) , windKnots :: String -- speed (knot) + , windKmh :: String -- speed (km/h) + , windMs :: String -- speed (m/s) } deriving (Show) data WeatherInfo = @@ -91,7 +95,7 @@ pTime = do y <- getNumbersAsString return (y, m, d ,h:hh:":"++mi:mimi) noWind :: WindInfo -noWind = WindInfo "μ" "μ" "0" "0" +noWind = WindInfo "μ" "μ" "0" "0" "0" "0" pWind :: Parser WindInfo pWind = @@ -105,7 +109,7 @@ pWind = string "MPH (" knot <- tospace manyTill anyChar newline - return $ WindInfo "μ" "μ" mph knot + return $ WindInfo "μ" "μ" mph knot (toKmh knot) (toMs knot) wind = do manyTill skipRestOfLine (string "Wind: from the ") cardinal <- tospace char '(' @@ -115,8 +119,13 @@ pWind = string "MPH (" knot <- tospace manyTill anyChar newline - return $ WindInfo cardinal azimuth mph knot + return $ WindInfo cardinal azimuth mph knot (toKmh knot) (toMs knot) in try wind0 <|> try windVar <|> try wind <|> return noWind + where + toKmh knots = knots $* 1.852 + toMs knots = knots $* 0.514 + ($*) :: String -> Double -> String + op1 $* op2 = show (round ((read op1::Double) * op2)::Integer) pTemp :: Parser (Int, Int) pTemp = do let num = digit <|> char '-' <|> char '.' @@ -199,10 +208,10 @@ getData station = do #endif formatWeather :: [WeatherInfo] -> Monitor String -formatWeather [WI st ss y m d h (WindInfo wc wa wm wk) v sk tC tF dC dF r p] = +formatWeather [WI st ss y m d h (WindInfo wc wa wm wk wkh wms) v sk tC tF dC dF r p] = do cel <- showWithColors show tC far <- showWithColors show tF - parseTemplate [st, ss, y, m, d, h, wc, wa, wm, wk, v, sk, cel, far, show dC, show dF, show r , show p ] + parseTemplate [st, ss, y, m, d, h, wc, wa, wm, wk, wkh, wms, v, sk, cel, far, show dC, show dF, show r , show p ] formatWeather _ = getConfigValue naString runWeather :: [String] -> Monitor String -- cgit v1.2.3