# HG changeset patch # User Michiel Broek # Date 1544390858 -3600 # Node ID cd1403633e9601889399dc0c9716988475d8f1f0 # Parent be59b91279784aa998eee90904b1df641cefcf6f Added boil time change logic. Better precision. diff -r be59b9127978 -r cd1403633e96 www/js/rec_edit.js --- a/www/js/rec_edit.js Sun Dec 09 20:55:40 2018 +0100 +++ b/www/js/rec_edit.js Sun Dec 09 22:27:38 2018 +0100 @@ -46,7 +46,6 @@ var dataRecord = {}; var to_100 = false; // Fermentables adjust to 100% - var g_batch_size = 20; var preboil_sg = 0; var sugarsm = 0; // Sugars after mash var sugarsf = 0; // Sugars after boil @@ -71,7 +70,6 @@ var colorw = 0; // Colors working var my_100 = false; - g_batch_size = parseFloat($("#batch_size").jqxNumberInput('decimal')); var rows = $('#fermentableGrid').jqxGrid('getrows'); for (var i = 0; i < rows.length; i++) { var row = rows[i]; @@ -87,12 +85,12 @@ sugarsm += d; } sugarsf += d; - colorw += row.f_amount * ebc_to_srm(row.f_color) / g_batch_size * 8.34436; + colorw += row.f_amount * ebc_to_srm(row.f_color) / parseFloat($("#batch_size").jqxNumberInput('decimal')) * 8.34436; } if (to_100 != my_100) console.log("change to_100 to:"+my_100); to_100 = my_100; - $('#est_og').val(estimate_sg(sugarsf, g_batch_size)); + $('#est_og').val(estimate_sg(sugarsf, parseFloat($("#batch_size").jqxNumberInput('decimal')))); preboil_sg = estimate_sg(sugarsm, parseFloat($("#boil_size").jqxNumberInput('decimal'))); $('#est_color').val(kw_to_ebc($("#color_method").val(), colorw)); }; @@ -145,15 +143,18 @@ function calcInit () { console.log("calc.init()"); + $('#color_method').on('change', function (event) { calcFermentables(); }); $('#ibu_method').on('change', function (event) { calcFermentables(); calcIBUs(); }); $('#batch_size').on('change', function (event) { - console.log("batch_size change:"+event.args.value+" old:"+g_batch_size); - var new_boil = Math.round((parseFloat(event.args.value) + parseFloat($("#boil_size").jqxNumberInput('decimal')) - g_batch_size) * 10) / 10; - $("#boil_size").val(new_boil); + console.log("batch_size change:"+event.args.value+" old:"+dataRecord.batch_size); + var new_boil = parseFloat(event.args.value) + dataRecord.boil_size - dataRecord.batch_size; + dataRecord.boil_size = new_boil; + $("#boil_size").val(Math.round(new_boil * 100) / 100); + dataRecord.batch_size = parseFloat(event.args.value); calcFermentablesFromOG(parseFloat($("#est_og").jqxNumberInput('decimal'))); // Keep the OG calcFermentables(); calcABV(); @@ -161,7 +162,18 @@ calcIBUs(); }); $('#boil_time').on('change', function (event) { - console.log("boil_time change:"+event.args.value); + console.log("boil_time change:"+parseFloat(event.args.value)+" old:"+dataRecord.boil_time); + var old_evap = parseFloat(dataRecord.boil_size) - parseFloat(dataRecord.batch_size); + var new_evap = old_evap * (parseFloat(event.args.value) / dataRecord.boil_time); + var new_boil = parseFloat(dataRecord.batch_size) + new_evap; + // console.log("old_evap:"+old_evap+" new_evap:"+new_evap+" new_boil:"+new_boil); + dataRecord.boil_time = parseFloat(event.args.value); + dataRecord.boil_size = new_boil; + $("#boil_size").val(Math.round(new_boil * 100) / 100); + calcFermentables(); + calcABV(); + // TODO: adjust the hops, miscs, yeast, water. + calcIBUs(); }); $('#efficiency').on('change', function (event) { console.log("efficiency change:"+event.args.value); @@ -1457,7 +1469,7 @@ $("#st_type").jqxInput({ theme: theme, width: 90, height: 23 }); $("#type").jqxDropDownList({ theme: theme, source: srcType, width: 125, height: 23, dropDownHeight: 95 }); $("#batch_size").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 4, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1, symbol: 'L', symbolPosition: 'right' }); - $("#boil_size").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 100, height: 23, decimalDigits: 1, readOnly: true, symbol: 'L', symbolPosition: 'right' }); + $("#boil_size").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 100, height: 23, decimalDigits: 2, readOnly: true, symbol: 'L', symbolPosition: 'right' }); $("#boil_time").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 4, max: 360, decimalDigits: 0, spinButtons: true }); $("#efficiency").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 40, max: 100, decimalDigits: 0, spinButtons: true, symbol: '%', symbolPosition: 'right' }); $("#est_og").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 1.000, max: 1.200, decimalDigits: 3, spinButtons: true, spinButtonsStep: 0.001 });