Make depreciation functions more flexible.

[?]
Jan 17, 2015, 7:51 PM
SLL7262CJUE7TZDDZZXFROHCVVDA527WA4PHXCKEGZUJF2EN5MQAC

Dependencies

  • [2] 7XN3I3QJ Add 'loggedIntervals' endpoint.
  • [3] TLQ72DSJ Lenses, sqlite-simple
  • [4] 2OIPAQCB Merge branch 'master' of github.com:nuttycom/ananke
  • [5] RSEB2NFG Replacing Snap with Scotty.
  • [6] Y35QCWYW Minor improvement in WorkIndex type to eliminate duplicated information.
  • [7] P6NR2CGX Beginning of implementation of depreciation.
  • [8] A2J7B4SC Initial impl of depreciation function.
  • [9] 7DBNV3GV Initial, stack-based impl of time log event reduction.
  • [10] NVOCQVAS Initial failing tests.
  • [11] GKGVYBZG Added JSON serialization to TimeLog
  • [12] 64C6AWH6 Rename Ananke -> Quixotic, project reboot.
  • [13] 4QX5E5AC Initial compilation of payouts function succeeds.
  • [14] N4NDAZYT Initial implementation of payouts.

Change contents

  • replacement in lib/Quixotic/TimeLog.hs at line 16
    [3.3635][3.3:24](),[3.107][3.3:24]()
    , Depreciation(..)
    [3.3635]
    [3.5326]
    , DepF
  • edit in lib/Quixotic/TimeLog.hs at line 62
    [3.2287]
    [2.337]
    type Payouts = Map BtcAddr Rational
  • edit in lib/Quixotic/TimeLog.hs at line 64
    [2.377][3.123:159](),[3.849][3.123:159](),[3.350][3.123:159](),[3.159][3.61:88]()
    type Payouts = Map BtcAddr Rational
    type NDT = NominalDiffTime
  • edit in lib/Quixotic/TimeLog.hs at line 65
    [2.434]
    [3.350]
    type NDT = NominalDiffTime
  • replacement in lib/Quixotic/TimeLog.hs at line 72
    [3.278][3.278:343]()
    newtype Depreciation = Depreciation { depf :: NDT -> Rational }
    [3.278]
    [3.2353]
    type DepF = UTCTime -> Interval -> NDT
  • replacement in lib/Quixotic/TimeLog.hs at line 79
    [3.529][3.529:588]()
    payouts :: Depreciation -> UTCTime -> WorkIndex -> Payouts
    [3.529]
    [3.850]
    payouts :: DepF -> UTCTime -> WorkIndex -> Payouts
  • replacement in lib/Quixotic/TimeLog.hs at line 90
    [3.1022][3.1373:1561](),[3.1223][3.599:600](),[3.1561][3.599:600](),[3.599][3.599:600](),[3.600][3.1562:1892]()
    workCredit :: (Functor f, Foldable f) => Depreciation -> UTCTime -> f Interval -> NDT
    workCredit dep ptime ivals = F.foldl' (+) (fromInteger 0) $ fmap (depreciateInterval dep ptime) ivals
    {-|
    Compute the depreciated difftime for a single Interval value.
    -}
    depreciateInterval :: Depreciation -> UTCTime -> Interval -> NDT
    depreciateInterval dep ptime ival =
    let depreciation :: Rational
    depreciation = depf dep $ diffUTCTime ptime (end $ ival)
    in fromRational $ depreciation * (toRational . ilen $ ival)
    [3.1022]
    [3.1581]
    workCredit :: (Functor f, Foldable f) => DepF -> UTCTime -> f Interval -> NDT
    workCredit depf ptime ivals =
    F.foldl' (+) (fromInteger 0) $ fmap (depf ptime) ivals
  • replacement in lib/Quixotic/TimeLog.hs at line 119
    [3.162][3.162:261]()
    linearDepreciation :: Months -> Months -> Depreciation
    linearDepreciation undepPeriod depPeriod =
    [3.162]
    [3.261]
    linearDepreciation :: Months -> Months -> DepF
    linearDepreciation undepPeriod depPeriod = \ptime ival ->
  • replacement in lib/Quixotic/TimeLog.hs at line 127
    [3.971][3.2917:3011](),[3.3011][3.482:497](),[3.482][3.482:497]()
    depf' :: NominalDiffTime -> Rational
    depf' dt = if dt < monthsLength undepPeriod
    then 1
    [3.971]
    [3.497]
    depPct :: NominalDiffTime -> Rational
    depPct dt =
    if dt < monthsLength undepPeriod then 1
  • replacement in lib/Quixotic/TimeLog.hs at line 131
    [3.586][3.3012:3036]()
    in Depreciation depf'
    [3.586]
    depreciation = depPct $ diffUTCTime ptime (end $ ival)
    in fromRational $ depreciation * (toRational . ilen $ ival)