-
Notifications
You must be signed in to change notification settings - Fork 0
/
recipe.py
executable file
·154 lines (120 loc) · 5.51 KB
/
recipe.py
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
# Copyright (c) 2009 Jeremy English <jhe@jeremyenglish.org>
# Permission to use, copy, modify, distribute, and sell this software
# and its documentation for any purpose is hereby granted without fee,
# provided that the above copyright notice appear in all copies and
# that both that copyright notice and this permission notice appear in
# supporting documentation. No representations are made about the
# suitability of this software for any purpose. It is provided "as
# is" without express or implied warranty.
# Created: 06-April-2009
from brewconst import *
from grains import *
from ingredients import *
from batchsparge import *
from extractNeeded import *
from brewconv import *
from hops import *
from report import runReport
from yeast import *
class Recipe:
def __init__(self, name="", tg=0.0, boiltime=1, grain_bill=[], vol=5,
mash_temp=153, hops=[], yeast=[], notes="", trub=0.5,
brew_const = DEF_BREW_CONST):
self.tg = tg
self.grain_bill = grain_bill
self.vol = vol
self.name = name
self.boiltime = boiltime
self.mash_temp = mash_temp
self.hops = hops
self.yeast = yeast
self.notes = notes
self.trub = trub
self.brew_const = brew_const
def add_to_grain_bill(self,ingredient):
self.grain_bill.append(ingredient)
def add_hops(self,hop):
self.hops.append(hop)
def add_yeast(self,yeast):
self.yeast.append(yeast)
def set_lbs_by_percent(self):
"""Call this function to set pounds of the grain bill to match
their percentages."""
nlbs = lbs_needed_by_percent(self.tg, self.vol, self.grain_bill)
for i in range(len(nlbs)):
self.grain_bill[i].lbs = nlbs[i]
def total_lbs(self):
tlbs = 0
for i in self.grain_bill:
tlbs = i.lbs + tlbs
return tlbs
def report(self, type='pdf'):
if len(self.grain_bill) <= 0:
raise "We needed some grains for the recipe."
trub = self.trub
text = '*%s\n' % (self.name)
text = text + "\nRecipe for a %f gallon batch\n" % (self.vol)
text = text + "\n+Grains\n\n"
if self.grain_bill[0].percent > 0:
if self.tg == 0:
raise "When specifing ingredients by percent a target gravity is needed."
else:
self.set_lbs_by_percent()
tlbs = self.total_lbs()
for i in self.grain_bill:
ppg = float(i.grain)
p = float_div(i.lbs,tlbs) * 100.0
ps = "%3.3f%s" % (p, '%')
lbss = "%.3f" % (i.lbs)
ozs = "%5.3f" % (lbs_to_oz(i.lbs))
text = text + "|%s|%s|%s|%s|\n" % (str(i.grain),
lbss + ' lbs',
ozs + ' oz',
ps)
text = text + "total lbs: %f\n" % tlbs
sg = sg_of_grain_bill(self.vol,self.grain_bill)
text = text + "\nog: %s (%d Plato)\n" % (round_sg(sg), sg_to_plato(sg))
preboil = self.vol + trub + (self.boiltime * self.brew_const.evph)
bog = sg_of_grain_bill(preboil, self.grain_bill)
text = text + "bg: %s (%d Plato) for %f gallons\n" % (round_sg(bog),sg_to_plato(bog),preboil)
text = text + "\n+Hops\n\n"
tibu = 0.0
for i in self.hops:
n = ibu(i.woz, i.hop.aa, bog, i.time, self.vol)
text = text + "%s IBU|%d|\n" %( str(i), n)
tibu = n + tibu
text = text + "Total IBUs = %5.3f\n" % (tibu)
text = text + "\n+Yeast\n\n"
for i in self.yeast:
text = text + '|' + str(i) + '|'
text = text + '%dB cells|' % (i.cells_needed(sg, self.vol)/1000000000)
if i.liquid:
tubes, starter = i.amount_needed(sg, self.vol)
text = text + '%.3f tubes| %dL starter|'% (tubes, starter)
else:
grams, starter = i.amount_needed(sg, self.vol)
text = text + '%.3fg||' % (grams) #no starter for dry yeast
text = text + '%d-%dF|\n' %(i.lowTemp, i.highTemp)
sw, br, hv = batch_sparge_nums(tlbs,self.vol)
text = text + "\n+Brewing Instructions\n\n"
swt = strike_water_temp(tlbs, sw, self.mash_temp, brew_const=self.brew_const)
sw, br, hv = batch_sparge_nums(tlbs,preboil)
swq = gal_to_qt(sw)
hvq = gal_to_qt(hv)
brq = gal_to_qt(br)
t = sw + hv + br
tq = gal_to_qt(t)
text = text + "You will need %.4f gallons (or %.4f qt) of \
%3.1fF or %3.1fC strike water.\n" % (sw, swq, swt, fah_to_cel(swt))
text = text + "Mash at %3.2fF (%3.2fC) until complete.\n" % (self.mash_temp, fah_to_cel(self.mash_temp))
text = text + "\nUsing the batch sparge method.\n"
text = text + "You will need to add %.4f gallons \
(or %.4f qt) of water before the runoff.\n" % (br, brq)
text = text + "You will need %.4f gallons (or %.4f qt) of sparge water.\n" % (hv, hvq)
text = text + "\nPre-Boil Volume: %.3f\n" % (preboil)
text = text + "Length of the boil: %.3f hours\n" % (self.boiltime)
text = text + "\nTotal amount of water needed %.4f gallons (or %.4f qt)\n" % (t, tq)
text = text + "\n+Notes\n\n"
for i in self.notes.split('\n'):
text = text + i.strip() + '\n'
runReport(type, text=text, filename='%s.%s' % (self.name.replace(" ", "-"),type))