Rake tasks for simple personal reporting in Ledger

71 views
Skip to first unread message

Lifepillar

unread,
Nov 3, 2012, 7:08:19 PM11/3/12
to ledge...@googlegroups.com
Hi,
while learning Ledger, I have collected a few commands that I frequently
use into a Rakefile, which I have just made public, thinking that it may
be interesting to other newbies like me:

https://gist.github.com/4009128

Note that I have tested the commands against a fairly recent development
snapshot of Ledger 3.0.0. Some of them (e.g., budget reports) may not
work with other releases.

These are the tasks currently defined:

# Balance report (with and without virtual transactions, with optional
conversion to a given currency).
# Budget expense report for the current year.
# Monthly average for an account during the current year.
# Monthly expenses, sorted by amount, for a specified period.
# Monthly net worth.
# Weekly average for an account during the current year.
# Weekly expenses, sorted by amount, for a specified period.
# Weekly net worth.
# Total income and expenses for a specified period, with savings
percentage.

To use the Rakefile, cd into the directory where you have saved it (I
suggest that you keep it along with your ledger file), and type

rake -T

to get a list of the available tasks. The default task (a balance
report) can be invoked by simply typing

rake

For tasks that take optional arguments, such arguments can be specified
in square brackets or as <parameter name>=<value>. For example,

rake tot['last week']

and

rake tot period='last week'

produce exactly the same report, which might look like this (and I
wished mine looked like this!):

1.572,33 USD Expenses
-2.478,91 USD Income
--------------------
-906,58 USD
36,57 % Savings rate


If you run rake with -v, the executed command will also be shown. This
may be useful both for debugging and for learning.

Do not forget to take a look at the constants defined at the top of the
source code, and adjust their values to your needs.

It would be nice if the commands for generating the above reports, and
possibly others, could be collected in a single place. I was thinking to
edit the Examples section in the Github wiki. Do you think it's a good
idea?

Life

Lifepillar

unread,
Nov 4, 2012, 2:23:35 AM11/4/12
to ledge...@googlegroups.com
On a slightly unrelated note, I am wondering whether it is possible to
produce an output like this using --format:

> 1.572,33 USD Expenses
> -2.478,91 USD Income
> --------------------
> -906,58 USD
> 36,57 % Savings rate

I am trying to get acquainted with Ledger's formatting syntax, but I
cannot find much documentation about it...

Life

Craig Earls

unread,
Nov 4, 2012, 6:57:02 AM11/4/12
to ledge...@googlegroups.com
Have you looked at the latest documentation?  It isn't written as well as I would like, but it has lots of examples.
--
Craig, Corona De Tucson, AZ
enderw88.wordpress.com

Lifepillar

unread,
Nov 4, 2012, 9:56:32 AM11/4/12
to ledge...@googlegroups.com
In article
<CAKs9TOKP+y6Pw0SpMx6S1jpU...@mail.gmail.com>,
Craig Earls <ende...@gmail.com> wrote:

> Have you looked at the latest documentation? It isn't written as well as I
> would like, but it has lots of examples.

If you mean http://www.ledger-cli.org/3.0/doc/ledger3.html, yes, I have
read it, and I have also taken a look at report.h. They left me with
more questions than answers, however. What a "template" is and how to
use it is not clear to me. Is it something between % and %/? For
example, I understand what this does:

ledger bal ^exp ^inc -n -F '%(total) %A %(quantity(total))\n'

But I do not understand any of the following variants (what does %$<N>
refer to?):

-F '%(total) %A %(quantity(total))\n%/'
-F '%(total) %A %(quantity(total))\n%/ %$1'
-F '%(total) %A %(quantity(total))\n%/ %$2'
-F '%(total) %A %(quantity(total))\n%/ %$3'
-F '%(total) %A%/ %(quantity(total))\n%/'
-F '%(total) %A%/ %(quantity(total))\n%/ %$1'
-F '%(total) %A%/ %(quantity(total))\n%/ %$2'

Besides, does a format specification apply to a row at a time? If so,
how can I format different rows differently? How do I refer to a value
in a previous row? In the instance below, I would like to refer to the
income row in order to compute the savings rate, but I have no idea how
to do that.

Finally, certain functions, like scrub and get_at, are totally obscure
to me. In other cases, like for total and total_expr, I do not
understand the difference between the two.

Please bear with me, I am new to Ledger, and the documentation is
extensive, so I have possibly overlooked something obvious.

Life

Craig Earls

unread,
Nov 4, 2012, 2:31:35 PM11/4/12
to ledge...@googlegroups.com
No, you haven't missed anything, I just haven't gotten around to writing about that in detail, because the answers aren't really clear. I am getting there though! Please bear with me.
Reply all
Reply to author
Forward
0 new messages