From 1c6c46fecf426a6a324a69c905fd2d4ad94f8d9d Mon Sep 17 00:00:00 2001 From: Tomas Mudrunka Date: Mon, 21 Oct 2013 23:22:32 +0200 Subject: [PATCH] Mathematics in beermeter --- c/beermeter/beermeter.sh | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/c/beermeter/beermeter.sh b/c/beermeter/beermeter.sh index 1ff0c1b..c43701e 100755 --- a/c/beermeter/beermeter.sh +++ b/c/beermeter/beermeter.sh @@ -1,4 +1,9 @@ #!/bin/sh +pulses_per_liter='4380' +beer_liters='0.5' +beer_price='23' +currency='Kč' + title='Beer-O-Meter' accounts='./accounts' totals="$accounts/.totals" @@ -6,8 +11,16 @@ backend='./audio.sh' tmp="/tmp/beertmp-$$"; dialog=$(which dialog); +calc() { + echo 'scale=2; '"$@" | bc +} + beer_stat() { - echo $(wc -c "$accounts/$1" | cut -d ' ' -f 1) piv + pulses=$(wc -c "$accounts/$1" | cut -d ' ' -f 1) + litres=$(calc $pulses/$pulses_per_liter) + beers=$(calc $litres/$beer_liters) + price=$(calc $beers*$beer_price) + echo $beers piv '('$price $currency, $litres l, $pulses pulses')' } add_account() { -- 2.30.2