diff options
-rwxr-xr-x | energyadder.pl | 18 | ||||
-rwxr-xr-x | mat | 403 | ||||
-rwxr-xr-x | sts | 9 |
3 files changed, 338 insertions, 92 deletions
diff --git a/energyadder.pl b/energyadder.pl index e91a4b4..501a04b 100755 --- a/energyadder.pl +++ b/energyadder.pl @@ -13,7 +13,7 @@ use utf8; binmode STDOUT, 'utf8'; -use constant GOAL_ENERGY => 900; +my $goal_energy = 900; tie my %Config, "Config::Simple", '/etc/mat.conf'; @@ -62,9 +62,10 @@ open my $cooking_file, '<', $ARGV[0]; my $cooking = YAML::LoadFile($cooking_file); my @ingredients = @{ $cooking->{'ingredients'} }; -print "Goal energy: ", GOAL_ENERGY, " kJ\n\n"; +print "Goal energy: ", $goal_energy, " kJ\n\n"; my $energy = 0; +my $ingredient_weight = 0; my $proteins = 0; my $carbs = 0; @@ -79,6 +80,8 @@ for my $ingredient ( @ingredients ) { my ( $row ) = $db->selectrow_hashref($sql); if ($row->{'Livsmedelsnamn'}) { # print $row->{'Livsmedelsnamn'}; + $ingredient->{quantity} = eval($ingredient->{quantity}); + $ingredient_weight += $ingredient->{quantity}; $energy += $ingredient->{quantity} * $row->{'Energi'} / 100; $proteins += $ingredient->{quantity} * $row->{'Protein'}; @@ -103,9 +106,13 @@ for my $ingredient ( @ingredients ) { # $ingredient->{quantity} * $row->{'Energi'} / 100, $energy; } -#my $total_food_weight = SCALE_READING - CONTAINER_WEIGHT; +#my $total_food_weight = SCALE_READING - CONTAINER_WEIGHT + ALREADY_EATEN; my $total_food_weight = $cooking->{'scale_reading'} - $cooking->{'container_weight'} - + $cooking->{'scale_reading'} * (1.0 * $cooking->{'already_eaten'} / $cooking->{'original_scale_reading'}); + + 1.0 * $cooking->{'already_eaten'}; +#my $total_food_weight = $cooking->{'scale_reading'} - $cooking->{'container_weight'} +# + ($cooking->{'scale_reading'} - $cooking->{'container_weight'}) * +# (1.0 * $cooking->{'already_eaten'} / +# ($cooking->{'original_scale_reading'} - $cooking->{'container_weight'})); my $specific_energy = $energy / $total_food_weight * 100; # kJ/100 g #my $left = ( $total_food_weight - 198 ) * $specific_energy; @@ -116,12 +123,13 @@ $carbs /= $total_ingredient_weight; $fats /= $total_ingredient_weight; print "\n"; +printf "Total ingredient weight: %d g\n", $ingredient_weight; printf "Total energy (all %d g): %d kJ\n", $total_food_weight, $energy; printf "Specific energi: %d kJ/100 g\n", $specific_energy; print "\n"; -my $portions = int($energy/GOAL_ENERGY); +my $portions = int($energy/$goal_energy); print $portions, " matlådor på ", int($total_food_weight/$portions), " g ger ", int($total_food_weight/$portions/100 * $specific_energy) ," kJ/matlåda.\n"; $portions++; @@ -11,6 +11,7 @@ use GD; use GD::Barcode; use GD::Barcode::QRcode; use Text::Iconv; +#use Text::QRCode; use utf8; binmode(STDOUT, 'utf8:'); @@ -122,10 +123,60 @@ my @schedule = ( } ); +sub convert_to_type { + my ( $out_type, $id, $in_amount, $in_type ) = @_; + my %out_amount; + my $out_factor; + + my $sql = "SELECT density, piece_weight FROM ingredients WHERE id=".$id.";"; + my $ingredient = $db->selectrow_hashref($sql); + my $volume; + my $weight; + if ($in_type eq 'volume') { + $volume = 0.001 * $in_amount; # m³ + } + + if ( $in_type eq 'volume' ) { + $out_amount{'volume'} = $volume * 1000; # l + if ($ingredient->{'density'}) { + $out_amount{'weight'} = $ingredient->{'density'} * $volume * 1000; # g + } + } elsif ( $in_type eq 'weight' ) { + $out_amount{'weight'} = $in_amount; + if ($ingredient->{'density'}) { + $out_amount{'volume'} = $in_amount / $ingredient->{'density'}; # g + } + } elsif ( $in_type eq 'piece' ) { + if ($ingredient->{'piece_weight'}) { + my $piece_weight = $ingredient->{'piece_weight'}; # g/piece + $out_amount{'weight'} = $in_amount * $piece_weight; # g + if ($ingredient->{'density'}) { + $out_amount{'volume'} = + $out_amount{'weight'} / $ingredient->{'density'}; + } + } + } + + if ( $out_type eq "piece" ) { + if ($ingredient->{'piece_weight'}) { + return $out_amount{'weight'} / $ingredient->{'piece_weight'}; # piece + } else { + return undef; + } + } + + return $out_amount{$out_type}; +} + sub convert_to_unit { my ( $out_unit, $id, $in_amount, $in_unit ) = @_; + my $in_type; + my $return_unit; my %out_amount; + my $out_type; + my $out_factor; my %convert; # volume [l], weight [g], piece [st] + my $debug_conversion = "no"; # SELECT DISTINCT unit FROM contents; # msk, krm, dl, tsk, cl, l, ml, nypa @@ -148,67 +199,127 @@ sub convert_to_unit { $convert{'volume'} = $in_amount * 0.005; } elsif ($in_unit eq "krm") { $convert{'volume'} = $in_amount * 0.001; + } elsif ($in_unit eq "mg") { + $convert{'weight'} = $in_amount / 1000; } elsif ($in_unit eq "g") { $convert{'weight'} = $in_amount; } elsif ($in_unit eq "kg") { $convert{'weight'} = $in_amount * 1000; } elsif ($in_unit eq "st") { $convert{'piece'} = $in_amount; + } elsif ($in_unit eq "ark") { + $convert{'piece'} = $in_amount; + } elsif ( ($in_unit eq "cm") and ($in_unit eq $ingredients[$id]->{'primary_unit'}) ) { + # FIXME This really isn't piece_weight, but something else. 1 cm of leek is + # not a the same as one leek + $convert{'piece'} = $in_amount; + } elsif ( ($in_unit eq "knippen") and ($in_unit eq $ingredients[$id]->{'primary_unit'}) ) { + # FIXME This really isn't piece_weight, but something else. 1 cm of leek is + # not a the same as one leek + $convert{'piece'} = $in_amount; } -# print $ingredients[$id]->{'name'}, " ", $id, " in_unit: ", $in_unit, "\n"; -# print " V:", $convert{'volume'}, " W:", $convert{'weight'}, " P:", -# $convert{'piece'}, " out_unit: ", $out_unit, " \n"; - - my $sql = "SELECT density, piece_weight FROM ingredients WHERE id=".$id.";"; - my $ingredient = $db->selectrow_hashref($sql); - my $volume; - my $density; - my $weight; - $density = $ingredient->{density}; # kg/m³ - my $piece_weight; if ( $convert{'volume'} ) { - $volume = 0.001 * $convert{'volume'}; # m³ - if ($ingredient->{density}) { - $out_amount{'weight'} = $density * $volume * 1000; # g - } + $in_type='volume'; } elsif ( $convert{'weight'} ) { - $weight = $convert{'weight'}; # g - $out_amount{'weight'} = $weight; - if ($ingredient->{'piece_weight'}) { - $piece_weight = $ingredient->{'piece_weight'}; # g/piece - $out_amount{'piece'} = $convert{'weight'} / - $ingredient->{'piece_weight'}; # piece - } - if ($ingredient->{density}) { - $out_amount{'volume'} = $weight / $density; # g - } + $in_type='weight'; } elsif ( $convert{'piece'} ) { - if ($ingredient->{'piece_weight'}) { - $piece_weight = $ingredient->{'piece_weight'}; # g/piece - $out_amount{'weight'} = $convert{'piece'} * $piece_weight; # g - } + $in_type='piece'; } -# print " ", " V:", $out_amount{'volume'}, " W:", $out_amount{'weight'}, " P:", $out_amount{'piece'}, " \n\n"; - - if ($out_unit eq "g") { - if($out_amount{'weight'}) { - return $out_amount{'weight'}; - } else { - return - } + if ($out_unit eq "weight") { + $out_type = 'weight'; + $out_factor = 0; + } elsif ($out_unit eq "g") { + $out_type = 'weight'; + $out_factor = 1; + } elsif ($out_unit eq "mg") { + $out_type = 'weight'; + $out_factor = 1000; } elsif ($out_unit eq "kg") { - return $out_amount{'weight'}; + $out_type = 'weight'; + $out_factor = 0.001; } elsif ($out_unit eq "st") { - return $out_amount{'piece'}; + $out_type = 'piece'; + $out_factor = 1; } elsif ($out_unit eq "l") { - return $out_amount{'volume'}; + $out_type = 'volume'; + $out_factor = 1; } elsif ($out_unit eq "dl") { - return $out_amount{'volume'}*10; + $out_type = 'volume'; + $out_factor = 10; + } elsif ($out_unit eq "cl") { + $out_type = 'volume'; + $out_factor = 100; + } elsif ($out_unit eq "ml") { + $out_type = 'volume'; + $out_factor = 1000; + } elsif ($out_unit eq "tsk") { + $out_type = 'volume'; + $out_factor = (1 / 0.005); + } elsif ($out_unit eq "msk") { + $out_type = 'volume'; + $out_factor = (1 / 0.015); + } elsif ($out_unit eq "cm") { + $out_type = 'piece'; + } elsif ($out_unit eq "knippen") { + $out_type = 'piece'; + } + + if ( $debug_conversion eq "yes" or $debug_conversion eq $id) { + print $ingredients[$id]->{'name'}, " ", $id, " in_unit: ", $in_unit, + " out_unit: ", $out_unit, "\n"; + print " V:", (defined($convert{'volume'})?$convert{'volume'}:"undef"), + " W:", (defined($convert{'weight'})?$convert{'weight'}:"undef"), " P:", + (defined($convert{'piece'})?$convert{'piece'}:"undef"), " \n"; + } + + if ( ($out_type eq 'piece') and ($in_unit eq $out_unit) ) { + $out_amount{$out_type} = $in_amount; + } else { + if ( $in_type ) { + $out_amount{$out_type} = convert_to_type( $out_type, $id, $convert{$in_type}, $in_type ); + } else { + print STDERR "Could not convert $id\n"; + } + } + + my $sql = "SELECT density, piece_weight FROM ingredients WHERE id=".$id.";"; + my $ingredient = $db->selectrow_hashref($sql); + + if ( $debug_conversion eq "yes" or $debug_conversion eq $id) { + print " ", + " V:", (defined($out_amount{'volume'})?$out_amount{'volume'}:"undef"), + " W:", (defined($out_amount{'weight'})?$out_amount{'weight'}:"undef"), + " P:", (defined($out_amount{'piece'})?$out_amount{'piece'}:"undef"), + "", + " piece_weight: ", (defined($ingredient->{'piece_weight'})?$ingredient->{'piece_weight'}:"undef"), + " \n\n"; } - return undef; + if ( defined($out_amount{$out_type}) ) { +# unless ( $out_factor ) { +# if ( $out_type eq "weight" ) { +# if ( $out_amount{$out_type} < 1 ) { +# $return_unit = "mg"; +# $out_factor = 1000; +# } elsif ( $out_amount{$out_type} > 1000 ) { +# $return_unit = "kg"; +# $out_factor = 0.001; +# } else { +# $return_unit = "g"; +# $out_factor = 1; +# } +## printf "> %5.2f, %s", $out_amount{$out_type} * $out_factor, $return_unit; +# } +# } + + if ( $out_factor ) { + return $out_amount{$out_type} * $out_factor; + } + } else { + return undef; + } } sub cmd_setmeal { @@ -661,6 +772,7 @@ sub cmd_help() { print "searchrecipes <search_string>\n"; print "editrecipe <recipe_id>\n"; print "showrecipe <recipe_id>\n"; + print "showingredient <ingredient_id>\n"; print "movemeal <source_date> <destination_date>\n"; print "setmeal <date> <mealtype> <meal_id>\n"; print "setcomment <date> <mealtype> <comment>\n"; @@ -795,6 +907,60 @@ sub cmd_addrecipe { return interactive_edit_recipe_ingredients($recipe_id[0]); } +sub ingredient_row { + my ( $ingredient, $original_quantity, $original_unit ) = @_; + + my $ingredient_row = $db->selectrow_hashref("SELECT * FROM ingredients WHERE id=".$ingredient.";"); + + my $primary_unit; + my $primary_quantity; + my $weight_unit; + my $weight_quantity; + my $volume_unit; + my $volume_quantity; + if ( $ingredient_row->{primary_unit} ) { + $primary_unit = $ingredient_row->{primary_unit}; + $primary_quantity = convert_to_unit($primary_unit, $ingredient, $original_quantity, $original_unit); + } else { + $primary_unit = $original_unit; + $primary_quantity = $original_quantity; + } +# if ($original_unit eq "g" ) { +# $convert_unit = $ingredient_row->{primary_unit}; +# } else { +# $convert_unit = "g"; +# } +# if ($convert_unit) { +# $convert_quantity = convert_to_unit($convert_unit, $ingredient, $original_quantity, $original_unit); +# } + $weight_unit = 'g'; + $weight_quantity = convert_to_unit($weight_unit, $ingredient, $original_quantity, $original_unit); + $volume_unit = 'ml'; + $volume_quantity = convert_to_unit($volume_unit, $ingredient, $original_quantity, $original_unit); + +# printf "%4s %-8s ", $original_quantity, $original_unit; +# if ( $convert_quantity ) { +# printf "(%4.4s %-8s)", $convert_quantity, $convert_unit; +# } else { +# printf "%15s", " "; +# } +# printf " %s\n", $ingredient_row->{name}; + + printf "%4.4s %-8s ", $original_quantity, $original_unit; + if ( $weight_quantity ) { + printf "(%5.4s %-1s,", int($weight_quantity), $weight_unit; + } else { + printf "(%8s", ""; + } + if ( $volume_quantity ) { + printf "%5.4s %-2s)", int($volume_quantity), $volume_unit; + } else { + printf "%8s)", ""; + } + printf " %s\n", $ingredient_row->{name}; + +} + sub cmd_showrecipe { # Argument is recipe_id @@ -803,7 +969,20 @@ sub cmd_showrecipe { my $recipe_row = $db->selectrow_arrayref("SELECT name, uri, servings FROM recipes WHERE id=".$recipe_id.";"); my $servings; my $ingredient_multipler = 1; - + my $debug_substitution = "no"; + +# my $qrcode = Text::QRCode->new(); +# my $urlqr = $qrcode->plot(@$recipe_row[1]); +# for ( @$urlqr ) { +# for ( @$_ ) { +# if ( $_ eq "*" ) { +# print "██"; +# } else { +# print " "; +# } +# } +# print "\n"; +# } print @$recipe_row[0]; if(defined(@$recipe_row[1])) { printf ", %s\n", @$recipe_row[1]; @@ -823,28 +1002,61 @@ sub cmd_showrecipe { print "WARNING servings is not set for recipe $recipe_id!\n\n"; } - my $contents = $db->selectall_hashref("SELECT * FROM contents WHERE recipe_id=".$recipe_id.";", 'ingredient_id'); - for my $content ( keys(%$contents)) { - $$contents{$content}{quantity} = $$contents{$content}{quantity} * $ingredient_multipler; - my $ingredientcol = $db->selectrow_arrayref("SELECT name, primary_unit FROM ingredients WHERE id=".$content.";"); - my $convert_unit; - my $convert_result; - if ($$contents{$content}{unit} eq "g" ) { - $convert_unit = @$ingredientcol[1]; - } else { - $convert_unit = "g"; + my $total_weight = 0; + my $total_volume = 0; + my $parts = $db->selectcol_arrayref("SELECT DISTINCT(recipe_part) FROM contents WHERE recipe_id=".$recipe_id.";"); + for my $part ( @$parts ) { + my $part_sql = ""; + my $ingredient_weight; + my $ingredient_volume; + if( defined($part) ) { + print "part $part\n"; + $part_sql = " AND recipe_part='".$part."'"; } - if ($convert_unit) { - $convert_result = convert_to_unit($convert_unit, $content, $$contents{$content}{quantity}, $$contents{$content}{unit}); - } - printf "%4s %-8s ", $$contents{$content}{quantity}, $$contents{$content}{unit}; - if ( $convert_result ) { - printf "(%4.4s %-8s)", $convert_result, $convert_unit; - } else { - printf "%15s", " "; + my $contents = $db->selectall_hashref("SELECT * FROM contents WHERE recipe_id=".$recipe_id.$part_sql.";", 'ingredient_id'); + for my $content ( keys(%$contents)) { + $$contents{$content}{quantity} = $$contents{$content}{quantity} * $ingredient_multipler; + printf "%8s", ""; + ingredient_row($content, $$contents{$content}{quantity}, $$contents{$content}{unit}); + $ingredient_weight = convert_to_unit('g', $content, $$contents{$content}{quantity}, $$contents{$content}{unit}); + $ingredient_volume = convert_to_unit('dl', $content, $$contents{$content}{quantity}, $$contents{$content}{unit}); + $total_weight += ($ingredient_weight?$ingredient_weight:0); + $total_volume += ($ingredient_volume?$ingredient_volume:0); + + my $substitutes = $db->selectall_arrayref("SELECT substitute_ingredient FROM substitutes WHERE original_ingredient=".$content.";"); + if ( $substitutes->[0] ) { + for ( @$substitutes ) { + my $substitute = $db->selectrow_hashref("SELECT * FROM substitutes WHERE original_ingredient=".$content." AND substitute_ingredient=$_->[0];"); + my $substituted_quantity; + + # Attempt at converting original ingredient to unit reqiured for substitution + my $convert_me = convert_to_unit($substitute->{original_unit}, $content, $$contents{$content}{quantity}, $$contents{$content}{unit}); + if ( defined($convert_me) ) { + # Convert according to substitution table + $substituted_quantity = $convert_me / $substitute->{original_quantity} * $substitute->{substitute_quantity}; + } else { + # ( $out_unit, $id, $in_amount, $in_unit ) = @_; + $substituted_quantity = 1.0 * $$contents{$content}{quantity} * + convert_to_unit($substitute->{original_unit}, $content, 1, $$contents{$content}{unit}) / + $substitute->{original_quantity}; + } + + if ( $debug_substitution ne "no" ) { + printf "ingredient: %d, recipe_unit: '%s', original_unit: '%s', + convert_me: %d, substituted_quantity: %d\n\n", $content, + $$contents{$content}{unit}, $substitute->{original_unit}, + $convert_me, $substituted_quantity; + } + + printf "%8s", "eller "; + ingredient_row($substitute->{substitute_ingredient}, $substituted_quantity, $substitute->{substitute_unit}); + } + } } - printf " %s\n", @$ingredientcol[0]; + print "\n"; } + printf "\nTotal ingredients: (about) %5d g, %3.1f dl\n", $total_weight, $total_volume; + print "\n"; my $cooking_comments = $db->selectall_hashref("SELECT date, comment FROM cookings WHERE recipe_id=".$recipe_id." AND comment IS NOT NULL;", 'date'); my $eating_comments = $db->selectall_hashref("SELECT date, comment FROM eatings AS e JOIN inventory AS i ON e.inventory_id=i.id WHERE recipe_id=".$recipe_id." AND comment IS NOT NULL;", 'date'); @@ -861,6 +1073,26 @@ sub cmd_showrecipe { return 1; } +sub cmd_showingredient { + my ( $ingredient_id, $multiplier ) = @_; + + my $row = $db->selectrow_hashref("SELECT name, primary_unit, density, piece_weight FROM ingredients WHERE id=".$ingredient_id.";"); + $multiplier = 1 unless ($multiplier); + + print "Ingredient: ".$row->{name}."\n"; + if ($row->{piece_weight}) { + print " Piece weight ($multiplier): ".$multiplier*$row->{piece_weight}." g\n"; + } + if ($row->{density}) { + for my $unit ('ml', 'cl', 'dl', 'l', 'krm', 'tsk', 'msk') { + print " $multiplier $unit: ".convert_to_unit('g', $ingredient_id, $multiplier, $unit)." g\n"; + } + } + + return 1; +} + + sub cmd_searchrecipes { # Argument is search regexp @@ -978,15 +1210,15 @@ sub cmd_shoppinglist { my @shop_ingredients; for my $recipe (@shop_recipes) { # my $contents = $db->selectall_arrayref("SELECT * FROM contents WHERE recipe_id=".$recipe.";"); - my $contents = $db->selectall_hashref("SELECT * FROM contents WHERE recipe_id=".$recipe.";", 'ingredient_id'); +# my $contents = $db->selectall_hashref("SELECT * FROM contents WHERE recipe_id=".$recipe.";", 'ingredient_id'); +# my $contents = $db->selectall_hashref("SELECT recipe_id, ingredient_id, SUM(quantity), unit FROM contents WHERE recipe_id=".$recipe." GROUP BY ingredient_id;", 'ingredient_id'); + my $contents = $db->selectall_hashref("SELECT recipe_id, ingredient_id, SUM(quantity) AS quantity, unit FROM contents WHERE recipe_id=".$recipe." GROUP BY ingredient_id;", 'ingredient_id'); unless (%$contents) { print "WARNING recipe $recipe contains no ingredients!\n"; } for my $content ( keys(%$contents)) { my %shop; -# print %$contents, "\n"; my $ingredientrow = $db->selectrow_arrayref("SELECT name, primary_unit FROM ingredients WHERE id=".$content.";"); -# print $content, " ", @$ingredientcol[0], "\n"; # print $$contents{$content}{unit}, $content, " ", @$ingredientcol[0], "\n"; # print keys(%$contents), "\n"; $shop{id} = $content; @@ -1063,26 +1295,27 @@ sub cmd_shoppinglist { read_recipe_db; my $commands = { - "help" => { func => \&cmd_help, min => 0, max => 0 }, - "addrecipe" => { func => \&cmd_addrecipe, min => 0, max => 0 }, - "searchrecipes" => { func => \&cmd_searchrecipes, min => 1, max => 1 }, - "editrecipe" => { func => \&cmd_editrecipe, min => 1, max => 1 }, - "showrecipe" => { func => \&cmd_showrecipe, min => 1, max => 2 }, - "movemeal" => { func => \&cmd_movemeal, min => 2, max => 2 }, - "setmeal" => { func => \&cmd_setmeal, min => 3, max => 3 }, - "setcomment" => { func => \&cmd_setcomment, min => 3, max => 3 }, - "randmeal" => { func => \&cmd_randmeal, min => 1, max => 1 }, - "showplan" => { func => \&cmd_showplan, min => 0, max => 2 }, - "postpone" => { func => \&cmd_postpone, min => 2, max => 2 }, - "inventory" => { func => \&cmd_inventory, min => 1, max => 1 }, - "storeportion" => { func => \&cmd_storeportion, min => 1, max => 3 }, - "reprintlabel" => { func => \&cmd_reprintlabel, min => 1, max => 1 }, - "relocate" => { func => \&cmd_relocate, min => 2, max => 2 }, - "queueadd" => { func => \&cmd_queueadd, min => 2, max => 2 }, - "queuerm" => { func => \&cmd_queuerm, min => 1, max => 1 }, - "queuemv" => { func => \&cmd_queuemv, min => 2, max => 2 }, - "queueshow" => { func => \&cmd_queueshow, min => 0, max => 0 }, - "shoppinglist" => { func => \&cmd_shoppinglist, min => 0, max => 1 } + "help" => { func => \&cmd_help, min => 0, max => 0 }, + "addrecipe" => { func => \&cmd_addrecipe, min => 0, max => 0 }, + "searchrecipes" => { func => \&cmd_searchrecipes, min => 1, max => 1 }, + "editrecipe" => { func => \&cmd_editrecipe, min => 1, max => 1 }, + "showrecipe" => { func => \&cmd_showrecipe, min => 1, max => 2 }, + "showingredient" => { func => \&cmd_showingredient, min => 1, max => 2 }, + "movemeal" => { func => \&cmd_movemeal, min => 2, max => 2 }, + "setmeal" => { func => \&cmd_setmeal, min => 3, max => 3 }, + "setcomment" => { func => \&cmd_setcomment, min => 3, max => 3 }, + "randmeal" => { func => \&cmd_randmeal, min => 1, max => 1 }, + "showplan" => { func => \&cmd_showplan, min => 0, max => 2 }, + "postpone" => { func => \&cmd_postpone, min => 2, max => 2 }, + "inventory" => { func => \&cmd_inventory, min => 1, max => 1 }, + "storeportion" => { func => \&cmd_storeportion, min => 1, max => 3 }, + "reprintlabel" => { func => \&cmd_reprintlabel, min => 1, max => 1 }, + "relocate" => { func => \&cmd_relocate, min => 2, max => 2 }, + "queueadd" => { func => \&cmd_queueadd, min => 2, max => 2 }, + "queuerm" => { func => \&cmd_queuerm, min => 1, max => 1 }, + "queuemv" => { func => \&cmd_queuemv, min => 2, max => 2 }, + "queueshow" => { func => \&cmd_queueshow, min => 0, max => 0 }, + "shoppinglist" => { func => \&cmd_shoppinglist, min => 0, max => 1 } }; if ($ARGV[0]) { @@ -1,10 +1,15 @@ #!/bin/sh # scale triggered store +WEIGHT="$1" + +[ "${WEIGHT}" ] || { echo "First argument must be an amount." >&2; exit 1; } +[ "${WEIGHT}" -gt 0 ] || { echo "Amount must be larger than zero." >&2; exit 1; } + cd $HOME/mat/matplan/ if (grep -q v currently_cooking); then - PRINT_WITH_LOGO=y ./mat storeportion `cat currently_cooking|sed 's/v//'` "$1" hemfrys + PRINT_WITH_LOGO=y ./mat storeportion `cat currently_cooking|sed 's/v//'` "${WEIGHT}" hemfrys else - ./mat storeportion `cat currently_cooking|sed 's/v//'` "$1" hemfrys + ./mat storeportion `cat currently_cooking|sed 's/v//'` "${WEIGHT}" hemfrys fi |