histogram command, undocumented for now
This commit is contained in:
parent
32a3af8334
commit
dee37efc1c
46
HistogramCommand.hs
Normal file
46
HistogramCommand.hs
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
{-|
|
||||||
|
|
||||||
|
Print a histogram report.
|
||||||
|
|
||||||
|
-}
|
||||||
|
|
||||||
|
module HistogramCommand
|
||||||
|
where
|
||||||
|
import qualified Data.Map as Map
|
||||||
|
import Data.Map ((!))
|
||||||
|
import Ledger
|
||||||
|
import Options
|
||||||
|
|
||||||
|
|
||||||
|
barchar = '*'
|
||||||
|
|
||||||
|
-- | Print a histogram of some statistic per reporting interval, such as
|
||||||
|
-- number of transactions per day.
|
||||||
|
histogram :: [Opt] -> [String] -> Ledger -> IO ()
|
||||||
|
histogram opts args l =
|
||||||
|
mapM_ (printDayWith countBar) daytxns
|
||||||
|
where
|
||||||
|
i = intervalFromOpts opts
|
||||||
|
interval | i == NoInterval = Daily
|
||||||
|
| otherwise = i
|
||||||
|
fullspan = rawLedgerDateSpan $ rawledger l
|
||||||
|
days = filter (DateSpan Nothing Nothing /=) $ splitSpan interval fullspan
|
||||||
|
daytxns = [(s, filter (isTransactionInDateSpan s) ts) | s <- days]
|
||||||
|
-- same as RegisterCommand
|
||||||
|
ts = sortBy (comparing date) $ filterempties $ filter matchapats $ filterdepth $ ledgerTransactions l
|
||||||
|
filterempties
|
||||||
|
| Empty `elem` opts = id
|
||||||
|
| otherwise = filter (not . isZeroMixedAmount . amount)
|
||||||
|
matchapats t = matchpats apats $ account t
|
||||||
|
(apats,_) = parsePatternArgs args
|
||||||
|
filterdepth | interval == NoInterval = filter (\t -> (accountNameLevel $ account t) <= depth)
|
||||||
|
| otherwise = id
|
||||||
|
depth = depthFromOpts opts
|
||||||
|
|
||||||
|
printDayWith f (DateSpan b _, ts) = putStrLn $ printf "%s %s" (show $ fromJust b) (f ts)
|
||||||
|
|
||||||
|
countBar ts = replicate (length ts) barchar
|
||||||
|
|
||||||
|
total ts = show $ sumTransactions ts
|
||||||
|
|
||||||
|
-- totalBar ts = replicate (sumTransactions ts) barchar
|
||||||
@ -40,6 +40,7 @@ module Main (
|
|||||||
module BalanceCommand,
|
module BalanceCommand,
|
||||||
module PrintCommand,
|
module PrintCommand,
|
||||||
module RegisterCommand,
|
module RegisterCommand,
|
||||||
|
module HistogramCommand,
|
||||||
#ifdef VTY
|
#ifdef VTY
|
||||||
module UICommand,
|
module UICommand,
|
||||||
#endif
|
#endif
|
||||||
@ -60,6 +61,7 @@ import Tests
|
|||||||
import BalanceCommand
|
import BalanceCommand
|
||||||
import PrintCommand
|
import PrintCommand
|
||||||
import RegisterCommand
|
import RegisterCommand
|
||||||
|
import HistogramCommand
|
||||||
#ifdef VTY
|
#ifdef VTY
|
||||||
import UICommand
|
import UICommand
|
||||||
#endif
|
#endif
|
||||||
@ -79,6 +81,7 @@ main = do
|
|||||||
| cmd `isPrefixOf` "balance" = withLedgerDo opts args balance
|
| cmd `isPrefixOf` "balance" = withLedgerDo opts args balance
|
||||||
| cmd `isPrefixOf` "print" = withLedgerDo opts args print'
|
| cmd `isPrefixOf` "print" = withLedgerDo opts args print'
|
||||||
| cmd `isPrefixOf` "register" = withLedgerDo opts args register
|
| cmd `isPrefixOf` "register" = withLedgerDo opts args register
|
||||||
|
| cmd `isPrefixOf` "histogram" = withLedgerDo opts args histogram
|
||||||
#ifdef VTY
|
#ifdef VTY
|
||||||
| cmd `isPrefixOf` "ui" = withLedgerDo opts args ui
|
| cmd `isPrefixOf` "ui" = withLedgerDo opts args ui
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user