Added ABV calculation. Added calculate fermentables from OG calculation. Scale fermentables when the OG changes.

Sun, 09 Dec 2018 17:29:51 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 09 Dec 2018 17:29:51 +0100
changeset 133
22d28dd9c041
parent 132
aaefac2d08a3
child 134
be59b9127978

Added ABV calculation. Added calculate fermentables from OG calculation. Scale fermentables when the OG changes.

www/js/global.js file | annotate | diff | comparison | revisions
www/js/prod_edit.js file | annotate | diff | comparison | revisions
www/js/rec_edit.js file | annotate | diff | comparison | revisions
--- a/www/js/global.js	Sat Dec 08 17:30:09 2018 +0100
+++ b/www/js/global.js	Sun Dec 09 17:29:51 2018 +0100
@@ -106,6 +106,18 @@
 
 
 /*
+ * Alcohol By Volume
+ */
+function abvol(og, fg) {
+
+	if ((4.749804 - fg) != 0)
+		return 486.8693 * (og - fg) / (4.749804 - fg);
+	return 0;
+}
+
+
+
+/*
  * Kleurwerking naar SRM
  */
 function kw_to_srm(colormethod, c) {
@@ -187,7 +199,7 @@
 		ibu = Math.round((mass * (alpha * 100) * boilfactor * 0.1) / (liters * (1 + sgfactor)) * 10) / 10;
 	}
 
-	console.log("toIBU("+Use+","+Form+","+SG+","+Volume+","+Amount+","+Boiltime+","+Alpha+","+Method+"):"+ibu+" fm:"+fmoment+" pf:"+pfactor);
+//	console.log("toIBU("+Use+","+Form+","+SG+","+Volume+","+Amount+","+Boiltime+","+Alpha+","+Method+"):"+ibu+" fm:"+fmoment+" pf:"+pfactor);
 	return ibu;
 }
 
--- a/www/js/prod_edit.js	Sat Dec 08 17:30:09 2018 +0100
+++ b/www/js/prod_edit.js	Sun Dec 09 17:29:51 2018 +0100
@@ -90,6 +90,66 @@
 		$('#est_color').val(kw_to_ebc(dataRecord.color_method, colorw));
 	};
 
