Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--digits argument #25

Merged
merged 12 commits into from
Sep 29, 2024
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
2. AeroPress concentrate
3. AeroPress inverted
4. Steep-and-release
- `--digits` argument
### Changed
- `README.md` updated
- Test system modified
- `filter_params` function updated
## [0.3] - 2024-09-24
### Added
- Logo
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ Info: Chemex method
<td align="center">String</td>
<td align="center"><code>Custom brewing method</code></td>
</tr>
<tr>
<td align="center"><code>--digits</code></td>
<td align="center">Number of digits up to which the result is rounded</td>
<td align="center">Integer</td>
<td align="center"><code>3</code></td>
</tr>
</tbody>
</table>

Expand Down
5 changes: 5 additions & 0 deletions mycoffee/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ def main():
parser.add_argument('--water-ratio', help='coefficient for the water component in the ratio', type=float)
parser.add_argument('--water', help='amount of water in each cup (gr)', type=float)
parser.add_argument('--cups', help='number of cups', type=int)
parser.add_argument(
'--digits',
help='number of digits up to which the result is rounded',
type=int,
default=3)
parser.add_argument('--methods-list', help='brewing methods list', nargs="?", const=1)
parser.add_argument('--version', help='version', nargs="?", const=1)
args = parser.parse_args()
Expand Down
5 changes: 2 additions & 3 deletions mycoffee/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,15 @@ def load_params(args):
return params


def filter_params(params, digits=3):
def filter_params(params):
"""
Filter params.

:param params: parameters
:type params: dict
:param digits: number of digits up to which the given number is to be rounded
:type digits: int
:return: filtered parameters as dict
"""
digits = params["digits"]
params["coffee"] = round(params["coffee"], digits)
if is_int(params["coffee"]):
params["coffee"] = int(params["coffee"])
Expand Down
1 change: 1 addition & 0 deletions mycoffee/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"water": 0,
"coffee_ratio": 1,
"water_ratio": 1,
"digits": 3,
"info": ""

}
Expand Down
35 changes: 30 additions & 5 deletions test/functions_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<BLANKLINE>
Info: V60 method
<BLANKLINE>
>>> test_params = {"method":"v60", "cups":2, "coffee":30, "water":500, "coffee_ratio": 3, "water_ratio":50, "info":""}
>>> test_params = {"method":"v60", "cups":2, "coffee":30, "water":500, "coffee_ratio": 3, "water_ratio":50, "info":"", "digits":3}
>>> test_params = filter_params(test_params)
>>> print_message(test_params)
__ __ _ _ ___ _____ ____ ____ ____ ____
Expand All @@ -47,7 +47,7 @@
Info: Nothing :)
<BLANKLINE>
>>> chemex_params = load_method_params("chemex")
>>> chemex_params == {'info': 'Chemex method', 'water': 240, 'cups': 1, 'coffee_ratio': 1, 'water_ratio': 15}
>>> chemex_params == {'info': 'Chemex method', 'water': 240, 'cups': 1, 'coffee_ratio': 1, 'water_ratio': 15, 'digits': 3}
True
>>> show_methods_list()
Methods list:
Expand All @@ -74,7 +74,7 @@
>>> test_params = {"method":"v60", "cups":2, "coffee":30, "water":335, "coffee_ratio": 3, "water_ratio":50, "info":"V60 method"}
>>> calc_coffee(test_params)
20.1
>>> test_params = {"method":"v60", "cups":2, "coffee":20.0, "water":335.0, "coffee_ratio": 3.0, "water_ratio":50.0, "info":""}
>>> test_params = {"method":"v60", "cups":2, "coffee":20.0, "water":335.0, "coffee_ratio": 3.0, "water_ratio":50.0, "info":"", "digits":3}
>>> test_params = filter_params(test_params)
>>> test_params["coffee"]
20
Expand All @@ -86,8 +86,8 @@
335
>>> test_params["info"]
'Nothing :)'
>>> test_params = {"method":"v60", "cups":2, "coffee":20.12345, "water":335.12345, "coffee_ratio": 3.12345, "water_ratio":50.12345, "info":""}
>>> test_params = filter_params(test_params, digits=2)
>>> test_params = {"method":"v60", "cups":2, "coffee":20.12345, "water":335.12345, "coffee_ratio": 3.12345, "water_ratio":50.12345, "info":"", "digits":2}
>>> test_params = filter_params(test_params)
>>> test_params["coffee"]
20.12
>>> test_params["coffee_ratio"]
Expand All @@ -111,6 +111,7 @@
>>> _ = parser.add_argument('--water-ratio', help='water ratio', type=float)
>>> _ = parser.add_argument('--water', help='water(ml)', type=float)
>>> _ = parser.add_argument('--cups', help='number of cups', type=int)
>>> _ = parser.add_argument('--digits', help='number of digits up to which the result is rounded', type=int, default=3)
>>> _ = parser.add_argument('--methods-list', help='brewing methods list', nargs="?", const=1)
>>> _ = parser.add_argument('--version', help='version', nargs="?", const=1)
>>> args = parser.parse_args({"--version":True})
Expand Down Expand Up @@ -156,6 +157,30 @@
23
>>> params["water"]
5000
>>> args = parser.parse_args(["--method", 'steep-and-release', "--digits", '1'])
>>> params = load_params(args)
>>> params["coffee"] = calc_coffee(params)
>>> params["water"]
255
>>> params["coffee"]
15.9375
>>> params["water_ratio"]
16
>>> params["coffee_ratio"]
1
>>> params["method"]
'steep-and-release'
>>> params = filter_params(params)
>>> params["water_ratio"]
16
>>> params["coffee_ratio"]
1
>>> params["water"]
255
>>> params["coffee"]
15.9
Comment on lines +160 to +181
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we want to add params['digits']

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in 999bf5f

>>> params["digits"]
1
>>> args = parser.parse_args(["--methods-list"])
>>> run(args)
Methods list:
Expand Down
Loading