summaryrefslogtreecommitdiff
path: root/scripts/mean
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/mean')
-rwxr-xr-xscripts/mean27
1 files changed, 27 insertions, 0 deletions
diff --git a/scripts/mean b/scripts/mean
new file mode 100755
index 00000000..3c6f779a
--- /dev/null
+++ b/scripts/mean
@@ -0,0 +1,27 @@
+#!/usr/bin/perl
+
+$last = $ARGV[-1];
+splice(@ARGV, -1);
+
+open(PIPE, "ledger -MG @ARGV register $last |") || die;
+@values = ();
+while (<PIPE>) {
+ ($date, $value) = split;
+ push @values, $value;
+}
+close(PIPE);
+
+@values = sort @values;
+splice(@values, 0, 1);
+splice(@values, -1);
+
+$value = 0.0;
+for $item (@values) {
+ $value += $item;
+}
+
+if (@values) {
+ printf("%.2f\n", $value / @values);
+} else {
+ die "There are no values to average!\n";
+}