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BMO76F55ZKIVOLSG3O63VP3RHRZVANXYT3OLZ3OWQC
appendLogEntry idx entry =
let acc = reduceToIntervals $ pushEntry entry idx
in MS.insert (entry ^. btcAddr) acc idx
appendLogEntry idx (LogEntry k ev) =
let combine (WorkEvent StartWork t _) (WorkEvent StopWork t' _) | t' > t = Right $ Interval t t'
combine (e1 @ (WorkEvent StartWork _ _)) (e2 @ (WorkEvent StartWork _ _)) = Left $ max e1 e2
combine (e1 @ (WorkEvent StopWork _ _)) (e2 @ (WorkEvent StopWork _ _)) = Left $ min e1 e2
combine _ e2 = Left e2
{-|
- Find the set of accumulated log intervals and log entries
- for a given BTC address, and concatenate the entry to the entry list.
-}
pushEntry :: LogEntry -> RawIndex -> ([LogEntry], [LogInterval])
pushEntry entry = first (entry :) . MS.findWithDefault ([], []) (entry ^. btcAddr)
ivals = case MS.lookup k idx of
Just (Left ev' : xs) -> combine ev' ev : xs
Just xs -> Left ev : xs
Nothing -> Left ev : []
reduceToIntervals :: ([LogEntry], [LogInterval]) -> ([LogEntry], [LogInterval])
reduceToIntervals ((LogEntry addr (WorkEvent StopWork end' _)) : (LogEntry _ (WorkEvent StartWork start' _)) : xs, acc) =
(xs, (LogInterval addr (interval start' end')) : acc)
reduceToIntervals misaligned =
misaligned
in MS.insert k ivals idx
, parseISO8601 "2014-02-12T00:18:00Z" ]
testLogEntries :: NonEmpty LogEntry
testLogEntries = do
addr <- testAddrs
(start', end') <- L.zip starts ends
L.fromList [ LogEntry addr (WorkEvent StartWork start' Nothing)
, LogEntry addr (WorkEvent StopWork end' Nothing) ]
, parseISO8601 "2014-01-01T00:18:00Z" ]