# HG changeset patch # User Michiel Broek # Date 1556291331 -7200 # Node ID 82184e3be6d93904950bb1d3af2933699ed193c0 # Parent 3ac81572bb28052ffdfaacf8803ee5e003da262b Backport hop calculations from product editor. diff -r 3ac81572bb28 -r 82184e3be6d9 www/js/rec_edit.js --- a/www/js/rec_edit.js Thu Apr 25 21:52:35 2019 +0200 +++ b/www/js/rec_edit.js Fri Apr 26 17:08:51 2019 +0200 @@ -291,15 +291,15 @@ if (result < 0.10) result = 0.10; // assume 10% flavourcontribution as a minimum } - result = (result * amount * 1000) / vol; - // console.log("hopFlavourContribution("+bt+","+vol+","+use+","+amount+"): "+result); - return result; + return (result * amount * 1000) / vol; } function hopAromaContribution(bt, vol, use, amount) { var result = 0; - if (bt > 20) { + if (use == 5) { // Dry hop + result = 1.33; + } else if (bt > 20) { result = 0; } else if (bt > 7.5) { result = 10.03 / (4 * Math.sqrt(2 * Math.PI)) * Math.exp(-0.5 * Math.pow((bt - 7.5) /4, 2)); @@ -309,18 +309,17 @@ result = 1.2; } else if (use == 4) { // Whirlpool result = 1.2; - } else if (use == 5) { // Dry hop - result = 1.33; } - result = (result * amount * 1000) / vol; - // console.log("hopAromaContribution("+bt+","+vol+","+use+","+amount+"): "+result); - return result; + return (result * amount * 1000) / vol; } function calcIBUs() { var total_ibus = 0; hop_aroma = hop_flavour = 0; - var rows = $('#hopGrid').jqxGrid('getrows'); + var rows = {}; + if (!(rows = $('#hopGrid').jqxGrid('getrows'))) { + return; + } for (var i = 0; i < rows.length; i++) { var row = rows[i]; total_ibus += toIBU(row.h_useat, row.h_form, preboil_sg, parseFloat(dataRecord.batch_size), @@ -330,13 +329,19 @@ hop_aroma += hopAromaContribution(parseFloat(row.h_time), parseFloat(dataRecord.batch_size), row.h_useat, parseFloat(row.h_amount)); } - total_ibus = Math.round(total_ibus); + total_ibus = Math.round(total_ibus * 10) / 10; + hop_flavour = Math.round(hop_flavour * 100) / 10; + hop_aroma = Math.round(hop_aroma * 100) / 10; + if (hop_flavour > 100) + hop_flavour = 100; + if (hop_aroma > 100) + hop_aroma = 100; console.log("calcIBUs(): " + total_ibus + " flavour: " + hop_flavour + " aroma: " + hop_aroma); dataRecord.est_ibu = total_ibus; $('#est_ibu').val(total_ibus); $('#est_ibu2').val(total_ibus); - $("#hop_flavour").jqxProgressBar('val', hop_flavour * 10); - $("#hop_aroma").jqxProgressBar('val', hop_aroma * 10); + $("#hop_flavour").jqxProgressBar('val', hop_flavour); + $("#hop_aroma").jqxProgressBar('val', hop_aroma); }; function adjustHops(factor) {