From: Tomas Mudrunka Date: Mon, 21 Oct 2013 21:22:32 +0000 (+0200) Subject: Mathematics in beermeter X-Git-Url: https://git.harvie.cz/?a=commitdiff_plain;h=1c6c46fecf426a6a324a69c905fd2d4ad94f8d9d;p=mirrors%2FPrograms.git Mathematics in beermeter --- 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() {