Best practices to generate pretty reports

92 views
Skip to first unread message

Tobias Pfeiffer

unread,
Oct 13, 2019, 12:46:42 AM10/13/19
to ledge...@googlegroups.com
Hi,

I have a fairly long history of transactions in my ledger files and I
would like to generate some pretty reports from this data. Think a one-
page PDF (or HTML) file that opens with a sentence like "this month's
revenue was X, expenses were Y, P% higher than average" and then has
some charts about, say, distribution of expenses, historical data,
comparison with forecast data.

I guess many people on this list have a similar thing running already,
so I would like to hear about recommendations with respect to
toolchain, libraries, etc. that you are using.

Currently I have an emacs org-mode file and use babel to get the ledger
output, as follows:

```
#+TITLE: Financial Report
#+PROPERTY: header-args :results output :exports results :cache true
#+PROPERTY: header-args+ :var F="-f all.ledger" :var MONTH="sep 2019"

#+BEGIN_HTML
<link rel="stylesheet" href="web/graphs.js" />
#+END_HTML

#+BEGIN_SRC sh
PARAMS="${F} --effective -p ${MONTH}"
ledger balance $PARAMS Expenses
#+END_SRC
```

Then the HTML export contains a <pre> block with the ledger output and
my script in `web/graphs.js` parses it and creates some charts.

It somehow works that way, but I don't think it's a very nice pipeline.
It's all very tightly coupled and seems fairly fragile, I need to parse
the output of ledger in JavaScript, the application logic to compute
averages etc. is also in JavaScript, there are a lot of components
involved (which makes it hard to debug), and still it is not simple to
generate a simple sentence like "this month's revenue was X".

If anyone has any suggestions or can point at tools suited for that
purpose, please let me know.

Thanks
Tobias
signature.asc

Jim Robinson

unread,
Oct 14, 2019, 12:31:58 AM10/14/19
to Ledger
Have you considered using the Python API?


Python has lots of libraries, including statistics, html templating and PDF APIs, so I imagine you could build what you wanted within it.

Tobias Pfeiffer

unread,
Oct 17, 2019, 8:39:48 AM10/17/19
to ledge...@googlegroups.com
Hi,
To be honest, since the openSUSE ledger packages don't come with Python
bindings I haven't looked into the Python API too deeply; but I guess I
will end up using Python one way or another for the reasons you
mentioned. Maybe I should start by packaging the Python bindings for
openSUSE ;-)

Thanks for your help
Tobias
signature.asc

Yuri Khan

unread,
Oct 17, 2019, 8:56:36 AM10/17/19
to ledge...@googlegroups.com
On Thu, 17 Oct 2019 at 19:39, Tobias Pfeiffer <tgpfe...@web.de> wrote:

> To be honest, since the openSUSE ledger packages don't come with Python
> bindings I haven't looked into the Python API too deeply; but I guess I
> will end up using Python one way or another for the reasons you
> mentioned. Maybe I should start by packaging the Python bindings for
> openSUSE ;-)

You can also parse the output of ‘ledger xml’. It gives you the data
equivalent to ‘ledger register’ though, so you may have to calculate
the balances on your own.
Reply all
Reply to author
Forward
0 new messages