From 6ccecb6ae0b147758e3fea0b9e1ee7f4f715ef7c Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Wed, 30 May 2012 09:17:18 +0000 Subject: [PATCH] stats: list included journal files --- hledger-lib/Hledger/Utils.hs | 4 ++-- hledger/Hledger/Cli/Stats.hs | 14 +++++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/hledger-lib/Hledger/Utils.hs b/hledger-lib/Hledger/Utils.hs index 9501dc8a3..0cc4a883c 100644 --- a/hledger-lib/Hledger/Utils.hs +++ b/hledger-lib/Hledger/Utils.hs @@ -135,8 +135,8 @@ concatBottomPadded strs = intercalate "\n" $ map concat $ transpose padded lss = map lines strs h = maximum $ map length lss ypad ls = ls ++ replicate (difforzero h (length ls)) "" - xpad ls = map (padleft w) ls where w | null ls = 0 - | otherwise = maximum $ map length ls + xpad ls = map (padright w) ls where w | null ls = 0 + | otherwise = maximum $ map length ls padded = map (xpad . ypad) lss -- | Compose strings vertically and right-aligned. diff --git a/hledger/Hledger/Cli/Stats.hs b/hledger/Hledger/Cli/Stats.hs index 6777d13d9..a499f8b41 100644 --- a/hledger/Hledger/Cli/Stats.hs +++ b/hledger/Hledger/Cli/Stats.hs @@ -34,13 +34,15 @@ stats CliOpts{reportopts_=reportopts_} j = do showLedgerStats :: Ledger -> Day -> DateSpan -> String showLedgerStats l today span = - unlines (map (uncurry (printf fmt)) stats) + unlines $ map (\(label,value) -> concatBottomPadded [printf fmt1 label, value]) stats where - fmt = "%-" ++ show w1 ++ "s: %-" ++ show w2 ++ "s" + fmt1 = "%-" ++ show w1 ++ "s: " + -- fmt2 = "%-" ++ show w2 ++ "s" w1 = maximum $ map (length . fst) stats - w2 = maximum $ map (length . show . snd) stats + -- w2 = maximum $ map (length . show . snd) stats stats = [ - ("Journal file", journalFilePath $ ledgerJournal l) + ("Main journal file", path) -- ++ " (from " ++ source ++ ")") + ,("Included journal files", unlines $ drop 1 $ journalFilePaths j) ,("Transactions span", printf "%s to %s (%d days)" (start span) (end span) days) ,("Last transaction", maybe "none" show lastdate ++ showelapsed lastelapsed) ,("Transactions", printf "%d (%0.1f per day)" tnum txnrate) @@ -55,7 +57,9 @@ showLedgerStats l today span = -- Days since last transaction : %(recentelapsed)s ] where - ts = sortBy (comparing tdate) $ filter (spanContainsDate span . tdate) $ jtxns $ ledgerJournal l + j = ledgerJournal l + path = journalFilePath j + ts = sortBy (comparing tdate) $ filter (spanContainsDate span . tdate) $ jtxns j as = nub $ map paccount $ concatMap tpostings ts cs = Map.keys $ canonicaliseCommodities $ nub $ map commodity $ concatMap amounts $ map pamount $ concatMap tpostings ts lastdate | null ts = Nothing