LANGUAGE BangPatterns import Data List import Data List Split import D

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
{-# LANGUAGE BangPatterns #-}
import Data.List
import Data.List.Split
import Data.Maybe
import qualified Data.Map as M
line = map (l2t . sepBy "=") . tail . sepBy ", "
l2t [a, b] = (a, b)
look k = fromMaybe "NULL" . lookup k
upd 0 value = value
upd e (ok, dur) = (ok+1, dur+e)
upd' (_, e) = upd e
count = foldl' $ \(!allc, !total, !hours, !dial, !term) x ->
let e = read (look "ELAPSED-TIME" x) :: Int
setup = read $ takeWhile (/=':') $ look "SETUP-TIME" x :: Int
(hours', dial', term') =
(M.insertWith upd' setup (1, e) hours
,M.insertWith upd' (look "DIALPEER-NAME" x) (1, e) dial
,M.insertWith upd' (look "DST-NAME" x) (1, e) term)
in (allc+1, upd e total, hours', dial', term')
main = getContents >>=
print . count (0, (0, 0), M.empty, M.empty, M.empty) . map line . lines