summaryrefslogtreecommitdiff
path: root/contrib/trend
blob: 3c189c0b7fa8fff4a690eede1f1b25eea853d078 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/sh

# This script requires Python support.
#
# To use, just run "trend" with the accounts to compute the trend for:
#
#   trend dining
#
# The trend values are not terribly meaningful, but this gives an
# example of how Python can be used to create more complex reports.

ledger --import-stdin -T "@rdev()" reg "$@" <<EOF
import ledger

mean = ledger.parse_value_expr ("AT")
last_mean = None
last_dev = None

def rdev (details):
    global last_mean, last_dev
    mval = mean.compute (details)
    if last_mean is None:
	dev = ledger.Value ()
    else:
	dev = mval - last_mean
	dev = (last_dev + dev) / 2
    last_mean = mval
    last_dev = dev
    return dev
EOF