Added JSON serialization to TimeLog

[?]
Mar 26, 2014, 3:56 AM
GKGVYBZGPJXO7N7GLHLRNYQPXFHBQSNQN53OKRFCXLQEYDTC5I4QC

Dependencies

  • [2] P6NR2CGX Beginning of implementation of depreciation.
  • [3] Y35QCWYW Minor improvement in WorkIndex type to eliminate duplicated information.
  • [4] NMWWP4ZN Trying out Hspec
  • [5] NVOCQVAS Initial failing tests.
  • [6] EQXRXRZD Changed to use tasty instead of test-framework
  • [7] 2KZPOGRB Once you get Haskell to compile, the tests pass!
  • [8] 7DBNV3GV Initial, stack-based impl of time log event reduction.
  • [9] ADMKQQGC Initial empty Snap project.
  • [10] N4NDAZYT Initial implementation of payouts.
  • [11] 4QX5E5AC Initial compilation of payouts function succeeds.

Change contents

  • edit in ananke.cabal at line 29
    [3.31]
    [3.299]
    aeson >= 0.7.0.2,
  • edit in ananke.cabal at line 43
    [3.69]
    [3.41]
    ananke,
    aeson,
  • edit in ananke.cabal at line 46
    [3.71][3.788:808](),[3.788][3.788:808]()
    text,
    time,
  • replacement in ananke.cabal at line 48
    [3.826][3.826:837]()
    ananke
    [3.826]
    [3.801]
    text,
    time
  • replacement in src/Ananke/TimeLog.hs at line 1
    [3.846][3.3:60]()
    {-# LANGUAGE DeriveDataTypeable, ScopedTypeVariables #-}
    [3.846]
    [3.883]
    {-# LANGUAGE DeriveDataTypeable, ScopedTypeVariables, OverloadedStrings #-}
  • edit in src/Ananke/TimeLog.hs at line 18
    [3.119]
    [3.65]
    import Data.Aeson
    import qualified Data.Aeson.Types as A
  • edit in src/Ananke/TimeLog.hs at line 22
    [3.119]
    [3.1028]
    import qualified Data.Text as T
  • edit in src/Ananke/TimeLog.hs at line 28
    [3.1194]
    [3.1194]
    import Control.Monad
  • edit in src/Ananke/TimeLog.hs at line 30
    [3.1224]
    [3.1224]
    import Debug.Trace
  • replacement in src/Ananke/TimeLog.hs at line 36
    [3.1283][3.1283:1361](),[3.1362][3.1362:1406]()
    data LogEventParseError = LogEventParseError String deriving (Show, Typeable)
    instance Exception LogEventParseError where
    [3.1283]
    [3.1406]
    instance FromJSON WorkEvent where
    parseJSON (Object jv) = do
    t <- jv .: "type" :: A.Parser T.Text
    case t of
    "start" -> StartWork <$> jv .: "timestamp"
    "stop" -> StopWork <$> jv .: "timestamp"
    _ -> mzero
  • replacement in src/Ananke/TimeLog.hs at line 44
    [3.1407][3.321:654]()
    -- instance FromField WorkEvent where
    -- fromField f m = let fromText "start_work" = return StartWork
    -- fromText "stop_work" = return StopWork
    -- fromText a = conversionError $ LogEventParseError $ "unrecognized log event type " ++ a
    -- in fromField f m >>= fromText
    [3.1407]
    [3.1724]
    data LogEntry = LogEntry
    { btcAddr :: BtcAddr
    , event :: WorkEvent
    } deriving (Show, Eq)
  • replacement in src/Ananke/TimeLog.hs at line 49
    [3.1725][3.1725:1771](),[3.1771][3.655:702](),[3.702][3.1863:1910](),[3.1863][3.1863:1910]()
    data LogEntry = LogEntry { btcAddr :: BtcAddr
    , event :: WorkEvent
    } deriving (Show, Eq)
    [3.1725]
    [3.2123]
    instance FromJSON LogEntry where
    parseJSON (Object jv) = LogEntry <$>
    jv .: "btcAddr" <*>
    jv .: "workEvent"
  • replacement in src/Ananke/TimeLog.hs at line 54
    [3.2124][3.703:793]()
    -- instance FromRow LogEntry where
    -- fromRow = LogEntry <$> field <*> field <*> field
    [3.2124]
    [3.2285]
    parseJSON _ = mzero
  • replacement in src/Ananke/TimeLog.hs at line 56
    [3.2286][3.120:292]()
    data LogInterval = LogInterval { intervalBtcAddr :: BtcAddr
    , workInterval :: Interval
    } deriving (Show, Eq)
    [3.2286]
    [3.2286]
    data LogInterval = LogInterval
    { intervalBtcAddr :: BtcAddr
    , workInterval :: Interval
    } deriving (Show, Eq)
  • replacement in src/Ananke/TimeLog.hs at line 101
    [3.403][3.1893:2008]()
    intervals logEntries = M.map (bimap (fmap event) (fmap workInterval)) $ F.foldl' appendLogEntry M.empty logEntries
    [3.403]
    [3.448]
    intervals logEntries =
    let logSum = F.foldl' appendLogEntry M.empty logEntries
    in M.map (bimap (fmap event) (fmap workInterval)) $ logSum
  • replacement in src/Ananke/TimeLog.hs at line 118
    [3.2482][3.928:970](),[3.928][3.928:970]()
    reduceToIntervals misaligned = misaligned
    [3.2482]
    [3.970]
    reduceToIntervals misaligned =
    misaligned
  • replacement in src/Ananke/TimeLog.hs at line 123
    [2.106][2.106:149]()
    let depf = undefined
    Depreciation depf
    [2.106]
    let depf ndt = undefined
    in Depreciation depf
    -- data LogEventParseError = LogEventParseError String deriving (Show, Typeable)
    -- instance Exception LogEventParseError where
    -- instance FromField WorkEvent where
    -- fromField f m = let fromText "start_work" = return StartWork
    -- fromText "stop_work" = return StopWork
    -- fromText a = conversionError $ LogEventParseError $ "unrecognized log event type " ++ a
    -- in fromField f m >>= fromText
    -- instance FromRow LogEntry where
    -- fromRow = LogEntry <$> field <*> field <*> field
  • edit in src/Ananke.hs at line 7
    [3.2548]
    [3.2484]
    import Data.Aeson
    import Data.Aeson.Types as JV
    import Control.Monad
  • edit in src/Ananke.hs at line 17
    [3.2764]
    [3.2531]
    instance FromJSON BtcAddr where
    parseJSON (JV.String t) = return $ BtcAddr t
    parseJSON _ = mzero
  • edit in test/Ananke/TimeLogSpec.hs at line 12
    [3.312]
    [3.2658]
    import Data.Aeson
  • edit in test/Ananke/TimeLogSpec.hs at line 23
    [3.381]
    [2.153]
    describe "work event parsing" $ do
    it "parses a start event" $ do
    let startText = "{\"type\":\"start\", \"timestamp\":\"2014-03-22T11:37:08Z\"}"
    expected = fmap StartWork $ parseISO8601 "2014-03-22T11:37:08Z"
    (decode startText) `shouldBe` expected