1
0
Fork 0
mirror of https://github.com/shouptech/humulus.git synced 2026-02-03 17:19:42 +00:00

Add percentages of fermentables

This commit is contained in:
Emma 2019-07-11 17:49:29 -06:00
parent 0260d300d3
commit d658780d56
No known key found for this signature in database
GPG key ID: 68434BFE85360755
3 changed files with 28 additions and 1 deletions

View file

@ -134,6 +134,21 @@ def sort_hops(hops, form=False):
return hops_sorted 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): def create_filters(app):
app.add_template_filter(recipe_og) app.add_template_filter(recipe_og)
app.add_template_filter(recipe_fg) 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_abv)
app.add_template_filter(recipe_srm) app.add_template_filter(recipe_srm)
app.add_template_filter(sort_hops) app.add_template_filter(sort_hops)
app.add_template_filter(ferm_pct)

View file

@ -122,14 +122,16 @@
<th>Amount</th> <th>Amount</th>
<th>PPG</th> <th>PPG</th>
<th>Color</th> <th>Color</th>
<th>%</th>
</tr> </tr>
</thead> </thead>
{%- for fermentable in recipe.fermentables|sort(attribute='amount', reverse=True) -%} {%- for fermentable in recipe.fermentables|ferm_pct|sort(attribute='amount', reverse=True) -%}
<tr> <tr>
<td>{{ fermentable.name }}</td> <td>{{ fermentable.name }}</td>
<td>{{ fermentable.amount|float|round(2) }} lb.</td> <td>{{ fermentable.amount|float|round(2) }} lb.</td>
<td>{{ fermentable.ppg|float|round }}</td> <td>{{ fermentable.ppg|float|round }}</td>
<td>{{ fermentable.color|float|round(1) }}°L</td> <td>{{ fermentable.color|float|round(1) }}°L</td>
<td>{{ fermentable.pct|float|round(1) }}%</td>
</tr> </tr>
{%- endfor -%} {%- endfor -%}
</table> </table>

View file

@ -103,3 +103,12 @@ def test_sort_hops():
for num, hop in enumerate(sort_hops(hop_forms, form=True)): for num, hop in enumerate(sort_hops(hop_forms, form=True)):
assert hop.name.data == str(num) 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}
]