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y5ZVGY5O4CJX2LNP63MS3NRHHZQC
2KZPOGRBY6KBMO76F55ZKIVOLSG3O63VP3RHRZVANXYT3OLZ3OWQC
EQXRXRZDYCM7BDAVBOXQYPG6C7IJT3OFGNIXCDAHJJBRKAXNGL7AC
P6NR2CGXCWAW6GXXSIXCGOBIRAS2BM4LEM6D5ADPN4IL7TMW6UVAC
FD7SV5I6VCW27HZ3T3K4MMGB2OYGJTPKFFA263TNTAMRJGQJWVNAC
N4NDAZYTLSI2W22KT3SYXL257DBMSH3UT2BXOYM7LH7FSZAY4RLAC
let logSum :: RawIndex
logSum = F.foldl' appendLogEntry MS.empty logEntries
in fmap (fmap workInterval . snd) $ logSum
let sortedEntries :: Heap LogEntry
sortedEntries = F.foldr H.insert H.empty $ logEntries
rawIndex :: RawIndex
rawIndex = F.foldl' appendLogEntry MS.empty $ sortedEntries
accum k (_, l) m = case nonEmpty l of
Just l' -> MS.insert k (workInterval <$> l') m
Nothing -> m
in WorkIndex $ MS.foldrWithKey accum MS.empty rawIndex
import Data.AffineSpace
import Data.Map.Strict as M
import Data.Time.ISO8601
import Data.Thyme.Clock
import Data.Thyme.Time
import qualified Data.Text as T
it "reduces a log to a work index" $ do
let testAddrs = catMaybes [ parseBtcAddr "123"
, parseBtcAddr "456"
, parseBtcAddr "789" ]
it "reduces a log to a work index" $
let testAddrs = L.fromList $ catMaybes
[ parseBtcAddr "123"
, parseBtcAddr "456"
, parseBtcAddr "789" ]
(start', end') <- zip starts ends
[ LogEntry addr (WorkEvent StartWork start' Nothing), LogEntry addr (WorkEvent StopWork end' Nothing) ]
(start', end') <- L.zip starts ends
L.fromList [ LogEntry addr (WorkEvent StartWork start' Nothing)
, LogEntry addr (WorkEvent StopWork end' Nothing) ]
(start', end') <- zip starts ends
return $ LogInterval addr (I.interval start' end')
(start', end') <- L.zip starts ends
pure $ LogInterval addr (I.interval start' end')
expected :: WorkIndex
expected = WorkIndex . fromListWith (<>) . L.toList $ (intervalBtcAddr &&& pure . workInterval) <$> testIntervals
expected :: WorkIndex
expected = fmap (fmap workInterval . snd) expected0
it "recovers a work index from events" $ property $
\widx ->
let ivalEntries addr ival = [ LogEntry addr (WorkEvent StartWork (ival ^. start) Nothing)
, LogEntry addr (WorkEvent StopWork (ival ^. end) Nothing) ]
{--
(fromList [
(BtcAddr "S\187\156\a\SOx\229`[\133a%7o%'XBt\249\226\n\ENQ\SOH\GS<\241WU5{Si\251",
[ Interval {_start = 1858-11-16 23:59:59.999997 UTC, _end = 1858-11-16 23:59:59.999997 UTC}
, Interval {_start = 1858-11-16 23:59:59.999998 UTC, _end = 1858-11-17 00:00:00.000002 UTC}]),
(BtcAddr "\138;\GS\132U0\SUB\ESCf[\NAKo`\ACKR[\EMq\b\v\159\184u\ACK&jS#n#?\SI&v",
[Interval {_start = 1858-11-16 23:59:59.999999 UTC, _end = 1858-11-17 00:00:00 UTC}
,Interval {_start = 1858-11-17 00:00:00.000002 UTC, _end = 1858-11-17 00:00:00.000006 UTC}
,Interval {_start = 1858-11-16 23:59:59.999994 UTC, _end = 1858-11-16 23:59:59.999998 UTC}])
])
-}