diff -r e977a505ea8c -r 7f1d0abe5571 www/import/from_brouwhulp.php --- a/www/import/from_brouwhulp.php Sun Nov 11 17:53:33 2018 +0100 +++ b/www/import/from_brouwhulp.php Sun Nov 11 23:15:46 2018 +0100 @@ -452,6 +452,9 @@ $f_sugars = 0; $efficiency = 75; $batch_size = 20; + $pCara = 0; + $pSugar = 0; + $svg = 77; $sql = "INSERT INTO recipes SET name='" . mysqli_real_escape_string($db, $recipe->NAME); if ($recipe->NOTES) @@ -473,10 +476,7 @@ $efficiency = floatval($recipe->EFFICIENCY); $sql .= "', efficiency='" . $efficiency; /* Don't use $recipe->EST_OG but recalculate it */ - if ($recipe->EST_FG) - $sql .= "', est_fg='" . floatval($recipe->EST_FG); - else - $sql .= "', est_fg='1.000"; + /* Don't use $recipe->EST_FG but recalculate it */ if ($recipe->EST_COLOR) { $srm = floatval($recipe->EST_COLOR); $ebc = srm_to_ebc($srm); @@ -555,7 +555,8 @@ $famount = floatval($fermentable->AMOUNT); $fermentables .= ',"f_amount":' . $famount; $fermentables .= ',"f_cost":' . floatval($fermentable->COST); - $fermentables .= ',"f_type":"' . mysqli_real_escape_string($db, $fermentable->TYPE) . '"'; + $ftype = mysqli_real_escape_string($db, $fermentable->TYPE); + $fermentables .= ',"f_type":"' . $ftype . '"'; $fyield = floatval($fermentable->YIELD); $fermentables .= ',"f_yield":' . $fyield; if ($fermentable->COLOR) { @@ -584,10 +585,12 @@ $fermentables .= ',"f_max_in_batch":' . floatval($fermentable->MAX_IN_BATCH); else $fermentables .= ',"f_max_in_batch":100.0'; + $fgraintype = mysqli_real_escape_string($db, $fermentable->GRAINTYPE); if ($fermentable->GRAINTYPE) - $fermentables .= ',"f_graintype":"' . mysqli_real_escape_string($db, $fermentable->GRAINTYPE) . '"'; + $fgraintype = mysqli_real_escape_string($db, $fermentable->GRAINTYPE); else - $fermentables .= ',"f_graintype":"Base"'; + $fgraintype = "Base"; + $fermentables .= ',"f_graintype":"' . $fgraintype . '"'; if ($fermentable->ADDED) $fadded = mysqli_real_escape_string($db, $fermentable->ADDED); else @@ -600,7 +603,8 @@ else $fermentables .= ',"f_dissolved_protein":0'; ($fermentable->ADJUST_TO_TOTAL_100 == "TRUE") ? $fermentables .= ',"f_adjust_to_total_100":true' : $fermentables .= ',"f_adjust_to_total_100":false'; - $fermentables .= ',"f_percentage":' . floatval($fermentable->PERCENTAGE); + $percent = floatval($fermentable->PERCENTAGE); + $fermentables .= ',"f_percentage":' . $percent; if ($fermentable->DI_pH) $fermentables .= ',"f_di_ph":' . floatval($fermentable->DI_pH); else @@ -611,6 +615,10 @@ if ($fadded == "Mash") $d = floatval($efficiency) / 100 * $d; $f_sugars += $d; + if ($fgraintype == "Crystal") + $pCara += $percent; + if ($ftype == "Sugar") + $pSugar += $percent; } $fermentables .= ']'; @@ -722,6 +730,7 @@ ($yeast->AMOUNT_IS_WEIGHT== "TRUE") ? $yeasts .= ',"y_amount_is_weight":true' : $yeasts.= ',"y_amount_is_weight":false'; if ($yeast->ADD_TO_SECONDARY=="FALSE") { $yeasts .= ',"y_use":"Primary"'; + $svg = floatval($yeast->ATTENUATION); } else if ($yeast->PRODUCT_ID=="F2") { $yeasts .= ',"y_use":"Bottle"'; } else { @@ -824,15 +833,10 @@ * Added the calculated values * OG, FG, color, IBU */ - $plato = 100 * $f_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 * $f_sugars / ($batch_size * $sg); - $sg = plato_to_sg($plato); - } - $sql .= "', est_og='" . floatval($sg); + $og = estimate_og($f_sugars, $batch_size); + $sql .= "', est_og='" . floatval($og); + $fg = estimate_fg($pSugar, $pCara, 0, 0, 0, $svg, $og); + $sql .= "', est_fg='" . floatval($fg); $sql .= "';"; if (! $result = mysqli_query($db, $sql)) {