IBU calculation moved to formulas.php and added Daniels and Rager methods.

Mon, 12 Nov 2018 22:47:49 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Mon, 12 Nov 2018 22:47:49 +0100
changeset 90
d4246abee34e
parent 89
082c23b26055
child 91
44981507b781

IBU calculation moved to formulas.php and added Daniels and Rager methods.

www/includes/formulas.php file | annotate | diff | comparison | revisions
www/rec_print.php file | annotate | diff | comparison | revisions
--- a/www/includes/formulas.php	Mon Nov 12 16:34:43 2018 +0100
+++ b/www/includes/formulas.php	Mon Nov 12 22:47:49 2018 +0100
@@ -196,6 +196,69 @@
 
 
 
+function calc_IBU($useat, $form, $sg, $volume, $mass, $boiltime, $alpha, $method) {
+
+	$fmoment  = 1.0;
+	if (($useat == "Dry Hop") || ($useat == "Dry hop") || ($useat == "Whirlpool") || ($useat == "Aroma")) {
+		$fmoment = 0.0;
+	} else if ($useat == "Mash") {
+		$fmoment += /* Settings.MashHopFactor.Value = -30% */ -30 / 100;         // Brouwhulp
+	} else if (($useat == "First Wort") || ($useat == "First wort")) {
+		$fmoment += /* Settings.FWHFactor.Value = 10% */ 10 / 100;         // Brouwhulp, Louis, Ozzie
+	}
+
+	$pfactor  = 1.0;
+	if ($form == "Pellet") {
+		$pfactor += /* Settings.PelletFactor.Value = 10% */ 10 / 100;
+	}
+	if ($form == "Plug") {
+		$pfactor += /* Settings.PlugFactor.Value = 2% */ 2 / 100;
+	}
+
+	$ibu = 0;
+	if (($method == "Tinseth") || ($method == "Garetz")) {	// For Garetz, we need the $ibu
+		$AddedAlphaAcids = (($alpha / 100) * $mass * 1000) / $volume;
+		$Bigness_factor = 1.65 * pow( 0.000125, $sg - 1);
+		$BoilTime_factor = ((1 - exp(-0.04 * $boiltime)) / 4.15);
+		$utiisation = $Bigness_factor * $BoilTime_factor;
+		$ibu = (round($utiisation * $AddedAlphaAcids * $fmoment * $pfactor * 10) / 10.0);
+	}
+	if ($method == "Daniels") {
+
+		if ($form == "Leaf")
+			$boilfactor = -(0.0041*$boiltime*$boiltime)+(0.6162*$boiltime)+1.5779;
+		else
+			$boilfactor = -(0.0051*$boiltime*$boiltime)+(0.7835*$boiltime)+1.9348;
+		if ($sg < 1.050)
+			$sgfactor = 0;
+		else
+			$sgfactor = (($sg * 1000) - 1050) / 200;
+		$ibu = $fmoment * (($mass * $alpha * $boilfactor * 0.1) / ($volume * (1 + $sgfactor)));
+	}
+	if ($method == "Rager") {
+		$boilfactor = $fmoment * 18.11 + 13.86 * tanh(($boiltime * 31.32) / 18.27);
+		if ($sg < 1.050)
+			$sgfactor = 0;
+		else
+			$sgfactor = (($sg * 1000) - 1050) / 200;
+		$ibu = ($mass * $alpha * $boilfactor * 0.1) / ($volume * (1 + $sgfactor));
+	}
+	if ($method == "Garetz") {
+		/* Something is wrong, late hops and dryhops give negative results. */
+		$boilfactor = $fmoment * 6.03253 + 16.5289 * tanh(($boiltime - 19.17323) / 26.8013);
+		$cfactor = $volume / (1.1 * $volume);	// ConcentratieFactor = (Volume na koelen) / (Volume bij Koken)
+		$kookdichtheid = ($cfactor * (($sg * 1000) - 1000) / 1000) + 1;
+		$sgfactor = ($kookdichtheid - 1.05) / 0.2 + 1;
+		$hopratefactor = (($cfactor * $ibu) / 260) + 1;	// $ibu is Tinseth bitterness. Weird.
+		$tempfactor = (32.8/550)*0.02+1;
+		$ibu = ($boilfactor * $alpha * $mass * 0.1) / ($volume * $sgfactor * $hopratefactor * $tempfactor);
+	}
+	/* TODO: Noonan and Mosher */
+
+	return $ibu;
+}
+
+
 /*
 
 Brouwhulp data.pas
--- a/www/rec_print.php	Mon Nov 12 16:34:43 2018 +0100
+++ b/www/rec_print.php	Mon Nov 12 22:47:49 2018 +0100
@@ -204,34 +204,11 @@
 			$cost_hops += $cost;
 			$total_hops += $amount;
 
-			$fmoment  = 1.0;
 			$moment = hop_useat_names($useat);
-			if (($useat == "Dry Hop") || ($useat == "Dry hop")) {
-				$fmoment = 0.0;
-			} else if ($useat == "Whirlpool") {
-				$fmoment = 0.0;
-			} else if ($useat == "Mash") {
-				$fmoment = 0.7;		// Brouwhulp
-			} else if (($useat == "First Wort") || ($useat == "First wort")) {
-				$fmoment = 1.1;		// Brouwhulp, Louis, Ozzie
-			} else if ($useat == "Aroma") {
-				$fmoment = 0.0;		// Brouwhulp 1.0 redeneert vlamuit.
-			} else if ($useat == "Boil") {
-				$fmoment  = 1.0;
+			if ($useat == "Boil") {
 				$moment   = "Kook@".$time;
 			}
-
-			$pfactor  = 1.0;
-			if ($form == "Pellet") {
-				$pfactor = 1.1;
-			}
-
-			/* Tinseth only for now */
-			$AddedAlphaAcids = (($alpha / 100) * $mass * 1000) / floatval($row['batch_size']);
-			$Bigness_factor = 1.65 * pow( 0.000125, floatval($row['est_og']) - 1);
-			$BoilTime_factor = ((1 - exp(-0.04 * $time)) / 4.15);
-			$utiisation = $Bigness_factor * $BoilTime_factor;
-			$ibu = (round($utiisation * $AddedAlphaAcids * $fmoment * $pfactor * 10) / 10.0);
+			$ibu = calc_IBU($useat, $form, floatval($row['est_og']), floatval($row['batch_size']), $mass, $time, $alpha, $row['ibu_method']);
 
 			$this->Cell($vul,5,$name,0,0,'L',true);
 			$this->Cell(35,5,$origin,0,0,'L',true);

mercurial