# HG changeset patch # User Michiel Broek # Date 1600543511 -7200 # Node ID 4d7394ced1c383c172b25b2b783e2c35e2bbc232 # Parent b6a616372a26d3286eb7c1534251cb1b3d774cd7 Better FG calculation from the refractometer reading. Now using the Petr Novotny formula. diff -r b6a616372a26 -r 4d7394ced1c3 www/js/global.js --- a/www/js/global.js Fri Sep 18 21:28:45 2020 +0200 +++ b/www/js/global.js Sat Sep 19 21:25:11 2020 +0200 @@ -1084,32 +1084,28 @@ -function brix_to_fg(OBrix, FBrix) { - // Brouwhulp, werkt zonder brix_correctie, waarom? - var FGbh = Round(1.0031 - 0.002318474 * OBrix - 0.000007775 * (OBrix * OBrix) - 0.000000034 * Math.pow(OBrix, 3) + +function brix_to_fg(OPt, FBrix) { + // OPt = Original Plato + // FBrix = Refractometer reading. + // Brouwhulp + var FGbh = Round(1.0031 - 0.002318474 * OPt - 0.000007775 * (OPt * OPt) - 0.000000034 * Math.pow(OPt, 3) + 0.00574 * (FBrix) + 0.00003344 * (FBrix * FBrix) + 0.000000086 * Math.pow(FBrix, 3), 4); - // from http://seanterrill.com FGoc = old cubic, FGnc = new cubic, FGnl = new linear - var OBc = OBrix / my_brix_correction; + // from http://seanterrill.com FGnc = new cubic var FBc = FBrix / my_brix_correction; - - // Old Cubic, almost the same a BrouwHulp, different offset and with brix_correction. - var FGoc = Round(1.001843 - 0.002318474 * OBc - 0.000007775 * (OBc * OBc) - 0.000000034 * Math.pow(OBc, 3) + - 0.00574 * (FBc) + 0.00003344 * (FBc * FBc) + 0.000000086 * Math.pow(FBc, 3), 4); + //console.log('Correction ' + my_brix_correction + ' OPt ' + OPt + ' FBrix ' + FBrix + ' FBc ' + FBc); - // New cubic. This looks the best to use. - var FGnc = Round(1 - 0.0044993 * (OBc) + 0.0117741 * (FBc) + - 0.000275806 * (OBc * OBc) - 0.00127169 * (FBc * FBc) - - 0.00000727999 * Math.pow(OBc, 3) + 0.0000632929 * Math.pow(FBc, 3), 4); - - // New linear, results are pretty much too high and way off for heavy beers. - var FGnl = Round(1 - 0.000856829 * OBc + 0.00349412 * FBc, 4); + // New cubic by Sean Terrill. + var FGnc = Round(1 - 0.0044993 * (OPt) + 0.0117741 * (FBc) + + 0.000275806 * (OPt * OPt) - 0.00127169 * (FBc * FBc) - + 0.00000727999 * Math.pow(OPt, 3) + 0.0000632929 * Math.pow(FBc, 3), 4); // Petr Novotny, Zymurgy July/August 2017. Used by Brewers Friend. - var FGbf = Round(1 + 0.006276 * FBc - 0.002349 * OBc, 4); + var FGbf = Round(1 + 0.006276 * FBc - 0.002349 * OPt, 4); - console.log('brix_to_fg(' + Round(OBrix, 2) + ', ' + FBrix + ') FGbh:' + FGbh + ' FGoc:' + FGoc + ' FGnc:' + FGnc + ' FGnl:' + FGnl + ' FGbf:' + FGbf); - return FGnc; + // The real battle is now between Brouwhulp and Petr Novotny. + console.log('brix_to_fg(' + Round(OPt, 2) + ', ' + FBrix + ') FGbh:' + FGbh + ' FGnc:' + FGnc + ' FGbf:' + FGbf); + return FGbf; } diff -r b6a616372a26 -r 4d7394ced1c3 www/js/prod_edit.js --- a/www/js/prod_edit.js Fri Sep 18 21:28:45 2020 +0200 +++ b/www/js/prod_edit.js Sat Sep 19 21:25:11 2020 +0200 @@ -4329,7 +4329,7 @@ $('#primary_end_brix').on('change', function(event) { var OBrix, FBrix, FG; if (dataRecord.brew_fermenter_sg >= 1.020) { - OBrix = sg_to_brix(dataRecord.brew_fermenter_sg); + OBrix = sg_to_plato(dataRecord.brew_fermenter_sg); FBrix = parseFloat(event.args.value); FG = brix_to_fg(OBrix, FBrix); if (FBrix > 0.05) { @@ -4346,7 +4346,7 @@ $('#secondary_end_brix').on('change', function(event) { var OBrix, FBrix, FG; if (dataRecord.brew_fermenter_sg >= 1.020) { - OBrix = sg_to_brix(dataRecord.brew_fermenter_sg); + OBrix = sg_to_plato(dataRecord.brew_fermenter_sg); FBrix = parseFloat(event.args.value); FG = brix_to_fg(OBrix, FBrix); if (FBrix > 0.05) { @@ -4359,7 +4359,7 @@ $('#final_brix').on('change', function(event) { var OBrix, FBrix, FG; if (dataRecord.brew_fermenter_sg >= 1.020) { - OBrix = sg_to_brix(dataRecord.brew_fermenter_sg); + OBrix = sg_to_plato(dataRecord.brew_fermenter_sg); FBrix = parseFloat(event.args.value); FG = brix_to_fg(OBrix, FBrix); if (FBrix > 0.05) {