Added JSON serialization to TimeLog
[?]
Mar 26, 2014, 3:56 AM
GKGVYBZGPJXO7N7GLHLRNYQPXFHBQSNQN53OKRFCXLQEYDTC5I4QCDependencies
- [2]
P6NR2CGXBeginning of implementation of depreciation. - [3]
Y35QCWYWMinor improvement in WorkIndex type to eliminate duplicated information. - [4]
NMWWP4ZNTrying out Hspec - [5]
NVOCQVASInitial failing tests. - [6]
EQXRXRZDChanged to use tasty instead of test-framework - [7]
2KZPOGRBOnce you get Haskell to compile, the tests pass! - [8]
7DBNV3GVInitial, stack-based impl of time log event reduction. - [9]
ADMKQQGCInitial empty Snap project. - [10]
N4NDAZYTInitial implementation of payouts. - [11]
4QX5E5ACInitial compilation of payouts function succeeds.
Change contents
- edit in ananke.cabal at line 29
aeson >= 0.7.0.2, - edit in ananke.cabal at line 43
ananke,aeson, - edit in ananke.cabal at line 46
text,time, - replacement in ananke.cabal at line 48
ananketext,time - replacement in src/Ananke/TimeLog.hs at line 1
{-# LANGUAGE DeriveDataTypeable, ScopedTypeVariables #-}{-# LANGUAGE DeriveDataTypeable, ScopedTypeVariables, OverloadedStrings #-} - edit in src/Ananke/TimeLog.hs at line 18
import Data.Aesonimport qualified Data.Aeson.Types as A - edit in src/Ananke/TimeLog.hs at line 22
import qualified Data.Text as T - edit in src/Ananke/TimeLog.hs at line 28
import Control.Monad - edit in src/Ananke/TimeLog.hs at line 30
import Debug.Trace - replacement in src/Ananke/TimeLog.hs at line 36
data LogEventParseError = LogEventParseError String deriving (Show, Typeable)instance Exception LogEventParseError whereinstance FromJSON WorkEvent whereparseJSON (Object jv) = dot <- jv .: "type" :: A.Parser T.Textcase t of"start" -> StartWork <$> jv .: "timestamp""stop" -> StopWork <$> jv .: "timestamp"_ -> mzero - replacement in src/Ananke/TimeLog.hs at line 44
-- 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 >>= fromTextdata 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)instance FromJSON LogEntry whereparseJSON (Object jv) = LogEntry <$>jv .: "btcAddr" <*>jv .: "workEvent" - replacement in src/Ananke/TimeLog.hs at line 54
-- instance FromRow LogEntry where-- fromRow = LogEntry <$> field <*> field <*> fieldparseJSON _ = mzero - replacement in src/Ananke/TimeLog.hs at line 56
data LogInterval = LogInterval { intervalBtcAddr :: BtcAddr, workInterval :: Interval} deriving (Show, Eq)data LogInterval = LogInterval{ intervalBtcAddr :: BtcAddr, workInterval :: Interval} deriving (Show, Eq) - replacement in src/Ananke/TimeLog.hs at line 101
intervals logEntries = M.map (bimap (fmap event) (fmap workInterval)) $ F.foldl' appendLogEntry M.empty logEntriesintervals logEntries =let logSum = F.foldl' appendLogEntry M.empty logEntriesin M.map (bimap (fmap event) (fmap workInterval)) $ logSum - replacement in src/Ananke/TimeLog.hs at line 118
reduceToIntervals misaligned = misalignedreduceToIntervals misaligned =misaligned - replacement in src/Ananke/TimeLog.hs at line 123
let depf = undefinedDepreciation depf[2.106]let depf ndt = undefinedin 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
import Data.Aesonimport Data.Aeson.Types as JVimport Control.Monad - edit in src/Ananke.hs at line 17
instance FromJSON BtcAddr whereparseJSON (JV.String t) = return $ BtcAddr tparseJSON _ = mzero - edit in test/Ananke/TimeLogSpec.hs at line 12
import Data.Aeson - edit in test/Ananke/TimeLogSpec.hs at line 23
describe "work event parsing" $ doit "parses a start event" $ dolet startText = "{\"type\":\"start\", \"timestamp\":\"2014-03-22T11:37:08Z\"}"expected = fmap StartWork $ parseISO8601 "2014-03-22T11:37:08Z"(decode startText) `shouldBe` expected