7DBNV3GV773FH5ZLQWFX4RBOS4Q3CIK2RYZNNABY3ZOETYZCXRNQC
intervals :: [LogEntry] -> [LogInterval]
intervals e = undefined
intervals :: Foldable f => f LogEntry -> WorkIndex
intervals = F.foldl' appendLogEntry M.empty
appendLogEntry :: WorkIndex -> LogEntry -> WorkIndex
appendLogEntry workIndex entry = let acc = reduce $ pushEntry entry workIndex
in insert (btcAddr entry) acc workIndex
groupBy f = fromListWith (++) . fmap (f &&& pure)
pushEntry :: LogEntry -> WorkIndex -> ([LogEntry], [LogInterval])
pushEntry entry idx = consLeft entry $ findWithDefault ([], []) (btcAddr entry) idx where
consLeft a (ex, ix) = (a : ex, ix)
reduce :: ([LogEntry], [LogInterval]) -> ([LogEntry], [LogInterval])
reduce ((LogEntry addr end StopWork) : (LogEntry _ start StartWork) : xs, intervals) = (xs, (LogInterval addr (interval start end)) : intervals)
reduce other = other