From ae8c9242c9dc0155a6e1c5ab9e0cf6bdc726e430 Mon Sep 17 00:00:00 2001 From: cos Date: Sun, 6 Dec 2015 22:37:48 +0100 Subject: Make some fixes to faulty unit conversion. --- mat | 14 +++++++------- 1 file 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 } -- cgit v1.2.3