Units are coupled to food attribute names
mattrossman opened this issue · 1 comments
First of all, this is really neat Simon. I am planning on making a REST API for UMass dining hall menu data and I might end up using this package for the menu parsing functions.
umass-toolkit/umass_toolkit/dining.py
Lines 60 to 65 in 9318556
For the nutritional facts, it seems weird that some properties are linked to certain unit types. It would be nice to have that job delegated to something like a Quantity
data structure from the pint
package (package documentation). That package has string parsing so a statement like "5.6g"
can automatically be parsed as <Quantity(5.6, 'gram')>
.
This could perhaps be extended to the serving size attribute by defining custom units for things like "slice", "each", etc.
I like it!
I'm a bit hesitant about the defining custom units thing though. The endpoint we're using is actually for the UMass Dining app, and the app displays them straight away without any sort of processing. I'm guessing that someone at UMass is typing these things in manually every day and can type whatever string they want. This means we may need to deal with typos and a "odd"/one-off serving sizes, leading to clutter and frustration.
I really like this though! Will definitely be playing with pint sometime soonish (I'm a bit busy right now so I can't dedicate as much time to this project as I'd like). If anyone's interested in taking this on, go for it!