Skip to content

Commit

Permalink
Merge pull request #7 from chrisgilmerproj/decimal_precision_percentage
Browse files Browse the repository at this point in the history
Add more decimal precision in percentage outputs
  • Loading branch information
chrisgilmerproj committed Jan 1, 2017
2 parents 9bd6018 + 755215e commit 6df176c
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Version 0.0.7

- Increase decimal precision in percentage outputs for Grain and Hops
- Make Grain() return self.name instead of using string.capwords()
- Change all strings to unicode
- Add __unicode__ method to all objects
Expand Down
2 changes: 1 addition & 1 deletion brew/hops.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __ne__(self, other):

def to_dict(self):
return {u'name': self.name,
u'percent_alpha_acids': round(self.percent_alpha_acids, 2),
u'percent_alpha_acids': round(self.percent_alpha_acids, 3),
}

def to_json(self):
Expand Down
8 changes: 4 additions & 4 deletions brew/recipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ def to_dict(self):
u'start_volume': round(self.start_volume, 2),
u'final_volume': round(self.final_volume, 2),
u'data': {
u'percent_brew_house_yield': round(self.percent_brew_house_yield, 2), # noqa
u'percent_brew_house_yield': round(self.percent_brew_house_yield, 3), # noqa
u'original_gravity': round(og, 3),
u'boil_gravity': round(bg, 3),
u'final_gravity': round(fg, 3),
Expand All @@ -581,8 +581,8 @@ def to_dict(self):
grain = grain_add.to_dict()
wort_color_srm = self.get_wort_color(grain_add)
wort_color_ebc = srm_to_ebc(wort_color_srm)
working_yield = round(grain_add.grain.get_working_yield(self.percent_brew_house_yield), 2) # noqa
percent_malt_bill = round(self.get_percent_malt_bill(grain_add), 2)
working_yield = round(grain_add.grain.get_working_yield(self.percent_brew_house_yield), 3) # noqa
percent_malt_bill = round(self.get_percent_malt_bill(grain_add), 3)
grain[u'data'].update({
u'working_yield': working_yield,
u'percent_malt_bill': percent_malt_bill,
Expand All @@ -604,7 +604,7 @@ def to_dict(self):

hop[u'data'].update({
u'ibus': round(ibus, 1),
u'utilization': round(utilization, 2),
u'utilization': round(utilization, 3),
})
recipe_dict[u'hops'].append(hop)

Expand Down
10 changes: 5 additions & 5 deletions tests/test_recipes_imperial.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def test_get_total_wort_color_map(self):
def test_to_json(self):
self.assertEquals(self.recipe.units, IMPERIAL_UNITS)
out = self.recipe.to_json()
expected = u'{"data": {"abv_alternative": 0.0798, "abv_standard": 0.0749, "abw_alternative": 0.0633, "abw_standard": 0.0595, "boil_gravity": 1.054, "bu_to_gu": 0.6, "final_gravity": 1.019, "original_gravity": 1.076, "percent_brew_house_yield": 0.7, "total_ibu": 33.0, "total_wort_color_map": {"ebc": {"daniels": "N/A", "morey": 13.0, "mosher": 14.4}, "srm": {"daniels": "N/A", "morey": 6.6, "mosher": 7.3}}, "units": "imperial"}, "final_volume": 5.0, "grains": [{"data": {"color": 2.0, "hwe": 308.78, "percent_malt_bill": 0.95, "ppg": 37.0, "working_yield": 0.56, "wort_color_ebc": 9.6, "wort_color_srm": 4.9}, "grain_type": "cereal", "name": "pale 2-row", "units": "imperial", "weight": 13.96}, {"data": {"color": 20.0, "hwe": 292.09, "percent_malt_bill": 0.05, "ppg": 35.0, "working_yield": 0.53, "wort_color_ebc": 6.4, "wort_color_srm": 3.3}, "grain_type": "cereal", "name": "crystal C20", "units": "imperial", "weight": 0.78}], "hops": [{"boil_time": 60.0, "data": {"ibus": 29.2, "percent_alpha_acids": 0.14, "utilization": 0.24}, "hop_type": "pellet", "name": "centennial", "units": "imperial", "utilization_cls": "Glenn Tinseth", "utilization_cls_kwargs": {}, "weight": 0.57}, {"boil_time": 5.0, "data": {"ibus": 3.9, "percent_alpha_acids": 0.07, "utilization": 0.05}, "hop_type": "pellet", "name": "cascade", "units": "imperial", "utilization_cls": "Glenn Tinseth", "utilization_cls_kwargs": {}, "weight": 0.76}], "name": "pale ale", "start_volume": 7.0, "yeast": {"data": {"percent_attenuation": 0.75}, "name": "Wyeast 1056"}}' # noqa
expected = u'{"data": {"abv_alternative": 0.0798, "abv_standard": 0.0749, "abw_alternative": 0.0633, "abw_standard": 0.0595, "boil_gravity": 1.054, "bu_to_gu": 0.6, "final_gravity": 1.019, "original_gravity": 1.076, "percent_brew_house_yield": 0.7, "total_ibu": 33.0, "total_wort_color_map": {"ebc": {"daniels": "N/A", "morey": 13.0, "mosher": 14.4}, "srm": {"daniels": "N/A", "morey": 6.6, "mosher": 7.3}}, "units": "imperial"}, "final_volume": 5.0, "grains": [{"data": {"color": 2.0, "hwe": 308.78, "percent_malt_bill": 0.947, "ppg": 37.0, "working_yield": 0.56, "wort_color_ebc": 9.6, "wort_color_srm": 4.9}, "grain_type": "cereal", "name": "pale 2-row", "units": "imperial", "weight": 13.96}, {"data": {"color": 20.0, "hwe": 292.09, "percent_malt_bill": 0.053, "ppg": 35.0, "working_yield": 0.53, "wort_color_ebc": 6.4, "wort_color_srm": 3.3}, "grain_type": "cereal", "name": "crystal C20", "units": "imperial", "weight": 0.78}], "hops": [{"boil_time": 60.0, "data": {"ibus": 29.2, "percent_alpha_acids": 0.14, "utilization": 0.244}, "hop_type": "pellet", "name": "centennial", "units": "imperial", "utilization_cls": "Glenn Tinseth", "utilization_cls_kwargs": {}, "weight": 0.57}, {"boil_time": 5.0, "data": {"ibus": 3.9, "percent_alpha_acids": 0.07, "utilization": 0.049}, "hop_type": "pellet", "name": "cascade", "units": "imperial", "utilization_cls": "Glenn Tinseth", "utilization_cls_kwargs": {}, "weight": 0.76}], "name": "pale ale", "start_volume": 7.0, "yeast": {"data": {"percent_attenuation": 0.75}, "name": "Wyeast 1056"}}' # noqa
self.assertEquals(out, expected)

def test_format(self):
Expand Down Expand Up @@ -301,15 +301,15 @@ def test_format(self):
-----------------------------------
Grain Type: cereal
Weight: 13.96 lbs
Percent Malt Bill: 95.0%
Percent Malt Bill: 94.7%
Working Yield: 56.0%
SRM/EBC: 4.9 degL / 9.6
crystal C20 Addition
-----------------------------------
Grain Type: cereal
Weight: 0.78 lbs
Percent Malt Bill: 5.0%
Percent Malt Bill: 5.3%
Working Yield: 53.0%
SRM/EBC: 3.3 degL / 6.4
Expand All @@ -323,7 +323,7 @@ def test_format(self):
Weight: 0.57 oz
Boil Time: 60.0 min
IBUs: 29.2
Utilization: 24.0%
Utilization: 24.4%
cascade Addition
-----------------------------------
Expand All @@ -332,7 +332,7 @@ def test_format(self):
Weight: 0.76 oz
Boil Time: 5.0 min
IBUs: 3.9
Utilization: 5.0%
Utilization: 4.9%
Yeast
===================================
Expand Down
14 changes: 9 additions & 5 deletions tests/test_recipes_si.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ def test_get_total_ibu(self):
total_ibu = self.recipe.get_total_ibu()
self.assertEquals(round(total_ibu, 2), 33.03)

def test_ibu(self):
total_ibu = self.recipe.ibu
self.assertEquals(round(total_ibu, 2), 33.03)

def test_bu_to_gu(self):
self.assertEqual(round(self.recipe.get_bu_to_gu(), 2), 0.61)

Expand Down Expand Up @@ -273,7 +277,7 @@ def test_get_total_wort_color_map(self):
def test_to_json(self):
self.assertEquals(self.recipe.units, SI_UNITS)
out = self.recipe.to_json()
expected = u'{"data": {"abv_alternative": 0.0798, "abv_standard": 0.0749, "abw_alternative": 0.0633, "abw_standard": 0.0595, "boil_gravity": 1.054, "bu_to_gu": 0.6, "final_gravity": 1.019, "original_gravity": 1.076, "percent_brew_house_yield": 0.7, "total_ibu": 33.0, "total_wort_color_map": {"ebc": {"daniels": "N/A", "morey": 13.0, "mosher": 14.4}, "srm": {"daniels": "N/A", "morey": 6.6, "mosher": 7.3}}, "units": "metric"}, "final_volume": 18.93, "grains": [{"data": {"color": 2.0, "hwe": 308.78, "percent_malt_bill": 0.95, "ppg": 37.0, "working_yield": 0.56, "wort_color_ebc": 9.6, "wort_color_srm": 4.9}, "grain_type": "cereal", "name": "pale 2-row", "units": "metric", "weight": 6.33}, {"data": {"color": 20.0, "hwe": 292.09, "percent_malt_bill": 0.05, "ppg": 35.0, "working_yield": 0.53, "wort_color_ebc": 6.4, "wort_color_srm": 3.3}, "grain_type": "cereal", "name": "crystal C20", "units": "metric", "weight": 0.35}], "hops": [{"boil_time": 60.0, "data": {"ibus": 29.2, "percent_alpha_acids": 0.14, "utilization": 0.24}, "hop_type": "pellet", "name": "centennial", "units": "metric", "utilization_cls": "Glenn Tinseth", "utilization_cls_kwargs": {"units": "metric"}, "weight": 16159.21}, {"boil_time": 5.0, "data": {"ibus": 3.9, "percent_alpha_acids": 0.07, "utilization": 0.05}, "hop_type": "pellet", "name": "cascade", "units": "metric", "utilization_cls": "Glenn Tinseth", "utilization_cls_kwargs": {"units": "metric"}, "weight": 21545.62}], "name": "pale ale", "start_volume": 26.5, "yeast": {"data": {"percent_attenuation": 0.75}, "name": "Wyeast 1056"}}' # noqa
expected = u'{"data": {"abv_alternative": 0.0798, "abv_standard": 0.0749, "abw_alternative": 0.0633, "abw_standard": 0.0595, "boil_gravity": 1.054, "bu_to_gu": 0.6, "final_gravity": 1.019, "original_gravity": 1.076, "percent_brew_house_yield": 0.7, "total_ibu": 33.0, "total_wort_color_map": {"ebc": {"daniels": "N/A", "morey": 13.0, "mosher": 14.4}, "srm": {"daniels": "N/A", "morey": 6.6, "mosher": 7.3}}, "units": "metric"}, "final_volume": 18.93, "grains": [{"data": {"color": 2.0, "hwe": 308.78, "percent_malt_bill": 0.947, "ppg": 37.0, "working_yield": 0.56, "wort_color_ebc": 9.6, "wort_color_srm": 4.9}, "grain_type": "cereal", "name": "pale 2-row", "units": "metric", "weight": 6.33}, {"data": {"color": 20.0, "hwe": 292.09, "percent_malt_bill": 0.053, "ppg": 35.0, "working_yield": 0.53, "wort_color_ebc": 6.4, "wort_color_srm": 3.3}, "grain_type": "cereal", "name": "crystal C20", "units": "metric", "weight": 0.35}], "hops": [{"boil_time": 60.0, "data": {"ibus": 29.2, "percent_alpha_acids": 0.14, "utilization": 0.244}, "hop_type": "pellet", "name": "centennial", "units": "metric", "utilization_cls": "Glenn Tinseth", "utilization_cls_kwargs": {"units": "metric"}, "weight": 16159.21}, {"boil_time": 5.0, "data": {"ibus": 3.9, "percent_alpha_acids": 0.07, "utilization": 0.049}, "hop_type": "pellet", "name": "cascade", "units": "metric", "utilization_cls": "Glenn Tinseth", "utilization_cls_kwargs": {"units": "metric"}, "weight": 21545.62}], "name": "pale ale", "start_volume": 26.5, "yeast": {"data": {"percent_attenuation": 0.75}, "name": "Wyeast 1056"}}' # noqa
self.assertEquals(out, expected)

def test_format(self):
Expand Down Expand Up @@ -308,15 +312,15 @@ def test_format(self):
-----------------------------------
Grain Type: cereal
Weight: 6.33 kg
Percent Malt Bill: 95.0%
Percent Malt Bill: 94.7%
Working Yield: 56.0%
SRM/EBC: 4.9 degL / 9.6
crystal C20 Addition
-----------------------------------
Grain Type: cereal
Weight: 0.35 kg
Percent Malt Bill: 5.0%
Percent Malt Bill: 5.3%
Working Yield: 53.0%
SRM/EBC: 3.3 degL / 6.4
Expand All @@ -330,7 +334,7 @@ def test_format(self):
Weight: 16159.21 mg
Boil Time: 60.0 min
IBUs: 29.2
Utilization: 24.0%
Utilization: 24.4%
cascade Addition
-----------------------------------
Expand All @@ -339,7 +343,7 @@ def test_format(self):
Weight: 21545.62 mg
Boil Time: 5.0 min
IBUs: 3.9
Utilization: 5.0%
Utilization: 4.9%
Yeast
===================================
Expand Down

0 comments on commit 6df176c

Please sign in to comment.