Inspiration

For a while we (Zac) have had an interest in scraping nutrient data from many various foods to try and do some algorithms on them, to try and min-max our diets within certain constraints.

What it does

You enter the target values for various macronutrients, vitamins and minerals, and it calculates the optimal ingredients to achieve all of these values while trying to minimize cost. For instance, given the UK Government's nutrition guidelines, we are given the following recipe for soup:

  • Add to a pot:
    • 126g black beans
    • 53g barley
    • 95g cereal
    • 49g whole wheat bread
    • 88g almonds
    • 20g whole wheat biscuits
    • 15g baked beans
    • 38g flour
  • Soup

This has the perfect macro breakdown according to our government, although I do disagree so we also added support for custom nutritional goals, as well as vitamins (we allow for specifying all vitamins, and have data for thousands of different foods).

How we built it

  1. Web scraping (across many cloud services) to fetch sufficient data from Tesco
  2. Text embeddings in Python to glue together our two very different datasets (nutrition information, and price information)
  3. A Flask backend and a web front-end
  4. Two custom solves written in Python
    • One written by hand making use of heuristics to seek out the goal by adding soup ingredients until none more are needed
    • One using scipy's minimisation libraries to find a local optimum
  5. Web browser automation with selenium to automatically add selected soup ingredients to the online Tesco basket
  6. A soup maker to make the soup

Challenges we ran into

So many... Firstly, we wanted to scrape the product data from over 30,000 tesco food products off of their website, but unfortunately they very harshly rate limited us which meant that wasnt exactly feasible. Instead, we used an open source food database, but they don't contain prices, so we had to superficially scrape the Tesco food data for those, and then try and use embedding-based matching to try and link the two, which was much easier said than done! We also had to use some very shady libraries to get the functionality to automatically log in to the tesco website and add all of the products automatically to your cart.

Accomplishments that we're proud of

We made a (hopefully) very good soup

What we learned

Lots, each of us were doing a lot of things we had very little experience with!

What's next for What's In Stock?

Depends on how much we actually end up finishing doing..!

Built With

Share this project:

Updates