Skip to content

A fistful of tomatoes

February 24, 2011

One of the innovative aspects of KitchenPC is its ability to convert and aggregate ingredients from one form into another.  For example, chopped tomatoes and whole tomatoes can be tallied up and added to a shopping list expressed in weight.  Since a grocery store sells tomatoes by weight, you probably want that on your shopping list and not “5 cups chopped tomatoes.”  This “form conversion engine” is essential to not only accurate and meaningful shopping lists, but the meal planner as well.  If I say I have 3 tomatoes that I want to use up, the modeler can consider recipes that use tomatoes in chopped form, whole, or by weight.  Without this collection of ingredient metadata, KitchenPC would be relegated to your average recipe database with wanna-be shopping and planning tools that don’t really work.

The first version of the form conversion engine was extremely basic, and provided just enough functionality to prove the initial concept of a recipe website that innovated around this sort of ability.  However, the engine lacked certain functionality.  Primarily, it was only able to represent conversion ratios through weight.  For example, a form (1 cup of chopped tomatoes) would have a weight, always expressed in grams.  Since tomatoes were sold in weight, we could calculate how many “grams” of tomatoes you’d have to buy so that, when chopped, would give you x cups.  This worked for units as well, such as “1 slice of cheddar cheese” weighs about 28 grams, thus if you needed 4 slices of cheese, we can add this ingredient expressed in weight to your shopping list.

However, this design didn’t support the less popular conversions, such as items sold in whole unit or in liquid form.  I could not represent “two scoops of vanilla ice cream is equal to one cup. ”  If there was an ingredient used by weight but sold in volume (I have no idea what this would be!), then that sort of conversion path could not be represented either.

Earlier this week, I took some time to improve the conversion engine to allow these sorts of conversions.  The database can now store conversion coefficients in any unit (weight, volume or whole unit) and convert to any other unit, as long as a conversion path can be found.  This allows me to add some new units such as “squirts of Hershey’s Syrup” and “splashes of soy sauce.”  Though the database doesn’t yet make much use of this far more powerful conversion engine, you can expect some new unit types for the more popular ingredients in the near future.

Going through this code (which was among the oldest code in the KitchenPC source depot) also gave me the opportunity to do a lot more testing on the less common conversion paths.  I noticed converting from volume to whole unit (such as 1cup chopped onions = x whole onions) simply never worked, it just happens that this conversion path is not surfaced through any current ingredient in the database.  I wrote several new unit tests that now offer complete code coverage for every conversion type (no matter how silly) by mocking up fake ingredients and forms to convert.

If I did my job right, you won’t notice any change at all in KitchenPC.  Your shopping list will be as accurate as it’s always been, and digging up meal plans based on what’s in your pantry should be as smooth as ever.  Keep an eye out for new units being added to existing ingredients, and let me know if you notice any problems or have any feedback on how I can improve the existing database.


From → Technical

One Comment
  1. Sharry permalink

    Hey Mike – admittedly, I haven’t yet taken a look at the updates you mention, but I did notice a problem that maybe you hadn’t thought of. It would be nice to know how many whole tomatoes (or widgets), I need for all of my recipes, in addition to the weight. For instance – let’s say I have 2 recipes that each call for 1 tomato. So the grocery list tells me to buy (let’s say) a 1/2 pound of tomatoes. I go to the store and buy 1 tomato that is a 1/2 pound (yes, big tomatoes). So – now I only have 1 tomato, but my recipes want 1 tomato each, so I don’t really have enough, even though I bought the correct weight. I hope I’m making sense, because I face this issue every time I go to the store with a KPC shopping list now. I keep forgetting to count up how many of the whole items I need, as well as the sheer weight I need.

    Would be nice if KPC would tell me something like “1/2 lb. tomatoes (2 whole tomatoes)” or something like this, so I know I need to look for 2 tomatoes that are about 1/4 lb. each. Now – again, I have not looked at your updates, so if you did address this, then great! and ignore me….


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: