Add payouts spec.
[?]
Jan 31, 2021, 5:28 AM
CI4OPKQMU4CIX3QPGA5GWSEOPJ2FAREDBVU6X33E7X3EEQXAICRQCDependencies
- [2]
U7YAT2ZKAdd error reporting to signup form. - [3]
EFSXYZPOAutoformat everything with brittany. - [4]
Y35QCWYWMinor improvement in WorkIndex type to eliminate duplicated information. - [5]
64C6AWH6Rename Ananke -> Quixotic, project reboot. - [6]
OV5AKJHARemove unused LogInterval type. - [7]
KNSI575VCleanup of EventLog types. - [8]
IR75ZMX3Return actual events for interval ends, not just timestamps. - [9]
SCXG6TJWMake log reduction safer in presence of overlapping events. - [10]
LHJ2HFXVAdd property test for auction algorithm. - [11]
5DRIWGLUImproving TimeLog specs - [12]
X3ES7NUAFine. I'll use ormolu. At least it doesn't break the code. - [13]
M4PWY5RUPreliminary work to add support for Zcash payments. - [14]
B6HWAPDPModularize & update to recent haskoin. - [15]
EMVTF2IWWIP moving back to snap. - [16]
LTSVBVA2Update to a recent haskoin-core. Fix Stack build. - [17]
RPAJLHMTChange to use UUIDs instead of ints for primary keys. - [18]
NEDDHXUKReformat via stylish-haskell - [19]
7KZP4RHZSwitch from Data.Time to Data.Thyme - [20]
4SCFOJGNSpecs for recovering intervals from the log now pass. - [21]
A6HKMINBAttempting to improve JSON handling. - [22]
UUR6SMCAAdd start of specs for auctions. - [23]
IPG33FAWAdd billing daemon - [*]
NVOCQVASInitial failing tests. - [*]
NMWWP4ZNTrying out Hspec
Change contents
- replacement in lib/Aftok/Database/PostgreSQL/Events.hs at line 68
eventTime,leEventTime, - replacement in lib/Aftok/Database/PostgreSQL/Events.hs at line 173
fromThyme $ e ^. eventTime,fromThyme $ e ^. leEventTime, - replacement in lib/Aftok/Database/PostgreSQL/Events.hs at line 189
fromThyme $ e ^. eventTime,fromThyme $ e ^. leEventTime, - replacement in lib/Aftok/Database/PostgreSQL/Events.hs at line 205
fromThyme $ e ^. eventTime,fromThyme $ e ^. leEventTime, - replacement in lib/Aftok/Database/PostgreSQL/Events.hs at line 315
pure (aid, set (logEntry . event . eventTime) t kle, "amend_event_time")pure (aid, set (logEntry . event . leEventTime) t kle, "amend_event_time") - edit in lib/Aftok/TimeLog.hs at line 4
{-# LANGUAGE FlexibleInstances #-}{-# LANGUAGE UndecidableInstances #-} - replacement in lib/Aftok/TimeLog.hs at line 24
import Control.Lens ((.~), (^.), makeClassy, makeLenses, makePrisms, view)import Control.Lens (Lens', (.~), (^.), makeClassy, makeLenses, makePrisms, view) - edit in lib/Aftok/TimeLog.hs at line 37
class HasEventTime a whereeventTime :: Lens' a C.UTCTimeinstance HasEventTime C.UTCTime whereeventTime = id - replacement in lib/Aftok/TimeLog.hs at line 50
= StartWork {_eventTime :: !C.UTCTime}| StopWork {_eventTime :: !C.UTCTime}= StartWork {_leEventTime :: !C.UTCTime}| StopWork {_leEventTime :: !C.UTCTime} - edit in lib/Aftok/TimeLog.hs at line 55
makeLenses ''LogEvent - replacement in lib/Aftok/TimeLog.hs at line 57
makeLenses ''LogEventinstance HasEventTime LogEvent whereeventTime = leEventTime - edit in lib/Aftok/TimeLog.hs at line 91
instance {-# OVERLAPPABLE #-} HasLogEntry a => HasEventTime a whereeventTime = event . leEventTime - replacement in lib/Aftok/TimeLog.hs at line 130
newtype WorkIndex t = WorkIndex (Map CreditTo (NonEmpty (Interval t))) deriving (Show, Eq)newtype WorkIndex t = WorkIndex (Map CreditTo (NonEmpty (Interval t)))deriving (Show, Eq, Functor) - replacement in lib/Aftok/TimeLog.hs at line 142
workCredit :: (Foldable f, HasLogEntry le) => DepF -> C.UTCTime -> f (Interval le) -> (NDT, NDT)workCredit :: (Foldable f, HasEventTime le) => DepF -> C.UTCTime -> f (Interval le) -> (NDT, NDT) - replacement in lib/Aftok/TimeLog.hs at line 144
bimap getSum getSum $ F.foldMap ((Sum . ilen &&& Sum . depf ptime) . fmap (view $ event . eventTime)) ivalsbimap getSum getSum $ F.foldMap ((Sum . ilen &&& Sum . depf ptime) . fmap (view eventTime)) ivals - replacement in lib/Aftok/TimeLog.hs at line 150
payouts :: forall le. (HasLogEntry le) => DepF -> C.UTCTime -> WorkIndex le -> WorkSharespayouts :: forall le. (HasEventTime le) => DepF -> C.UTCTime -> WorkIndex le -> WorkShares - replacement in lib/Aftok/TimeLog.hs at line 192
case extension (view (event . eventTime) <$> ival) logEvent ofcase extension (view (event . leEventTime) <$> ival) logEvent of - edit in test/Aftok/TimeLogSpec.hs at line 2
{-# LANGUAGE TypeApplications #-} - edit in test/Aftok/TimeLogSpec.hs at line 12
import Prelude hiding (head, tail) - replacement in test/Aftok/TimeLogSpec.hs at line 16
import Aftok.Types (UserId (..))import Control.Lens ((^.))import Aftok.Types (UserId (..), DepreciationFunction(..))import Control.Lens ((^.), view, to) - edit in test/Aftok/TimeLogSpec.hs at line 19
import Data.Maybe (fromJust)import Data.List (head, tail)import Data.Ratio ((%)) - replacement in test/Aftok/TimeLogSpec.hs at line 35
genIntervals :: Gen (L.NonEmpty I.Interval)genIntervals :: Gen (L.NonEmpty (I.Interval T.UTCTime)) - replacement in test/Aftok/TimeLogSpec.hs at line 40
buildIntervals :: T.UTCTime -> [NominalDiffTime] -> [I.Interval]buildIntervals :: T.UTCTime -> [NominalDiffTime] -> [I.Interval T.UTCTime] - replacement in test/Aftok/TimeLogSpec.hs at line 51
genWorkIndex :: Gen WorkIndexgenWorkIndex :: Gen (WorkIndex T.UTCTime) - replacement in test/Aftok/TimeLogSpec.hs at line 53
let recordGen :: Gen (CreditTo, L.NonEmpty I.Interval)let recordGen :: Gen (CreditTo, L.NonEmpty (I.Interval T.UTCTime)) - replacement in test/Aftok/TimeLogSpec.hs at line 77
testIntervals :: [(CreditTo, I.Interval)]testIntervals :: [(CreditTo, I.Interval T.UTCTime)] - edit in test/Aftok/TimeLogSpec.hs at line 83
- edit in test/Aftok/TimeLogSpec.hs at line 88
- replacement in test/Aftok/TimeLogSpec.hs at line 91
(workIndex testLogEntries) `shouldBe` expectedactual = view eventTime <$> workIndex id testLogEntriesactual `shouldBe` expected - replacement in test/Aftok/TimeLogSpec.hs at line 112
in workIndex logEntries`shouldBe` (WorkIndex $ fmap (L.reverse . L.sort) widx')expected = (WorkIndex $ fmap (L.reverse . L.sort) widx')actual = view eventTime <$> workIndex id logEntriesin actual `shouldBe` expectedit "computes correct work shares" $ do[u0, u1, u2] <- fmap CreditToUser . take 3 <$> sample' (UserId <$> genUUID)let initTime = toThyme . fromJust $ parseISO8601 "2014-01-01T00:08:00Z"len = fromInteger @NominalDiffTime 360timestamps = iterate (addUTCTime len) initTimeintervals =fmap (uncurry I.Interval . snd). filter (\i -> fst i `mod` 2 == 0)$ ([(0 :: Int)..] `zip` (timestamps `zip` tail timestamps))widx = WorkIndex $ M.fromList[ (u0, L.fromList $ take 10 intervals), (u1, L.fromList $ take 30 intervals), (u2, L.fromList $ take 120 intervals)]-- for this test we'll be entirely within undepreciated perioddepf = toDepF $ LinearDepreciation 180 1800evalTime = I._start . head $ drop 120 intervals - edit in test/Aftok/TimeLogSpec.hs at line 136[3.3976][26.1680]
shares = payouts depf evalTime widx(shares ^. loggedTotal `shouldBe` (fromInteger @NominalDiffTime (360 * 160)))(shares ^. creditToShares . to (fromJust . M.lookup u0) . wsShare) `shouldBe` (10 % 160)(shares ^. creditToShares . to (fromJust . M.lookup u1) . wsShare) `shouldBe` (30 % 160)(shares ^. creditToShares . to (fromJust . M.lookup u2) . wsShare) `shouldBe` (120 % 160)