cookbook icon indicating copy to clipboard operation
cookbook copied to clipboard

Handle fractional ingredients (Fixes #2004)

Open Weissnix4711 opened this issue 1 year ago β€’ 2 comments

Topic and Scope

My solution to #2004. This handles 16ths, else falls back to decimal. I think this is a nice balance between using some fractions, without ending up with stupid denominators.

Concerns/issues

Will only work if the initial ingredient is given as a fraction. If it's a decimal, or just a whole number, will still remain decimal. Maybe it would make sense to convert everything to fractions where possible, but then maybe not. Perhaps being able to change the behavior in settings would be useful, idk. Also, by design does not do 1/3, 1/5, etc. I don't mind this, in fact I would prefer this way, but I guess in the end it's not up to me.

Formal requirements

There are some formal requirements that should be satisfied. Please mark those by checking the corresponding box.

  • [x] I did check that the app can still be opened and does not throw any browser logs
  • [x] I created tests for newly added PHP code (check this if no PHP changes were made)
  • [x] I updated the OpenAPI specs and added an entry to the API changelog (check if API was not modified)
  • [ ] I notified the matrix channel if I introduced an API change

Weissnix4711 avatar Jul 13 '24 20:07 Weissnix4711

Thank you for your contribution! Smaller than 1/16 probably does not make any sense indeed. 1/3 and 1/5 are debatable, though. However, as a starting point, having any conversion is better than none. In future iterations there could even be a toggle in the recipe view or some options in the configuration but that is not required immediately.

I did not check the details yet, but one thing that comes to my mind is, there are ASCII/Unicode symbols for fractions like ΒΎ. I think they should be handled, too. Maybe not all of them, but the most common ones?

A quick Google search turned up this reference:

https://www.compart.com/de/unicode/decomposition/%3Cfraction%3E

seyfeb avatar Jul 15 '24 08:07 seyfeb

Done. Should now parse unicode fractions, but will always display the output as 'normal' text (ie. using digits and a slash). I guess it would be possible to display the output with unicode fractions too, but at least for me they don't always display too nice in the browser.

Weissnix4711 avatar Jul 15 '24 13:07 Weissnix4711

Test Results

β€‡β€ˆβ€‡12 filesβ€„β€ƒβ€‡β€ˆ584 suites   1m 37s :stopwatch: β€‡β€ˆ575 testsβ€ƒβ€‡β€ˆ575 :white_check_mark: 0 :zzz: 0 :x: 2β€ˆ300 runsβ€Šβ€ƒ2β€ˆ299 :white_check_mark: 1 :zzz: 0 :x:

Results for commit 8a395408.

:recycle: This comment has been updated with latest results.

github-actions[bot] avatar Sep 12 '24 12:09 github-actions[bot]