-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
941 lines (822 loc) · 25.8 KB
/
index.js
File metadata and controls
941 lines (822 loc) · 25.8 KB
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
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
import round from 'lodash/round';
import every from 'lodash/every';
import isFinite from 'lodash/isFinite';
// Helper functions
const isNum = (...args) => every(args, isFinite);
// Calculations
/**
* Convert specific gravity (sg) to plato
* @module sg2plato
* @param {number} sg the specific gravity (sg)
* @return {number} (-616.868) + (1111.14 x sg) - (630.272 x sg^2) + (135.997 x sg^3)
*
* @example
* // returns 21.1
* sg2plato(1.088);
*/
export const sg2plato = (sgravity) => {
if (isNum(sgravity)) {
const calc = (-616.868)
+ (1111.14 * sgravity)
- (630.272 * (sgravity ** 2))
+ (135.997 * (sgravity ** 3));
const calcRound = round(calc, 1);
return calcRound;
}
// if its not a number, throw an error
throw new Error('arguments must be a number');
};
/**
* Convert plato to specific gravity (sg)
* @module plato2sg
* @param {number} plato plato number to be converted
* @return {number} plato / (258.6 -((plato / 258.2) x 227.1)) + 1
*
* @example
* // returns 1.074
* plato2sg(18);
*/
export const plato2sg = (plato) => {
if (isNum(plato)) {
const calc = ((plato / (258.6 - ((plato / 258.2) * 227.1))) + 1);
const calcRound = round(calc, 3);
return calcRound;
}
// if its not a number, throw an error
throw new Error('arguments must be a number');
};
/**
* Calculate original extract from original gravity.
* @module originalExtract
* @param {number} og original gravity (og)
* @see Dr. Michael Hall article, Zymurgy, Summer 1995
* @return {number} OE = -668.962 + (1262.45 * OG ) - (776.43 * OG^2) + (182.94 * OG^3)
*
* @example
* // returns 21.1
* originalExtract(1.088);
*/
export const originalExtract = (og) => {
if (isNum(og)) {
const calc = -668.962 + (1262.45 * og) - (776.43 * (og ** 2)) + (182.94 * (og ** 3));
return calc;
}
// if its not a number, throw an error
throw new Error('originalExtract arguments must be a number');
};
/**
* Calculate apparent extract from final gravity.
* @module apparentExtract
* @param {number} fg final gravity (fg)
* @see Dr. Michael Hall article, Zymurgy, Summer 1995
* @return {number} AE = -668.962 + (1262.45 * FG ) - (776.43 * FG^2) + (182.94 * FG^3)
*
* @example
* // returns 3.07
* apparentExtract(1.012);
*/
export const apparentExtract = (fg) => {
if (isNum(fg)) {
const calc = -668.962 + (1262.45 * fg) - (776.43 * (fg ** 2)) + (182.94 * (fg ** 3));
return calc;
}
// if its not a number, throw an error
throw new Error('apparentExtract arguments must be a number');
};
/**
* Calculate attenuation coefficient from original extract.
* @module attenuationCoefficient
* @param {number} oe original extract (oe)
* @see Dr. Michael Hall article, Zymurgy, Summer 1995
* @return {number} q = .22 + (.001 * OE)
*
* @example
* // returns 3.07
* attenuationCoefficient(21.1);
*/
export const attenuationCoefficient = (oe) => {
if (isNum(oe)) {
const calc = 0.22 + (0.001 * oe);
return calc;
}
// if its not a number, throw an error
throw new Error('attenuationCoefficient arguments must be a number');
};
/**
* Calculate real extract from starting gravity & final gravity.
* @module realExtract
* @param {number} og original gravity (og)
* @param {number} fg final gravity (fg)
* @see Dr. Michael Hall article, Zymurgy, Summer 1995
* @see (not currently used) {@link http://hbd.org/ensmingr/|hbd.org/ensmingr}
* @return {number} RE = ((q * OE) + AE) / (1 + q)
*
* @example
* // returns 6.5697
* realExtract(1.088, 1.012);
*/
export const realExtract = (og, fg) => {
if (isNum(og, fg)) {
const oe = originalExtract(og);
const ae = apparentExtract(fg);
const q = attenuationCoefficient(oe);
const calc = ((q * oe) + ae) / (1 + q);
const calcRound = round(calc, 4);
return calcRound;
}
// if its not a number, throw an error
throw new Error('arguments must be a number');
};
/**
* Calculates the Alcohol by weight (ABW)
* @module abw
* @param {number} og The original gravity (og)
* @param {number} fg The final gravity (nfg)
* @return {number} (abv x 0.79336) / fg
*
* @example
* // returns 7.23
* abw(1.088, 1.019);
*/
export const abw = (og, fg) => {
if (!isNum(og, fg)) {
// if arguments are not a number, throw error
throw new Error('arguments must be a number');
} else if (og < fg) {
// if original gravity is not greater than final gravity, throw error
throw new Error('Original Gravity should be greater than Final Gravity');
} else {
const oe = originalExtract(og);
const re = realExtract(og, fg);
const calc = (oe - re) / (2.0665 - (0.010665 * oe));
const calcRound = round(calc, 2);
return calcRound;
}
};
/**
* Calculates the alcohol by volume (abv) <br>
* @module abv
* @param {number} og original gravity (og)
* @param {number} fg final gravity (fg)
* @return {number} abw * (FG / .749);
*
* @example
* // returns 10.2
* abv(1.089, 1.012);
*/
export const abv = (og, fg) => {
if (!isNum(og, fg)) {
// if not a number, throw an error
throw new Error('arguments must be a number');
} else if (og < fg) {
// if original gravity is less than final gravity, throw an error
throw new Error('Original Gravity should be greater than Final Gravity');
} else {
const getAbw = abw(og, fg);
const calc = getAbw * (fg / 0.794);
const calcRound = round(calc, 1);
return calcRound;
}
};
/**
* Calculate number of calories from Alcohol in 12oz serving.
* @module caloriesAlcohol
* @param {number} og original gravity (og)
* @param {number} fg final gravity (fg)
* @see {@link https://www.homebrewersassociation.org/how-to-brew/how-many-calories-are-in-beer/|www.homebrewersassociation.org}
* @return {number} 1881.22 * fg * ((og - fg) / (1.775 - og))
*
* @example
* // returns 210.61
* caloriesAlcohol(1.088, 1.012);
*/
export const caloriesAlcohol = (og, fg) => {
if (isNum(og, fg)) {
const calc = 1881.22 * fg * ((og - fg) / (1.775 - og));
const calcRound = round(calc, 2);
return calcRound;
}
// if its not a number, throw an error
throw new Error('arguments must be a number');
};
/**
* Calculate number of calories from carbs in 12oz serving.
* @module caloriesCarbs
* @param {number} og original gravity (og)
* @param {number} fg final gravity (fg)
* @see {@link https://www.homebrewersassociation.org/how-to-brew/how-many-calories-are-in-beer/|www.homebrewersassociation.org}
* @return {number} 3550.0 * fg * ((0.1808 * og) + ((0.8192 * fg) - 1.0004))
*
* @example
* // returns 91.04
* caloriesCarbs(1.088, 1.012);
*/
export const caloriesCarbs = (og, fg) => {
if (isNum(og, fg)) {
const calc = 3550.0 * fg * ((0.1808 * og) + ((0.8192 * fg) - 1.0004));
const calcRound = round(calc, 2);
return calcRound;
}
// if its not a number, throw an error
throw new Error('arguments must be a number');
};
/**
* Calculate number of calories in 12oz serving.
* @module caloriesTotal
* @param {number} og original gravity (og)
* @param {number} fg final gravity (fg)
* @see {@link https://www.homebrewersassociation.org/how-to-brew/how-many-calories-are-in-beer/|www.homebrewersassociation.org}
* @return {number} calories from alcohol + calories from carbs
*
* @example
* // returns 301.65
* caloriesTotal(1.088, 1.012);
*/
export const caloriesTotal = (og, fg) => {
if (isNum(og, fg)) {
const calc = caloriesAlcohol(og, fg) + caloriesCarbs(og, fg);
const calcRound = round(calc, 2);
return calcRound;
}
// if its not a number, throw an error
throw new Error('arguments must be a number');
};
/**
* Calculate the apparent attenuation
* @module aAttenuation
* @param {number} og original gravity (og)
* @param {number} fg final gravity (fg)
* @see {@link http://hbd.org/ensmingr/|hbd.org/ensmingr}
* @return {number} 100 x (1 - (°Pf / °Pi))
*
* @example
* // return 85.3
* aAttenuation(1.088, 1.012);
*/
export const aAttenuation = (og, fg) => {
if (isNum(og, fg)) {
const calc = 100 * (1 - (sg2plato(fg) / sg2plato(og)));
const calcRound = round(calc, 1);
return calcRound;
}
// if its not a number, throw an error
throw new Error('arguments must be a number');
};
/**
* Calculate the real attenuation
* @module rAttenuation
* @param {number} og original gravity (og)
* @param {number} fg final gravity (fg)
* @see {@link http://hbd.org/ensmingr/|hbd.org/ensmingr}
* @return {number} 100 x (1 - (real extract / °Pi)
*
* @example
* // return 68.9
* rAttenuation(1.088, 1.012);
*/
export const rAttenuation = (og, fg) => {
if (isNum(og, fg)) {
const calc = 100 * (1 - (realExtract(og, fg) / sg2plato(og)));
const calcRound = round(calc, 1);
return calcRound;
}
// if its not a number, throw an error
throw new Error('arguments must be a number');
};
/**
* Calculate Alpha Acid Units
* @module aau
* @param {number} weight weight of hops (in oz)
* @param {number} aa Alpha Acidic percentage
* @todo Add imperial unit option (grams)
* @return {number} weight x Alpha Acid Percentage
*
* @example
* // returns 18
* aau(1.5, 12);
*/
export const aau = (weight, aa) => {
if (isNum(weight, aa)) {
return weight * aa;
}
// if its not a number, throw an error
throw new Error('arguments must be a number');
};
/**
* Hop Utilization (Tinseth)
* @module utilization
* @param {number} time time left in boil (minutes)
* @param {number} gravity Specific gravity (sg) of pre-boil wort
* @see {@link http://realbeer.com/hops/research.html|realbeer.com}
* @todo Add rager scale option
* @return {number} utilization = bigness factor x boil time factor
*
* @example
* // returns 0.2348476097710606
* utilization(60, 1.048);
*/
export const utilization = (time, gravity) => {
if (isNum(time, gravity)) {
const bigness = (1.65 * (0.000125 ** (gravity - 1)));
const timeFactor = (1 - (Math.E ** (-0.04 * time))) / 4.15;
return bigness * timeFactor;
}
// if its not a number, throw an error
throw new Error('arguments must be a number');
};
/**
* Calculate IBU for hop addition (Tinseth / pellets)
* @module ibu
* @param {number} weight Weight of hops (oz)
* @param {number} aa Alpha acids percentage of hops
* @param {number} time time left in boil (minutes)
* @param {number} gravity Specific Gravity of wort (pre-boil)
* @param {number} volume post boil volume (gallons)
* @param {number} adjust percentage to adjust hop utilization
* @see {@link http://howtobrew.com/book/section-1/hops/hop-bittering-calculations|howtobrew.com/}
* @todo allow for grams for hops
* @todo allow for liter for volume
* @todo allow for rager scale
* @todo allow for whole hops
* @return {number} (aau x utilization x 74.89) / volume
*
* @example
* // returns 63.3
* ibu(1.5, 12, 60, 1.048, 5.5);
*/
export const ibu = (weight, aa, time, gravity, volume, adjust) => {
if (isNum(weight, aa, time, gravity, volume)) {
let utilizationNum;
if (adjust) {
utilizationNum = utilization(time, gravity) * ((adjust / 100) + 1);
} else {
utilizationNum = utilization(time, gravity);
}
const calc = (aau(weight, aa) * utilizationNum * 74.89) / volume;
const calcRound = round(calc, 1);
return calcRound;
}
// if its not a number, throw an error
throw new Error('arguments must be a number');
};
/**
* SRM to Lovibond
* @module srm2lovibond
* @param {number} srm SRM # to be converted
* @see {@link https://en.wikipedia.org/wiki/Standard_Reference_Method}
* @return {number} Lovibond = (SRM + 0.76) / 1.3546
*
* @example
* // return 6.5
* srm2lovibond(8);
*
* // return 22.7
* srm2lovibond(30);
*/
export const srm2lovibond = (srm) => {
if (isNum(srm)) {
const calc = (srm + 0.76) / 1.3546;
const calcRound = round(calc, 1);
return calcRound;
}
// if its not a number, throw an error
throw new Error('arguments must be a number');
};
/**
* Lovibond to SRM
* @module lovibond2srm
* @param {number} srm Lovibond # to be converted
* @see {@link https://en.wikipedia.org/wiki/Standard_Reference_Method}
* @return {number} SRM = (1.3546 × lovibond) - 0.76
*
* @example
* // return 8.7
* lovibond2srm(7);
*
* // return 30.4
* lovibond2srm(23);
*/
export const lovibond2srm = (lovibond) => {
if (isNum(lovibond)) {
const calc = (1.3546 * lovibond) - 0.76;
const calcRound = round(calc, 1);
return calcRound;
}
// if its not a number, throw an error
throw new Error('arguments must be a number');
};
/**
* Calculate Malt Color Units
* @module mcu
* @param {number} weight weight of grain/fermentable (in lb)
* @param {number} lovibond color of grains in lovibond
* @param {number} volume batch size (in gallons) including deadspace/trub loss
* @todo support kg for weight
* @todo support liter for volume
* @return {number} (weight * lovibond) / volume
*
* @example
* // return 5.727
* mcu(9, 3.5, 5.5);
*/
export const mcu = (weight, lovibond, volume) => {
if (isNum(weight, lovibond, volume)) {
const calc = (weight * lovibond) / volume;
const calcRound = round(calc, 3);
return calcRound;
}
// if its not a number, throw an error
throw new Error('arguments must be a number');
};
/**
* Calculates color (SRM) of eer using standard reference method (Morey equation)
* @module srm.
* @param {...number} mcuNum MCU units to covert to SRM. Accepts infinite # of arguments.
* @return {number} 1.4922 x (MCU ^ 0.6859)
*
* @example
* // returns 4.9
* srm(5.72);
*
* // returns 6.4
* srm(5.72, 2.54);
*/
export const srm = (...mcuNum) => {
let totalMcu = 0;
for (let i = 0; i < mcuNum.length; i += 1) {
if (isNum(mcuNum[i])) {
totalMcu += mcuNum[i];
} else {
// if its not a number, throw an error
throw new Error('arguments must be a number');
}
}
const calc = 1.4922 * (totalMcu ** 0.6859);
const calcRound = round(calc, 1);
return calcRound;
};
/**
* Convert specific gravity (sg) to gravity points.
* @module sg2gp
* @param {number} sg The specific gravity (sg)
* @return {number} (sg - 1) x 1000
*
* @example
* // return 88
* sg2gp(1.088);
*/
export const sg2gp = (sg) => {
if (isNum(sg)) {
const calc = (sg - 1) * 1000;
const calcRound = round(calc);
return calcRound;
}
// if its not a number, throw an error
throw new Error('arguments must be a number');
};
/**
* Convert gravity points to specific gravity (sg)
* @module gp2sg
* @param {number} gp Gravitiy points
* @return {number} (gravity points / 1000) + 1
*
* @example
* // return 1.088
* gp2sg(88);
*/
export const gp2sg = (gp) => {
if (isNum(gp)) {
const calc = (gp / 1000) + 1;
return calc;
}
// if its not a number, throw an error
throw new Error('arguments must be a number');
};
/**
* Calculate new SG when wort is diluted
* @module dilute
* @param {number} sg Specific Gravity of pre-diluted wort
* @param {number} volume initial volume
* @param {number} volumeAdd Volume of water to add
* @return {number} (returns SG) GP = (Initial Volume * initial GP) / New Total Volume
*
* @example
* // return 1.046
* dilute(1.054, 6, 1);
*/
export const dilute = (sg, volume, volumeAdd) => {
if (isNum(sg, volume, volumeAdd)) {
const sgNum = sg2gp(sg);
let calc = (sgNum * volume) / (volume + volumeAdd);
calc = gp2sg(calc);
const calcRound = round(calc, 3);
return calcRound;
}
// if its not a number, throw an error
throw new Error('arguments must be a number');
};
/**
* Calculate water needed to reach target gravity.
* @module adjustWater
* @param {number} sg Current/Specific gravity (sg)
* @param {number} tg Target gravity
* @param {number} volume current volume (gallons)
* @todo support liters for input volume
* @todo support liters for return
* @return {number} (volume x sg / target gravity points) - volume
*
* @example
* // return .64
* adjustWater(1.088, 1.078, 5);
*/
export const adjustWater = (sg, tg, volume) => {
if (!isNum(sg, tg, volume)) {
// if arguments are not a number, throw an error
throw new Error('arguments must be a number');
} else if (sg < tg) {
// if target gravity number is not less than specific gravity.
throw new Error('target gravity must be less than specific gravity');
} else {
const calc = ((volume * sg2gp(sg)) / sg2gp(tg)) - volume;
const calcRound = round(calc, 2);
return calcRound;
}
};
/**
* Calculate how much extract (in lb) is needed to reach target gravity.
* @module adjustExtract
* @param {number} sg Current / specific gravity (sg)
* @param {number} tg target gravity
* @param {number} volume volume (gallons)
* @param {(string|number)} extract 'DME', 'LME', or custom gravity point value.
* @todo support liters for input volume.
* @todo support kilograms for output volume
* @return {number} lb = (target gravity - sg) x volume / extract gravity points
*
* @example
* // return 1.39
* adjustExtract(1.078, 1.088, 5, 'LME');
*
* // return 1.14
* adjustExtract(1.078, 1.088, 5, 'DME');
*
* // return 1.14
* adjustExtract(1.078, 1.088, 5, 46);
*/
export const adjustExtract = (sg, tg, volume, extract) => {
if (sg > tg) {
throw new Error('target travity must be greater than specific gravity');
} else if (!isNum(sg, tg, volume)) {
// if arguments are not a number, throw an error
throw new Error('arguments must be a number');
} else {
let extractType = '';
if (extract === 'LME') {
extractType = 36;
} else if (extract === 'DME') {
extractType = 44;
} else if (isNum(extract)) {
extractType = extract;
} else {
throw new Error('invalid extract argument');
}
const calc = (sg2gp(tg) - sg2gp(sg)) * volume / extractType;
const calcRound = round(calc, 2);
return calcRound;
}
};
/**
* Calculate how much volume (gallons) is lost per hour to evaperation
* @module evapLossPerHour
* @param {number} volume pre-boil volume (gallons)
* @param {number} ratePerHour percentage or voluem lost per hour
* @param {string} [rateMeasurement=percentage] set rate measurement to 'percentage' or 'volume'
* @todo option for input volume to be liters
* @todo option for output volume to be liters
* @return {number} volume x (percentage lost per hour / 100)
*
* @example
* // return 0.60
* evapPerHour(6, 10);
*
* // return 0.60
* evapPerHour(6, 10, 'percentage');
*
* // return 0.50
* evapPerHour(6, .5, 'volume');
*/
export const evapLossPerHour = (volume, ratePerHour, rateMeasurement = 'percentage') => {
if (isNum(volume, ratePerHour)) {
if (rateMeasurement === 'percentage') {
const calc = volume * (ratePerHour / 100);
const calcRound = round(calc, 2);
return calcRound;
} else if (rateMeasurement === 'volume') {
const calcRound = round(ratePerHour, 2);
return calcRound;
}
throw new Error('invalid measurement argument');
}
// if arguments are not a number, throw an error
throw new Error('volume & rate must be a number');
};
/**
* Calculate total volume (gallons) lost during boil to evaperation
* @module totalBoilLoss
* @param {number} lossPerHour amount of volume (in lb) lost per hour to evaperation
* @param {number} boilTime length of boil (in minutes)
* @todo support volume input in liters
* @todo support volume output in liters
* @return {number} evapLossPerHour x (boilTime / 60)
*
* @example
* // return 0.90
* totalBoilLoss(.60, 90);
*/
export const totalBoilLoss = (lossPerHour, boilTime) => {
if (isNum(lossPerHour, boilTime)) {
const calc = lossPerHour * (boilTime / 60);
const calcRound = round(calc, 2);
return calcRound;
}
// if arguments are not a number, throw an error
throw new Error('arguments must be a number');
};
/**
* Volume lost after wort cools (in gallons)
* @module shrinkage
* @param {number} volume pre-boil volume (gallons)
* @param {number} boilLoss Amount of volume (gallons) lost to boil.
* @param {number} [percentage = 4] percentage the wort shrinks due to cooling
* @todo support input volume in liters
* @todo support return volume in liters
* @todo support boilLoss in liters
* @return {number} volume x (percentage/100)
*
* @example
* // return 0.24
* shrinkage(7, 0.90);
*
* // return 0.15
* shrinkage(7, 0.90, 3);
*/
export const shrinkage = (volume, boilLoss, percentage = 4) => {
if (isNum(volume, boilLoss, percentage)) {
const calc = (volume - boilLoss) * (percentage / 100);
const calcRound = round(calc, 2);
return calcRound;
}
// if arguments are not a number, throw an error
throw new Error('arguments must be a number');
};
/**
* Calculate post boil volume (gallons)
* @module postBoilVolume
* @param {number} startVol Starting volume pre-boil (gallons)
* @param {number} boilLoss volume loss to boil (gallons)
* @param {number} shrinkLoss volume loss to shrinking during cooling (gallons)
* @todo support input startVal in liters
* @todo support input boilLoss in liters
* @todo support input shrinkLoss in liters
* @todo support return value in liters
* @return {number} start_volume - (boil_loss + shrink_loss)
*
* @example
* // return 6.86
* postBoilVolume(7, 0.90, 0.24)
*/
export const postBoilVolume = (startVol, boilLoss, shrinkLoss) => {
if (isNum(startVol, boilLoss, shrinkLoss)) {
const calc = startVol - (boilLoss + shrinkLoss);
const calcRound = round(calc, 2);
return calcRound;
}
// if arguments are not a number, throw an error
throw new Error('arguments must be a number');
};
/**
* Calculate post boil gravity.
* @module postBoilGravity
* @param {number} startVol Starting volume (gallons)
* @param {number} sg starting gravity (sg)
* @param {number} finalVol Final volume (gallons)
* @todo support starting volume in liters
* @todo support final volume in liters
* @return {number} (starting_volume x gravity_points) / final_volume
*
* @example
* // return 1.072
* postBoilGravity(7, 1.059, 5.71)
*/
export const postBoilGravity = (startVol, sg, finalVol) => {
if (isNum(startVol, sg, finalVol)) {
let calc = (startVol * sg2gp(sg)) / finalVol;
calc = gp2sg(calc);
const calcRound = round(calc, 3);
return calcRound;
}
// if arguments are not a number, throw an error
throw new Error('arguments must be a number');
};
/**
* Estimate Original Gravity
* @module estimateOriginalGravity
* @param {number} gravityPoints Total gravity points of fermentables
* @param {number} sugarPoints Total gravity points from sugars (dextrose, etc)
* @param {number} efficiency (mash or brewhouse)
* @param {number} vol into fermentor (if brewhouse eff) or pre-boil vol (if mash eff)
* @todo support liters
* @return {number} (gravityPoints * efficiency) / volume
*
* @example
* // return 1.061
* estimateOriginalGravity(429, 46, 75, 6)
*/
export const estimateOriginalGravity = (
gravityPoints,
sugarPoints,
efficiency,
volume // eslint-disable-line
) => {
if (isNum(gravityPoints, efficiency, volume)) {
// first get the gravity points for sugars
const sugarGravityPoints = sugarPoints / volume;
// then get gravity points for all fermentables
let calc = ((gravityPoints * efficiency * 0.01) / volume);
// combine the two
calc += sugarGravityPoints;
calc = gp2sg(calc);
const calcRound = round(calc, 3);
return calcRound;
}
throw new Error('arguments must be a number');
};
/**
* Estimate Final Gravity Points
* @module estimateFinalGravity
* @param {number} attenuation Attenuiation % from yeast
* @param {number} gravityPoints Gravity points
* @param {bool} rounded if return value should be rounded (optional)
* @return {number} Final GP = (1 - (attenuation)) * gravityPoints
* @todo allow to adjust center temp & slope %
*
* @example
* // return 13.5
* estimateFinalGravity(75, 54)
*
* // return 14
* estimateFinalGravity(75, 54, true)
*/
export const estimateFinalGP = (attenuation, gravityPoints, rounded) => {
if (isNum(attenuation, gravityPoints)) {
let calc = (1 - (attenuation * 0.01)) * gravityPoints;
if (rounded) {
calc = round(calc, 0);
}
return calc;
}
throw new Error('estimateFinalGP must be a number');
};
/**
* Estimate Final Gravity (adjusted for simple sugars & mash temp)
* @module estimateFinalGravity
* @param {number} grainPoints Total gravity points from grains (exclude sugars like dextrose)
* @param {number} sugarPoints Total gravity points from sugars (dextrose, etc)
* @param {number} attenuation % from yeast
* @param {number} mashTemp (optional)
* @return {number} FG = (1 - (attenuation x .01)) * GP
*
* @example
* // return 1.061
* estimateFinalGravity(54, 17, 75, 154)
*/
export const estimateFinalGravity = (
grainPoints,
sugarPoints,
attenuation,
mashTemp // eslint-disable-line
) => {
if (isNum(grainPoints, sugarPoints, attenuation)) {
let finalAttenuation = attenuation;
// first, update attenuation from provided mash temp
if (mashTemp) {
// constants (may update formula to customize later)
const adjustTempConstant = 151;
const adjustPerDegree = -1.25;
// how much to adjust attenuation because of mash temp
const attenuationAdjust = (mashTemp - adjustTempConstant) * adjustPerDegree;
finalAttenuation = attenuation + attenuationAdjust;
}
// first get the gravity points for grains (or all non-simple sugars)
const finalGrainPoints = estimateFinalGP(finalAttenuation, grainPoints);
// then get gravity points for all simple sugars
const finalSugarPoints = estimateFinalGP(122, sugarPoints);
// combine
const finalPoints = finalGrainPoints + finalSugarPoints;
// convert to specific gravity
let calc = gp2sg(finalPoints);
calc = calc.toFixed(3);
return calc;
}
throw new Error('estimateFinalGravity arguments must be a number');
};