www/includes/formulas.php

changeset 87
7f1d0abe5571
parent 85
ca7a37586551
child 88
0a39cbdcf085
--- a/www/includes/formulas.php	Sun Nov 11 17:53:33 2018 +0100
+++ b/www/includes/formulas.php	Sun Nov 11 23:15:46 2018 +0100
@@ -127,6 +127,49 @@
 
 
 /*
+ * sugars is the total extract weight of sugars.
+ */
+function estimate_og($sugars, $batch_size) {
+	$plato = 100 * $sugars / $batch_size;
+	$sg = plato_to_sg($plato);
+
+	/* Average loops, HansH 5x. Brouwhulp 20x, about 10x is enough so keep 20. */
+	for ($i = 0; $i < 20; $i++) {
+		if ($sg > 0)
+			$plato = 100 * $sugars / ($batch_size * $sg);
+		$sg = plato_to_sg($plato);
+	}
+	return $sg;
+}
+
+
+
+function estimate_fg($percSugar, $percCara, $WGratio, $TotTme, $Temp, $attenuation, $og) {
+	if ($percSugar > 40)
+		$percSugar = 0;
+	if ($percCara > 50)
+		$percCara = 0;
+	if (($WGratio > 0) && ($TotTme > 0)) {
+		$BD = $WGratio;
+		$BD = max(2, min(5.5, $BD));
+		$Temp = max(60, min(72, $Temp));
+	} else {
+		$BD = 3.5;
+		$Temp = 67;
+		$TotTme = 75;
+	}
+	if ($attenuation < 30)
+		$attenuation = 77;
+
+	$AttBeer = 0.00825 * $attenuation + 0.00817 * $BD - 0.00684 * $Temp + 0.00026 * $TotTme - 0.00356 * $percCara + 0.00553 * $percSugar + 0.547;
+	$fg = 1 + (1 - $AttBeer) * ($og - 1);
+//	echo $percSugar.' '.$percCara.' '.$attenuation.' attn '.$AttBeer.'  FG '.$fg.PHP_EOL;
+	return $fg;
+}
+
+
+
+/*
 
 Brouwhulp data.pas
 
@@ -589,152 +632,7 @@
 
 
 
-procedure TRecipe.CalcOG;
-var
-  i, j, k: integer;
-  v, v2, sg, d, tot, tot2, vol, vol1, vol2, sugF, sug, sug2, p, x: double;
-  mass1, mass2 : double;
-  F: TFermentable;
-begin
-  for j := 1 to 1 do
-  begin
-    sug:= 0;
-    sugf:= 0;
-    sug2:= 0;
-    tot := 0;
-    tot2:= 0;
-    vol:= 0;
-    FEfficiency.Value := GetEfficiency;
-    for i := 0 to NumFermentables - 1 do
-    begin
-      F := TFermentable(Fermentable[i]);
-      if (F.AddedType = atMash) or (F.AddedType = atBoil) then
-      begin
-        d := F.Amount.Value * (F.Yield.Value / 100) * (1 - F.Moisture.Value / 100);
-        if (F.AddedType = atMash) then
-          d := FEfficiency.Value / 100 * d;
-        sugf := sugf + d;
-        tot := tot + F.Amount.Value;
-      end
-      else
-      begin
-        x:= (F.Yield.Value / 100) * (1 - F.Moisture.Value / 100);
-        sug2:= sug2 + F.Amount.Value * x;
-        tot2:= tot2 + F.Amount.Value;
-        tot := tot + F.Amount.Value;
-        vol:= vol + F.Amount.Value / (x * SugarDensity + (1 - x) * 1);
-      end;
-    end;
-    if tot > 0 then
-      for i := 0 to NumFermentables - 1 do
-      begin
-        F := Fermentable[i];
-        F.Percentage.Value := 100 * F.Amount.Value / tot;
-      end;
 
-    if (FEquipment <> NIL) and (FBatchSize.Value > 0) then
-    begin
-      vol1:= FBatchSize.Value - FEquipment.TrubChillerLoss.Value;
-      vol2:= vol1 + FEquipment.TopUpWater.Value + vol;
-      sug:= sugf * vol1 / FBatchSize.Value;       //kg
-      sug:= sug + sug2;                     //kg
-      if vol2 > 0 then
-        sug:= sug / vol2; //kg/l
-      p:= 100 * sug;
-      sg:= PlatoToSG(p);
-      for k:= 1 to 30 do
-      begin
-        if sg > 0 then
-          p := 100 * sug / sg; //deg. Plato
-        sg := PlatoToSG(p);
-      end;
-      FEstOG.Value:= sg;
-    end
-    else if FBatchSize.Value <> 0 then
-    begin
-      p := 100 * sugf / FBatchSize.Value; //deg. Plato
-      sg := PlatoToSG(p);
-      for k:= 1 to 20 do
-      begin
-        if sg > 0 then
-          p := 100 * sugf / (FBatchSize.Value * sg); //deg. Plato
-        sg := PlatoToSG(p);
-      end;
-      FEstOG.Value := sg;
-    end
-    else
-      FEstOG.Value := 1.0;
-  end;
-
-  CalcWaterBalance;
-end;
-
-
-
-procedure TRecipe.EstimateFG;
-var
-  i: integer;
-  percS, percCara, BD, Att, AttBeer, sg: double;
-  Temp, TotTme: double;
-  Y: TYeast;
-//  Eq: TEquipment;
-begin
-  percS := GetPercSugar;
-  //if PercS > 40 then PercS:= 0;
-  percCara := GetPercCrystalMalt;
-  if percCara > 50 then PercCara:= 0;
-  if (Mash <> nil) and (Mash.MashStep[0] <> nil) then
-  begin
-    BD := Mash.MashStep[0].WaterToGrainRatio;
-    BD:= Max(2, Min(5.5, BD));
-    Temp := Mash.AverageTemperature;
-    Temp:= Max(60, Min(72, Temp));
-    TotTme := Mash.TotalMashTime;
-    TotTme:= Max(20, Min(90, TotTme));
-  end
-  else
-  begin
-    BD := 3.5;
-    Temp := 67;
-    TotTme := 75;
-  end;
-  Y := Yeast[0];
-  if Y <> nil then
-  begin
-    Att := Y.Attenuation.Value;
-    if Att < 30 then Att:= 77;
-  end
-  else
-    Att := 77;
-  AttBeer := 0.00825 * Att + 0.00817 * BD - 0.00684 * Temp + 0.00026 *
-             TotTme - 0.00356 * PercCara + 0.00553 * PercS + 0.547;
-
-{  Eq := nil;
-  if FEquipment <> nil then
-    Eq := TEquipment(Equipments.FindByName(FEquipment.Name.Value));
-  if Eq <> nil then
-    AttBeer2 := Eq.EstimateFG(Att, BD, Temp, TotTme, PercCara, PercS);}
-
-  FEstFG.Value := 1 + (1 - AttBeer) * (FEstOG.Value - 1);
-  CalcOGFermenter;
-  if FOGFermenter.Value > 1.001 then
-  begin
-    sg:= FOGFermenter.Value;
-    FEstFG2.Value := 1 + (1 - AttBeer) * (sg - 1);
-    FEstABV.Value := ABVol(FEstOG.Value, FEstFG.Value);
-  end
-  else if FOG.Value > 1.001 then
-  begin
-    sg:= FOG.Value;
-    FEstFG2.Value := 1 + (1 - AttBeer) * (sg - 1);
-    FEstABV.Value := ABVol(FEstOG.Value, FEstFG.Value);
-  end
-  else
-  begin
-    FEstFG2.Value := 1 + (1 - AttBeer) * (FEstOG.Value - 1);
-    FEstABV.Value := ABVol(FEstOG.Value, FEstFG.Value);
-  end;
-end;
 
 Procedure TRecipe.CalcCalories;
 var sug, alc, org, fig : double;

mercurial