File: trend

package info (click to toggle)
ledger 3.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,964 kB
  • sloc: cpp: 39,393; python: 4,476; perl: 1,309; sh: 477; lisp: 435; yacc: 103; makefile: 58
file content (30 lines) | stat: -rwxr-xr-x 671 bytes parent folder | download | duplicates (10)
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