simon-andrews/umass-toolkit

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.

elif attribute_name in ['cholesterol', 'sodium']:
data = parse_milligrams(data)
attribute_name += '-mg'
elif attribute_name in ['dietary-fiber', 'protein', 'sat-fat', 'sugars', 'total-carb', 'total-fat', 'trans-fat']:
data = parse_grams(data)
attribute_name += '-g'

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!