summaryrefslogtreecommitdiff
path: root/energyadder.pl
diff options
context:
space:
mode:
authorcos <cos>2019-01-30 22:03:52 +0100
committercos <cos>2019-01-30 22:03:52 +0100
commit8605774e163737c5377f05fad7c38b7d27da5df4 (patch)
tree40c5c1182127c1a096223fc57c792249042b0771 /energyadder.pl
parentcd83c4b79bc49bd45c1c58e7b8dcec785bb9222c (diff)
downloadmat-8605774e163737c5377f05fad7c38b7d27da5df4.zip
Assorted changes from the last few years
Diffstat (limited to 'energyadder.pl')
-rwxr-xr-xenergyadder.pl18
1 files changed, 13 insertions, 5 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++;