From dae353ce7246642654eeba6ae2f138c5cb3f6e5b Mon Sep 17 00:00:00 2001 From: Mike Shoup Date: Fri, 4 Jan 2019 08:41:37 -0700 Subject: [PATCH] Fix #1 Updates so that dry hop time is displayed in time. --- src/synthale/recipes.py | 10 +++++++++- tests/recipes/weizen.xml | 13 +++++++++++++ tests/test_recipes.py | 11 ++++++++--- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/synthale/recipes.py b/src/synthale/recipes.py index 66bdaee..790c3a6 100644 --- a/src/synthale/recipes.py +++ b/src/synthale/recipes.py @@ -185,6 +185,7 @@ class MarkdownRecipe: headers = ('Name', 'Origin', 'Alpha', 'Amount', 'Time', 'Use') rows = [] for hop in self.recipe.hops: + # Determine hop unit if self.hop_unit == 'pounds': amt = convert.pounds(hop.amount, '.2f') elif self.hop_unit == 'grams': @@ -193,12 +194,19 @@ class MarkdownRecipe: amt = convert.kilograms(hop.amount, '.2f') else: amt = convert.ounces(hop.amount, '.1f') + + # Determine hop timing + if hop.use == 'Dry Hop': + # 1 day = 1440 minutes + time = '{:.1f} days'.format(hop.time / 1440.0) + else: + time = '{} min'.format(int(round(hop.time))) rows.append(( hop.name, hop.origin, '{:.1f} %'.format(hop.alpha), amt, - '{}'.format(int(round(hop.time))), + time, hop.use, )) return ( diff --git a/tests/recipes/weizen.xml b/tests/recipes/weizen.xml index 03885bd..a2d757e 100644 --- a/tests/recipes/weizen.xml +++ b/tests/recipes/weizen.xml @@ -76,6 +76,19 @@ 60.0 min + + Cascade + U.S. + 5.5 + + 0.0141747 + 0.5 oz + Dry Hop +
Pellet
+ + 5 days + +
diff --git a/tests/test_recipes.py b/tests/test_recipes.py index ccb8b06..eea12bb 100644 --- a/tests/test_recipes.py +++ b/tests/test_recipes.py @@ -128,9 +128,14 @@ def test_recipe_hops(md_weizen): assert md_weizen.hops == ( 'Hops\n' '----\n' - '| Name | Origin | Alpha | Amount | Time | Use |\n' - '| -------------------- | ------- | ----- | ------ | ---- | ---- |\n' - '| Northern Brewer (DE) | Germany | 4.9 % | 1.0 oz | 60 | Boil |' + '| Name | Origin | Alpha | Amount | Time |' + ' Use |\n' + '| -------------------- | ------- | ----- | ------ | -------- |' + ' ------- |\n' + '| Northern Brewer (DE) | Germany | 4.9 % | 1.0 oz | 60 min |' + ' Boil |\n' + '| Cascade | U.S. | 5.5 % | 0.5 oz | 5.0 days |' + ' Dry Hop |' )