-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
615 lines (388 loc) · 14.3 KB
/
script.js
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
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
/* jshint browser: true */
/* /ABV CALCULATOR APP /
// Brewing calculator.
var startingGravity = prompt('What is your starting gravity?');
var finalGravity = prompt('What is your final gravity?');
var abv = (startingGravity - finalGravity) * 131.25;
alert('Your ABV is approximately ' + abv.toFixed(2) + '%');
*/
var startingGravity;
var finalGravity;
var abv;
function calcGrav() {
startingGravity = document.getElementById("starting-grav").value;
finalGravity = document.getElementById("final-grav").value;
abv = (startingGravity - finalGravity) * 131.25;
document.querySelector(".grav-result").innerHTML = "Your ABV is approximately " + abv.toFixed(2) + "%";
}
/* IBU CALCULATOR*/
/*var batchSize = 19;
var grams = [35, 15, 10, 5];
var percentAa = [10, 12, 7, 5];
var minsBoil = [60, 20, 10, 0];
var utilisation =[];
var ibus = [];*/
var batchSize = 19;
var numberOfHops = 1;
var grams = [];
var percentAa = [];
var minsBoil = [];
var utilisation =[];
var ibus = [];
var ga;
function getIbuData() {
//First check if the Starting Gravity has been filled out. If so, get the Gravity Adjustment (ga), otherwise prompt them to fill it out.
if ((document.getElementById("sg").value) == false) {
sweetAlert('Please set your Starting Gravity');
return;
} else {
ga = ((document.getElementById("sg").value) - 1.050) / 0.2;
}
// Now let's get the rest of the data from the DOM.
for(i=1; i <= numberOfHops; i++) {
grams[i] = document.getElementById("grams" + i).value;
percentAa[i] = document.getElementById("aa" + i).value;
minsBoil[i] = document.getElementById("minsboil" + i).value;
};
//If there's something there (or if there's NOT nothing there), grab it.
if((document.getElementById("batch").value) != false) {
batchSize = document.getElementById("batch").value;
}
// Now we can use the data to calc the Utilisation.
utilisation = minsBoil.map(utilCalc);
// Next we can work out the individual IBUs contributed.
for (var i = 1; i <= grams.length - 1; i++) {
ibus[i] = (utilisation[i] * ((percentAa[i] / 100) * (grams[i] * 0.035274) * 7462) / (batchSize / 3.7854) * (1 + ga)).toFixed(2)/1;
};
// This calculates the Total IBUs.
var totalIbu = ibus.reduce(function(a, b){return a+b;})
//Display and check all data
console.log(grams);
console.log(percentAa);
console.log(minsBoil);
console.log(utilisation);
console.log(ibus);
console.log('The total IBU for this beer is ' + totalIbu);
for (var i = 1; i <= numberOfHops; i++) {
document.querySelector(".ibus-contributed" + i).innerHTML = ibus[i];
};
document.querySelector(".ibu-total").innerHTML = "TOTAL IBU: " + totalIbu.toFixed(2);
for (var i = 1; i <= numberOfHops; i++) {
console.log('Hop addition ' + (i) + ' contributes ' + ibus[i] + ' IBU.');
};
hopSummarys();
};
function hopSummarys() {
for (var i = 1; i <= numberOfHops; i++) {
console.log('Hop addition ' + (i) + ' is ' + grams[i] + ' grams of ' + percentAa[i] + '%AA hops, added at ' + minsBoil[i] + ' minutes.');
}
}
// Pulled from this chart: http://www.straighttothepint.com/ibu-calculator/
function utilCalc(Boil) {
if (Boil == 0) {
return 0;
}
else if (Boil <= (5)) {
return 0.05;
} else if (Boil > (5) && Boil <= 10) {
return 0.06;
} else if (Boil > (10) && Boil <= 15) {
return 0.08;
} else if (Boil > (15) && Boil <= 20) {
return 0.101;
} else if (Boil > (20) && Boil <= 25) {
return 0.121;
} else if (Boil > (25) && Boil <= 30) {
return 0.153;
} else if (Boil > (30) && Boil <= 35) {
return 0.188;
} else if (Boil > (35) && Boil <= 40) {
return 0.228;
} else if (Boil > (40) && Boil <= 45) {
return 0.269;
} else if (Boil > (45) && Boil <= 50) {
return 0.281;
} else if (Boil > (50)) {
return 0.30;
}
};
function addHops() {
if(numberOfHops < 10) {
numberOfHops++;
document.getElementById("hop" + numberOfHops).reset();
document.querySelector(".ibus-contributed" + numberOfHops).innerHTML = "";
document.getElementById("hop" + numberOfHops).style.display = "block";
} else {
sweetAlert("Maximum 10 Hops Allowed");
}
};
function removeHops() {
if(numberOfHops > 1) {
document.getElementById("hop" + numberOfHops).reset();
document.getElementById("hop" + numberOfHops).style.display = "none";
grams[numberOfHops] = 0;
percentAa[numberOfHops] = 0;
minsBoil[numberOfHops] = 0;
numberOfHops--;
} else {
sweetAlert("You must leave at least 1 hop addition!");
sweetAlert("You must leave at least 1 hop addition!");
}
}
function reset() {
batchSize = 19;
numberOfHops = 1;
ga = undefined;
//This is a neat way of clearing the arrays.
grams.length= 0;
percentAa.length = 0;
minsBoil.length = 0;
utilisation.length = 0;
ibus.length = 0;
/*document.getElementById("ibu-calculator").reset();*/
document.getElementById("batch").value = "";
document.getElementById("sg").value = "";
document.querySelector(".ibus-contributed1").innerHTML = "";
document.querySelector(".ibu-total").innerHTML = "";
document.getElementById("hop2").style.display = "none";
document.getElementById("hop3").style.display = "none";
document.getElementById("hop4").style.display = "none";
document.getElementById("hop5").style.display = "none";
document.getElementById("hop6").style.display = "none";
document.getElementById("hop7").style.display = "none";
document.getElementById("hop8").style.display = "none";
document.getElementById("hop9").style.display = "none";
document.getElementById("hop10").style.display = "none";
};
/************ TO ADD *****************/
/*
Consider moving to Rager formula which adjusts for higher gravity beers.
IBU = (OUNCES OF HOPS * %UTILIZATION * %ALPHA * 7462) / (Batch Volume* (1 + GA))
GA = (Boil Gravity - 1.050) / 0.2 //GRAVITY ADJUSTMENT
^^^DONE
Would need to update Utilisation table too.
Would need to add form space for Original Gravity.
*/
/* TIMER */
var i;
var z;
var originalCount;
var fillerBar = document.querySelector(".filler");
var firstHops;
var secondHops;
var thirdHops = "";
var fourthHops = "";
var fifthHops = "";
var sixthHops = "";
var seventhHops = "";
var eighthHops = "";
var ninthHops = "";
var tenthHops = "";
var firstHopsSeconds;
var secondHopsSeconds;
var thirdHopsSeconds;
var numberOfAdditions = 2;
function setTimer() {
//originalCount = document.getElementById("set-timer").value;
firstHops = parseInt(document.getElementById("hopmins1").value) * 60;
secondHops = parseInt(document.getElementById("hopmins2").value) * 60;
thirdHops = parseInt(document.getElementById("hopmins3").value) * 60;
fourthHops = parseInt(document.getElementById("hopmins4").value) * 60;
fifthHops = parseInt(document.getElementById("hopmins5").value) * 60;
sixthHops = parseInt(document.getElementById("hopmins6").value) * 60;
seventhHops = parseInt(document.getElementById("hopmins7").value) * 60;
eighthHops = parseInt(document.getElementById("hopmins8").value) * 60;
ninthHops = parseInt(document.getElementById("hopmins9").value) * 60;
tenthHops = parseInt(document.getElementById("hopmins10").value) * 60;
firstHopsSeconds = parseInt(document.getElementById("hopmins1").value) * 60;
secondHopsSeconds = parseInt(document.getElementById("hopmins2").value) * 60;
thirdHopsSeconds = parseInt(document.getElementById("hopmins3").value) * 60;
i = firstHops;
}
// PASS THIS FUNCTION SOMETHING...
document.getElementById("timer-start").addEventListener('click',function(){
document.getElementById("timer-stop").style.display = "block";
document.getElementById("timer-start").style.display = "none";
});
document.getElementById("timer-stop").addEventListener('click',function(){
document.getElementById("timer-start").style.display = "block";
document.getElementById("timer-stop").style.display = "none";
});
/*
$( "#timer-start" ).click(function() {
$( "#timer-stop" ).show();
$( "#timer-start" ).hide();
});
$( "#timer-stop" ).click(function() {
$( "#timer-start" ).show();
$( "#timer-stop" ).hide();
});
*/
function countDown(currentTime, timeUntilNextAddition) {
document.getElementById("timer-stop").addEventListener('click',function(){
window.location.reload();
});
console.log(currentTime);
currentTime--;
var audio = new Audio('css/audio/Seinfeld.mp3');
audio.preload = "auto";
audio.loop = true;
var x = (currentTime / 60).toFixed(0);
if (x >= 1) {
document.getElementById("timer").innerHTML = "~ " + x + " minutes left";
} else {
document.getElementById("timer").innerHTML = "Less than 1 minute left!";
};
if (currentTime == firstHops -1) {
audio.play();
sweetAlert({
title: "Begin Boil",
text: "Begin your boil and add your first hop addition now!"
}, function () {
audio.pause();
setTimeout(function() {
countDown(currentTime, timeUntilNextAddition);
},1000)});
} else if (currentTime > timeUntilNextAddition) {
setTimeout(function() {
countDown(currentTime, timeUntilNextAddition);
},1000);
} else if (currentTime == secondHops) {
audio.play();
sweetAlert({
title: "Second Hops",
text: "Add your second hop addition now!"
}, function () {
document.querySelector(".icon-2").style.display = "initial";
audio.pause();
setTimeout(function() {
countDown(secondHops, thirdHops);
},1000)});
} else if (currentTime == thirdHops) {
audio.play();
sweetAlert({
title: "Third Hops",
text: "Add your third hop addition now!"
}, function () {
document.querySelector(".icon-3").style.display = "initial";
audio.pause();
setTimeout(function() {
countDown(thirdHops, fourthHops);
},1000)});
} else if (currentTime == fourthHops) {
audio.play();
sweetAlert({
title: "Fourth Hops",
text: "Add your fourth hop addition now!"
}, function () {
document.querySelector(".icon-4").style.display = "initial";
audio.pause();
setTimeout(function() {
countDown(fourthHops, fifthHops);
},1000)});
} else if (currentTime == fifthHops) {
audio.play();
sweetAlert({
title: "Fifth Hops",
text: "Add your fifth hop addition now!"
}, function () {
document.querySelector(".icon-5").style.display = "initial";
audio.pause();
setTimeout(function() {
countDown(fifthHops, sixthHops);
},1000)});
} else if (currentTime == sixthHops) {
audio.play();
sweetAlert({
title: "Sixth Hops",
text: "Add your sixth hop addition now!"
}, function () {
document.querySelector(".icon-6").style.display = "initial";
audio.pause();
setTimeout(function() {
countDown(sixthHops, seventhHops);
},1000)});
} else if (currentTime == seventhHops) {
audio.play();
sweetAlert({
title: "Seventh Hops",
text: "Add your seventh hop addition now!"
}, function () {
document.querySelector(".icon-7").style.display = "initial";
audio.pause();
setTimeout(function() {
countDown(seventhHops, eighthHops);
},1000)});
} else if (currentTime == eighthHops) {
audio.play();
sweetAlert({
title: "Eighth Hops",
text: "Add your eighth hop addition now!"
}, function () {
document.querySelector(".icon-8").style.display = "initial";
audio.pause();
setTimeout(function() {
countDown(eighthHops, ninthHops);
},1000)});
} else if (currentTime == ninthHops) {
audio.play();
sweetAlert({
title: "Ninth Hops",
text: "Add your ninth hop addition now!"
}, function () {
document.querySelector(".icon-9").style.display = "initial";
audio.pause();
setTimeout(function() {
countDown(ninthHops, tenthHops);
},1000)});
} else if (currentTime == tenthHops) {
audio.play();
sweetAlert({
title: "Tenth Hops",
text: "Add your tenth hop addition now!"
}, function () {
document.querySelector(".icon-10").style.display = "initial";
audio.pause();
setTimeout(function() {
countDown(tenthHops, 0);
},1000)});
} else if (currentTime == 0) {
audio.play();
sweetAlert({
title: "Boil Completed",
text: "Your boil is done. You're one step closer to beer. :)"
}, function () {
audio.pause();
document.getElementById("timer").innerHTML = "Boil Completed";
document.getElementById("timer-stop").style.display = "none";
document.getElementById("timer-start").style.display = "block";
});
} else {
setTimeout(function() {
countDown(currentTime, 0);
},1000);
}
};
function addAddition() {
// Need to create these variables.
if(numberOfAdditions < 10) {
numberOfAdditions++;
//document.getElementById("addition" + numberOfAdditions).reset();
//document.querySelector(".ibus-contributed" + numberOfHops).innerHTML = "";
document.getElementById("addition" + numberOfAdditions).style.display = "block";
} else {
sweetAlert("Maximum 10 Hop Additions Allowed");
}
};
function removeAddition() {
if(numberOfAdditions > 2) {
document.getElementById("hopmins" + numberOfAdditions).value ="";
document.getElementById("addition" + numberOfAdditions).style.display = "none";
//document.getElementById("addition" + numberOfAdditions).innerHTML = "";
numberOfAdditions--;
} else {
sweetAlert("You must leave at least 2 hop additions!");
}
}
/************ TO ADD *****************/
// Stylize.