Skip to content

Commit

Permalink
Grind limits (#76)
Browse files Browse the repository at this point in the history
* feat : grind_limits parameters added

* feat : check_grind_limits function added

* feat : GRIND_WARNING_MESSAGE added

* fix : functions_test.py updated

* fix : verified_test.py updated

* fix : functions_test.py updated

* doc : CHANGELOG.md updated
  • Loading branch information
sepandhaghighi authored Jan 8, 2025
1 parent a90e70e commit 96e17db
Show file tree
Hide file tree
Showing 5 changed files with 205 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- 1 new coffee unit
1. Troy Pounds (`t lb`)
- `--grind` argument
- Grind upper limit
- Grind lower limit
- `check_grind_limits` function
### Changed
- `README.md` updated
## [1.1] - 2025-01-02
Expand Down
24 changes: 23 additions & 1 deletion mycoffee/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from mycoffee.params import MESSAGE_TEMPLATE, METHODS_LIST_TEMPLATE, EMPTY_INFO
from mycoffee.params import MY_COFFEE_VERSION, DEFAULT_PARAMS
from mycoffee.params import METHODS_MAP, COFFEE_UNITS_MAP, WATER_UNITS_MAP
from mycoffee.params import RATIO_WARNING_MESSAGE
from mycoffee.params import RATIO_WARNING_MESSAGE, GRIND_WARNING_MESSAGE
from art import tprint


Expand Down Expand Up @@ -47,6 +47,10 @@ def print_result(params):
ratio_lower_limit = METHODS_MAP[method]["ratio_lower_limit"]
ratio_upper_limit = METHODS_MAP[method]["ratio_upper_limit"]
print(RATIO_WARNING_MESSAGE.format(method, str(ratio_lower_limit), str(ratio_upper_limit)))
if not check_grind_limits(params):
grind_lower_limit = METHODS_MAP[method]["grind_lower_limit"]
grind_upper_limit = METHODS_MAP[method]["grind_upper_limit"]
print(GRIND_WARNING_MESSAGE.format(method, str(grind_lower_limit), str(grind_upper_limit)))


def load_method_params(method_name):
Expand Down Expand Up @@ -171,6 +175,24 @@ def check_ratio_limits(params):
return True


def check_grind_limits(params):
"""
Check grind limits.
:param params: parameters
:type params: dict
:return: result as bool (False --> the grind is out of range)
"""
method = params["method"]
if "grind_lower_limit" in METHODS_MAP[method] and "grind_upper_limit" in METHODS_MAP[method]:
grind = params["grind"]
grind_lower_limit = METHODS_MAP[method]["grind_lower_limit"]
grind_upper_limit = METHODS_MAP[method]["grind_upper_limit"]
if grind < grind_lower_limit or grind > grind_upper_limit:
return False
return True


def convert_coffee(coffee, unit):
"""
Convert coffee unit.
Expand Down
37 changes: 37 additions & 0 deletions mycoffee/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
MY_COFFEE_VERSION = "1.1"
INPUT_ERROR_MESSAGE = "[Error] Wrong input"
RATIO_WARNING_MESSAGE = "[Warning] The ratio is not within the standard range. For `{0}`, the ratio can be anywhere between `{1}` and `{2}`"
GRIND_WARNING_MESSAGE = "[Warning] The grind is not within the standard range. For `{0}`, the grind can be anywhere between `{1}` and `{2}`"
INPUT_EXAMPLE = "Example: mycoffee --method=v60"
EXIT_MESSAGE = "See you. Bye!"
EMPTY_INFO = "Nothing :)"
Expand Down Expand Up @@ -53,6 +54,8 @@
"coffee_ratio": 3,
"water_ratio": 50,
"grind": 550,
"grind_lower_limit": 400,
"grind_upper_limit": 700,
"ratio_lower_limit": Fraction(1, 18),
"ratio_upper_limit": Fraction(1, 14),
"water": 250,
Expand All @@ -62,6 +65,8 @@
"coffee_ratio": 1,
"water_ratio": 2,
"grind": 280,
"grind_lower_limit": 180,
"grind_upper_limit": 380,
"ratio_lower_limit": Fraction(2, 5),
"ratio_upper_limit": Fraction(2, 3),
"water": 36,
Expand All @@ -71,6 +76,8 @@
"coffee_ratio": 1,
"water_ratio": 1,
"grind": 280,
"grind_lower_limit": 180,
"grind_upper_limit": 380,
"ratio_lower_limit": Fraction(2, 3),
"ratio_upper_limit": Fraction(1, 1),
"water": 18,
Expand All @@ -80,6 +87,8 @@
"coffee_ratio": 1,
"water_ratio": 4,
"grind": 280,
"grind_lower_limit": 180,
"grind_upper_limit": 380,
"ratio_lower_limit": Fraction(1, 4),
"ratio_upper_limit": Fraction(2, 5),
"water": 72,
Expand All @@ -89,6 +98,8 @@
"coffee_ratio": 1,
"water_ratio": 15,
"grind": 670,
"grind_lower_limit": 410,
"grind_upper_limit": 930,
"ratio_lower_limit": Fraction(1, 21),
"ratio_upper_limit": Fraction(1, 10),
"water": 240,
Expand All @@ -98,6 +109,8 @@
"coffee_ratio": 1,
"water_ratio": 15,
"grind": 995,
"grind_lower_limit": 690,
"grind_upper_limit": 1300,
"ratio_lower_limit": Fraction(1, 18),
"ratio_upper_limit": Fraction(1, 12),
"water": 120,
Expand All @@ -107,6 +120,8 @@
"coffee_ratio": 1,
"water_ratio": 15,
"grind": 588,
"grind_lower_limit": 375,
"grind_upper_limit": 800,
"ratio_lower_limit": Fraction(1, 16),
"ratio_upper_limit": Fraction(1, 12),
"water": 240,
Expand All @@ -116,6 +131,8 @@
"coffee_ratio": 1,
"water_ratio": 15,
"grind": 670,
"grind_lower_limit": 410,
"grind_upper_limit": 930,
"ratio_lower_limit": Fraction(1, 16),
"ratio_upper_limit": Fraction(1, 14),
"water": 240,
Expand All @@ -125,6 +142,8 @@
"coffee_ratio": 1,
"water_ratio": 16,
"grind": 600,
"grind_lower_limit": 300,
"grind_upper_limit": 900,
"ratio_lower_limit": Fraction(1, 17),
"ratio_upper_limit": Fraction(1, 14),
"water": 128,
Expand All @@ -134,6 +153,8 @@
"coffee_ratio": 1,
"water_ratio": 11,
"grind": 1100,
"grind_lower_limit": 800,
"grind_upper_limit": 1400,
"ratio_lower_limit": Fraction(1, 15),
"ratio_upper_limit": Fraction(1, 8),
"water": 242,
Expand All @@ -143,6 +164,8 @@
"coffee_ratio": 1,
"water_ratio": 5,
"grind": 1100,
"grind_lower_limit": 800,
"grind_upper_limit": 1400,
"ratio_lower_limit": Fraction(1, 6),
"ratio_upper_limit": Fraction(1, 4),
"water": 120,
Expand All @@ -152,6 +175,8 @@
"coffee_ratio": 1,
"water_ratio": 10,
"grind": 510,
"grind_lower_limit": 360,
"grind_upper_limit": 660,
"ratio_lower_limit": Fraction(1, 12),
"ratio_upper_limit": Fraction(1, 7),
"water": 60,
Expand All @@ -161,6 +186,8 @@
"coffee_ratio": 1,
"water_ratio": 10,
"grind": 130,
"grind_lower_limit": 40,
"grind_upper_limit": 220,
"ratio_lower_limit": Fraction(1, 12),
"ratio_upper_limit": Fraction(1, 8),
"water": 50,
Expand All @@ -170,6 +197,8 @@
"coffee_ratio": 11,
"water_ratio": 200,
"grind": 655,
"grind_lower_limit": 460,
"grind_upper_limit": 850,
"ratio_lower_limit": Fraction(1, 19),
"ratio_upper_limit": Fraction(1, 17),
"water": 150,
Expand All @@ -179,6 +208,8 @@
"coffee_ratio": 1,
"water_ratio": 15,
"grind": 640,
"grind_lower_limit": 320,
"grind_upper_limit": 960,
"ratio_lower_limit": Fraction(1, 18),
"ratio_upper_limit": Fraction(1, 12),
"water": 135,
Expand All @@ -188,6 +219,8 @@
"coffee_ratio": 1,
"water_ratio": 6,
"grind": 640,
"grind_lower_limit": 320,
"grind_upper_limit": 960,
"ratio_lower_limit": Fraction(1, 7),
"ratio_upper_limit": Fraction(1, 5),
"water": 90,
Expand All @@ -197,6 +230,8 @@
"coffee_ratio": 1,
"water_ratio": 12,
"grind": 640,
"grind_lower_limit": 320,
"grind_upper_limit": 960,
"ratio_lower_limit": Fraction(1, 14),
"ratio_upper_limit": Fraction(1, 10),
"water": 132,
Expand All @@ -206,6 +241,8 @@
"coffee_ratio": 1,
"water_ratio": 16,
"grind": 638,
"grind_lower_limit": 450,
"grind_upper_limit": 825,
"ratio_lower_limit": Fraction(1, 17),
"ratio_upper_limit": Fraction(1, 14),
"water": 255,
Expand Down
74 changes: 70 additions & 4 deletions test/functions_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
>>> test_params = filter_params(test_params)
>>> check_ratio_limits(test_params) == True
True
>>> check_grind_limits(test_params) == True
True
>>> print_result(test_params)
__ __ _ _ ___ _____ ____ ____ ____ ____
( \/ )( \/ ) / __)( _ )( ___)( ___)( ___)( ___)
Expand All @@ -64,10 +66,12 @@
<BLANKLINE>
Info: Nothing :)
<BLANKLINE>
>>> test_params = {"method":"v60", "cups":2, "coffee":60, "water":0.5, "coffee_ratio": 3, "water_ratio":50, "info":"", "digits":3, "coffee_unit": "g", "water_unit": "kg", "grind": 750}
>>> test_params = {"method":"v60", "cups":2, "coffee":60, "water":0.5, "coffee_ratio": 3, "water_ratio":50, "info":"", "digits":3, "coffee_unit": "g", "water_unit": "kg", "grind": 700}
>>> test_params = filter_params(test_params)
>>> check_ratio_limits(test_params) == True
True
>>> check_grind_limits(test_params) == True
True
>>> print_result(test_params)
__ __ _ _ ___ _____ ____ ____ ____ ____
( \/ )( \/ ) / __)( _ )( ___)( ___)( ___)( ___)
Expand All @@ -86,14 +90,16 @@
<BLANKLINE>
Ratio: 3/50
<BLANKLINE>
Grind: 750 um
Grind: 700 um
<BLANKLINE>
Info: Nothing :)
<BLANKLINE>
>>> test_params = {"method":"v60", "cups":2, "coffee":6.0, "water":500, "coffee_ratio": 6, "water_ratio":1000, "info":"", "digits":3, "coffee_unit": "g", "water_unit": "g", "grind": 230}
>>> test_params = {"method":"v60", "cups":2, "coffee":6.0, "water":500, "coffee_ratio": 6, "water_ratio":1000, "info":"", "digits":3, "coffee_unit": "g", "water_unit": "g", "grind": 500}
>>> test_params = filter_params(test_params)
>>> check_ratio_limits(test_params) == False
True
>>> check_grind_limits(test_params) == True
True
>>> print_result(test_params)
__ __ _ _ ___ _____ ____ ____ ____ ____
( \/ )( \/ ) / __)( _ )( ___)( ___)( ___)( ___)
Expand All @@ -112,15 +118,75 @@
<BLANKLINE>
Ratio: 6/1000
<BLANKLINE>
Grind: 230 um
Grind: 500 um
<BLANKLINE>
Info: Nothing :)
<BLANKLINE>
[Warning] The ratio is not within the standard range. For `v60`, the ratio can be anywhere between `1/18` and `1/14`
>>> test_params = {"method":"v60", "cups":2, "coffee":27.7, "water":500, "coffee_ratio": 1, "water_ratio":18, "info":"", "digits":3, "coffee_unit": "g", "water_unit": "g", "grind": 1400}
>>> test_params = filter_params(test_params)
>>> check_ratio_limits(test_params) == False
True
>>> print_result(test_params)
__ __ _ _ ___ _____ ____ ____ ____ ____
( \/ )( \/ ) / __)( _ )( ___)( ___)( ___)( ___)
) ( \ / ( (__ )(_)( )__) )__) )__) )__)
(_/\/\_) (__) \___)(_____)(__) (__) (____)(____)
<BLANKLINE>
<BLANKLINE>
<BLANKLINE>
Method: `v60`
<BLANKLINE>
Cups: 2
<BLANKLINE>
Coffee: 27.7 g
<BLANKLINE>
Water: 500 g
<BLANKLINE>
Ratio: 1/18
<BLANKLINE>
Grind: 1400 um
<BLANKLINE>
Info: Nothing :)
<BLANKLINE>
[Warning] The ratio is not within the standard range. For `v60`, the ratio can be anywhere between `1/18` and `1/14`
[Warning] The grind is not within the standard range. For `v60`, the grind can be anywhere between `400` and `700`
>>> test_params = {"method":"v60", "cups":2, "coffee":27.7, "water":500, "coffee_ratio": 1, "water_ratio":18, "info":"", "digits":3, "coffee_unit": "g", "water_unit": "g", "grind": 20}
>>> test_params = filter_params(test_params)
>>> check_ratio_limits(test_params) == False
True
>>> check_grind_limits(test_params) == False
True
>>> print_result(test_params)
__ __ _ _ ___ _____ ____ ____ ____ ____
( \/ )( \/ ) / __)( _ )( ___)( ___)( ___)( ___)
) ( \ / ( (__ )(_)( )__) )__) )__) )__)
(_/\/\_) (__) \___)(_____)(__) (__) (____)(____)
<BLANKLINE>
<BLANKLINE>
<BLANKLINE>
Method: `v60`
<BLANKLINE>
Cups: 2
<BLANKLINE>
Coffee: 27.7 g
<BLANKLINE>
Water: 500 g
<BLANKLINE>
Ratio: 1/18
<BLANKLINE>
Grind: 20 um
<BLANKLINE>
Info: Nothing :)
<BLANKLINE>
[Warning] The ratio is not within the standard range. For `v60`, the ratio can be anywhere between `1/18` and `1/14`
[Warning] The grind is not within the standard range. For `v60`, the grind can be anywhere between `400` and `700`
>>> test_params = {"method":"custom", "cups":2, "coffee":6.0, "water":500, "coffee_ratio": 6, "water_ratio":1000, "info":"", "digits":3, "coffee_unit": "g"}
>>> test_params = filter_params(test_params)
>>> check_ratio_limits(test_params) == True
True
>>> check_grind_limits(test_params) == True
True
>>> chemex_params = load_method_params("chemex")
>>> chemex_params == {'info': 'Chemex method', 'water': 240, 'cups': 1, 'coffee_ratio': 1, 'water_ratio': 15, 'digits': 3, 'coffee_unit': 'g', 'water_unit': 'g', 'grind': 670}
True
Expand Down
Loading

0 comments on commit 96e17db

Please sign in to comment.