mirror of
https://github.com/shouptech/humulus.git
synced 2026-02-03 14:59:43 +00:00
Add percentages of fermentables
This commit is contained in:
parent
0260d300d3
commit
d658780d56
3 changed files with 28 additions and 1 deletions
|
|
@ -134,6 +134,21 @@ def sort_hops(hops, form=False):
|
|||
return hops_sorted
|
||||
|
||||
|
||||
def ferm_pct(fermentables):
|
||||
"""Adds a 'pct' to each fermentable in fermentables.
|
||||
|
||||
'pct' represents the total percentage a fermentable makes up of the grist.
|
||||
"""
|
||||
total = 0
|
||||
# Calculate total
|
||||
for ferm in fermentables:
|
||||
total += float(ferm['amount'])
|
||||
# Add a pct to each ferm
|
||||
for ferm in fermentables:
|
||||
ferm['pct'] = 100*float(ferm['amount'])/total
|
||||
return fermentables
|
||||
|
||||
|
||||
def create_filters(app):
|
||||
app.add_template_filter(recipe_og)
|
||||
app.add_template_filter(recipe_fg)
|
||||
|
|
@ -142,3 +157,4 @@ def create_filters(app):
|
|||
app.add_template_filter(recipe_abv)
|
||||
app.add_template_filter(recipe_srm)
|
||||
app.add_template_filter(sort_hops)
|
||||
app.add_template_filter(ferm_pct)
|
||||
|
|
|
|||
|
|
@ -122,14 +122,16 @@
|
|||
<th>Amount</th>
|
||||
<th>PPG</th>
|
||||
<th>Color</th>
|
||||
<th>%</th>
|
||||
</tr>
|
||||
</thead>
|
||||
{%- for fermentable in recipe.fermentables|sort(attribute='amount', reverse=True) -%}
|
||||
{%- for fermentable in recipe.fermentables|ferm_pct|sort(attribute='amount', reverse=True) -%}
|
||||
<tr>
|
||||
<td>{{ fermentable.name }}</td>
|
||||
<td>{{ fermentable.amount|float|round(2) }} lb.</td>
|
||||
<td>{{ fermentable.ppg|float|round }}</td>
|
||||
<td>{{ fermentable.color|float|round(1) }}°L</td>
|
||||
<td>{{ fermentable.pct|float|round(1) }}%</td>
|
||||
</tr>
|
||||
{%- endfor -%}
|
||||
</table>
|
||||
|
|
|
|||
|
|
@ -103,3 +103,12 @@ def test_sort_hops():
|
|||
|
||||
for num, hop in enumerate(sort_hops(hop_forms, form=True)):
|
||||
assert hop.name.data == str(num)
|
||||
|
||||
|
||||
def test_ferm_pct():
|
||||
ferms = [{'amount': '4'}, {'amount': '2'}, {'amount': '2'}]
|
||||
assert ferm_pct(ferms) == [
|
||||
{'amount': '4', 'pct': 50.0},
|
||||
{'amount': '2', 'pct': 25.0},
|
||||
{'amount': '2', 'pct': 25.0}
|
||||
]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue