Make log reduction safer in presence of overlapping events.
[?]
Apr 23, 2015, 4:28 AM
SCXG6TJWYIPRUMT27KGKIIF6FYKTUTY74UNZ2FQTT63XZ6HIF3AACDependencies
- [2]
5DRIWGLUImproving TimeLog specs - [3]
SLL7262CMake depreciation functions more flexible. - [4]
Y35QCWYWMinor improvement in WorkIndex type to eliminate duplicated information. - [5]
EZQG2APBUpdate task list. - [6]
EQXRXRZDChanged to use tasty instead of test-framework - [7]
4QX5E5ACInitial compilation of payouts function succeeds. - [8]
2KZPOGRBOnce you get Haskell to compile, the tests pass! - [9]
64C6AWH6Rename Ananke -> Quixotic, project reboot. - [10]
7XN3I3QJAdd 'loggedIntervals' endpoint. - [11]
A6HKMINBAttempting to improve JSON handling. - [12]
NMWWP4ZNTrying out Hspec - [13]
A2J7B4SCInitial impl of depreciation function. - [14]
GKGVYBZGAdded JSON serialization to TimeLog - [15]
TLQ72DSJLenses, sqlite-simple - [16]
7KZP4RHZSwitch from Data.Time to Data.Thyme - [17]
N4NDAZYTInitial implementation of payouts. - [18]
RSEB2NFGReplacing Snap with Scotty. - [19]
Z7KS5XHHVery WIP. Wow. - [20]
JUUMYIQEAdd groupBy utility function for use in TimeLog. - [21]
NVOCQVASInitial failing tests. - [22]
2OIPAQCBMerge branch 'master' of github.com:nuttycom/ananke - [23]
EMVTF2IWWIP moving back to snap. - [24]
7DBNV3GVInitial, stack-based impl of time log event reduction.
Change contents
- replacement in lib/Quixotic/Interval.hs at line 4
( Interval, interval, start, end, ilen( Interval(Interval), interval, start, end, ilen - edit in lib/Quixotic/Interval.hs at line 6
, containsInclusive - replacement in lib/Quixotic/Interval.hs at line 21
} deriving (Show, Eq)} deriving (Show, Eq, Ord) - edit in lib/Quixotic/Interval.hs at line 26
containsInclusive :: C.UTCTime -> Interval -> BoolcontainsInclusive t (Interval s e) = t >= s && t <= e - replacement in lib/Quixotic/TimeLog.hs at line 46
compare StartWork StopWork = LTcompare StopWork StartWork = GTcompare StartWork StopWork = GTcompare StopWork StartWork = LT - edit in lib/Quixotic/TimeLog.hs at line 68
instance Ord WorkEvent wherecompare a b =let cv x = (x ^. eventTime, x ^. eventType)in compare (cv a) (cv b) - replacement in lib/Quixotic/TimeLog.hs at line 120
type RawIndex = Map BtcAddr ([LogEntry], [LogInterval])type RawIndex = Map BtcAddr [Either WorkEvent Interval] - replacement in lib/Quixotic/TimeLog.hs at line 160
let sortedEntries :: Heap LogEntrysortedEntries = F.foldr H.insert H.empty $ logEntriesrawIndex :: RawIndexlet sortedEntries = F.foldr H.insert H.empty $ logEntries - replacement in lib/Quixotic/TimeLog.hs at line 163
accum k (_, l) m = case nonEmpty l ofJust l' -> MS.insert k (workInterval <$> l') maccum k l m = case nonEmpty (rights l) ofJust l' -> MS.insert k l' m - replacement in lib/Quixotic/TimeLog.hs at line 170
appendLogEntry idx entry =let acc = reduceToIntervals $ pushEntry entry idxin MS.insert (entry ^. btcAddr) acc idxappendLogEntry 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 e2combine (e1 @ (WorkEvent StopWork _ _)) (e2 @ (WorkEvent StopWork _ _)) = Left $ min e1 e2combine _ e2 = Left e2 - replacement in lib/Quixotic/TimeLog.hs at line 176[3.2253]→[2.1070:1212](∅→∅),[2.1212]→[3.2253:2318](∅→∅),[3.2253]→[3.2253:2318](∅→∅),[3.2318]→[3.4695:4779](∅→∅)
{-|- 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 ofJust (Left ev' : xs) -> combine ev' ev : xsJust xs -> Left ev : xsNothing -> Left ev : [] - replacement in lib/Quixotic/TimeLog.hs at line 181[3.870]→[3.692:772](∅→∅),[3.772]→[3.4024:4147](∅→∅),[3.4147]→[3.2859:2916](∅→∅),[3.4899]→[3.2859:2916](∅→∅),[3.2859]→[3.2859:2916](∅→∅),[3.2916]→[3.1086:1131](∅→∅),[3.2482]→[3.1086:1131](∅→∅)
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 =misalignedin MS.insert k ivals idx - replacement in test/Quixotic/TimeLogSpec.hs at line 33
delta <- arbitrarypure $ I.interval startTime (startTime .+^ delta)delta <- arbitrary :: Gen (Positive T.NominalDiffTime)pure $ I.interval startTime (startTime .+^ getPositive delta) - replacement in test/Quixotic/TimeLogSpec.hs at line 52
, parseISO8601 "2014-02-12T00:12:00Z" ], parseISO8601 "2014-01-01T00:12:00Z" ] - replacement in test/Quixotic/TimeLogSpec.hs at line 56[2.2674]→[2.2674:2726](∅→∅),[3.904]→[3.2686:2687](∅→∅),[2.2726]→[3.2686:2687](∅→∅),[3.3974]→[3.2686:2687](∅→∅),[3.4380]→[3.2686:2687](∅→∅),[3.2687]→[2.2727:2773](∅→∅),[2.2773]→[3.944:1004](∅→∅),[3.944]→[3.944:1004](∅→∅),[3.1004]→[2.2774:2973](∅→∅)
, parseISO8601 "2014-02-12T00:18:00Z" ]testLogEntries :: NonEmpty LogEntrytestLogEntries = doaddr <- testAddrs(start', end') <- L.zip starts endsL.fromList [ LogEntry addr (WorkEvent StartWork start' Nothing), LogEntry addr (WorkEvent StopWork end' Nothing) ], parseISO8601 "2014-01-01T00:18:00Z" ] - replacement in test/Quixotic/TimeLogSpec.hs at line 59
testIntervals = L.reverse $ dotestIntervals = do - edit in test/Quixotic/TimeLogSpec.hs at line 63
testLogEntries :: NonEmpty LogEntrytestLogEntries = do(LogInterval addr (Interval start' end')) <- testIntervalsL.fromList [ LogEntry addr (WorkEvent StartWork start' Nothing), LogEntry addr (WorkEvent StopWork end' Nothing) ] - edit in test/Quixotic/TimeLogSpec.hs at line 70
expected' = fromListWith (<>) . L.toList $ (intervalBtcAddr &&& pure . workInterval) <$> testIntervals - replacement in test/Quixotic/TimeLogSpec.hs at line 72
expected = WorkIndex . fromListWith (<>) . L.toList $ (intervalBtcAddr &&& pure . workInterval) <$> testIntervalsexpected = WorkIndex $ fmap (L.reverse . L.sort) expected' - replacement in test/Quixotic/TimeLogSpec.hs at line 77
\widx ->\(WorkIndex widx) -> - replacement in test/Quixotic/TimeLogSpec.hs at line 82
logEntries = foldrWithKey acc [] (widx ^. _WorkIndex)in workIndex logEntries `shouldBe` widxlogEntries = foldrWithKey acc [] widxin workIndex logEntries `shouldBe` (WorkIndex $ fmap (L.reverse . L.sort) widx)