Switch from Data.Time to Data.Thyme
[?]
Apr 19, 2015, 10:41 PM
7KZP4RHZ3QSYTPPQ257A65Z5UPX44TF2LAI2U5EMULQCLDCEUK2ACDependencies
- [2]
FD7SV5I6Fix handling of event_t columns. - [3]
WO2MINIFAuctions now compile! - [4]
SLL7262CMake depreciation functions more flexible. - [5]
4IQVQL4TAdded client for payouts endpoint. - [6]
A6HKMINBAttempting to improve JSON handling. - [7]
EQXRXRZDChanged to use tasty instead of test-framework - [8]
GKGVYBZGAdded JSON serialization to TimeLog - [9]
A2J7B4SCInitial impl of depreciation function. - [10]
2KZPOGRBOnce you get Haskell to compile, the tests pass! - [11]
WZUHEZSBStart of migration back toward snap. - [12]
XTBSG4C7Adding serveJSON combinator to eliminate some boilerplate from handlers. - [13]
4QX5E5ACInitial compilation of payouts function succeeds. - [14]
7XN3I3QJAdd 'loggedIntervals' endpoint. - [15]
N4NDAZYTInitial implementation of payouts. - [16]
TNR3TEHKSwitch to Postgres + snaplet arch compiles. - [17]
64C6AWH6Rename Ananke -> Quixotic, project reboot. - [18]
HE3JTXO3Added client call to payouts. - [19]
OBFPJS2GProject successfully builds and tests under nix. - [20]
IZEVQF62Work in progress replacing sqlite with postgres. - [21]
TCOAKCGGCompleted conversion to snap. - [22]
RSEB2NFGReplacing Snap with Scotty. - [23]
P6NR2CGXBeginning of implementation of depreciation. - [24]
TJEUE7TYAdded OverloadedStrings to eliminate Text fiddling. - [25]
7DBNV3GVInitial, stack-based impl of time log event reduction. - [26]
TLQ72DSJLenses, sqlite-simple - [27]
Z7KS5XHHVery WIP. Wow. - [28]
I2KHGVD4Require project permissions for access to most data. - [29]
2OIPAQCBMerge branch 'master' of github.com:nuttycom/ananke - [30]
NMWWP4ZNTrying out Hspec - [31]
NVOCQVASInitial failing tests. - [32]
BROSTG5KBeginning of modularization of server. - [33]
Y35QCWYWMinor improvement in WorkIndex type to eliminate duplicated information. - [34]
EMVTF2IWWIP moving back to snap. - [35]
EZQG2APBUpdate task list. - [*]
PBD7LZYQPostgres & auth are beginning to function.
Change contents
- edit in lib/Quixotic/Database/PostgreSQL.hs at line 10
import Data.Thyme.Clock as Cimport Data.Thyme.Time - edit in lib/Quixotic/Database/PostgreSQL.hs at line 51
utcParser :: FieldParser C.UTCTimeutcParser f v = toThyme <$> fromField f v - replacement in lib/Quixotic/Database/PostgreSQL.hs at line 57
workEventParser = WorkEvent <$> fieldWith eventTypeParser <*> field <*> fieldworkEventParser = WorkEvent <$> fieldWith eventTypeParser <*> fieldWith utcParser <*> field - replacement in lib/Quixotic/Database/PostgreSQL.hs at line 144
, e ^. eventTime, fromThyme $ e ^. eventTime - replacement in lib/Quixotic/Database/PostgreSQL.hs at line 153
( eid, mt ^. _ModTime, t )( eid, fromThyme $ mt ^. _ModTime, fromThyme t ) - replacement in lib/Quixotic/Database/PostgreSQL.hs at line 158
( eid, mt ^. _ModTime, addr ^. _BtcAddr )( eid, fromThyme $ mt ^. _ModTime, addr ^. _BtcAddr ) - replacement in lib/Quixotic/Database/PostgreSQL.hs at line 163
( eid, mt ^. _ModTime, v )( eid, fromThyme $ mt ^. _ModTime, v ) - edit in lib/Quixotic/Interval.hs at line 12
import Data.AffineSpace - replacement in lib/Quixotic/Interval.hs at line 14[3.114]→[3.1494:1517](∅→∅),[3.487]→[3.1494:1517](∅→∅),[3.1747]→[3.1494:1517](∅→∅),[3.3309]→[3.1494:1517](∅→∅),[3.1494]→[3.1494:1517](∅→∅),[3.1517]→[3.2546:2575](∅→∅)
import Data.Time.Clockimport Data.Time.LocalTime()import Data.Thyme.Clock as Cimport Data.Thyme.LocalTime()import Data.Thyme.Format.Aeson() - replacement in lib/Quixotic/Interval.hs at line 18
data Interval = Interval { _start :: UTCTime, _end :: UTCTimedata Interval = Interval { _start :: C.UTCTime, _end :: C.UTCTime - replacement in lib/Quixotic/Interval.hs at line 23
interval :: UTCTime -> UTCTime -> Intervalinterval :: C.UTCTime -> C.UTCTime -> Interval - replacement in lib/Quixotic/Interval.hs at line 26
ilen :: Interval -> NominalDiffTimeilen i = diffUTCTime (_end i) (_start i)ilen :: Interval -> C.NominalDiffTimeilen i = (_end i) .-. (_start i) - edit in lib/Quixotic/TimeLog.hs at line 27
import Data.AdditiveGroup - edit in lib/Quixotic/TimeLog.hs at line 30
import Data.AffineSpace - replacement in lib/Quixotic/TimeLog.hs at line 34[3.21]→[3.1028:1051](∅→∅),[3.119]→[3.1028:1051](∅→∅),[3.258]→[3.1028:1051](∅→∅),[3.2665]→[3.1028:1051](∅→∅),[3.1028]→[3.1028:1051](∅→∅)
import Data.Time.Clockimport Data.Thyme.Clock as Cimport Data.VectorSpace - replacement in lib/Quixotic/TimeLog.hs at line 54
, _eventTime :: UTCTime, _eventTime :: C.UTCTime - replacement in lib/Quixotic/TimeLog.hs at line 70
newtype ModTime = ModTime UTCTimenewtype ModTime = ModTime C.UTCTime - replacement in lib/Quixotic/TimeLog.hs at line 73
data LogModification = TimeChange ModTime UTCTimedata LogModification = TimeChange ModTime C.UTCTime - replacement in lib/Quixotic/TimeLog.hs at line 102
type NDT = NominalDiffTimetype NDT = C.NominalDiffTime - replacement in lib/Quixotic/TimeLog.hs at line 111
The depreciation function should return a value between 0 and 1;this result is multiplied by the length of an interval of work to determinethe depreciated value of the work.-}type DepF = UTCTime -> Interval -> NDT- 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.-}type DepF = C.UTCTime -> Interval -> NDT - replacement in lib/Quixotic/TimeLog.hs at line 118
Payouts are determined by computing a depreciated duration value foreach work interval. This function computes the percentage of the totalwork allocated to each address.-}payouts :: DepF -> UTCTime -> WorkIndex -> Payouts- Given a depreciation function, the "current" time, and a foldable functor of log intervals,- produce the total, depreciated length of work to be credited to an address.-}workCredit :: (Functor f, Foldable f) => DepF -> C.UTCTime -> f Interval -> NDTworkCredit depf ptime ivals = getSum $ F.foldMap (Sum . depf ptime) ivals{-|- 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 :: DepF -> C.UTCTime -> WorkIndex -> Payouts - replacement in lib/Quixotic/TimeLog.hs at line 132
addIntervalDiff total ivals = (\dt -> (dt + total, dt)) $ workCredit dep ptime ivals(totalTime, keyTimes) = MS.mapAccum addIntervalDiff (fromInteger 0) $ widxin Payouts $ fmap (\kt -> toRational $ kt / totalTime) keyTimesaddIntervalDiff total ivals = (^+^ total) &&& id $ workCredit dep ptime ivals - replacement in lib/Quixotic/TimeLog.hs at line 134[3.1012]→[3.1012:1016](∅→∅),[3.1016]→[3.1200:1372](∅→∅),[3.1372]→[3.1019:1022](∅→∅),[3.1019]→[3.1019:1022](∅→∅),[3.1022]→[3.171:337](∅→∅)
{-|Given a depreciation function, the "current" time, and a foldable functor of log intervals,produce the total, depreciated length of work to be credited to an address.-}workCredit :: (Functor f, Foldable f) => DepF -> UTCTime -> f Interval -> NDTworkCredit depf ptime ivals =F.foldl' (+) (fromInteger 0) $ fmap (depf ptime) ivals(totalTime, keyTimes) = MS.mapAccum addIntervalDiff zeroV $ widxin Payouts $ fmap ((/ toSeconds totalTime) . toSeconds) keyTimes - replacement in lib/Quixotic/TimeLog.hs at line 160
monthsLength :: Months -> NominalDiffTimemonthsLength (Months i) = fromInteger $ 60 * 60 * 24 * 30 * ilinearDepreciation :: Months -> Months -> DepFlinearDepreciation undepPeriod depPeriod = \ptime ival ->let maxDepreciable :: NominalDiffTimemaxDepreciable = monthsLength undepPeriod + monthsLength depPeriod{-|- A very simple linear function for calculating depreciation.--}linearDepreciation :: Months -> -- ^ The number of initial months during which no depreciation occursMonths -> -- ^ The number of months over which each logged interval will be depreciatedDepFlinearDepreciation undepPeriod depPeriod =let monthsLength :: Months -> NDTmonthsLength (Months i) = fromSeconds $ 60 * 60 * 24 * 30 * i - replacement in lib/Quixotic/TimeLog.hs at line 171
zeroTime :: NominalDiffTimezeroTime = fromInteger 0maxDepreciable :: NDTmaxDepreciable = monthsLength undepPeriod ^+^ monthsLength depPeriod - replacement in lib/Quixotic/TimeLog.hs at line 174
depPct :: NominalDiffTime -> RationaldepPct :: NDT -> Rational - replacement in lib/Quixotic/TimeLog.hs at line 177
else toRational (max zeroTime (maxDepreciable - dt)) / toRational maxDepreciableelse toSeconds (max zeroV (maxDepreciable ^-^ dt)) / toSeconds maxDepreciable - replacement in lib/Quixotic/TimeLog.hs at line 179
depreciation = depPct $ diffUTCTime ptime (ival ^. end)in fromRational $ depreciation * (toRational $ ilen ival)[3.558]in \ptime ival ->let depreciation = depPct $ ptime .-. (ival ^. end)in depreciation *^ (ilen ival) - replacement in quixotic.cabal at line 50
, time >= 1.4.2 && < 1.5, thyme >= 0.3.5 - edit in quixotic.cabal at line 55[37.1200][3.1070]
, vector-space - edit in quixotic.cabal at line 71
, QuickCheck >= 2.7 - replacement in quixotic.cabal at line 78
, time, thyme - edit in quixotic.cabal at line 81
, vector-space - replacement in quixotic.cabal at line 104
, time, thyme - replacement in quixotic.cabal at line 136
, time, thyme - edit in server/Quixotic/Snaplet/WorkLog.hs at line 8
import Data.Thyme.Clock as C - replacement in server/Quixotic/Snaplet/WorkLog.hs at line 28
timestamp <- liftIO getCurrentTimetimestamp <- liftIO C.getCurrentTime - replacement in server/Quixotic/Snaplet/WorkLog.hs at line 48
ptime <- liftIO $ getCurrentTimeptime <- liftIO $ C.getCurrentTime - edit in test/Quixotic/TimeLogSpec.hs at line 2
{-# OPTIONS_GHC -Wwarn -fno-warn-orphans #-} - edit in test/Quixotic/TimeLogSpec.hs at line 13
import Data.AffineSpace - edit in test/Quixotic/TimeLogSpec.hs at line 16
import Data.Thyme.Clockimport Data.Thyme.Timeimport qualified Data.Text as Timport Test.QuickCheckinstance Arbitrary EventType wherearbitrary = elements [StartWork, StopWork]newtype EventLog = EventLog [LogEntry]instance Arbitrary BtcAddr wherearbitrary = BtcAddr . T.pack <$> vectorOf 34 arbitrary - edit in test/Quixotic/TimeLogSpec.hs at line 29
instance Arbitrary Interval wherearbitrary = dostart <- arbitrarydelta <- arbitrarypure $ I.interval start (start .+^ delta) - replacement in test/Quixotic/TimeLogSpec.hs at line 43
starts = catMaybes [ parseISO8601 "2014-01-01T00:08:00Z", parseISO8601 "2014-02-12T00:12:00Z" ]starts = toThyme <$> catMaybes [ parseISO8601 "2014-01-01T00:08:00Z", parseISO8601 "2014-02-12T00:12:00Z" ] - replacement in test/Quixotic/TimeLogSpec.hs at line 46
ends = catMaybes [ parseISO8601 "2014-01-01T00:12:00Z", parseISO8601 "2014-02-12T00:18:00Z" ]ends = toThyme <$> catMaybes [ parseISO8601 "2014-01-01T00:12:00Z", parseISO8601 "2014-02-12T00:18:00Z" ] - edit in test/Quixotic/TimeLogSpec.hs at line 68
describe "EventType serialization" $ doit "serialization is invertible" $ property $\e -> (nameEvent . eventName) e == Just e