www/js/global.js

Sat, 17 Nov 2018 19:44:39 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Sat, 17 Nov 2018 19:44:39 +0100
changeset 100
08c92cb740b9
parent 98
92d6bc8a4cdd
child 101
5b6bb99bc52a
permissions
-rw-r--r--

Fix for missing coor info on fermentables during recipes import. Log when srm or ebc values are negatie during conversions. Load setup record in global.inc.php and make some variables available for PHP and JS.

/*****************************************************************************
 * 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.
 *****************************************************************************/


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



/*
 * 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 += /* Settings.MashHopFactor.Value = -30% */ -30 / 100;		// Brouwhulp
	} else if ((Use == "First Wort") || (Use == "First wort"))  {
		fmoment += /* Settings.FWHFactor.Value = 10% */ 10 / 100;		// Brouwhulp, Louis, Ozzie
	}

	if (Form == "Pellet") {
		pfactor += /* Settings.PelletFactor.Value = 10% */ 10 / 100;
	}
	if (Form == "Plug" ) {
		pfactor += /* Settings.PlugFactor.Value = 2% */ 2 / 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);
	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;
}


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

mercurial