Initial compilation of payouts function succeeds.

[?]
Feb 28, 2014, 5:08 AM
4QX5E5ACVN57KJLCWOM4JEI6JSV4XZNCWVYPOTKSOMUW3SOMCNJAC

Dependencies

  • [2] N4NDAZYT Initial implementation of payouts.
  • [3] EQXRXRZD Changed to use tasty instead of test-framework
  • [4] 7DBNV3GV Initial, stack-based impl of time log event reduction.
  • [5] JUUMYIQE Add groupBy utility function for use in TimeLog.
  • [6] NVOCQVAS Initial failing tests.

Change contents

  • replacement in src/Ananke/TimeLog.hs at line 1
    [3.846][3.847:883]()
    {-# LANGUAGE DeriveDataTypeable #-}
    [3.846]
    [3.883]
    {-# LANGUAGE DeriveDataTypeable, ScopedTypeVariables #-}
  • edit in src/Ananke/TimeLog.hs at line 49
    [2.159]
    [3.350]
    type NDT = NominalDiffTime
  • replacement in src/Ananke/TimeLog.hs at line 51
    [3.351][2.160:306]()
    sumLogIntervals :: [LogInterval] -> Rational
    sumLogIntervals ivals = F.foldl' (+) (fromInteger 0) $ fmap (toRational . ilen . workInterval) ivals
    [3.351]
    [3.2353]
    {-|
    The depreciation function should return a value between 0 and 1;
    this result is multiplied by the length of an interval of work to determine
    the depreciated value of the work.
    -}
    newtype Depreciation = Depreciation { depf :: NDT -> Rational }
  • replacement in src/Ananke/TimeLog.hs at line 58
    [3.2354][2.307:599]()
    payouts :: WorkIndex -> Payouts
    payouts widx = let addIntervalDiff total ivals = (\dt -> (dt + total, dt)) $ sumLogIntervals ivals
    (totalTime, keyTimes) = M.mapAccum addIntervalDiff (fromInteger 0) $ M.map snd widx
    in M.map (\kt -> kt / totalTime) keyTimes
    [3.2354]
    [2.599]
    {-|
    Payouts are determined by computing a depreciated duration value for
    each work interval. This function computes the percentage of the total
    work allocated to each address.
    -}
    payouts :: Depreciation -> UTCTime -> WorkIndex -> Payouts
    payouts dep ptime widx = let addIntervalDiff :: (Functor f, Foldable f) => NDT -> f LogInterval -> (NDT, NDT)
    addIntervalDiff total ivals = (\dt -> (dt + total, dt)) $ sumLogIntervals dep ptime ivals
    (totalTime, keyTimes) = M.mapAccum addIntervalDiff (fromInteger 0) $ M.map snd widx
    in M.map (\kt -> toRational $ kt / totalTime) keyTimes
    {-|
    -}
    sumLogIntervals :: (Functor f, Foldable f) => Depreciation -> UTCTime -> f LogInterval -> NDT
    sumLogIntervals dep ptime ivals = F.foldl' (+) (fromInteger 0) $ fmap (depreciateInterval dep ptime) ivals
  • edit in src/Ananke/TimeLog.hs at line 75
    [2.600]
    [3.352]
    depreciateInterval :: Depreciation -> UTCTime -> LogInterval -> NDT
    depreciateInterval dep ptime ival = let depreciation :: Rational
    depreciation = depf dep $ diffUTCTime ptime (end . workInterval $ ival)
    in fromRational $ depreciation * (toRational . ilen . workInterval $ ival)