-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
503 lines (434 loc) · 15.3 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
<!DOCTYPE html>
<html>
<meta charset="UTF-8">
<!-- The MIT License (MIT)
Copyright (c) 2015 James Cipar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. -->
<head>
<title>Brewing Salts</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/themes/smoothness/jquery-ui.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js"></script>
<script type="text/javascript" src="numeric-1.2.6.js"></script>
<script type="text/javascript" src="brewing-salts-numeric.js"></script>
<script type="text/javascript" src="water-profile-library.js"></script>
<link rel="stylesheet" type="text/css" href="brewing-salts.css" />
<!-- Google Analytics -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-60077875-1', 'auto');
ga('send', 'pageview');
</script>
<script type="text/javascript">
"use strict";
var salt_names = {
"gypsum": {
"name": "Gypsum",
},
"epsom": {
"name": "Epsom",
},
"table": {
"name": "Table Salt"
},
"baking_soda": {
"name": "Baking Soda"
},
"calcium_chloride": {
"name": "Calcium Chloride",
},
"chalk": {
"name": "Chalk (Calcium Carbonate)",
"default_off": true,
"tip": "Chalk is very poorly soluble in water. Do not use this unless you are willing to go to extra lengths to dissolve it.",
},
"pickling_lime": {
"name": "Pickling Lime (Calcium Hydroxide)",
},
"magnesium_chloride": {
"name": "Magnesium Chloride",
},
"sauermalz": {
"name": "Sauermalz (Acidulated Malt)",
"units": "oz",
"tip": "Most calculators consider this part of the recipe, but here it is treated as a water modification. To treat it as part of your recipe, adjust your target RA appropriately."
},
"lactic": {
"name": "Lactic Acid 88%",
"units": "ml",
},
"phosphoric": {
"name": "Phosphoric Acid 10%",
"units": "ml",
}
}
var ion_names = {
"calcium": {
"name": "Calcium"
},
"magnesium": {
"name": "Magnesium"
},
"sodium": {
"name": "Sodium"
},
"sulfate": {
"name": "Sulfate"
},
"chloride": {
"name": "Chloride",
},
"bicarbonate": {
"name": "Bicarbonate"
}
}
function round(value, exp) {
if (typeof exp === 'undefined' || +exp === 0)
return Math.round(value);
value = +value;
exp = +exp;
if (isNaN(value) || !(typeof exp === 'number' && exp % 1 === 0))
return NaN;
// Shift
value = value.toString().split('e');
value = Math.round(+(value[0] + 'e' + (value[1] ? (+value[1] + exp) : exp)));
// Shift back
value = value.toString().split('e');
return +(value[0] + 'e' + (value[1] ? (+value[1] - exp) : -exp));
}
function optimize()
{
var input = example_input;
for (var ion in input.target_profile) {
var input_name = "#input-" + ion;
input.target_profile[ion] = Number($(input_name).val());
}
for (var ion in input.initial_profile) {
var input_name = "#starting-" + ion;
input.initial_profile[ion] = Number($(input_name).val());
}
input.mash_gallons = Number($('#mash-gallons').val());
input.sparge_gallons = Number($('#sparge-gallons').val());
input.target_residual_alkalinity = Number($('#target-residual-alkalinity').val())
for (var salt in parameters.salts) {
if ($('#use-'+salt).is(':checked')) {
input.max_salts[salt] = 1000.0;
} else {
delete input.max_salts[salt];
}
}
for (var acid in parameters.acids) {
if ($('#use-'+acid).is(':checked')) {
input.max_acids[acid] = 1000.0;
} else {
delete input.max_acids[acid];
}
}
var maintain_ratios = $('#maintain-sulfate-chloride-ratio').is(':checked') ;
// preserve sulfate:chloride ratio, rather than hitting targets
if (maintain_ratios && (input.initial_profile.chloride > input.target_profile.chloride)) {
var b = input.initial_profile.chloride / input.target_profile.chloride;
input.target_profile.chloride = input.initial_profile.chloride;
input.target_profile.sulfate *= b;
// alert("Increasing sulfate target to maintain chloride:sulfate ratio, due to high chloride.");
}
if (maintain_ratios && (input.initial_profile.sulfate > input.target_profile.sulfate)) {
var b = input.initial_profile.sulfate / input.target_profile.sulfate;
input.target_profile.sulfate = input.initial_profile.sulfate;
input.target_profile.chloride *= b;
// alert("Increasing chloride target to maintain chloride:sulfate ratio, due to high sulfate.");
}
console.log(JSON.stringify(input));
var result = optimize_salts(parameters, input);
clear_output_tables();
reset_ion_table(input);
console.log(JSON.stringify(result, null,2));
for (var salt in result.additions_per_gallon) {
// console.log("%%% " + salt);
var output_name = '#g-gal-' + salt;
$(output_name).html(round(result.additions_per_gallon[salt],2) + units(salt));
}
for (var salt in result.additions_total) {
var output_name = '#g-' + salt;
$(output_name).html(round(result.additions_total[salt],2)+ units(salt));
}
for (var salt in result.additions_tsp) {
var output_name = '#tsp-' + salt;
$(output_name).html(round(result.additions_tsp[salt],2));
}
for (var ion in input.target_profile) {
var output_name = "#target-" + ion;
$(output_name).html(round(input.target_profile[ion],2));
}
for (var ion in input.target_profile) {
var output_name = "#added-" + ion;
$(output_name).html(round(result.ions_added[ion],2));
}
for (var ion in input.target_profile) {
var output_name = "#total-" + ion;
$(output_name).html(round(result.ions[ion],2));
}
for (var ion in input.target_profile) {
var output_name = "#error-" + ion;
$(output_name).html(round(result.ion_errors[ion],2));
}
$("#g-gallons").html("g in " + input.mash_gallons + " gal")
$("#tsp-gallons").html("tsp in " + input.mash_gallons + " gal")
$("#g-gallons-sparge").html("g in " + input.sparge_gallons + " gal")
$("#tsp-gallons-sparge").html("tsp in " + input.sparge_gallons + " gal")
}
function units(salt)
{
if (salt_names[salt] && salt_names[salt].units) {
return " <span class='unit'>(" +salt_names[salt].units+")</span>";
} else {
return ""
}
}
function clear_output_tables()
{
for (var salt in parameters.salts) {
$('#g-gal-'+salt).html('');
$('#g-'+salt).html('');
$('#tsp-'+salt).html('');
$('#g-gal-sparge_'+salt).html('');
$('#g-sparge_'+salt).html('');
$('#tsp-sparge_'+salt).html('');
}
for (var acid in parameters.acids) {
$('#g-gal-'+acid).html('');
$('#g-'+acid).html('');
$('#tsp-'+acid).html('');
// $('#g-gal-sparge_'+salt).html('');
// $('#g-sparge_'+salt).html('');
// $('#tsp-sparge_'+salt).html('');
}
// TODO: clear ion table
}
function set_starting()
{
var profile_name = $("#starting-profile-select").val();
var profile = standard_initial_profiles[profile_name];
for (var ion in profile) {
var input_name = "#starting-" + ion;
$(input_name).val(profile[ion]);
}
}
function set_desired()
{
var profile_name = $("#desired-profile-select").val();
var profile = standard_target_profiles[profile_name];
for (var ion in profile) {
var input_name = "#input-" + ion;
$(input_name).val(profile[ion]);
console.log("## " + input_name);
}
}
function setup_salt_table(input)
{
var i=0;
var boil_salts = [];
$('#salt-table').append(
"<tr>"
+ "<th>Mash Additions</th>"
+ "<th>Enabled</th>"
+ "<th>grams/gal</th>"
+ "<th id='g-gallons'>g in X gal</th>"
+ "<th id='tsp-gallons'>tsp in X gal</th>"
+ "</tr>");
i = add_to_salt_table(parameters.salts, "", i, true);
i = add_to_salt_table(parameters.acids, "", i, true);
$('#salt-table').append(
"<tr>"
+ "<th>Sparge Additions</th>"
+ "<th></th>"
+ "<th>grams/gal</th>"
+ "<th id='g-gallons-sparge'>g in X gal</th>"
+ "<th id='tsp-gallons-sparge'>tsp in X gal</th>"
+ "</tr>");
i = add_to_salt_table(parameters.salts, "sparge_", i);
};
function add_to_salt_table(additions, prefix, i, first)
{
for (var salt in additions) {
var name = salt;
var href = null;
var tooltip = null;
var checked = "checked"
if (salt in salt_names) {
name = salt_names[salt].name;
href = salt_names[salt].href;
tooltip = salt_names[salt].tip;
if (first && tooltip) {
name = name + "<abbr class='tooltip' title='" + tooltip + "'>[?]</abbr>";
}
if (first && href) {
name = name+" <a class='buy-link' href='"+href+"'>[$]</a>"
}
if (salt_names[salt].default_off == true) {
checked = ""
}
}
var checkbox = "<input type='checkbox' id='use-"+salt+"' " + checked +" onChange='optimize();' />";
if (!first) { checkbox = ""; }
$('#salt-table').append("<tr " + (i%2==1 ? "class='grayrow'":"") + " >"
+ "<td>"+name+"</td>"
+ "<td>" + checkbox + "</td>"
+ "<td id='g-gal-"+prefix+salt+"'></td>"
+ "<td id='g-"+prefix+salt+"'></td>"
+ "<td id='tsp-"+prefix+salt+"'></td>"
+ "</tr>");
i++;
}
return i;
}
function reset_ion_table(input)
{
$('#ion-table').empty();
$('#ion-table').append("<tr>"
+ "<th></th>"
+ "<th>Added</th>"
+ "<th>Total</th>"
+ "<th>Target</th>"
+ "<th>Error</th>"
+ "</tr>");
if (!input) { return; }
var i=0;
for (var ion in input.target_profile) {
var ion_name = ion_names[ion] ? ion_names[ion].name : ion;
$('#ion-table').append(
"<tr " + (i%2==1 ? "class='grayrow'":"") + " >"
+ "<td>"+ion_name+"</td>"
+ "<td id='added-"+ion+"'></td>"
+ "<td id='total-"+ion+"'></td>"
+ "<td id='target-"+ion+"'></td>"
+ "<td id='error-"+ion+"'></td>"
+ "</tr>"
);
i++
}
}
$(document).ready(function() {
for (var profile_name in standard_initial_profiles) {
$('#starting-profile-select')
.append($('<option>', { value : profile_name })
.text(profile_name));
}
for (var profile_name in standard_target_profiles) {
$('#desired-profile-select')
.append($('<option>', { value : profile_name })
.text(profile_name));
}
setup_salt_table(example_input);
reset_ion_table(example_input);
$(document).tooltip();
$('#ra-tooltip').tooltip({hide: {delay: 3000}});
$('#ra-tooltip').tooltip("option", "content",
$('#top-note').html()
);
optimize();
});
</script>
</head>
<body>
<div id="content">
<h1>Brewing Salts Calculator</h1>
<div class='warning'>
This is a work in progress. You should check the suggested water modifications with a trusted
tool like <a href="https://sites.google.com/site/brunwater/" class='inlinelink'>Bru'n Water</a> or
<a href="http://www.brewersfriend.com/mash-chemistry-and-brewing-water-calculator/" class='inlinelink'>Brewer's Friend</a>.
(Brewer's friend uses a different model for residual alkalinity than Bru'n Water, or this tool. The
results from this tool should match Bru'n Water exactly. They should be close to Brewer's Friend, but
probably will not match precisely.)
<br><br>
It makes no attempt to model sparge acidification at all.<br><br>
</div>
<div id='top-parameters'>
<label>Gallons of water to treat (mash): </label><input type="number" id='mash-gallons' value=5.0 step='any' min=0 onChange='optimize();' />
<br>
<label>Gallons of water to treat (sparge): </label><input type="number" id='sparge-gallons' value=5.0 step='any' min=0 onChange='optimize();' />
<br>
<label>Target residual alkalinity <span class='tooltip' id='ra-tooltip' title='RA'>[?]</span>: </label><input type="number" id='target-residual-alkalinity' value=0.0 step='any' onChange='optimize();' />
<br>
</div>
<div id='top-note' hidden>
Residual Alkalinity (RA) combines the alkalinity of the water, the acid
additions, as well as a model of how calcium and magnesium
react with the grist to acidify the mash. If you don't know what RA value
is appropriate for your recipe, refer to <a href="http://braukaiser.com/wiki/index.php?title=Beer_color,_alkalinity_and_mash_pH#simple_Guidelines_for_beer_color_and_suitable_brewing_waters">these charts from Kai</a>, or
this <a href="http://howtobrew.com/section3/chapter15-3.html">page from How to Brew.</a>
</div>
<table>
<tr>
<th></th>
<th>Standard profiles</th>
<th>Calcium</th>
<th>Magnesium</th>
<th>Sodium</th>
<th>Sulfate</th>
<th>Chloride</th>
<th>Bicarbonate</th>
</tr>
<tr>
<td>Desired Profile</td>
<td>
<select id="desired-profile-select" onChange="set_desired(); optimize();">
<option></option>
</select>
</td>
<td><input type="number" class='ion-input' onChange='optimize();' step='any' min=0 id='input-calcium' value=0.0 /></td>
<td><input type="number" class='ion-input' onChange='optimize();' step='any' min=0 id='input-magnesium' value=0.0 /></td>
<td><input type="number" class='ion-input' onChange='optimize();' step='any' min=0 id='input-sodium' value=0.0 /></td>
<td><input type="number" class='ion-input' onChange='optimize();' step='any' min=0 id='input-sulfate' value=0.0 /></td>
<td><input type="number" class='ion-input' onChange='optimize();' step='any' min=0 id='input-chloride' value=0.0 /></td>
<td><input type="number" class='ion-input' onChange='optimize();' step='any' min=0 id='input-bicarbonate' value=0.0 /></td>
</tr>
<tr>
<td>Starting Profile</td>
<td>
<select id="starting-profile-select" onChange="set_starting(); optimize();">
<option></option>
</select>
</td>
<td><input type="number" class = 'ion-input' onChange='optimize();' step='any' min=0 id='starting-calcium' value=0.0 /></td>
<td><input type="number" class = 'ion-input' onChange='optimize();' step='any' min=0 id='starting-magnesium' value=0.0 /></td>
<td><input type="number" class = 'ion-input' onChange='optimize();' step='any' min=0 id='starting-sodium' value=0.0 /></td>
<td><input type="number" class = 'ion-input' onChange='optimize();' step='any' min=0 id='starting-sulfate' value=0.0 /></td>
<td><input type="number" class = 'ion-input' onChange='optimize();' step='any' min=0 id='starting-chloride' value=0.0 /></td>
<td><input type="number" class = 'ion-input' onChange='optimize();' step='any' min=0 id='starting-bicarbonate' value=0.0 /></td>
</tr>
</table>
<label>Maintain Sulfate:Chloride ratio even if it goes over targets: </label>
<input type="checkbox" id='maintain-sulfate-chloride-ratio' onChange='optimize();' /><br>
<table id='salt-table'>
</table>
<table id='ion-table'>
<tr>
<th></th>
<th>Added</th>
<th>Total</th>
<th>Target</th>
<th>Error</th>
</tr>
</table>
</div> <!-- Content -->
<center><a href='LICENSE.txt' class='smalllink'>Copyright, James Cipar. [MIT License]</a></center>
</body>
</html>