From 0ebad02de17fbaf79af6f3c4992c105152b1e256 Mon Sep 17 00:00:00 2001 From: Geoff Humphrey Date: Thu, 8 Sep 2011 20:01:12 +0000 Subject: [PATCH] Continuing consolidation effort. Eliminated efficiency.inc.php file - moved functionality to the functions.inc.php file and converted to a function. Called the function in the appropriate area in the recipe_mash.inc.php file. --- includes/efficiency.inc.php | 117 ----------------------------------- includes/functions.inc.php | 68 ++++++++++++++++++++ sections/recipe_mash.inc.php | 8 +-- 3 files changed, 70 insertions(+), 123 deletions(-) delete mode 100644 includes/efficiency.inc.php diff --git a/includes/efficiency.inc.php b/includes/efficiency.inc.php deleted file mode 100644 index 462c90a..0000000 --- a/includes/efficiency.inc.php +++ /dev/null @@ -1,117 +0,0 @@ -"; -echo $wort."
"; -echo $grain1." ".$grain1amt."
"; -echo $grain2." ".$grain2amt."
"; -echo $grain3." ".$grain3amt."
"; -echo $grain4." ".$grain4amt."
"; -echo $grain5." ".$grain5amt."
"; -echo $grain6." ".$grain6amt."
"; -echo $grain7." ".$grain7amt."
"; -echo $grain8." ".$grain8amt."
"; -echo $grain9." ".$grain9amt."
";; -*/ - -$ogconvert = ($gravity - 1) * 1000; -$ppg = ($ogconvert * $wort) / $grain; -switch ($units) { - case "gallons": - $ppg_display = $ppg; - break; - case "liters": - $ppg_display = ($ppg / 10); - break; -} - -// Calculate Efficiency -$efficiency_sum = 0; -switch ($units) { - case "gallons": - for ($i = 0; $i < MAX_GRAINS; $i++) { - $efficiency_sum += ($grainsPPG[$i] * $grainsWeight[$i]) / $wort; - } - /* - $grain1calc = ($grain1 * $grain1amt)/$wort; - $grain15calc = ($grain15 * $grain15amt)/$wort; - */ - break; - case "liters": - for ($i = 0; $i < MAX_GRAINS; $i++) { - $efficiency_sum += ($grainsPPG[$i] * ($grainsWeight[$i] * 2.202)) / ($wort * .264); - } - /* - $grain1calc = ($grain1 * ($grain1amt * 2.202))/($wort * .264); - $grain15calc = ($grain15 * ($grain15amt * 2.202))/($wort * .264); - */ - break; -} - -/* -$efficiency_sum = ( -$grain1calc + -$grain2calc + -$grain3calc + -$grain4calc + -$grain5calc + -$grain6calc + -$grain7calc + -$grain8calc + -$grain9calc + -$grain10calc + -$grain11calc + -$grain12calc + -$grain13calc + -$grain14calc + -$grain15calc -); -*/ - -if (($efficiency_sum != 0) && ($gravity != "")) { - $efficiency = ($ogconvert / $efficiency_sum) * 100; -} - -/* -echo $ogconvert."
"; -echo $efficiency_sum."
"; -echo $efficiency; -*/ -?> - diff --git a/includes/functions.inc.php b/includes/functions.inc.php index 496d157..97d7044 100644 --- a/includes/functions.inc.php +++ b/includes/functions.inc.php @@ -94,6 +94,74 @@ function calc_bugu($bitterness,$og) { return $calc; } +function calc_ppg($gravity,$wort,$grain,$units) { + $ppg = (($gravity - 1) * 1000 * $wort) / $grain; + switch ($units) { + case "gallons": + $ppg = $ppg; + break; + case "liters": + $ppg = ($ppg / 10); + break; + } + $ppg = round($ppg,0); + return $ppg; +} + +function calc_efficiency($gravity,$wort,$grain,$units,$log_id) { + include(CONFIG.'config.php'); + include(ADMIN_INCLUDES.'constants.inc.php'); + + $query_log = sprintf("SELECT * FROM brewing WHERE id='%s'",$log_id); + $log = mysql_query($query_log, $brewing) or die(mysql_error()); + $row_log = mysql_fetch_assoc($log); + + $grainsPPG = array(); + + $efficiency_sum = 0; + switch ($units) { + case "gallons": + for ($i = 0; $i < MAX_GRAINS; $i++) { + $key = "brewGrain" . ($i + 1); + $query = 'SELECT maltPPG FROM malt WHERE maltName="' . $row_log[$key] . '"'; + $grainsPPG[$i] = mysql_query($query, $brewing) or die(mysql_error()); + $row_grainsPPG[$i]= mysql_fetch_assoc($grainsPPG[$i]); + $key = "brewGrain" . ($i + 1) . "Weight"; + $grainsWeight[$i] = $row_log[$key]; + if ($grainsWeight[$i] > 0) { + $ppg = array_sum($row_grainsPPG[$i]); + $efficiency_sum = ($ppg * $grainsWeight[$i]) / $wort; + $efficiency[] = $efficiency_sum; + } + } + break; + case "liters": + for ($i = 0; $i < MAX_GRAINS; $i++) { + $key = "brewGrain" . ($i + 1); + $query = 'SELECT maltPPG FROM malt WHERE maltName="' . $row_log[$key] . '"'; + $grainsPPG[$i] = mysql_query($query, $brewing) or die(mysql_error()); + $row_grainsPPG[$i]= mysql_fetch_assoc($grainsPPG[$i]); + $key = "brewGrain" . ($i + 1) . "Weight"; + $grainsWeight[$i] = $row_log[$key]; + if ($grainsWeight[$i] > 0) { + $ppg = array_sum($row_grainsPPG[$i]); + $efficiency_sum = ($ppg * ($grainsWeight[$i] * 2.202)) / ($wort * .264); + $efficiency[] = $efficiency_sum; + } + } + break; + } + + $efficiency_sum = array_sum($efficiency); + + if (($efficiency_sum != 0) && ($gravity != "")) { + $efficiency = round(((($gravity - 1) * 1000) / $efficiency_sum * 100),1)."%"; + } + else $efficiency = ''; + + return $efficiency; +} + // ---------------------------- Date Conversion ----------------------------------------- // http://www.phpbuilder.com/annotate/message.php3?id=1031006 function dateconvert($date,$func) { diff --git a/sections/recipe_mash.inc.php b/sections/recipe_mash.inc.php index ce8edfc..1dbeaec 100644 --- a/sections/recipe_mash.inc.php +++ b/sections/recipe_mash.inc.php @@ -1,7 +1,3 @@ - -
Mash Profile
@@ -21,9 +17,9 @@ if (($row_log['brewPreBoilAmt'] != "") && ($row_log['brewMashGravity'] !="") && - + - + Notes: