Added IBU calculation in the fermenter on the brewday tab. More auto IBU updates.

Sat, 09 Feb 2019 16:49:04 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Sat, 09 Feb 2019 16:49:04 +0100
changeset 255
28953f9fc5b4
parent 254
3d61397fe9cd
child 256
4767a790d1f6

Added IBU calculation in the fermenter on the brewday tab. More auto IBU updates.

www/js/prod_edit.js file | annotate | diff | comparison | revisions
--- a/www/js/prod_edit.js	Sat Feb 09 15:43:13 2019 +0100
+++ b/www/js/prod_edit.js	Sat Feb 09 16:49:04 2019 +0100
@@ -50,8 +50,6 @@
 	var     preboil_sg = 0;
 	var	aboil_sg = 0;
 	var	est_mash_sg = 0;
-	var     sugarsm = 0;		// Sugars after mash
-	var     sugarsf = 0;		// Sugars after boil in kettle
 	var     psugar = 0;		// Percentage real sugars
 	var     pcara = 0;		// Percentage cara/crystal malts
 	var     svg = 77;               // Default attenuation
@@ -106,8 +104,8 @@
 	function calcFermentables() {
 
 		console.log("calcFermentables()");
-		sugarsf = 0;	// fermentable sugars mash + boil
-		sugarsm = 0;	// fermentable sugars in mash
+		var sugarsf = 0;	// fermentable sugars mash + boil
+		var sugarsm = 0;	// fermentable sugars in mash
 		psugar = 0;
 		pcara = 0;
 		mashkg = 0;
@@ -301,9 +299,7 @@
 			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) {
@@ -319,34 +315,38 @@
 			result = 1.2;
 		} else if (use == 4) {	// Whirlpool
 			result = 1.2;
-		} else if (use == 5) {	// Drt hop
+		} 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;
+		var ferm_ibus = 0;
 		hop_aroma = hop_flavour = 0;
 		var rows = $('#hopGrid').jqxGrid('getrows');
 		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),
 					parseFloat(row.h_amount), parseFloat(row.h_time), parseFloat(row.h_alpha), dataRecord.ibu_method);
+			ferm_ibus += toIBU(row.h_useat, row.h_form, preboil_sg,
+					parseFloat(dataRecord.brew_fermenter_volume) + parseFloat(dataRecord.brew_fermenter_tcloss),
+					parseFloat(row.h_amount), parseFloat(row.h_time), parseFloat(row.h_alpha), dataRecord.ibu_method);
 			hop_flavour += hopFlavourContribution(parseFloat(row.h_time), parseFloat(dataRecord.batch_size),
 					row.h_useat, parseFloat(row.h_amount));
 			hop_aroma += hopAromaContribution(parseFloat(row.h_time), parseFloat(dataRecord.batch_size),
 					row.h_useat, parseFloat(row.h_amount));
 		}
 		total_ibus = Math.round(total_ibus);
-		console.log("calcIBUs(): " + total_ibus + "  flavour: " + hop_flavour + "  aroma: " + hop_aroma);
+		ferm_ibus = Math.round(ferm_ibus);
+		console.log("calcIBUs(): " + total_ibus + "  flavour: " + hop_flavour + "  aroma: " + hop_aroma+"  fermenter:"+ferm_ibus);
 		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);
+		$("#brew_fermenter_ibu").val(ferm_ibus);
 		calcStage();
 	};
 
@@ -1506,10 +1506,12 @@
 		$("#brew_fermenter_extrawater").on('change', function (event) {
 			dataRecord.brew_fermenter_extrawater = parseFloat(event.args.value);
 			calcFermentables();
+			calcIBUs();
 		});
 		$("#brew_fermenter_tcloss").on('change', function (event) {
 			dataRecord.brew_fermenter_tcloss = parseFloat(event.args.value);
 			calcFermentables();
+			calcIBUs();
 		});
 
 		$("#BLog").jqxButton({ disabled: (dataRecord.log_brew) ? false:true });
@@ -3185,6 +3187,7 @@
 				$("#fermentableGrid").jqxGrid('setcellvalue', 0, "f_percentage", 100);
 			}
 			calcFermentables();
+			calcIBUs();
 		};
 	});
 	$("#wf_percentage").jqxNumberInput( Perc1dec );
@@ -3221,6 +3224,7 @@
 						}
 					}
 					calcFermentables();
+					calcIBUs();
 				} else {
 					// Adjust all the rows.
 					var nw = tw * diff / 100;
@@ -3239,6 +3243,7 @@
 						}
 					}
 					calcFermentables();
+					calcIBUs();
 				}
 			}
 		}
@@ -3280,6 +3285,7 @@
 			var index = event.args.index;
 			$("#fermentableGrid").jqxGrid('setcellvalue', fermentableRow, 'f_added', index);
 			calcFermentables();
+			calcIBUs();
 		}
 	});
 
@@ -3998,7 +4004,12 @@
 	$("#est_pre_sg").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 3 });
 	$("#brew_aboil_sg").jqxTooltip({ content: 'Het gemeten SG in de kookketel na het koken.' });
 	$("#brew_aboil_sg").jqxNumberInput( SGopts );
-	$("#brew_aboil_sg").on('valueChanged', function (event) { dataRecord.brew_aboil_sg = event.args.value; calcEfficiencyAfterBoil(); calcFermentables(); });
+	$("#brew_aboil_sg").on('valueChanged', function (event) {
+		dataRecord.brew_aboil_sg = event.args.value;
+		calcEfficiencyAfterBoil();
+		calcFermentables();
+		calcIBUs();
+	});
 	$("#est_og3").jqxTooltip({ content: 'Het gewenste SG in de kookketel na het koken.' });
 	$("#est_og3").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 70, height: 23, decimalDigits: 3, readOnly: true });
 	$("#brew_mash_efficiency").jqxTooltip({ content: 'Het behaalde maisch rendement.' });
@@ -4010,7 +4021,12 @@
 	$("#est_pre_vol").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 1 });
 	$("#brew_aboil_volume").jqxTooltip({ content: 'Het gemeten volume van het wort na het koken.' });
 	$("#brew_aboil_volume").jqxNumberInput( Spin1dec );
-	$("#brew_aboil_volume").on('valueChanged', function (event) { dataRecord.brew_aboil_volume = event.args.value; calcEfficiencyAfterBoil(); calcFermentables(); });
+	$("#brew_aboil_volume").on('valueChanged', function (event) {
+		dataRecord.brew_aboil_volume = event.args.value;
+		calcEfficiencyAfterBoil();
+		calcFermentables();
+		calcIBUs();
+	});
 	$("#est_a_vol").jqxTooltip({ content: 'Het gewenste volume na het koken.' });
 	$("#est_a_vol").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 1 });
 	$("#brew_preboil_efficiency").jqxTooltip({ content: 'Het berekende rendement voor het koken.' });

mercurial