# HG changeset patch # User Michiel Broek # Date 1563116934 -7200 # Node ID b72478cd2c18deb72c1ae239046965f30cb457e4 # Parent 61436d428454e52b02c8d1d882ece330582a6fa6 Fixed possible division/zero. Code compress and some cleanup. diff -r 61436d428454 -r b72478cd2c18 www/js/global.js --- a/www/js/global.js Sun Jul 14 15:25:23 2019 +0200 +++ b/www/js/global.js Sun Jul 14 17:08:54 2019 +0200 @@ -980,7 +980,7 @@ function sg_to_plato(sg){return ((135.997*sg-630.272)*sg+1111.14)*sg-616.868;} function plato_to_sg(plato){return 1+(plato/(258.6-((plato/258.2)*227.1)));} -function brix_to_sg(brix){return plato_to_sg(brix/my_brix_correction);} +function brix_to_sg(brix){if(my_brix_correction>0)return plato_to_sg(brix/my_brix_correction);else return plato_to_sg(brix);} function sg_to_brix(sg){return sg_to_plato(sg)*my_brix_correction;} diff -r 61436d428454 -r b72478cd2c18 www/js/prod_edit.js --- a/www/js/prod_edit.js Sun Jul 14 15:25:23 2019 +0200 +++ b/www/js/prod_edit.js Sun Jul 14 17:08:54 2019 +0200 @@ -289,7 +289,7 @@ if ((dataRecord.brew_fermenter_volume * ogx + addedmass) > 0) { var pt = 100 * sug / (dataRecord.brew_fermenter_volume * ogx + addedmass + top); - dataRecord.brew_fermenter_sg = Math.round(plato_to_sg(pt) * 10000) / 10000; + dataRecord.brew_fermenter_sg = Round(plato_to_sg(pt),4); $("#brew_fermenter_sg").val(dataRecord.brew_fermenter_sg); // color if (dataRecord.color_method == 4) { @@ -1761,23 +1761,17 @@ $("#sparge_acid_amount").val(Acid); } - function calcFermentation() { - if (dataRecord.brew_fermenter_sg < 1.020) - return; - var obrix = sg_to_brix(dataRecord.brew_fermenter_sg); - console.log("calcFermentation() og:"+dataRecord.brew_fermenter_sg+" brix:"+obrix); - if ((dataRecord.primary_end_sg > 0.990) && (dataRecord.primary_end_sg < dataRecord.brew_fermenter_sg)) { - var primary_svg = 100 * (dataRecord.brew_fermenter_sg - dataRecord.primary_end_sg) / (dataRecord.brew_fermenter_sg - 1); - //console.log("primary svg: "+primary_svg); - $("#primary_svg").val(primary_svg); - if ((dataRecord.fg > 0.990) && (dataRecord.fg < dataRecord.brew_fermenter_sg)) { - var final_svg = 100 * (dataRecord.brew_fermenter_sg - dataRecord.fg) / (dataRecord.brew_fermenter_sg - 1); - $("#final_svg").val(final_svg); - var ABV = abvol(dataRecord.brew_fermenter_sg, dataRecord.fg); - $("#final_abv").val(ABV); - } - } - } +function calcFermentation(){ +if(dataRecord.brew_fermenter_sg<1.020)return; +var obrix=sg_to_brix(dataRecord.brew_fermenter_sg); +if ((dataRecord.primary_end_sg>0.990)&&(dataRecord.primary_end_sg0.990)&&(dataRecord.fg= 1.020) { - OBrix = sg_to_brix(dataRecord.brew_fermenter_sg); - FBrix = parseFloat(event.args.value); - // http://seanterrill.com/2011/04/07/refractometer-fg-results/ - // var FG = 1.0000 - 0.0044993 * OBrix + 0.0117741 * FBrix + - // 0.000275806 * (OBrix * OBrix) - 0.00127169 * (FBrix * FBrix) - - // 0.00000727999 * Math.pow(OBrix, 3) + 0.0000632929 * Math.pow(FBrix, 3); - // var FG = 1.0000 - 0.00085683 * OBrix + 0.0034941 * FBrix; - // Brouwhulp - var FG = 1.0031 - 0.002318474 * OBrix - 0.000007775 * (OBrix * OBrix) - - 0.000000034 * Math.pow(OBrix, 3) + 0.00574 * (FBrix) + - 0.00003344 * (FBrix * FBrix) + 0.000000086 * Math.pow(FBrix, 3); - // var FG = ((1.001843 - 0.002318474 * OBrix - 0.000007775 * (OBrix * OBrix) - // - 0.000000034 * Math.pow(OBrix, 3) + 0.00574 * (FBrix) - // + 0.00003344 * (FBrix * FBrix) + 0.000000086 * Math.pow(FBrix, 3)) - // + (1.313454) * 0.001); - console.log("OBrix:"+OBrix+" FBrix:"+FBrix+" FG:"+FG); - if (FBrix > 0.05) { - $("#primary_end_sg").val(FG); - dataRecord.primary_end_sg = FG; - } + if(dataRecord.brew_fermenter_sg>=1.020){ + OBrix=sg_to_brix(dataRecord.brew_fermenter_sg); + FBrix=parseFloat(event.args.value); +var FG=Round(1.0031-0.002318474*OBrix-0.000007775*(OBrix*OBrix)-0.000000034*Math.pow(OBrix,3)+0.00574*(FBrix)+0.00003344*(FBrix*FBrix)+0.000000086*Math.pow(FBrix,3),4); + //console.log("OBrix:"+OBrix+" FBrix:"+FBrix+" FG:"+FG); + if(FBrix>0.05){$("#primary_end_sg").val(FG);dataRecord.primary_end_sg=FG;} calcFermentation(); } }); - $("#final_brix").on('change', function (event) { - // Brix reading from refractometer RI - if (dataRecord.brew_fermenter_sg >= 1.020) { - OBrix = sg_to_brix(dataRecord.brew_fermenter_sg); - FBrix = parseFloat(event.args.value); - // http://seanterrill.com/2011/04/07/refractometer-fg-results/ - // var FG = 1.0000 - 0.0044993 * OBrix + 0.0117741 * FBrix + - // 0.000275806 * (OBrix * OBrix) - 0.00127169 * (FBrix * FBrix) - - // 0.00000727999 * Math.pow(OBrix, 3) + 0.0000632929 * Math.pow(FBrix, 3); - // Brouwhulp BrixToFG() - var FG = 1.0031 - 0.002318474 * OBrix - 0.000007775 * (OBrix * OBrix) - - 0.000000034 * Math.pow(OBrix, 3) + 0.00574 * (FBrix) + - 0.00003344 * (FBrix * FBrix) + 0.000000086 * Math.pow(FBrix, 3); - // Ook brouwhulp SGFerm() maar is niet in gebruik. - // var FG = ((1.001843 - 0.002318474 * OBrix - 0.000007775 * (OBrix * OBrix) - // - 0.000000034 * Math.pow(OBrix, 3) + 0.00574 * (FBrix) - // + 0.00003344 * (FBrix * FBrix) + 0.000000086 * Math.pow(FBrix, 3)) - // + (1.313454) * 0.001); - console.log("OBrix:"+OBrix+" FBrix:"+FBrix+" FG:"+FG); - if (FBrix > 0.05) { - $("#fg").val(FG); - dataRecord.fg = FG; - } + $("#final_brix").on('change',function (event){ + if(dataRecord.brew_fermenter_sg>=1.020){ + OBrix=sg_to_brix(dataRecord.brew_fermenter_sg); + FBrix=parseFloat(event.args.value); +var FG=Round(1.0031-0.002318474*OBrix-0.000007775*(OBrix*OBrix)-0.000000034*Math.pow(OBrix,3)+0.00574*(FBrix)+0.00003344*(FBrix*FBrix)+0.000000086*Math.pow(FBrix,3),4); +// Ook brouwhulp SGFerm() maar is niet in gebruik. +//var FG=((1.001843-0.002318474*OBrix-0.000007775*(OBrix*OBrix)-0.000000034*Math.pow(OBrix,3)+0.00574*(FBrix)+0.00003344*(FBrix*FBrix)+0.000000086*Math.pow(FBrix,3))+(1.313454)*0.001); + //console.log("OBrix:"+OBrix+" FBrix:"+FBrix+" FG:"+FG); + if(FBrix>0.05){$("#fg").val(FG);dataRecord.fg=FG;} calcFermentation(); } }); - $("#BLog").jqxButton({ disabled: (dataRecord.log_brew) ? false:true }); - $("#FLog").jqxButton({ disabled: (dataRecord.log_fermentation) ? false:true }); + $("#fg").on('change',function (event){dataRecord.fg=parseFloat(event.args.value);calcFermentation();}); + $("#BLog").jqxButton({disabled:(dataRecord.log_brew)?false:true}); + $("#FLog").jqxButton({disabled:(dataRecord.log_fermentation)?false:true}); }; $("#styleSelect").jqxDropDownList({