From 6e4e2fa779b641711977ab921615ce3c803276c0 Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 11 Sep 2013 19:43:44 +0200 Subject: ledger balance: initial commit --- ledger/lib/balance | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100755 ledger/lib/balance diff --git a/ledger/lib/balance b/ledger/lib/balance new file mode 100755 index 00000000..8d84dd7b --- /dev/null +++ b/ledger/lib/balance @@ -0,0 +1,73 @@ +#! /bin/awk -f +# +# usage: [colorize=false] [scale=N] //ledger/lib/balance LEDGER_FILE +# see also: //cholerab/ledger-spec.markdown +# + +BEGIN { + colorize = ENVIRON["colorize"] == "" || ENVIRON["colorize"] == "true" + # TODO use bc for arbitrary precision arithmetic + scale = ENVIRON["scale"] +} + +/^[[:space:]]*[0-9]+-[0-9][0-9]-[0-9][0-9]/{ + tx($2, $3, $4, $5) +} + +END { + display_accounts() +} + +function tx (dst, src, amt, u) { + withdraw(src, amt, u) + deposit(dst, amt, u) +} + +function deposit (name, amt, u) { + accounts[name][u] += amt +} + +function withdraw (name, amt, u) { + accounts[name][u] -= amt +} + +function display_accounts() { + max_name_len = 0 + for (name in accounts) { + if (length(name) > max_name_len) { + max_name_len = length(name) + } + } + + max_balance_len = 0 + for (name in accounts) { + for (u in accounts[name]) { + s = accounts[name][u] + sub(/\..*/, "", s) + if (length(s) > max_balance_len) { + max_balance_len = length(s) + } + } + } + if (scale > 0) { + max_balance_len += 1 + scale + } + + for (name in accounts) { + for (u in accounts[name]) { + + fmt = "NAME BALANCE UNIT\n" + balance = accounts[name][u] + + if (colorize) { + sub("BALANCE", "[" (balance < 0 ? 31 : 32) "m&", fmt) + } + + sub("NAME", "%-" max_name_len "s", fmt) + sub("BALANCE", "%" max_balance_len "." scale "f", fmt) + sub("UNIT", "%s", fmt) + + printf fmt, name, balance, u + } + } +} -- cgit v1.2.3 From a48c908949884f1e550abbd5bda5b30131fe71c4 Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 11 Sep 2013 19:48:44 +0200 Subject: ledger balance: fix usage description --- ledger/lib/balance | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ledger/lib/balance b/ledger/lib/balance index 8d84dd7b..1e9e2db2 100755 --- a/ledger/lib/balance +++ b/ledger/lib/balance @@ -1,6 +1,6 @@ #! /bin/awk -f # -# usage: [colorize=false] [scale=N] //ledger/lib/balance LEDGER_FILE +# usage: [colorize=false] [scale=N] //ledger/lib/balance LEDGER_FILE... # see also: //cholerab/ledger-spec.markdown # -- cgit v1.2.3 From 87b90098679c9daccd558d6df0fef508cf7a4a24 Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 11 Sep 2013 19:59:53 +0200 Subject: ledger balance: clarify max_balance_len computation --- ledger/lib/balance | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/ledger/lib/balance b/ledger/lib/balance index 1e9e2db2..f75410c3 100755 --- a/ledger/lib/balance +++ b/ledger/lib/balance @@ -42,15 +42,14 @@ function display_accounts() { max_balance_len = 0 for (name in accounts) { for (u in accounts[name]) { - s = accounts[name][u] - sub(/\..*/, "", s) - if (length(s) > max_balance_len) { - max_balance_len = length(s) + n = length(int(accounts[name][u])) + if (n > max_balance_len) { + max_balance_len = n } } } if (scale > 0) { - max_balance_len += 1 + scale + max_balance_len += length(".") + scale } for (name in accounts) { -- cgit v1.2.3 From 74961ef05afc5d06d0af192752912466021882c4 Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 11 Sep 2013 20:14:06 +0200 Subject: ledger balance: add description and pipe-usage --- ledger/lib/balance | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/ledger/lib/balance b/ledger/lib/balance index f75410c3..77cb7f6d 100755 --- a/ledger/lib/balance +++ b/ledger/lib/balance @@ -1,7 +1,20 @@ #! /bin/awk -f # -# usage: [colorize=false] [scale=N] //ledger/lib/balance LEDGER_FILE... -# see also: //cholerab/ledger-spec.markdown +# ledger balance calculator +# +# usage: +# [colorize=false] [scale=N] //ledger/lib/balance LEDGER_FILE... +# [colorize=false] [scale=N] //ledger/lib/balance < LEDGER_FILE +# +# description: +# The ledger balance calculator computes the balance of each account it +# encounters in the provided ledger files. +# +# example: +# //ledger/lib/balance < //cholerab/ledger-spec.markdown +# +# see also: +# //cholerab/ledger-spec.markdown (ledger file format) # BEGIN { -- cgit v1.2.3 From c39c60f74a8d6be286648e2bdb264c9f93eaddef Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 11 Sep 2013 20:40:14 +0200 Subject: cholerab ledger-spec: talk about DATE and AMOUNT --- cholerab/ledger-spec.markdown | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/cholerab/ledger-spec.markdown b/cholerab/ledger-spec.markdown index 15a290bf..812bce33 100644 --- a/cholerab/ledger-spec.markdown +++ b/cholerab/ledger-spec.markdown @@ -1,8 +1,16 @@ -# Format +# Ledger Specification + +## Transaction Record + +### External Representation DATE DESTINATION-ACCOUNT SOURCE-ACCOUNT AMOUNT UNIT [COMMENT...] -# Example + where + - `DATE` has the form `YYYY-MM-DD` + - `AMOUNT` is a non-negative, decimal number + +### Example 2013-01-01 krebs-ml amazon 30 EUR C0DE-AAAA-BBBB-CCCC 2013-02-02 momo krebs-ml 50 EUR C0DE-AAAA-BBBB-CCCC -- cgit v1.2.3 From d064ae45514232825891357b3b31c80ae6f698e8 Mon Sep 17 00:00:00 2001 From: makefu Date: Mon, 16 Sep 2013 12:52:12 +0200 Subject: update soapi.wsdl --- ext/ovh/soapi/domainCapabilities | 2 +- ext/ovh/soapi/domainInfo | 2 +- ext/ovh/soapi/domainList | 2 +- ext/ovh/soapi/soapi-re-1.24.wsdl | 20105 ------------------------------- ext/ovh/soapi/soapi.wsdl | 23935 +++++++++++++++++++++++++++++++++++++ ext/ovh/soapi/zoneEntryAdd | 2 +- ext/ovh/soapi/zoneEntryDel | 2 +- ext/ovh/soapi/zoneEntryList | 2 +- ext/ovh/soapi/zoneExport | 3 +- ext/ovh/soapi/zoneImport | 2 +- 10 files changed, 23944 insertions(+), 20113 deletions(-) delete mode 100644 ext/ovh/soapi/soapi-re-1.24.wsdl create mode 100644 ext/ovh/soapi/soapi.wsdl diff --git a/ext/ovh/soapi/domainCapabilities b/ext/ovh/soapi/domainCapabilities index a438e0b8..252e2ca1 100755 --- a/ext/ovh/soapi/domainCapabilities +++ b/ext/ovh/soapi/domainCapabilities @@ -14,7 +14,7 @@ def default(o): return list(iterable) return JSONEncoder.default(o) -wsdl = dirname(realpath(__file__)) + '/soapi-re-1.24.wsdl' +wsdl = dirname(realpath(__file__)) + '/soapi.wsdl' soap = WSDL.Proxy(wsdl) username = environ['KREBS_OVH_USER'] diff --git a/ext/ovh/soapi/domainInfo b/ext/ovh/soapi/domainInfo index 35459d06..4bfad237 100755 --- a/ext/ovh/soapi/domainInfo +++ b/ext/ovh/soapi/domainInfo @@ -14,7 +14,7 @@ def default(o): return list(iterable) return JSONEncoder.default(o) -wsdl = dirname(realpath(__file__)) + '/soapi-re-1.24.wsdl' +wsdl = dirname(realpath(__file__)) + '/soapi.wsdl' soap = WSDL.Proxy(wsdl) username = environ['KREBS_OVH_USER'] diff --git a/ext/ovh/soapi/domainList b/ext/ovh/soapi/domainList index 342eec72..8f80793b 100755 --- a/ext/ovh/soapi/domainList +++ b/ext/ovh/soapi/domainList @@ -14,7 +14,7 @@ def default(o): return list(iterable) return JSONEncoder.default(o) -wsdl = dirname(realpath(__file__)) + '/soapi-re-1.24.wsdl' +wsdl = dirname(realpath(__file__)) + '/soapi.wsdl' soap = WSDL.Proxy(wsdl) username = environ['KREBS_OVH_USER'] diff --git a/ext/ovh/soapi/soapi-re-1.24.wsdl b/ext/ovh/soapi/soapi-re-1.24.wsdl deleted file mode 100644 index c628c564..00000000 --- a/ext/ovh/soapi/soapi-re-1.24.wsdl +++ /dev/null @@ -1,20105 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -