{-#LANGUAGE OverloadedStrings,MultiParamTypeClasses #-}
{-|
Module : Parry.DefaultUI
Copyright : (c) Pierre-Étienne Meunier 2014
License : GPL-3
Maintainer : pierre-etienne.meunier@lif.univ-mrs.fr
Stability : experimental
Portability : All
-}
module Parry.WebUI (
webUI,Html(..)
) where
import Control.Concurrent
import Network
import qualified Data.Map as M
import qualified Data.Set as S
import System.IO
import Data.Time.Clock
import Data.Time.Clock.POSIX
import Data.Time.Format
import System.Locale
import System.Directory
import System.Process
import qualified Data.ByteString.Char8 as B
import qualified Data.ByteString.Lazy.Char8 as L
import Data.ByteString.Lazy.Builder
import Data.ByteString.Lazy.Builder.ASCII
import Control.Exception
import Numeric
import Parry.Server
import Data.Monoid
type Graphs=MVar (L.ByteString,L.ByteString,L.ByteString,L.ByteString)
makeSvg::(Exhaustive j)=>Graphs->MVar (State j r)->IO ()
makeSvg graphs state=onException (
do {
st<-withMVar state $ return;
if M.size (ongoing st)==0 && (S.size (jobs st)==0) then return () else do {
t<-getPOSIXTime;
let { show_t=intDec $ round $ realToFrac t };
L.appendFile "parry.log" $
toLazyByteString $
show_t `mappend` (byteString " ") `mappend` (intDec $ M.size $ ongoing st)
`mappend` (byteString " ") `mappend` (intDec $ S.size $ jobs st)
`mappend` (byteString "\n");
let { jobs_=jobs st;
ongoing_=ongoing st;
(adepth0,njobs0)=M.foldl' (\(d,n) (_,_,j,_,_)->(d+depth j,n+1)) (0,0) $ ongoing_ :: (Int,Int);
(adepth1,njobs1)=S.foldl' (\(d,n) (_,j)->(d+depth j,n+1)) (0,0) $ jobs_ :: (Int,Int);
depth0=if njobs0>0 then (fromIntegral adepth0)/(fromIntegral njobs0) else 0 :: Double;
depth1=if njobs1>0 then (fromIntegral adepth1)/(fromIntegral njobs1) else 0 :: Double;
depth2=M.foldl' (\d (_,_,j,_,_)->min d $ depth j) maxBound $ ongoing_ :: Int;
depth3=S.foldl' (\d (_,j)->min d $ depth j) maxBound $ jobs_ :: Int
};
L.appendFile "solved.log" $
toLazyByteString $
show_t `mappend` (byteString " ") `mappend` (integerDec $ solved st) `mappend` (byteString "\n");
if njobs0>0 then
L.appendFile "depth.log" $
toLazyByteString $
show_t `mappend` (byteString " ") `mappend` (doubleDec depth0)`mappend` (byteString "\n")
else L.appendFile "depth.log" "\n";
if njobs1>0 then
L.appendFile "depth_av.log" $
toLazyByteString $
show_t `mappend` (byteString " ") `mappend` (doubleDec depth1)`mappend` (byteString "\n")
else L.appendFile "depth_av.log" "\n";
if depth2 "
])
`mappend`
{-
(mconcat $ map (\(_,x)->
mconcat [byteString " ",toHtml x,byteString "Results
",
toHtml $ results st,
byteString "
",
byteString "Available jobs
")
`mappend`
integerDec x
`mappend`
(byteString " ")
`mappend`
(byteString $ B.pack h)
`mappend`
(byteString "
Started: ")
`mappend`
(string8 $
formatTime defaultTimeLocale "%c" $
posixSecondsToUTCTime $ realToFrac t)
`mappend`
(byteString "
")
`mappend`
toHtml j
`mappend`
(byteString "