Improving TimeLog specs
[?]
Apr 22, 2015, 5:46 PM
5DRIWGLUKMQZU2ZPBXSTLAWJKAMOD5YXAHM5LEDQHDFGYYLHWCDQCDependencies
- [2]
WJO37T74Restored the single test to functionality. - [3]
7KZP4RHZSwitch from Data.Time to Data.Thyme - [4]
EMVTF2IWWIP moving back to snap. - [5]
2KZPOGRBOnce you get Haskell to compile, the tests pass! - [6]
PBD7LZYQPostgres & auth are beginning to function. - [7]
IZEVQF62Work in progress replacing sqlite with postgres. - [8]
64C6AWH6Rename Ananke -> Quixotic, project reboot. - [9]
FD7SV5I6Fix handling of event_t columns. - [10]
WO2MINIFAuctions now compile! - [11]
HE3JTXO3Added client call to payouts. - [12]
GKGVYBZGAdded JSON serialization to TimeLog - [13]
EQXRXRZDChanged to use tasty instead of test-framework - [14]
7DBNV3GVInitial, stack-based impl of time log event reduction. - [15]
NMWWP4ZNTrying out Hspec - [16]
A6HKMINBAttempting to improve JSON handling. - [17]
EZQG2APBUpdate task list. - [18]
NVOCQVASInitial failing tests. - [19]
TLQ72DSJLenses, sqlite-simple - [20]
4IQVQL4TAdded client for payouts endpoint. - [21]
RSEB2NFGReplacing Snap with Scotty. - [22]
BROSTG5KBeginning of modularization of server. - [23]
N4NDAZYTInitial implementation of payouts. - [24]
JV3UEPNCFix Aeson constructors. - [25]
TJEUE7TYAdded OverloadedStrings to eliminate Text fiddling. - [26]
Y35QCWYWMinor improvement in WorkIndex type to eliminate duplicated information. - [27]
SLL7262CMake depreciation functions more flexible. - [28]
4QX5E5ACInitial compilation of payouts function succeeds. - [29]
P6NR2CGXBeginning of implementation of depreciation. - [30]
OBFPJS2GProject successfully builds and tests under nix. - [31]
7XN3I3QJAdd 'loggedIntervals' endpoint.
Change contents
- replacement in lib/Quixotic/TimeLog.hs at line 12
, WorkIndex, WorkIndex(WorkIndex), _WorkIndex - edit in lib/Quixotic/TimeLog.hs at line 31
import Data.Heap as Himport Data.List.NonEmpty as L - edit in lib/Quixotic/TimeLog.hs at line 45
instance Ord EventType wherecompare StartWork StopWork = LTcompare StopWork StartWork = GTcompare _ _ = EQ - edit in lib/Quixotic/TimeLog.hs at line 73
instance Ord LogEntry wherecompare a b =let ordElems e = (e ^. (event.eventTime), e ^. (event.eventType), e ^. btcAddr)in ordElems a `compare` ordElems b - replacement in lib/Quixotic/TimeLog.hs at line 112
type WorkIndex = Map BtcAddr [Interval]newtype WorkIndex = WorkIndex (Map BtcAddr (NonEmpty Interval)) deriving (Show, Eq)makePrisms ''WorkIndex - replacement in lib/Quixotic/TimeLog.hs at line 119
workIndexJSON widx = toJSON $ (fmap intervalJSON) <$> (MS.mapKeysWith (++) (^._BtcAddr) widx)workIndexJSON (WorkIndex widx) =toJSON $ (L.toList . fmap intervalJSON) <$> (MS.mapKeysMonotonic (^._BtcAddr) widx) - replacement in lib/Quixotic/TimeLog.hs at line 145
payouts dep ptime widx =payouts dep ptime (WorkIndex widx) = - replacement in lib/Quixotic/TimeLog.hs at line 155
let logSum :: RawIndexlogSum = F.foldl' appendLogEntry MS.empty logEntriesin fmap (fmap workInterval . snd) $ logSumlet sortedEntries :: Heap LogEntrysortedEntries = F.foldr H.insert H.empty $ logEntriesrawIndex :: RawIndexrawIndex = F.foldl' appendLogEntry MS.empty $ sortedEntriesaccum k (_, l) m = case nonEmpty l ofJust l' -> MS.insert k (workInterval <$> l') mNothing -> min WorkIndex $ MS.foldrWithKey accum MS.empty rawIndex - replacement in lib/Quixotic/TimeLog.hs at line 170
in insert (entry ^. btcAddr) acc idxin MS.insert (entry ^. btcAddr) acc idx - edit in lib/Quixotic/TimeLog.hs at line 172
{-|- Find the set of accumulated log intervals and log entries- for a given BTC address, and concatenate the entry to the entry list.-} - replacement in quixotic.cabal at line 36
, template-haskell, base64-bytestring >= 1.0.0.1 - edit in quixotic.cabal at line 38
, blaze-builder - edit in quixotic.cabal at line 43
, lens >= 4.4.0.2, safe >= 0.3.8 - edit in quixotic.cabal at line 44
, groups >= 0.4, heaps >= 0.3.1, hourglass >= 0.2.6 && < 0.3, lens >= 4.4.0.2, network-bitcoin >= 1.7.0 - edit in quixotic.cabal at line 50
, sqlite-simple >= 0.4.8 && < 0.5 - replacement in quixotic.cabal at line 51
, blaze-builder, safe >= 0.3.8, semigroups, sqlite-simple >= 0.4.8 && < 0.5, template-haskell - edit in quixotic.cabal at line 57[3.2886]→[4.2029:2111](∅→∅),[4.2029]→[4.2029:2111](∅→∅),[4.2111]→[4.1048:1084](∅→∅),[4.1084]→[4.1162:1200](∅→∅)
, hourglass >= 0.2.6 && < 0.3, groups >= 0.4, network-bitcoin >= 1.7.0, base64-bytestring >= 1.0.0.1 - edit in quixotic.cabal at line 73
, QuickCheck >= 2.7 - edit in quixotic.cabal at line 78
, hspec >= 1.8.1, iso8601-time, lens, QuickCheck >= 2.7, semigroups - edit in quixotic.cabal at line 85[3.2944]→[4.3130:3149](∅→∅),[4.2210]→[4.3130:3149](∅→∅),[4.3149]→[4.2210:2231](∅→∅),[4.2210]→[4.2210:2231](∅→∅)
, iso8601-time, hspec >= 1.8.1 - replacement in test/Quixotic/TimeLogSpec.hs at line 8
import Test.Hspecimport Control.Lens ((^.))import Data.AffineSpaceimport Data.List.NonEmpty as Limport Data.Map.Strict as Mimport Data.Time.ISO8601import Data.Thyme.Time as T - replacement in test/Quixotic/TimeLogSpec.hs at line 17
import Quixotic.TimeLog as Limport Quixotic.TimeLog - edit in test/Quixotic/TimeLogSpec.hs at line 19[4.270]→[3.3152:3176](∅→∅),[4.3085]→[4.201:229](∅→∅),[3.3176]→[4.201:229](∅→∅),[4.3781]→[4.201:229](∅→∅),[4.3895]→[4.332:357](∅→∅),[4.357]→[3.3177:3256](∅→∅)
import Data.AffineSpaceimport Data.Map.Strict as Mimport Data.Time.ISO8601import Data.Thyme.Clockimport Data.Thyme.Timeimport qualified Data.Text as T - edit in test/Quixotic/TimeLogSpec.hs at line 20
import Test.Hspec - replacement in test/Quixotic/TimeLogSpec.hs at line 28
arbitrary = BtcAddr . T.pack <$> vectorOf 34 arbitraryarbitrary = BtcAddr . pack <$> vectorOf 34 arbitrary - replacement in test/Quixotic/TimeLogSpec.hs at line 32
start <- arbitrarystartTime <- arbitrary - replacement in test/Quixotic/TimeLogSpec.hs at line 34
pure $ I.interval start (start .+^ delta)pure $ I.interval startTime (startTime .+^ delta)instance Arbitrary WorkIndex wherearbitrary =let record = (,) <$> arbitrary <*> (L.fromList <$> listOf1 arbitrary)in WorkIndex . M.fromList <$> listOf record - replacement in test/Quixotic/TimeLogSpec.hs at line 44
it "reduces a log to a work index" $ dolet 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" ] - replacement in test/Quixotic/TimeLogSpec.hs at line 50
starts = toThyme <$> catMaybes [ parseISO8601 "2014-01-01T00:08:00Z", parseISO8601 "2014-02-12T00:12:00Z" ]starts = L.fromList $ toThyme <$> catMaybes[ parseISO8601 "2014-01-01T00:08:00Z", parseISO8601 "2014-02-12T00:12:00Z" ] - replacement in test/Quixotic/TimeLogSpec.hs at line 54
ends = toThyme <$> catMaybes [ parseISO8601 "2014-01-01T00:12:00Z", parseISO8601 "2014-02-12T00:18:00Z" ]ends = L.fromList $ toThyme <$> catMaybes[ parseISO8601 "2014-01-01T00:12:00Z", parseISO8601 "2014-02-12T00:18:00Z" ] - replacement in test/Quixotic/TimeLogSpec.hs at line 58
testLogEntries :: [LogEntry]testLogEntries :: NonEmpty LogEntry - replacement in test/Quixotic/TimeLogSpec.hs at line 61
(start', end') <- zip starts ends[ LogEntry addr (WorkEvent StartWork start' Nothing), LogEntry addr (WorkEvent StopWork end' Nothing) ](start', end') <- L.zip starts endsL.fromList [ LogEntry addr (WorkEvent StartWork start' Nothing), LogEntry addr (WorkEvent StopWork end' Nothing) ] - replacement in test/Quixotic/TimeLogSpec.hs at line 65
testIntervals :: [LogInterval]testIntervals = dotestIntervals :: NonEmpty LogIntervaltestIntervals = L.reverse $ do - replacement in test/Quixotic/TimeLogSpec.hs at line 68
(start', end') <- zip starts endsreturn $ LogInterval addr (I.interval start' end')(start', end') <- L.zip starts endspure $ LogInterval addr (I.interval start' end')expected :: WorkIndexexpected = WorkIndex . fromListWith (<>) . L.toList $ (intervalBtcAddr &&& pure . workInterval) <$> testIntervals - replacement in test/Quixotic/TimeLogSpec.hs at line 74
expected0 :: Map BtcAddr ([LogEntry], [LogInterval])expected0 = fmap (const [] &&& id) . fromListWith (++) . fmap (intervalBtcAddr &&& return) $ testIntervalsin (workIndex testLogEntries) `shouldBe` expected - replacement in test/Quixotic/TimeLogSpec.hs at line 76
expected :: WorkIndexexpected = fmap (fmap workInterval . snd) expected0it "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) ] - replacement in test/Quixotic/TimeLogSpec.hs at line 81
(workIndex testLogEntries) `shouldBe` expectedacc k a b = b ++ (L.toList a >>= ivalEntries k)logEntries = foldrWithKey acc [] (widx ^. _WorkIndex)in workIndex logEntries `shouldBe` widx - edit in test/Quixotic/TimeLogSpec.hs at line 93[4.977]
{--(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}])])-}