summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcos <cos>2015-12-06 22:37:48 +0100
committercos <cos>2016-07-17 20:10:58 +0200
commitae8c9242c9dc0155a6e1c5ab9e0cf6bdc726e430 (patch)
tree129eb750ec9f0c308f493c867aea8d9a0dddea07
parentf97a907b9c3a52ef78ebe12223157bac9399e042 (diff)
downloadmat-ae8c9242c9dc0155a6e1c5ab9e0cf6bdc726e430.zip
Make some fixes to faulty unit conversion.
-rwxr-xr-xmat14
1 files changed, 7 insertions, 7 deletions
diff --git a/mat b/mat
index 7d60ec8..2a2bff7 100755
--- a/mat
+++ b/mat
@@ -127,7 +127,7 @@ my @schedule = (
sub convert_to_unit {
my ( $out_unit, $id, $in_amount, $in_unit ) = @_;
my %out_amount;
- my %convert; # volume [l], weight [kg], piece [st]
+ my %convert; # volume [l], weight [g], piece [st]
# SELECT DISTINCT unit FROM contents;
# msk, krm, dl, tsk, cl, l, ml, nypa
@@ -147,9 +147,9 @@ sub convert_to_unit {
} elsif ($in_unit eq "krm") {
$convert{'volume'} = $in_amount * 0.001;
} elsif ($in_unit eq "g") {
- $convert{'weight'} = $in_amount / 1000;
- } elsif ($in_unit eq "kg") {
$convert{'weight'} = $in_amount;
+ } elsif ($in_unit eq "kg") {
+ $convert{'weight'} = $in_amount * 1000;
} elsif ($in_unit eq "st") {
$convert{'piece'} = $in_amount;
}
@@ -165,10 +165,10 @@ sub convert_to_unit {
if ( $convert{'volume'} ) {
$volume = 0.001 * $convert{'volume'}; # m³
if ($ingredient->{density}) {
- $out_amount{'weight'} = $density * $volume; # kg
+ $out_amount{'weight'} = $density * $volume * 1000; # g
}
} elsif ( $convert{'weight'} ) {
- $weight = $convert{'weight'}; # kg
+ $weight = $convert{'weight'}; # g
$out_amount{'weight'} = $weight;
if ($ingredient->{'piece_weight'}) {
$piece_weight = $ingredient->{'piece_weight'}; # g/piece
@@ -176,7 +176,7 @@ sub convert_to_unit {
$ingredient->{'piece_weight'}; # piece
}
if ($ingredient->{density}) {
- $out_amount{'volume'} = 1000 * $weight / $density; # g
+ $out_amount{'volume'} = $weight / $density; # g
}
} elsif ( $convert{'piece'} ) {
if ($ingredient->{'piece_weight'}) {
@@ -187,7 +187,7 @@ sub convert_to_unit {
if ($out_unit eq "g") {
if($out_amount{'weight'}) {
- return $out_amount{'weight'} * 1000;
+ return $out_amount{'weight'};
} else {
return
}