Skip to content

Latest commit

 

History

History
76 lines (50 loc) · 3.73 KB

readme.md

File metadata and controls

76 lines (50 loc) · 3.73 KB

Green Bite API 🌱

Green Bite attempts to calculate sustainability scores for food.

301833855-2df0c8f0-e957-4385-aff2-60cc5d1afa05 (1)

How are sustainability scores calculated? 💡

Using this formula (amount_kg * land_usage) + (amount_kg * greenhouse_gas_emissions) = sustainability_score

Based on what data? 🤔

  • The SHARP database. Environmental impacts of 40,000 foods commonly eaten in 40 countries.
  • Simple weight tables to convert between volumetric and mass measurements.
  • A lot of assumptions and simplifications. Take the results with a pinch of salt. 🧂

Ingredient strings 🥕

The API uses ingredient strings to produce scores. A string of characters that consist of three key elements: a name, an amount and the unit used to specify that amount. Every recipe contains a set of them. For example: 1 kilogram of beef or cheese, 2 pounds (Parmesan) are both instances of an ingredient string.

Quickstart 🚀

  • Make sure you have Docker installed and that it is running.
  1. ✨ Clone repo git clone [email protected]:arienshibani/green-bite.git

  2. 🏗️ Navigate into repo and build the image docker build -t green-bite .

  3. 🐋 Run container docker run -p 80:80 green-bite

The Open API specification should now be available locally via your webbrowser 👉 http://0.0.0.0/docs, and you can test the API.

Usage 📚

The API exposes two main endpoints. One for parsing individual ingredient strings and one for scoring entire recipes.

GET /parse/ingredient/{ingredientString}

The parse/ingredient endpoint takes an ingredient string as input and returns a sustainability score along with details about the ingredient. The details can be useful for debugging and understanding which entry was actually used to produce the score.

  • The string must be sent in as a query parameter.
    • Example request URL for calculating the score of 1kg Bacon 👉 /parse/ingredient/1%20kg%20of%20bacon
{ // Successful 200 Response.
 "inputIngredientString": "1 kg of bacon",
 "ingredientMatched": "bacon",
 "sustainabilityScore": 26.05213129,
 "details": {
  "quantity": 1,
  "measurement": "kg",
  "description": "bacon"
  }
}

POST /score?ingredients=1%{ingredientString#1}%2{ingredientString#2}

The score endpoint can be used to score any number of ingredient strings. Given an array of ingredient strings, it returns the combined sustainability score. Only the score is returned, no details about the individual ingredients. This endpoint is particularly useful for scoring entire recipes.

  • The array of ingredient strings must be sent in as query parameters.
  • Example request URL for calculating a simple milk pudding recipe containing milk, sugar and cornstarch. 👇
    • http://0.0.0.0/score?ingredients=1%20cups%20of%20milk&ingredients=3%20tablespoons%20sugar&ingredients=2%20tablespoons%20cornstarch
// Successful 200 response
0.7855314915881078

Disclaimers 📜

  • This project is licensed under the Creative Commons Attribution-NonCommercial 4.0 International (CC BY-NC 4.0) license.
    • Feel free to use, share and adapt this software for any non-commercial purposes. Credit is appreciated.
  • This software was developed solely for academic purposes as part of my master's thesis: "Ingredient matching to determine the sustainability of online recipes (Information Science, UiB: 2022)".
  • The data used to calculate the scores is based on the SHARP database and is not my own. I take no responsibility for the accuracy of the data or the results produced by this software.