Mathematics in beermeter
authorTomas Mudrunka <tomas@mudrunka.cz>
Mon, 21 Oct 2013 21:22:32 +0000 (23:22 +0200)
committerTomas Mudrunka <tomas@mudrunka.cz>
Mon, 21 Oct 2013 21:22:32 +0000 (23:22 +0200)
c/beermeter/beermeter.sh

index 1ff0c1ba6b7ab193ad9962bed4bb29314875d097..c43701e33717bd542b36c27f8296037758a8e4d8 100755 (executable)
@@ -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() {
This page took 0.214861 seconds and 4 git commands to generate.