Green Bite attempts to calculate sustainability scores for food.
Using this formula
(amount_kg * land_usage) + (amount_kg * greenhouse_gas_emissions) = sustainability_score
- 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. π§
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.
- Make sure you have Docker installed and that it is running.
-
β¨ Clone repo
git clone [email protected]:arienshibani/green-bite.git
-
ποΈ Navigate into repo and build the image
docker build -t green-bite .
-
π 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.
The API exposes two main endpoints. One for parsing individual ingredient strings and one for scoring entire recipes.
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
- Example request URL for calculating the score of 1kg Bacon π
{ // Successful 200 Response.
"inputIngredientString": "1 kg of bacon",
"ingredientMatched": "bacon",
"sustainabilityScore": 26.05213129,
"details": {
"quantity": 1,
"measurement": "kg",
"description": "bacon"
}
}
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
- 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.