+	function calcFermentablesFromOG(OG) {
+
+		console.log("calcFermentablesFromOG("+OG+")");
+		var     i, j, sug, d, tot, totmass;
+		var     vol, vol1, vol2, sug2;
+		var     mass1, mass2, efficiency;
+
+		for (j = 1; j < 15; j++) {      // Maybe needed if there is equipment, not here.
+			vol = 0;
+			sug2 = 0;
+			efficiency = parseFloat($("#efficiency").jqxNumberInput('decimal'));
+			var rows = $('#fermentableGrid').jqxGrid('getrows');
+			for (i = 0; i < rows.length; i++) {
+				row = rows[i];
+				if ((row.f_added == "Fermentation") || (row.f_added == "Lagering") || (row.f_added == "Bottle")) {
+					var x = (row.f_yield / 100) * (1 - row.f_moisture / 100);
+					vol += row.f_amount / (x * sugardensity + (1 - x) * 1);
+					sug2 += row.f_amount * x;
+				}
+			}
+	//              if FEquipment <> NIL then               /* Use this for prod_edit.js
+	//              begin
+	//              	sug:= SGToPlato(OG) * OG / 100; //kg/l
+	//              	vol1:= FBatchSize.Value - FEquipment.TrubChillerLoss.Value;
+	//              	vol2:= vol1 + FEquipment.TopUpWater.Value + vol;
+	//              	sug:= sug * vol2; //kg in het gistvat
+	//              	sug:= sug - sug2; //kg voor toevoeging in gistvat
+	//              	if vol1 > 0 then
+	//              		sug:= sug * FBatchSize.Value / vol1; //kg in kookketel
+	//              	sug:= sug + sug2;
+	//              end
+	//              else
+				sug = sg_to_plato(OG) * parseFloat($("#batch_size").jqxNumberInput('decimal')) * OG / 100;      //total amount of sugars in kg
+
+			tot = 0;
+			d = 0;
+			for (i = 0; i < rows.length; i++) {
+				row = rows[i];
+				d = row.f_percentage / 100 * (row.f_yield / 100) * (1 - row.f_moisture / 100);
+				if (row.f_added == "Mash")
+					d = efficiency / 100 * d;
+				tot += d;
+			}
+			if (tot)
+				totmass = sug / tot;
+			else
+				totmass = 0;
+
+			if (totmass) {
+				console.log("pass:"+j+" totmass:"+totmass);
+				for (i = 0; i < rows.length; i++) {
+					row = rows[i];
+					row.f_amount = row.f_percentage / 100 * totmass;
+					$("#fermentableGrid").jqxGrid('setcellvalue', i, "f_amount", row.f_percentage / 100 * totmass);
+				}
+			}
+		};
+		//CalcWaterBalance;
+	};
+
 	function calcIBUs() {
 		var total_ibus = 0;
 		for (var i = 0; i < dataRecord.hops.length; i++) {
--- a/www/js/rec_edit.js	Sat Dec 08 17:30:09 2018 +0100
+++ b/www/js/rec_edit.js	Sun Dec 09 17:29:51 2018 +0100
@@ -107,9 +107,42 @@
 		$('#est_ibu').val(total_ibus);
 	};
 
+	function calcFermentablesFromOG(OG) {
+
+		console.log("calcFermentablesFromOG("+OG+")");
+		var	i;
+		var	efficiency = parseFloat($("#efficiency").jqxNumberInput('decimal'));
+		var	rows = $('#fermentableGrid').jqxGrid('getrows');
+		var	sug = sg_to_plato(OG) * parseFloat($("#batch_size").jqxNumberInput('decimal')) * OG / 100;	//total amount of sugars in kg
+		var	tot = 0;
+		var	d;
+		for (i = 0; i < rows.length; i++) {
+			row = rows[i];
+			d = row.f_percentage / 100 * (row.f_yield / 100) * (1 - row.f_moisture / 100);
+			if (row.f_added == "Mash")
+				d = efficiency / 100 * d;
+			tot += d;
+		}
+
+		var	totmass = 0;
+		if (tot)
+			totmass = sug / tot;
+
+		if (totmass) {
+			for (i = 0; i < rows.length; i++) {
+				row = rows[i];
+				$("#fermentableGrid").jqxGrid('setcellvalue', i, "f_amount", row.f_percentage / 100 * totmass);
+			}
+		}
+		//CalcWaterBalance;
+	};
+
+	function calcABV() {
+		$("#est_abv").val(abvol(parseFloat($("#est_og").jqxNumberInput('decimal')), parseFloat($("#est_fg").jqxNumberInput('decimal'))));
+	};
+
 	function calcInit () {
 		console.log("calc.init()");
-//		$('#est_og').on('change', function (event) { calcFermentables(); });
 		$('#color_method').on('change', function (event) { calcFermentables(); });
 		$('#ibu_method').on('change', function (event) {
 			calcFermentables();
@@ -477,7 +510,6 @@
 				});
 
 				// delete selected fermentable.
-				// Precentage aanpassen basis mout.
 				$("#fdeleterowbutton").jqxButton({ theme: theme, height: 27, width: 150 });
 				$("#fdeleterowbutton").on('click', function () {
 					var selectedrowindex = $("#fermentableGrid").jqxGrid('getselectedrowindex');
@@ -514,6 +546,7 @@
 						$("#fermentableGrid").jqxGrid('setcellvalue', 0, "f_percentage", 100);
 					}
 					calcFermentables();
+					calcABV();
 					calcIBUs();
 				});
 			},
@@ -649,6 +682,7 @@
 			};
 			$('#fermentableGrid').jqxGrid('sortby', 'f_amount', 'desc');	// TODO: not reliable
 			calcFermentables();
+			calcABV();
 			calcIBUs();	// Depends on gravity, so recalculate.
 		});
 	};
@@ -1402,7 +1436,14 @@
 	$("#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, max: 1.9, decimalDigits: 3, spinButtons: true, spinButtonsStep: 0.001 });
+	$("#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 });
+	$('#est_og').on('change', function (event) {
+		console.log("est_og change:"+event.args.value+"  by:"+event.args.type);
+		calcFermentablesFromOG(event.args.value);	// Adjust fermentables amounts
+		calcFermentables();				// Update the recipe details
+		calcABV();					// and ABV
+		calcIBUs();					// and the IBU's.
+	});
 	$("#st_og_min").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 3, readOnly: true });
 	$("#st_og_max").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 3, readOnly: true });
 

mercurial