hunk ./src/Main.hs 14 -import Data.Tuple.HT (swap, ) +import Data.Tuple.HT (swap, mapSnd, ) hunk ./src/Main.hs 19 -import Data.List (sort, ) +import Data.List (sort, mapAccumL, ) hunk ./src/Main.hs 106 - subtract timeZoneOffset $ - timeOfDayToTime $ - readTime defaultTimeLocale "%R" timeStr)) . + parseTime timeStr)) . hunk ./src/Main.hs 123 +parseTime :: String -> Time +parseTime = + subtract timeZoneOffset . + timeOfDayToTime . + readTime defaultTimeLocale "%R" + hunk ./src/Main.hs 131 - TimeFmt.formatTime defaultTimeLocale "%R" . timeToTimeOfDay . + TimeFmt.formatTime defaultTimeLocale "%R" . + timeToTimeOfDay . hunk ./src/Main.hs 236 + +loadPerTime :: String -> [(Time, Int)] +loadPerTime = + snd . + mapAccumL + (\oldLoad (time,loadDiff) -> + let newLoad = oldLoad + loadDiff + in (newLoad, (time, newLoad))) 0 . + map (mapSnd $ + sum . map (\dir -> case dir of Enter -> 1; Leave -> -1)) . + buckets (take (4*60+30) $ iterate (60+) (parseTime "09:00")) . + map (\(_cnt,dir,time) -> (time, dir)) . + parseLog + + +buckets :: (Eq a) => + [a] -> [(a,b)] -> [(a,[b])] +buckets as bs = + snd $ + mapAccumL + (\bs0 a -> + let (bucket, bs1) = span ((a==) . fst) bs0 + in (bs1, (a, map snd bucket))) + bs as + + hunk ./src/Main.hs 271 + writeFile "time-load.csv" . unlines . + map (\(time,load) -> formatTime time ++ " " ++ show load) . loadPerTime $ str