register: --average implies --empty

The -A flag now enables -E, so that with a report interval the averages
are always per-period and not per-report-line. (Without a report
interval, -E is already the default).
This commit is contained in:
Simon Michael 2014-08-07 14:03:56 -07:00
parent d0ad571321
commit f631e8e063
3 changed files with 24 additions and 16 deletions

View File

@ -751,17 +751,9 @@ The `--depth` option limits the amount of sub-account detail displayed:
$ hledger register assets:bank:checking --depth 2
With a [reporting interval](#reporting-interval) it shows aggregated
summary postings within each interval:
$ hledger register --monthly rent
$ hledger register --monthly -E food --depth 4
Note that the report start/end dates will be "enlarged" in this case
so that they encompass the displayed intervals. This is so that the
first and last intervals will be "full" and comparable to the others.
The `--average`/`-A` flag shows the running average posting amount instead of the running total.
The `--average`/`-A` flag shows the running average posting amount
instead of the running total (so, the final number displayed is the
average for the whole report period). This flag implies `--empty` (see below).
The `--related`/`-r` flag shows the *other* postings in the transactions
of the postings which would normally be shown.
@ -772,6 +764,22 @@ names, use `-w` to increase the width to 120 characters, or `-wN` to set
any desired width (at least 50 recommended).
Note, currently -w/--width can not have a space between flag and value ([#149](https://github.com/simonmichael/hledger/issues/149)).
With a [reporting interval](#reporting-interval) register shows
aggregated summary postings, within each interval:
$ hledger register --monthly rent
$ hledger register --monthly -E food --depth 4
One summary posting will be shown for each account in each interval.
Summary postings with a zero amount are not shown; use the `--empty`/`-E` flag to show them.
If necessary, use the `--depth` option to summarise the accounts.
It's often most useful to see just one line per interval.
When using report intervals, the report's normal start/end dates are
"enlarged" to contain a whole number of intervals, so that the first
and last intervals will be "full" and comparable to the others.
#### balance
The balance command displays accounts and their balances.

View File

@ -71,13 +71,13 @@ postingsReport opts q j = (totallabel, items)
journalPostings $ journalSelectingAmountFromOpts opts j
(precedingps, reportps) = dbg "precedingps, reportps" $ span (beforestartq `matchesPosting`) pstoend
empty = queryEmpty q
showempty = queryEmpty q || average_ opts
-- displayexpr = display_ opts -- XXX
interval = intervalFromOpts opts -- XXX
whichdate = whichDateFromOpts opts
itemps | interval == NoInterval = reportps
| otherwise = summarisePostingsByInterval interval whichdate depth empty reportspan reportps
| otherwise = summarisePostingsByInterval interval whichdate depth showempty reportspan reportps
items = postingsReportItems itemps nullposting whichdate depth startbal runningcalc 1
where
startbal = if balancetype_ opts == HistoricalBalance then sumPostings precedingps else 0
@ -117,9 +117,9 @@ mkpostingsReportItem showdate showdesc wd p b = (if showdate then Just date else
-- are one per account per interval and aggregated to the specified depth
-- if any.
summarisePostingsByInterval :: Interval -> WhichDate -> Int -> Bool -> DateSpan -> [Posting] -> [Posting]
summarisePostingsByInterval interval wd depth empty reportspan ps = concatMap summarisespan $ splitSpan interval reportspan
summarisePostingsByInterval interval wd depth showempty reportspan ps = concatMap summarisespan $ splitSpan interval reportspan
where
summarisespan s = summarisePostingsInDateSpan s wd depth empty (postingsinspan s)
summarisespan s = summarisePostingsInDateSpan s wd depth showempty (postingsinspan s)
postingsinspan s = filter (isPostingInDateSpan' wd s) ps
tests_summarisePostingsByInterval = [

View File

@ -29,7 +29,7 @@ registermode = (defCommandMode $ ["register"] ++ aliases) {
,modeGroupFlags = Group {
groupUnnamed = [
flagNone ["historical","H"] (\opts -> setboolopt "historical" opts) "include prior postings in the running total"
,flagNone ["average","A"] (\opts -> setboolopt "average" opts) "show a running average instead of the running total"
,flagNone ["average","A"] (\opts -> setboolopt "average" opts) "show a running average instead of the running total (implies --empty)"
,flagNone ["related","r"] (\opts -> setboolopt "related" opts) "show postings' siblings instead"
,flagReq ["width","w"] (\s opts -> Right $ setopt "width" s opts) "N" "set output width (default: 80)"
]