lib: multiBalanceReport: Move responsibility for display name into displayedAccounts
This commit is contained in:
parent
5f0918217a
commit
6467c252c7
@ -128,7 +128,7 @@ multiBalanceReportWith ropts@ReportOpts{..} q j priceoracle = report
|
|||||||
totalsrow = dbg' "totalsrow" $ calculateTotalsRow ropts' displayaccts sortedrows
|
totalsrow = dbg' "totalsrow" $ calculateTotalsRow ropts' displayaccts sortedrows
|
||||||
|
|
||||||
-- Postprocess the report, negating balances and taking percentages if needed
|
-- Postprocess the report, negating balances and taking percentages if needed
|
||||||
report = dbg' "report" . postprocessReport ropts' $
|
report = dbg' "report" . postprocessReport ropts' displayaccts $
|
||||||
PeriodicReport colspans sortedrows totalsrow
|
PeriodicReport colspans sortedrows totalsrow
|
||||||
|
|
||||||
|
|
||||||
@ -319,7 +319,7 @@ buildReportRows :: ReportOpts -> Query
|
|||||||
-> HashMap AccountName [Account]
|
-> HashMap AccountName [Account]
|
||||||
-> [MultiBalanceReportRow]
|
-> [MultiBalanceReportRow]
|
||||||
buildReportRows ropts q acctvalues =
|
buildReportRows ropts q acctvalues =
|
||||||
[ PeriodicReportRow (name a) rowbals rowtot rowavg
|
[ PeriodicReportRow (flatDisplayName a) rowbals rowtot rowavg
|
||||||
| (a,accts) <- HM.toList acctvalues
|
| (a,accts) <- HM.toList acctvalues
|
||||||
, let rowbals = map balance accts
|
, let rowbals = map balance accts
|
||||||
-- The total and average for the row.
|
-- The total and average for the row.
|
||||||
@ -330,25 +330,25 @@ buildReportRows ropts q acctvalues =
|
|||||||
, empty_ ropts || queryDepth q == 0 || any (not . mixedAmountLooksZero) rowbals -- TODO: Remove this eventually, to be handled elswhere
|
, empty_ ropts || queryDepth q == 0 || any (not . mixedAmountLooksZero) rowbals -- TODO: Remove this eventually, to be handled elswhere
|
||||||
]
|
]
|
||||||
where
|
where
|
||||||
name = if tree_ ropts then treeDisplayName else flatDisplayName
|
|
||||||
balance = if tree_ ropts then aibalance else aebalance
|
balance = if tree_ ropts then aibalance else aebalance
|
||||||
|
|
||||||
-- | Calculate accounts which are to be displayed in the report, as well as
|
-- | Calculate accounts which are to be displayed in the report, as well as
|
||||||
-- their name and depth
|
-- their name and depth
|
||||||
displayedAccounts :: ReportOpts -> Query
|
displayedAccounts :: ReportOpts -> Query
|
||||||
-> HashMap AccountName [Account]
|
-> HashMap AccountName [Account]
|
||||||
-> HashMap AccountName (AccountName, Int)
|
-> HashMap AccountName DisplayName
|
||||||
displayedAccounts ropts q valuedaccts =
|
displayedAccounts ropts q valuedaccts =
|
||||||
HM.fromList $ map (\a -> (a, elidedName a)) .
|
HM.fromList $ map (\a -> (a, displayedName a)) $
|
||||||
(if tree_ ropts then expandAccountNames else id) $
|
(if tree_ ropts then expandAccountNames else id) $
|
||||||
nub $ map (clipOrEllipsifyAccountName depth) $
|
nub $ map (clipOrEllipsifyAccountName depth) $
|
||||||
allpostedaccts
|
allpostedaccts
|
||||||
where
|
where
|
||||||
allpostedaccts = dbg'' "allpostedaccts" $ HM.keys valuedaccts
|
allpostedaccts = dbg'' "allpostedaccts" $ HM.keys valuedaccts
|
||||||
|
|
||||||
elidedName name
|
displayedName name
|
||||||
| depth == 0 = ("...", 0)
|
| depth == 0 = DisplayName "..." "..." 0
|
||||||
| otherwise = (elided, accountNameLevel name - boringParents)
|
| tree_ ropts = treeDisplayName name
|
||||||
|
| otherwise = flatDisplayName name
|
||||||
where
|
where
|
||||||
elided = accountNameFromComponents . reverse . map accountLeafName $
|
elided = accountNameFromComponents . reverse . map accountLeafName $
|
||||||
name : takeWhile (not . isDisplayed) parents
|
name : takeWhile (not . isDisplayed) parents
|
||||||
@ -399,7 +399,7 @@ sortRows ropts j
|
|||||||
-- | Build the report totals row.
|
-- | Build the report totals row.
|
||||||
--
|
--
|
||||||
-- Calculate the column totals. These are always the sum of column amounts.
|
-- Calculate the column totals. These are always the sum of column amounts.
|
||||||
calculateTotalsRow :: ReportOpts -> HashMap ClippedAccountName (ClippedAccountName, Int)
|
calculateTotalsRow :: ReportOpts -> HashMap ClippedAccountName DisplayName
|
||||||
-> [MultiBalanceReportRow] -> PeriodicReportRow () MixedAmount
|
-> [MultiBalanceReportRow] -> PeriodicReportRow () MixedAmount
|
||||||
calculateTotalsRow ropts displayaccts rows =
|
calculateTotalsRow ropts displayaccts rows =
|
||||||
PeriodicReportRow () coltotals grandtotal grandaverage
|
PeriodicReportRow () coltotals grandtotal grandaverage
|
||||||
@ -420,13 +420,20 @@ calculateTotalsRow ropts displayaccts rows =
|
|||||||
grandaverage = averageMixedAmounts coltotals
|
grandaverage = averageMixedAmounts coltotals
|
||||||
|
|
||||||
-- | Map the report rows to percentages and negate if needed
|
-- | Map the report rows to percentages and negate if needed
|
||||||
postprocessReport :: ReportOpts -> MultiBalanceReport -> MultiBalanceReport
|
postprocessReport :: ReportOpts -> HashMap AccountName DisplayName
|
||||||
postprocessReport ropts (PeriodicReport spans rows totalrow) =
|
-> MultiBalanceReport -> MultiBalanceReport
|
||||||
maybeInvert $ PeriodicReport spans (map percentage rows) (percentage totalrow)
|
postprocessReport ropts displaynames =
|
||||||
|
maybeInvert . maybePercent . setNames
|
||||||
where
|
where
|
||||||
|
setNames = prMapMaybeName $ (`HM.lookup` displaynames) . displayFull
|
||||||
|
|
||||||
maybeInvert = if invert_ ropts then prNegate else id
|
maybeInvert = if invert_ ropts then prNegate else id
|
||||||
percentage = if not (percent_ ropts) then id else \case
|
maybePercent = if percent_ ropts then prPercent else id
|
||||||
PeriodicReportRow name rowvals rowtotal rowavg ->
|
|
||||||
|
prPercent (PeriodicReport spans rows totalrow) =
|
||||||
|
PeriodicReport spans (map percentRow rows) (percentRow totalrow)
|
||||||
|
where
|
||||||
|
percentRow (PeriodicReportRow name rowvals rowtotal rowavg) =
|
||||||
PeriodicReportRow name
|
PeriodicReportRow name
|
||||||
(zipWith perdivide rowvals $ prrAmounts totalrow)
|
(zipWith perdivide rowvals $ prrAmounts totalrow)
|
||||||
(perdivide rowtotal $ prrTotal totalrow)
|
(perdivide rowtotal $ prrTotal totalrow)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user