mirror of
https://github.com/shouptech/humulus.git
synced 2026-02-03 22:29:42 +00:00
Compare commits
No commits in common. "673303a7bd65bf84f0c47372ab9270e10398a294" and "304f4c6d7e123483d66bf893df47a01c3440ac75" have entirely different histories.
673303a7bd
...
304f4c6d7e
5 changed files with 3 additions and 91 deletions
|
|
@ -111,62 +111,6 @@ def recipe_srm(recipe):
|
||||||
return '{:.0f}'.format(1.4922 * (mcu**0.6859))
|
return '{:.0f}'.format(1.4922 * (mcu**0.6859))
|
||||||
|
|
||||||
|
|
||||||
def sort_hops(hops, form=False):
|
|
||||||
"""Sorts a list of hops by use in recipe."""
|
|
||||||
by_use = {'FWH': [], 'Boil': [], 'Whirlpool': [], 'Dry-Hop': []}
|
|
||||||
|
|
||||||
# Split hops into each use type.
|
|
||||||
for hop in hops:
|
|
||||||
if form:
|
|
||||||
by_use[hop.use.data].append(hop)
|
|
||||||
else:
|
|
||||||
by_use[hop['use']].append(hop)
|
|
||||||
|
|
||||||
if form:
|
|
||||||
hops_sorted = sorted(
|
|
||||||
by_use['FWH'],
|
|
||||||
key=lambda hop: float(hop.duration.data),
|
|
||||||
reverse=True
|
|
||||||
)
|
|
||||||
hops_sorted.extend(
|
|
||||||
sorted(by_use['Boil'],
|
|
||||||
key=lambda hop: float(hop.duration.data),
|
|
||||||
reverse=True)
|
|
||||||
)
|
|
||||||
hops_sorted.extend(
|
|
||||||
sorted(by_use['Whirlpool'],
|
|
||||||
key=lambda hop: float(hop.duration.data),
|
|
||||||
reverse=True)
|
|
||||||
)
|
|
||||||
hops_sorted.extend(
|
|
||||||
sorted(by_use['Dry-Hop'],
|
|
||||||
key=lambda hop: float(hop.duration.data),
|
|
||||||
reverse=True)
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
hops_sorted = sorted(
|
|
||||||
by_use['FWH'],
|
|
||||||
key=lambda hop: float(hop['duration']),
|
|
||||||
reverse=True
|
|
||||||
)
|
|
||||||
hops_sorted.extend(
|
|
||||||
sorted(by_use['Boil'],
|
|
||||||
key=lambda hop: float(hop['duration']),
|
|
||||||
reverse=True)
|
|
||||||
)
|
|
||||||
hops_sorted.extend(
|
|
||||||
sorted(by_use['Whirlpool'],
|
|
||||||
key=lambda hop: float(hop['duration']),
|
|
||||||
reverse=True)
|
|
||||||
)
|
|
||||||
hops_sorted.extend(
|
|
||||||
sorted(by_use['Dry-Hop'],
|
|
||||||
key=lambda hop: float(hop['duration']),
|
|
||||||
reverse=True)
|
|
||||||
)
|
|
||||||
return hops_sorted
|
|
||||||
|
|
||||||
|
|
||||||
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)
|
||||||
|
|
@ -174,4 +118,3 @@ def create_filters(app):
|
||||||
app.add_template_filter(recipe_ibu_ratio)
|
app.add_template_filter(recipe_ibu_ratio)
|
||||||
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)
|
|
||||||
|
|
|
||||||
|
|
@ -108,6 +108,7 @@ def get_styles_list():
|
||||||
view = get_view('_design/styles', 'by-category')
|
view = get_view('_design/styles', 'by-category')
|
||||||
styles = [['', '']]
|
styles = [['', '']]
|
||||||
for row in view(include_docs=False)['rows']:
|
for row in view(include_docs=False)['rows']:
|
||||||
|
print(row)
|
||||||
styles.append([row['id'], '{}{} {}'.format(
|
styles.append([row['id'], '{}{} {}'.format(
|
||||||
row['key'][0],
|
row['key'][0],
|
||||||
row['key'][1],
|
row['key'][1],
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ function getSpecsURL() {
|
||||||
-#}
|
-#}
|
||||||
<div class="row"><div class="col"><h3>Hops</h3></div></div>
|
<div class="row"><div class="col"><h3>Hops</h3></div></div>
|
||||||
<div id="hops" data-length="{{ form.hops|length }}">
|
<div id="hops" data-length="{{ form.hops|length }}">
|
||||||
{% for hop in form.hops|sort_hops(form=True) %}
|
{% for hop in form.hops %}
|
||||||
<div class="border pl-2 pr-2 pt-1 pb-1 hop-form" data-index="{{ loop.index0 }}">
|
<div class="border pl-2 pr-2 pt-1 pb-1 hop-form" data-index="{{ loop.index0 }}">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
|
|
|
||||||
|
|
@ -149,7 +149,7 @@
|
||||||
<th>Usage</th>
|
<th>Usage</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
{%- for hop in recipe.hops|sort_hops -%}
|
{%- for hop in recipe.hops -%}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ hop.name }}</td>
|
<td>{{ hop.name }}</td>
|
||||||
<td>{{ hop.amount|float|round(2) }} oz.</td>
|
<td>{{ hop.amount|float|round(2) }} oz.</td>
|
||||||
|
|
|
||||||
|
|
@ -12,10 +12,8 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
from decimal import Decimal
|
|
||||||
|
|
||||||
from humulus.filters import *
|
from humulus.filters import *
|
||||||
from humulus.recipes import HopForm
|
|
||||||
|
|
||||||
|
|
||||||
def test_recipe_og(sample_recipes):
|
def test_recipe_og(sample_recipes):
|
||||||
|
|
@ -73,33 +71,3 @@ def test_recipe_srm(sample_recipes):
|
||||||
# Remove fermentables, verify 0 is returned
|
# Remove fermentables, verify 0 is returned
|
||||||
sample_recipes['lager'].pop('fermentables')
|
sample_recipes['lager'].pop('fermentables')
|
||||||
assert recipe_srm(sample_recipes['lager']) == '0'
|
assert recipe_srm(sample_recipes['lager']) == '0'
|
||||||
|
|
||||||
|
|
||||||
def test_sort_hops():
|
|
||||||
# Test with no form
|
|
||||||
hops = [
|
|
||||||
{'name': '4', 'use': 'Dry-Hop', 'duration': '5'},
|
|
||||||
{'name': '3', 'use': 'Whirlpool', 'duration': '10'},
|
|
||||||
{'name': '2', 'use': 'Boil', 'duration': '5'},
|
|
||||||
{'name': '1', 'use': 'Boil', 'duration': '15'},
|
|
||||||
{'name': '0', 'use': 'FWH', 'duration': '60'},
|
|
||||||
]
|
|
||||||
assert sort_hops(hops) == [
|
|
||||||
{'name': '0', 'use': 'FWH', 'duration': '60'},
|
|
||||||
{'name': '1', 'use': 'Boil', 'duration': '15'},
|
|
||||||
{'name': '2', 'use': 'Boil', 'duration': '5'},
|
|
||||||
{'name': '3', 'use': 'Whirlpool', 'duration': '10'},
|
|
||||||
{'name': '4', 'use': 'Dry-Hop', 'duration': '5'},
|
|
||||||
]
|
|
||||||
|
|
||||||
# Test with form
|
|
||||||
hop_forms = []
|
|
||||||
for hop in hops:
|
|
||||||
form = HopForm()
|
|
||||||
form.name.data = hop['name']
|
|
||||||
form.use.data = hop['use']
|
|
||||||
form.duration.data = Decimal(hop['duration'])
|
|
||||||
hop_forms.append(form)
|
|
||||||
|
|
||||||
for num, hop in enumerate(sort_hops(hop_forms, form=True)):
|
|
||||||
assert hop.name.data == str(num)
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue