, connectPassword = pass conf
, connectDatabase = dbnm conf
}
, connectPassword = pass conf
, connectDatabase = dbnm conf
}
today <- liftIO getClockTime
let tomorrow = addToClockTime (noTimeDiff {tdDay = 1}) today
daystart x = (toUTCTime x) { ctHour = 0, ctMin = 0
today <- liftIO getClockTime
let tomorrow = addToClockTime (noTimeDiff {tdDay = 1}) today
daystart x = (toUTCTime x) { ctHour = 0, ctMin = 0
-- ++ " dhi=" ++ show dhi ++ " ihi=" ++ show ihi
let slo = fromMaybe dlo ilo :: String
shi = fromMaybe dhi ihi :: String
-- ++ " dhi=" ++ show dhi ++ " ihi=" ++ show ihi
let slo = fromMaybe dlo ilo :: String
shi = fromMaybe dhi ihi :: String
\(select c.timestamp timestamp, c.value value, \
\(select sum(value) from coldadj a where a.timestamp <= c.timestamp \
\) adj from coldcnt c where timestamp between ? and ? \
\) t order by timestamp;" (slo, shi)
hot <- liftIO $ query conn
\(select c.timestamp timestamp, c.value value, \
\(select sum(value) from coldadj a where a.timestamp <= c.timestamp \
\) adj from coldcnt c where timestamp between ? and ? \
\) t order by timestamp;" (slo, shi)
hot <- liftIO $ query conn
\(select c.timestamp timestamp, c.value value, \
\(select sum(value) from hotadj a where a.timestamp <= c.timestamp \
\) adj from hotcnt c where timestamp between ? and ? \
\(select c.timestamp timestamp, c.value value, \
\(select sum(value) from hotadj a where a.timestamp <= c.timestamp \
\) adj from hotcnt c where timestamp between ? and ? \
- output $ "{\"range\": {\"lo\": " ++ show (olo :: Int)
- ++ ", \"hi\": " ++ show (ohi :: Int)
- ++ "}, \"current\": {\"cold\": " ++ show (floor (ccold :: Double))
- ++ ", \"hot\": " ++ show (floor (chot :: Double))
+ output $ "{\"range\": {\"lo\": " ++ show (floor (olo :: (Ratio Integer)))
+ ++ ", \"hi\": " ++ show (floor (ohi :: (Ratio Integer)))
+ ++ "}, \"current\": {\"cold\": " ++ show (floor (ccold :: (Ratio Integer)))
+ ++ ", \"hot\": " ++ show (floor (chot :: (Ratio Integer)))
++ "}, \"cold\": [" ++ showjson cold
++ "], \"hot\": [" ++ showjson hot ++ "]}\n"
++ "}, \"cold\": [" ++ showjson cold
++ "], \"hot\": [" ++ showjson hot ++ "]}\n"
showjson l = intercalate "," $ map (\(t, c) -> "[" ++ show t ++ "," ++ show (floor c) ++ "]") l
data Conf = Conf { host :: String
showjson l = intercalate "," $ map (\(t, c) -> "[" ++ show t ++ "," ++ show (floor c) ++ "]") l
data Conf = Conf { host :: String