www/js/global.js

Mon, 10 Dec 2018 22:20:19 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Mon, 10 Dec 2018 22:20:19 +0100
changeset 136
bcc4583fd013
parent 133
22d28dd9c041
child 139
eb1ac7487710
permissions
-rw-r--r--

Fixed estimate FG calculation during recipes import. Added estimate FG calculation in the recipe editor but do not yet update the recipe. Added SVG calculation to the recipes editor. Added calculations for hop aroma and flavour contribution.

/*****************************************************************************
 * Copyright (C) 2014
 *
 * Michiel Broek <mbroek at mbse dot eu>
 *
 * This file is part of BrewCloud
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2, or (at your option) any
 * later version.
 *
 * BrewCloud is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with ThermFerm; see the file COPYING.  If not, write to the Free
 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
 *****************************************************************************/


var	sugardensity = 1.611; //kg/l in solution


function getLocalization() {
	var localizationobj = {};
	localizationobj.pagerGoToPageString = "Gehe zu:";
	localizationobj.pagerShowRowsString = "Zeige Zeile:";
	localizationobj.pagerRangeString = " von ";
	localizationobj.pagerNextButtonString = "voriger";
	localizationobj.pagerFirstButtonString = "first";
	localizationobj.pagerLastButtonString = "last";
	localizationobj.pagerPreviousButtonString = "nächster";
	localizationobj.sortAscendingString = "Sortiere aufsteigend";
	localizationobj.sortDescendingString = "Sortiere absteigend";
	localizationobj.sortRemoveString = "Entferne Sortierung";
	localizationobj.firstDay = 1;
	localizationobj.percentSymbol = "%";
	localizationobj.currencySymbol = "€";
	localizationobj.currencySymbolPosition = "after";
	localizationobj.decimalSeparator = ",";
	localizationobj.thousandsSeparator = ".";
	var days = {
		// full day names
		names: ["Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"],
		// abbreviated day names
		namesAbbr: ["Sonn", "Mon", "Dien", "Mitt", "Donn", "Fre", "Sams"],
		// shortest day names
		namesShort: ["So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"]
	};
	localizationobj.days = days;
	var months = {
		// full month names (13 months for lunar calendards -- 13th month should be "" if not lunar)
		names: ["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember", ""],
		// abbreviated month names
		namesAbbr: ["Jan", "Feb", "Mär", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dez", ""]
	};
	var patterns = {
		d: "dd.MM.yyyy",
		D: "dddd, d. MMMM yyyy",
		t: "HH:mm",
		T: "HH:mm:ss",
		f: "dddd, d. MMMM yyyy HH:mm",
		F: "dddd, d. MMMM yyyy HH:mm:ss",
		M: "dd MMMM",
		Y: "MMMM yyyy"
	}
	localizationobj.patterns = patterns;
	localizationobj.months = months;
	return localizationobj;
}



$(document).ready(function () {

	$("#jqxMenu").jqxMenu({
		width: 1280,
		height: '30px',
		theme: theme
	});
	$("#jqxWidget").css('visibility', 'visible');
});



function ebc_to_srm(ebc) {
	var srm = -1.32303E-12 * Math.pow(ebc, 4) - 0.00000000291515 * Math.pow(ebc, 3) + 0.00000818515 * Math.pow(ebc, 2) + 0.372038 * ebc + 0.596351;
	if ((ebc < 0) || (srm < 0))
		console.log("ebc_to_srm("+ebc+") = "+srm);
	return srm
}



function srm_to_ebc(srm)
{
	var ebc = Math.round(0.000000000176506 * Math.pow(srm, 4) + 0.000000154529 * Math.pow(srm, 3) - 0.000159428 * Math.pow(srm, 2) + 2.68837 * srm - 1.6004);
	if ((ebc < 0) || (srm < 0))
		console.log("srm_to_ebc("+srm+") = "+ebc);
	return ebc;
}



/*
 * 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) {

	if (colormethod == "Morey")
		return 1.4922 * Math.pow(c, 0.6859);
	if (colormethod == "Mosher")
		return 0.3 * c + 4.7;
	if (colormethod == "Daniels")
		return 0.2 * c + 8.4;
}



function kw_to_ebc(colormethod, c) {
	return srm_to_ebc(kw_to_srm(colormethod, c));
}



/*
 * Berekeningen uit https://www.hobbybrouwen.nl/forum/index.php/topic,6079.msg69464.html#msg69464
 */
function toIBU(Use, Form, SG, Volume, Amount, Boiltime, Alpha, Method)
{
	var gravity = parseFloat(SG);
	var liters  = parseFloat(Volume);
	var alpha   = parseFloat(Alpha)/100;
	var mass    = parseFloat(Amount) * 1000;
	var time    = parseFloat(Boiltime);
	var fmoment = 1.0;
	var pfactor = 1.0;
	var ibu     = 0;

	if ((Use == "Dry Hop") || (Use == "Dry hop") || (Use == "Whirlpool") || (Use == "Aroma")) {
		fmoment = 0.0;
	} else if (Use == "Mash") {
		fmoment += my_factor_mashhop / 100;		// Brouwhulp
	} else if ((Use == "First Wort") || (Use == "First wort"))  {
		fmoment += my_factor_fwh  / 100;		// Brouwhulp, Louis, Ozzie
	}

	if (Form == "Pellet") {
		pfactor += my_factor_pellet / 100;
	}
	if (Form == "Plug" ) {
		pfactor += my_factor_plug / 100;
	}

	if (Method == "Tinseth") {
		/* http://realbeer.com/hops/research.html */
		var AddedAlphaAcids = (alpha * mass * 1000) / liters;
		var Bigness_factor = 1.65 * Math.pow( 0.000125, gravity - 1);
		var BoilTime_factor = ((1 - Math.exp(-0.04 * time)) / 4.15);
		var utiisation = Bigness_factor * BoilTime_factor;
		ibu = Math.round(utiisation * AddedAlphaAcids * fmoment * pfactor * 10) / 10.0;
	}
	if (Method == "Daniels") {
		var boilfactor;
		var sgfactor;
		if (Form == "Leaf")
			boilfactor = -(0.0041*time*time)+(0.6162*time)+1.5779;
		else
			boilfactor = -(0.0051*time*time)+(0.7835*time)+1.9348;
		if (gravity < 1050)
			sgfactor = 0;
		else
			sgfactor = (gravity - 1050) / 200;
		ibu = Math.round(fmoment * ((mass * (alpha * 100) * boilfactor * 0.1) / (liters * (1 + sgfactor))) * 10) / 10;
	}
	if (Method == "Rager") {
		var boilfactor;
		var sgfactor;
		boilfactor = fmoment * 18.11 + 13.86 * Math.tanh((time * 31.32) / 18.27);
		if (gravity < 1050)
			sgfactor = 0;
		else
			sgfactor = (gravity - 1050) / 200;
		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);
	return ibu;
}



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;
}



function estimate_fg(percSugar, percCara, WGratio, TotTme, Temp, attenuation, og) {

	var	BD;

	console.log("estimate_fg("+percSugar+","+percCara+","+WGratio+","+TotTme+","+Temp+","+attenuation+","+og+")");

	if (percSugar > 40)
		percSugar = 0;
	if (percCara > 50)
		percCara = 0;
	if ((WGratio > 0) && (TotTme > 0)) {
		BD = WGratio;
		BD = max(2, min(5.5, BD));
		Temp = max(60, min(72, Temp));
	} else {
		BD = 3.5;
		Temp = 67;
		TotTme = 75;
	}
	if (attenuation < 30)
		attenuation = 77;

	var AttBeer = 0.00825 * attenuation + 0.00817 * BD - 0.00684 * Temp + 0.00026 * TotTme - 0.00356 * percCara + 0.00553 * percSugar + 0.547;
	var fg = Math.round((1 + (1 - AttBeer) * (og - 1)) * 1000) / 1000;
	console.log("fg:"+fg);
	return fg;
}


/*
 * Steinie:
 *
 *
 * HCO3 = CaCo3 x 1,22
 * 1°F = 10mg/L CaCo3
 */

mercurial