From 57ab1d5776f832c3df5c8b2514f34e282b39fbd9 Mon Sep 17 00:00:00 2001 From: Eugene Crosser Date: Mon, 21 Dec 2015 23:52:09 +0300 Subject: [PATCH] provide last count values --- {linux => web}/query.cgi | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) rename {linux => web}/query.cgi (75%) diff --git a/linux/query.cgi b/web/query.cgi similarity index 75% rename from linux/query.cgi rename to web/query.cgi index a629c79..8720237 100755 --- a/linux/query.cgi +++ b/web/query.cgi @@ -1,5 +1,12 @@ #!/usr/bin/env runhaskell +-- -- +-- I am truly sorry. I would have used servant, but it failed to install. -- +-- I would have used sqeletto, but got thrown back by depencencies. -- +-- I would have used some standard config file parser but they are all -- +-- overkills. This program is a very quick and dirty hack. -- +-- -- + {-# LANGUAGE OverloadedStrings #-} module Main where @@ -51,11 +58,20 @@ cgiMain = do \) adj from hotcnt c \ \where timestamp between ? and ? order by timestamp \ \) t;" (slo, shi) + [(ccold, chot)] <- liftIO $ query_ conn + "select lcold+acold as cold, lhot+ahot as hot from \ + \(select value as lcold from coldcnt order by timestamp desc limit 1) cc, \ + \(select sum(value) as acold from coldadj) ac, \ + \(select value as lhot from hotcnt order by timestamp desc limit 1) ch, \ + \(select sum(value) as ahot from hotadj) ah;" _ <- liftIO $ close conn + setHeader "Content-type" "application/json" output $ "{\"range\": {\"lo\": " ++ show (olo :: Int) ++ ", \"hi\": " ++ show (ohi :: Int) - ++ "}, \"cold\": [" ++ showjson cold + ++ "}, \"current\": {\"cold\": " ++ show (floor (ccold :: Double)) + ++ ", \"hot\": " ++ show (floor (chot :: Double)) + ++ "}}, \"cold\": [" ++ showjson cold ++ "], \"hot\": [" ++ showjson hot ++ "]}\n" showjson :: [(Int, Double)] -> String -- 2.39.2