mirror of
https://github.com/shouptech/humulus.git
synced 2026-02-03 17:19:42 +00:00
Add all filters.
This commit is contained in:
parent
be8806c28f
commit
e5a9f35fcb
3 changed files with 87 additions and 9 deletions
|
|
@ -79,7 +79,38 @@ def recipe_ibu(recipe):
|
||||||
return '{:.0f}'.format(ibu)
|
return '{:.0f}'.format(ibu)
|
||||||
|
|
||||||
|
|
||||||
|
def recipe_ibu_ratio(recipe):
|
||||||
|
"""Return a recipe's IBU ratio"""
|
||||||
|
if 'fermentables' not in recipe or 'hops' not in recipe:
|
||||||
|
return '0'
|
||||||
|
og = float(recipe_og(recipe))
|
||||||
|
ibu = float(recipe_ibu(recipe))
|
||||||
|
return '{:.2f}'.format(round(0.001 * ibu / (og - 1), 2))
|
||||||
|
|
||||||
|
|
||||||
|
def recipe_abv(recipe):
|
||||||
|
"""Return a recipe's finished ABV"""
|
||||||
|
if 'fermentables' not in recipe or 'yeast' not in recipe:
|
||||||
|
return '0'
|
||||||
|
og = float(recipe_og(recipe))
|
||||||
|
fg = float(recipe_fg(recipe))
|
||||||
|
return '{:.1f}'.format(round((og - fg) * 131.25, 1))
|
||||||
|
|
||||||
|
|
||||||
|
def recipe_srm(recipe):
|
||||||
|
"""Return a recipe's SRM"""
|
||||||
|
if 'fermentables' not in recipe:
|
||||||
|
return '0'
|
||||||
|
mcu = 0
|
||||||
|
for f in recipe['fermentables']:
|
||||||
|
mcu += float(f['amount']) * float(f['color']) / float(recipe['volume'])
|
||||||
|
return '{:.0f}'.format(1.4922 * (mcu**0.6859))
|
||||||
|
|
||||||
|
|
||||||
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)
|
||||||
app.add_template_filter(recipe_ibu)
|
app.add_template_filter(recipe_ibu)
|
||||||
|
app.add_template_filter(recipe_ibu_ratio)
|
||||||
|
app.add_template_filter(recipe_abv)
|
||||||
|
app.add_template_filter(recipe_srm)
|
||||||
|
|
|
||||||
|
|
@ -32,12 +32,6 @@
|
||||||
<dd>{{ recipe.efficiency|int }}%</dd>
|
<dd>{{ recipe.efficiency|int }}%</dd>
|
||||||
<dt>Batch Volume</dt>
|
<dt>Batch Volume</dt>
|
||||||
<dd>{{ recipe.volume|float|round(1) }} gal.</dd>
|
<dd>{{ recipe.volume|float|round(1) }} gal.</dd>
|
||||||
<dt>OG</dt>
|
|
||||||
<dd>{{ recipe|recipe_og }}</dd>
|
|
||||||
<dt>FG</dt>
|
|
||||||
<dd>{{ recipe|recipe_fg }}</dd>
|
|
||||||
<dt>IBU</dt>
|
|
||||||
<dd>{{ recipe|recipe_ibu }}</dd>
|
|
||||||
</dl>
|
</dl>
|
||||||
</div>
|
</div>
|
||||||
<div class="col">
|
<div class="col">
|
||||||
|
|
@ -53,11 +47,34 @@
|
||||||
</dl>
|
</dl>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="row"><h3>Estimated Specifications</h3></div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col">
|
||||||
|
<dl>
|
||||||
|
<dt>Original Gravity</dt>
|
||||||
|
<dd>{{ recipe|recipe_og }}</dd>
|
||||||
|
<dt>Final Gravity</dt>
|
||||||
|
<dd>{{ recipe|recipe_fg }}</dd>
|
||||||
|
<dt>Alcohol</dt>
|
||||||
|
<dd>{{ recipe|recipe_abv }} %/vol.</dd>
|
||||||
|
</dl>
|
||||||
|
</div>
|
||||||
|
<div class="col">
|
||||||
|
<dl>
|
||||||
|
<dt>Bitterness</dt>
|
||||||
|
<dd>{{ recipe|recipe_ibu }} IBU</dd>
|
||||||
|
<dt>Bitterness Ratio</dt>
|
||||||
|
<dd>{{ recipe|recipe_ibu_ratio }} IBU/OG</dd>
|
||||||
|
<dt>Color</dt>
|
||||||
|
<dd>{{ recipe|recipe_srm }} SRM</dd>
|
||||||
|
</dl>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{#-
|
{#-
|
||||||
Fermentables
|
Fermentables
|
||||||
-#}
|
-#}
|
||||||
<div class="row border-top"><h2>Fermentables</h2></div>
|
<div class="row border-top"><h2>Fermentables</h2></div>
|
||||||
<div class="row"><div class="col">
|
<div class="row"><div class="table-responsive">
|
||||||
<table class="table table-hover table-sm">
|
<table class="table table-hover table-sm">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
|
@ -81,7 +98,7 @@
|
||||||
Hops
|
Hops
|
||||||
-#}
|
-#}
|
||||||
<div class="row border-top"><h2>Hops</h2></div>
|
<div class="row border-top"><h2>Hops</h2></div>
|
||||||
<div class="row"><div class="col">
|
<div class="row"><div class="table-responsive">
|
||||||
<table class="table table-hover table-sm">
|
<table class="table table-hover table-sm">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
|
@ -108,7 +125,7 @@
|
||||||
-#}
|
-#}
|
||||||
{% if 'yeast' in recipe %}
|
{% if 'yeast' in recipe %}
|
||||||
<div class="row border-top"><h2>Yeast</h2></div></div>
|
<div class="row border-top"><h2>Yeast</h2></div></div>
|
||||||
<div class="row"><div class="col">
|
<div class="row"><div class="table-responsive">
|
||||||
<table class="table table-hover table-sm">
|
<table class="table table-hover table-sm">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
|
|
||||||
|
|
@ -41,3 +41,33 @@ def test_recipe_ibu(sample_recipes):
|
||||||
# Remove hops, verify 0 is returned
|
# Remove hops, verify 0 is returned
|
||||||
sample_recipes['lager'].pop('hops')
|
sample_recipes['lager'].pop('hops')
|
||||||
assert recipe_ibu(sample_recipes['lager']) == '0'
|
assert recipe_ibu(sample_recipes['lager']) == '0'
|
||||||
|
|
||||||
|
|
||||||
|
def test_recipe_ibu_ratio(sample_recipes):
|
||||||
|
assert recipe_ibu_ratio(sample_recipes['lager']) == '0.48'
|
||||||
|
assert recipe_ibu_ratio(sample_recipes['sweetstout']) == '0.89'
|
||||||
|
# Remove fermentables, verify 0 is returned
|
||||||
|
sample_recipes['lager'].pop('fermentables')
|
||||||
|
assert recipe_ibu_ratio(sample_recipes['lager']) == '0'
|
||||||
|
# Remove hops, verify 0 is returned
|
||||||
|
sample_recipes['sweetstout'].pop('hops')
|
||||||
|
assert recipe_ibu_ratio(sample_recipes['sweetstout']) == '0'
|
||||||
|
|
||||||
|
|
||||||
|
def test_recipe_abv(sample_recipes):
|
||||||
|
assert recipe_abv(sample_recipes['lager']) == '5.3'
|
||||||
|
assert recipe_abv(sample_recipes['sweetstout']) == '3.0'
|
||||||
|
# Remove fermentables, verify 0 is returned
|
||||||
|
sample_recipes['lager'].pop('fermentables')
|
||||||
|
assert recipe_abv(sample_recipes['lager']) == '0'
|
||||||
|
# Remove yeast, verify 0 is returned
|
||||||
|
sample_recipes['sweetstout'].pop('yeast')
|
||||||
|
assert recipe_abv(sample_recipes['sweetstout']) == '0'
|
||||||
|
|
||||||
|
|
||||||
|
def test_recipe_srm(sample_recipes):
|
||||||
|
assert recipe_srm(sample_recipes['lager']) == '3'
|
||||||
|
assert recipe_srm(sample_recipes['sweetstout']) == '21'
|
||||||
|
# Remove fermentables, verify 0 is returned
|
||||||
|
sample_recipes['lager'].pop('fermentables')
|
||||||
|
assert recipe_srm(sample_recipes['lager']) == '0'
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue