From 4eae061536f4c83088bd8fb6c89e215da2c13c06 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Tue, 15 Nov 2022 09:53:20 -0500 Subject: add rolling averages script rather handy for calculating stuff from hledger output --- rollingavg | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 rollingavg (limited to 'rollingavg') diff --git a/rollingavg b/rollingavg new file mode 100755 index 0000000..c825fc0 --- /dev/null +++ b/rollingavg @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +# +# calculates rolling average for numbers via stdin +# +# here's an example with hledger: +# +# hledger bal ^in cur:USD -MA --end=thismonth --output-format=csv \ +# | tail -n 1 \ +# | cut -d',' -f 2- \ +# | tr -d '" USD-' \ +# | tr ',' '\n' \ +# | rollingavg +n=0 +total=0 +declare -i n +while read i +do + n+=1 + total=$(bc -l <<< "$total + $i") + printf "%.2f\n" $(bc -l <<< "$total / $n") +done -- cgit v1.2.3