# HG changeset patch # User Michiel Broek # Date 1542316971 -3600 # Node ID 107c12c3e49dddff99174961202120db12b03c3b # Parent 8dc0a00b1db4018660e7fb2c2cf37a6dbfc1fbfc Renamed estimate_og() to estimate_sg() formula. Updated the formulas in javascript. The calcFermenter() function now only calculates the gravities. The colors still need to be added. When a recept is loaded in the editor, all tabs are selected once to load all subgrid data. Ugly and slow but it at least it works. diff -r 8dc0a00b1db4 -r 107c12c3e49d www/import/from_brouwhulp.php --- a/www/import/from_brouwhulp.php Thu Nov 15 17:17:33 2018 +0100 +++ b/www/import/from_brouwhulp.php Thu Nov 15 22:22:51 2018 +0100 @@ -855,7 +855,7 @@ * Added the calculated values * OG, FG, color, IBU */ - $og = estimate_og($f_sugars, $batch_size); + $og = estimate_sg($f_sugars, $batch_size); $sql .= "', est_og='" . floatval($og); $fg = estimate_fg($pSugar, $pCara, 0, 0, 0, $svg, $og); $sql .= "', est_fg='" . floatval($fg); diff -r 8dc0a00b1db4 -r 107c12c3e49d www/includes/formulas.php --- a/www/includes/formulas.php Thu Nov 15 17:17:33 2018 +0100 +++ b/www/includes/formulas.php Thu Nov 15 22:22:51 2018 +0100 @@ -129,7 +129,7 @@ /* * sugars is the total extract weight of sugars. */ -function estimate_og($sugars, $batch_size) { +function estimate_sg($sugars, $batch_size) { $plato = 100 * $sugars / $batch_size; $sg = plato_to_sg($plato); diff -r 8dc0a00b1db4 -r 107c12c3e49d www/js/global.js --- a/www/js/global.js Thu Nov 15 17:17:33 2018 +0100 +++ b/www/js/global.js Thu Nov 15 22:22:51 2018 +0100 @@ -171,6 +171,36 @@ +function sg_to_plato(sg) { + if (sg > 0.5) + return 259 - 259 / sg; + return 0; +} + + + +function plato_to_sg(plato) { + if (plato < 259) + return 259 / (259 - plato); + return 1.000; +} + + + +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; +} + + /* * Steinie: * diff -r 8dc0a00b1db4 -r 107c12c3e49d www/js/rec_edit.js --- a/www/js/rec_edit.js Thu Nov 15 17:17:33 2018 +0100 +++ b/www/js/rec_edit.js Thu Nov 15 22:22:51 2018 +0100 @@ -44,6 +44,10 @@ $(document).ready(function () { + var preboil_sg = 0; + var psugar = 0; // Percentage real sugars + var pcara = 0; // Percentage cara/crystal malts + console.log("record:" + my_record + " return:" + my_return + " theme:" + theme); // $("#jqxNotification").jqxNotification({ width: "auto", position: "top-right", opacity: 0.9, @@ -51,33 +55,40 @@ // icon: { width: 25, height: 25, url: '../../images/smiley.png', padding: 5 } // }); - function calcFermentables (resize) { - console.log("calcFermentables(" + resize + ")"); - // recalc grid percentages. - var t_amount = 0; + function calcFermentables() { + console.log("calcFermentables()"); + +// var rows = $('#fermentableGrid').jqxGrid('getrows'); + var rows = $('#fermentableGrid').jqxGrid('getboundrows'); + var sugars = 0; // Sugar weight + psugar = 0; // Percentage real sugars + pcara = 0; // Percentage cara/crystal malts for (var i = 0; i < rows.length; i++) { var row = rows[i]; - t_amount += row.f_amount; - console.log ("loop: " + i + " kg:" + row.f_amount + " pct:" + row.f_percentage + " adjust:" + row.f_adjust_to_total_100); + if (row.f_type == "Sugar") + psugar += row.f_percentage; + if (row.f_type == "Crystal") + pcara += row.f_percentage; + var d = row.f_amount * (row.f_yield / 100) * (1 - row.f_moisture / 100); + if (row.f_added == "Mash") + d = parseFloat($("#efficiency").jqxNumberInput('decimal')) / 100 * d; + sugars += d; +// console.log("suikers: " + sugars + " suiker%:" + psugar + " cara%: " + pcara); + // colorw here too } - console.log("total:" + t_amount); - for (var i = 0; i < rows.length; i++) { - var row = rows[i]; - row.f_percentage = (row.f_amount / t_amount) * 100.0; - } - // if resize == true resize the malts bill. - // if recalc grid malts - $('#est_og').val(0); + $('#est_og').val(estimate_sg(sugars, parseFloat($("#batch_size").jqxNumberInput('decimal')))); + preboil_sg = estimate_sg(sugars, parseFloat($("#boil_size").jqxNumberInput('decimal'))); }; function calcInit () { console.log("calc.init()"); -// $('#est_og').on('change', function (event) { calcFermentables(true); }); - $('#efficiency').on('change', function (event) { calcFermentables(true); }); - $('#batch_size').on('change', function (event) { calcFermentables(true); }); - $('#boil_time').on('change', function (event) { calcFermentables(true); }); - $('#fermentableGrid').on('change', function (event) { calcFermentables(false); }); +// $('#est_og').on('change', function (event) { calcFermentables(); }); + $('#efficiency').on('change', function (event) { calcFermentables(); }); + $('#batch_size').on('change', function (event) { calcFermentables(); }); + $('#boil_time').on('change', function (event) { calcFermentables(); }); + $('#fermentableGrid').on('change', function (event) { calcFermentables(); }); + // calcFermentables(); }; // Styles dropdown list @@ -231,7 +242,7 @@ { name: 'mash_sparge_temp', type: 'float' }, { name: 'mash_ph', type: 'float' }, { name: 'mash_name', type: 'string' }, - { name: 'fermentables', type: 'string' }, + { name: 'fermentables', type: 'array' }, { name: 'hops', type: 'string' }, { name: 'miscs', type: 'string' }, { name: 'yeasts', type: 'string' }, @@ -288,6 +299,7 @@ editYeast(dataRecord); editWater(dataRecord); editMash(dataRecord); + $('#jqxTabs').jqxTabs('next'); }, loadError: function (jqXHR, status, error) { }, @@ -454,6 +466,10 @@ } }); }, + ready: function() { + calcFermentables(); + $('#jqxTabs').jqxTabs('next'); + }, columns: [ { text: 'Mout/suiker', editable: false, datafield: 'f_name', cellsrenderer: function (row, columnfield, value, defaulthtml, columnproperties) { @@ -494,7 +510,7 @@ ] }); $("#fermentableGrid").on('cellendedit', function (event) { - calcFermentables(false); + calcFermentables(); $('#fermentableGrid').jqxGrid('sortby', 'f_amount', 'desc'); }); }; @@ -624,6 +640,9 @@ } }); }, + ready: function() { + $('#jqxTabs').jqxTabs('next'); + }, columns: [ { text: 'Hop', editable: false, datafield: 'h_name' }, { text: 'Type', editable: false, width: 90, align: 'center', cellsalign: 'center', datafield: 'h_type' }, @@ -759,6 +778,9 @@ } }); }, + ready: function() { + $('#jqxTabs').jqxTabs('next'); + }, columns: [ { text: 'Ingredient', editable: false, datafield: 'm_name' }, { text: 'Type', editable: false, width: 120, align: 'center', cellsalign: 'center', datafield: 'm_type' }, @@ -897,6 +919,9 @@ } }); }, + ready: function() { + $('#jqxTabs').jqxTabs('next'); + }, columns: [ { text: 'Gist', editable: false, datafield: 'y_name' }, { text: 'Laboratorium', editable: false, width: 150, datafield: 'y_laboratory' }, @@ -1026,6 +1051,9 @@ } }); }, + ready: function() { + $('#jqxTabs').jqxTabs('next'); + }, columns: [ { text: 'Water bron', editable: false, datafield: 'w_name' }, { text: 'Volume', datafield: 'w_amount', width: 80, align: 'right', cellsalign: 'right', cellsformat: 'f1', @@ -1129,6 +1157,9 @@ } }); }, + ready: function() { + $('#jqxTabs').jqxTabs('first'); + }, columns: [ { text: 'Stap naam', datafield: 'step_name' }, { text: 'Stap type', datafield: 'step_type', width: 110, columntype: 'dropdownlist', diff -r 8dc0a00b1db4 -r 107c12c3e49d www/rec_print.php --- a/www/rec_print.php Thu Nov 15 17:17:33 2018 +0100 +++ b/www/rec_print.php Thu Nov 15 22:22:51 2018 +0100 @@ -156,8 +156,8 @@ $this->Ln(); } - $row['est_og'] = estimate_og($sugf, floatval($row['batch_size'])); - $preboil_sg = estimate_og($sugf, floatval($row['boil_size'])); + $row['est_og'] = estimate_sg($sugf, floatval($row['batch_size'])); + $preboil_sg = estimate_sg($sugf, floatval($row['boil_size'])); $this->SetFillColor(210,245,255); $this->Cell($vul+62,5,'',0,0,'L',false); $this->Cell(20,5,sprintf("%8.3f",$total_fermentables),0,0,'R',true);