# HG changeset patch # User Michiel Broek # Date 1561707363 -7200 # Node ID 6fa1d64f7f16135ea9bc4681918fd37cbbb5bb4e # Parent 0d2cf505957cc02603a52182731f6c6f00fde50c Compress code diff -r 0d2cf505957c -r 6fa1d64f7f16 www/js/global.js --- a/www/js/global.js Thu Jun 27 13:50:27 2019 +0200 +++ b/www/js/global.js Fri Jun 28 09:36:03 2019 +0200 @@ -774,32 +774,10 @@ -/* - * Alcohol By Volume - */ function abvol(og,fg){ - - if(((og-fg)<0)||(fg<0.9)) - return 0; - - /* - * Formule van Hans Halberstadt. De constante factor is afhankelijk van de - * zwaarte van het wort. - */ - var factor=og*3157*Math.pow(10,-5)+9.716*Math.pow(10,-2); - return (og*1000-fg*1000)*factor; - - /* - * Dit lijkt goed en wordt in veel moderne software gebruikt, maar... - * dit klopt niet. Busted door Hans Halberstadt. - * return (76.08 * (og-fg) / (1.775-og)) * (fg / 0.794); // Daniels - */ - - /* - * Brouwhulp, houdt geen rekening met zwaardere bieren. - * if ((4.749804 - fg) != 0) - * return 486.8693 * (og - fg) / (4.749804 - fg); - */ +if(((og-fg)<0)||(fg<0.9))return 0; +var factor=og*3157*Math.pow(10,-5)+9.716*Math.pow(10,-2); +return (og*1000-fg*1000)*factor; } @@ -974,42 +952,22 @@ -function sg_to_plato(sg) { - // http://www.brewersfriend.com/2012/10/31/on-the-relationship-between-plato-and-specific-gravity/ - 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 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 sg_to_brix(sg){return sg_to_plato(sg)*my_brix_correction;} -function brix_to_sg(brix) { - return plato_to_sg(brix / my_brix_correction); -} - - - -function sg_to_brix(sg) { - return sg_to_plato(sg) * my_brix_correction; -} - - - -function estimate_sg(sugars, batch_size) { +function estimate_sg(sugars,batch_size){ var plato = 100 * sugars / batch_size; - var sg = plato_to_sg(plato); for (var i = 0; i < 20; i++) { if (sg > 0) plato = 100 * sugars / (batch_size * sg); sg = plato_to_sg(plato); } -// console.log("estimate_sg(" + sugars + "," + batch_size + ") : " + sg); - return sg; + return Math.round(sg * 10000) / 10000; }