Commit Graph

565 Commits

Author SHA1 Message Date
Simon Michael
dafa8efada note possible combineJournalUpdates inefficiency 2015-09-26 16:01:27 -10:00
Simon Michael
5048d3bf06 lib: memoise accountNameApplyAliases too ?
This adds a accountNameApplyAliasesMemo, which memoises the result of
applying a set of aliases (simple and regex) to an account name. In
theory this should reduce more repetitive work, but in practice it
doesn't seem to make a difference, so it's unused for now.
2015-09-26 15:58:12 -10:00
Simon Michael
4326f88c26 lib: memoise aliasReplace for fast regex aliases (#244)
Roughly speaking, the time to apply regular expression account aliases
was O(aliases x transactions), and should now be O(aliases x accounts).
Also, the constant factor was reduced a lot by the recent commit
memoising toRegex. So now, regex aliases should be "free" like simple
aliases - use as many as you want, the slowdown shouldn't be noticeable.
2015-09-26 15:45:44 -10:00
Simon Michael
041541e466 lib: memoised versions of regexReplace[CI] (#244) 2015-09-26 15:45:17 -10:00
Simon Michael
f8f2d457b9 lib: memoize toRegex[CI] (#244)
The regex helpers were converting strings to regex-tdfa regular
expressions on the fly every time, but this appears to be quite
expensive. The simplest memoisation lib seems to solve it nicely.
2015-09-26 15:39:21 -10:00
Simon Michael
591abefe9e clarify modifiedaccountnamep 2015-09-24 14:23:52 -10:00
Simon Michael
f4c963b648 whitespace 2015-09-22 12:59:25 -07:00
Simon Michael
821f1b7120 lib: fix tests for zero amount style (#230, #276) 2015-09-02 16:38:45 -07:00
Simon Michael
b770190942 lib: clarify flattenAccounts 2015-09-02 16:22:08 -07:00
Simon Michael
b8d75b7728 balance, etc: fix amount style loss (fixes #230, #276)
hledger-lib-0.24's "track the commodity of zero amounts when
possible (useful eg for hledger-web's multi-commodity charts)" preserved
the commodity when normalising a zero mixed amount, but not the amount
style. This showed up as occasionally incorrect amount style (commodity
symbol placement, decimal point character, etc.) in balance reports with
certain journals, like this:

  $ hledger bal
              €3000.00  a     <------ not using the canonical € style
              4000,58€    1
             -1000,58€    D
             -3000,00€  e
  --------------------
                     0

I thought this would require a big rewrite of amount arithmetic, but it
seems that just being a little more careful is enough. When normalising
a mixed amount containing multiple zeros in the same commodity, we now
preserve the last zero with its amount style, instead of replacing them
all with a new one.
2015-09-02 16:21:56 -07:00
Simon Michael
92038b7d72 web: fix options breakage, add test code to tags 2015-08-28 15:23:49 -07:00
Simon Michael
74512814ec cli/ui/web: rename X.Options modules to X.XOptions
Make these modules' names more like the heavily-used types they
define (CliOpts, UIOpts, WebOpts). This is consistent with
RawOptions and ReportOptions, and helps with code navigation.
2015-08-28 12:43:51 -07:00
Simon Michael
8673332c8e ui, web: show fewer other accounts in acct register
To reduce noise in the "other accounts" field of hledger-ui's and
hledger-web's account register: if there are both real and virtual
postings to other accounts, show only the accounts posted to by real
postings.

Use case: in many transactions I have extra balanced-virtual postings
which adjust budget envelopes (subaccounts of checking). These clutter
up the register's other accounts field making it useless. Excluding them
(when there are also real postings) makes it more useful for me and
probably others.
2015-08-28 11:58:57 -07:00
Simon Michael
f3dd5eb830 fix options breakage with GHC < 7.10 2015-08-28 11:17:49 -07:00
Simon Michael
0d02262463 validate --depth/depth:'s argument is positive 2015-08-28 09:57:30 -07:00
Simon Michael
4dd1e9c725 clean up options validation a little 2015-08-28 09:57:01 -07:00
Simon Michael
5fa06453f1 lib: note depth's filtering and display control uses 2015-08-28 08:04:54 -07:00
Simon Michael
19c3749b50 balance: move -V helpers to the *Report modules 2015-08-26 10:38:45 -07:00
Simon Michael
d23d9acf33 fix haddock failures (#281) 2015-08-26 10:11:32 -07:00
Simon Michael
3a7a5d6035 lib: 6-tuple accessors 2015-08-24 16:24:11 -07:00
Simon Michael
866414a528 ui: provide a more useful transaction register
The register screen is now like the register view in hledger-web (and
other accounting systems), rather than hledger's register command.
This means:

- it shows transactions affecting a particular current account, rather
  than postings matching a pattern.

- Each line represents a whole transaction.

- The account field shows the *other* account being transacted with.
  When there is more than one, they are all listed, abbreviated and
  marked with "(split)".

- The amount field shows the effect of the transaction on the current
  account; positive for an inflow to this account, negative for an
  outflow.

- The balance field should usually show the current account's historic
  balance as of the transaction date, even when you change the report
  start date. (Not working yet - currently it always shows the running
  total).

- Transactions are listed most recent first, currently.
2015-08-24 16:24:11 -07:00
Simon Michael
cc98ee39f7 balance, lib: --format/StringFormat improvements
The balance command's --format option (in single-column mode) can now
adjust the rendering of multi-line strings, such as amounts with multiple
commodities. To control this, begin the format string with one of:

 %_  - renders on multiple lines, bottom-aligned (the default)
 %^  - renders on multiple lines, top-aligned
 %,  - render on one line, comma-separated

Also the final total (and the line above it) now adapt themselves to a
custom format.
2015-08-19 20:53:51 -07:00
Simon Michael
7aecbac851 lib: split up Utils more 2015-08-19 20:53:50 -07:00
Simon Michael
69c870c6f0 balance, lib: make StringFormat singular; cleanup
Pass around a StringFormat rather than [StringFormat].
Also more balance report item rendering refactoring.
2015-08-19 20:53:50 -07:00
Simon Michael
36dd64cf02 balance, lib: clarify --format implementation
The --format option's OutputFormat type was named confusingly like the
--output-format option.  It has been renamed StringFormat to distinguish
it from StorageFormat (aka the data file format, referenced by
--output-format). Related code and types have been consolidated.
Also the (single-column) balance report's item rendering has had
some cleanup.
2015-08-19 20:53:49 -07:00
Simon Michael
2b339667e2 Merge branch 'perf-polyparse' (early part) 2015-08-13 13:10:10 -07:00
Simon Michael
632a000f08 derive NFData in a way compatible with GHC < 7.10
The DeriveAnyClass extension requires GHC 7.10, so instead do this in a
more verbose backwards-compatible way. Adds a dependency on deepseq.
2015-08-13 12:58:44 -07:00
Simon Michael
790d42bfa4 derive NFData (and Generic) for all types
so we can benchmark things more easily with criterion.

As well as NFData, the Generic instance and a bunch more GHC extensions
seemed necessary. This is a little scary, impact unknown.
2015-08-13 12:58:35 -07:00
Simon Michael
42d452f99c abstract parsec's SourcePos so as to derive NFData
The NFData instance helps us time things with criterion.
2015-08-13 12:56:15 -07:00
Simon Michael
94094252be rename historical prices to market prices
Simpler and clearer. We now have "transaction prices" (recorded as part
of transaction amounts) and "market prices" (recorded with P
directives). Both are matters of historical record, also this avoids
confusion with the balance command's "historical balances".
2015-08-09 16:20:02 -07:00
Simon Michael
49be1f646e balance: add -V/--value to show as market value
Initial support of market value reporting and currency conversion,
similar in spirit to Ledger's.  The balance command now has a -V/--value
flag that converts all the reported amounts using their "default market
price". That is the latest market price (P directive, formerly called
"historical prices") found in the journal for their commodity that is on
or before the report end date.

Unlike Ledger, hledger's -V only uses the market prices recorded with P
directives, ignoring transaction prices recorded as part of posting
amounts (which -B/--cost uses). Using -B and -V together is allowed.
2015-08-09 16:03:16 -07:00
Simon Michael
040d00e8fb also canonicalise historical price amounts
So that when we convert amounts to market value, the result will have
the canonical style of the target commodity.
2015-08-09 15:12:16 -07:00
Simon Michael
73e4ccee80 allow year parser to handle arbitrarily large years 2015-07-12 12:32:53 -07:00
Simon Michael
7a050d65c8 bs/is/cf: recognise "debt..." as a synonym for "liabilities..." 2015-07-12 12:32:53 -07:00
Simon Michael
cddaa2724d rendering a June 30 date span properly (#272)
30 days hath september, april, JUNE and november
2015-07-02 20:44:39 -07:00
Simon Michael
b827f1a146 more balanceTransaction cleanup
Clarify: it's fine to try to infer prices on a transaction that has had
an amount inferred, it just won't have any effect.
2015-07-02 18:06:03 -07:00
Simon Michael
b735107f43 print: show inferred unit prices with at least 2 decimal places
We don't do a good job of calculating good-looking unit prices when the
commodity display precisions are low. Eg when a journal doesn't use any
decimal places, any inferred unit prices are shown by the print command
also with no decimal places, which makes them look wrong.

Now inferred unit prices always have a minimum display precision of 2,
which helps a bit. Could do better.
2015-07-02 17:36:09 -07:00
Simon Michael
5978a19b15 finish refactoring balanceTransaction 2015-07-02 16:59:43 -07:00
Simon Michael
61e4034de5 Journal's Show instance reported one too many accounts 2015-06-28 14:14:56 -07:00
Simon Michael
ba18f4a25a begin refactoring balanceTransaction 2015-06-28 12:03:42 -07:00
Simon Michael
b9883d9eb1 query: make real: equivalent to real:1 2015-06-12 06:23:34 -07:00
Simon Michael
ba6269981b begin reviving journalreader unit tests 2015-06-11 10:16:46 -07:00
Simon Michael
d1769d9d62 journal: allow journal entries with no postings
We now parse, and also print, posting-less journal entries, as I
proposed on the lists.

These are not real General Journal entries/transactions, but here is my
rationale:

- Ledger and beancount parse them
- if we parse them, we should print them
- they provide a natural way to record and report non-transaction events
- most of all, they permit more gradual introduction and learning of the concepts.
  Eg a beginner can keep a simple journal even before learning about accounts and postings.
2015-06-11 10:16:46 -07:00
Imuli
49f1744ae5 read multiple files: internals 2015-05-28 10:40:48 -07:00
Simon Michael
46bbc9e0aa fix simple aliases that match the whole account name 2015-05-28 10:40:48 -07:00
Simon Michael
ef890e1b23 add: quote file name consistently in output
Don't show quotes around the journal file path in the "Creating..."
message since there aren't any in the subsequent "Adding..." message.
2015-05-27 14:41:23 -07:00
Simon Michael
8d75635505 print: limit display precision of generated prices (#262)
When a transaction posts to two commodities without specifying the
conversion price, we generate a price which makes it balance
(cf http://hledger.org/manual.html#prices).

Until now, these generated prices were always shown with full precision
(all available decimal digits) so that a manual calculation with the
displayed numbers would agree.

If there's just one posting in the commodity being priced, we can use an
exact total price and the precision is no problem.

But if there are multiple postings in the commodity being priced, we
must show the averaged unit price. This can be an irrational number,
which with our current Decimal-based implementation would display an
excessive 255 decimal digits. So in this case we now set the price's
display precision to the sum of the (max) display precisions of the
commodities involved. An example:

hledgerdev -f- print
<<<
1/1
    c    C 10.00
    c    C 11.00
    d  D -320.00
>>>
2015/01/01
    c  C 10.00 @ D 15.2381
    c  C 11.00 @ D 15.2381
    d     D -320.00

>>>=0

There might still be cases where this will show more price decimal
places than necessary. For now, YAGNI.
2015-05-27 14:21:19 -07:00
Simon Michael
87d5ddfb71 query: drop the empty: query term
This seems to be equivalent to the --empty option, and overlaps
a bit confusingly with amt:0. I think we can drop it.
2015-05-21 16:44:11 -07:00
Simon Michael
fdc507bd13 match tag names with a regexp, like everything else 2015-05-21 16:25:19 -07:00
Simon Michael
9e2111106b drop regexpr dependency 2015-05-17 08:32:45 -07:00