Models¶
UserDB¶
-
class
diet_optimizer_website.models.
UserDB
(*args, **kwargs)¶ Class representing an user. In this class will be stored all data about an user.
Parameters: - user – This attribut is a One to One Field link to the django class User. In the class User are stored the first name, last name, username, email and pasword of an user.
- height – The user’s height.
- weight – The user’s weight.
- birth_date – The user’s birth date.
- activity_level – The user’s activity level. It’s a CharField and the user must choose between Sedentary, Low Active, Active, Very Active.
- diet – The user’s diet. It’s a CharField and the user must choose between a list of diet like Paleo, Vega, etc… If the user has any diet, he can chose None.
- gender – the user’s gender. It’s a CharField and the user must choose between Male or Female.
- accepts_popups – This is a boolean. It’s set to true if the user accepts to have a warning if during his recipe’s search he puts food prohibited by his diet or intolerences. The user can deactivate this pop up thus the attribut would be set to false.
- timeToCook – The user can set, in his preferences, the maximum time he usually have to cook. During a recipe’s search, the total time of suggested recipes wont exceed this time (if he doesn’t change it in the get recipe’s form).
Note
There is no intolerence attribut in this class. Indeed, there is an Intolerence class, which is link to the user’s data with a ForeignKey attribut userdb. Thus the UserDB class is link to the user’s intolerences thanks to the userdb attribut of the Intolerence class.
-
exception
DoesNotExist
¶
-
exception
MultipleObjectsReturned
¶
-
as_dict
()¶ This function cast an UserDB object into a dictionnary. This is usefull when we need to send an UserDB in a request.
Returns: The dictionnary representing the UserDB.
-
user_as_dict
()¶ This function cast an User object (attribut of an UserDB object) into a dictionnary. This is usefull when we need to send an UserDB or an User in a request.
Returns: The dictionnary representing the User.
Recipe¶
-
class
diet_optimizer_website.models.
Recipe
(*args, **kwargs)¶ Class representing a Recipe. In this class will be stored some data about a Recipe.
Parameters: - recipe_id_api – Recipes are referenced in spoonacular with a different id than the one automatically generate by django. recipes_id_api attribut is the recipe’s id of spoonacular.
- title – The title’s recipe.
- link – The spoonacular link’s recipe.
- likes – The number of likes that the recipe has.
- dislikes_no_opinion – The addition of dislikes and no opinion that the recipe has.
- percent – The percentage of likes out of all votes (likes + dislikes + no opinion) for the recipe.
Note
All recipes used are in Spoonacular. The diet optimizer website access these recipes and stores the data of previous fields in the Recipe’s table.
-
exception
DoesNotExist
¶
-
exception
MultipleObjectsReturned
¶
Saved_Recipes¶
-
class
diet_optimizer_website.models.
Saved_Recipes
(*args, **kwargs)¶ Class representing a Recipe. In this class will be stored some data about a Recipe.
Parameters: - user – The user who saved the recipes. This is a ForeignKey relation, thus this is a user object.
- diet_recipes – All data from spoonacular used for displaying information about a group of recipes saved by the user.
- total_nutrients_taken – The total nutrients that a group of recipes provides.
-
exception
DoesNotExist
¶
-
exception
MultipleObjectsReturned
¶
Feedback¶
-
class
diet_optimizer_website.models.
Feedback
(*args, **kwargs)¶ Class representing a Feedback from an user for a recipe.
Parameters: - recipe – The recipe concerned by the feedback. This is a ForeignKey relation, thus this is a Recipe object.
- user – The user whose the feedback it is. This is a ForeignKey relation, thus this is an UserDB object.
- mark – The mark that the user gave for the recipe’s feedback. mark = 1 means that the user liked it, mark = 2 means that the user disliked it, mark = 3 means that the user has no opinion, mark = 4 means that the user didn’t try it yet.
- title – The feedback’s title. It’s equal to the recipe’s title that is linked to the feedback, so the feedback’s title is not unique.
-
exception
DoesNotExist
¶
-
exception
MultipleObjectsReturned
¶
Intolerences¶
-
class
diet_optimizer_website.models.
Intolerences
(*args, **kwargs)¶ Class representing Introlerence(s) of users.
Parameters: - userdb – The user whose the cuisines intolerence it is. This is a ForeignKey relation, thus this is an UserDB object.
- intolerence_name – The name of the intolerence that the user has.
Note
There is a row per user and per intelorence. For instance if a user has 2 intolerences, there’ll be 2 rows in the db, with the reference to the user and the name of each intolerence.
-
exception
DoesNotExist
¶
-
exception
MultipleObjectsReturned
¶
PreferenceCuisines¶
-
class
diet_optimizer_website.models.
PreferenceCuisines
(*args, **kwargs)¶ Class representing the cuisines the user prefer.
Parameters: - userdb – The user whose the cuisines preference it is. This is a ForeignKey relation, thus this is an UserDB object.
- cuisine_name – The name of the preference that the user has.
Note
This class is used to store the cuisines preference in order to pre fill the form when the user wants to get recipes. The user can change his preferences in the diet settings page. There is a row per user and per cuisines preference. For instance if a user has 2 cuisines preference, there’ll be 2 rows in the db, with the reference to the user and the name of each cuisines preference.
-
exception
DoesNotExist
¶
-
exception
MultipleObjectsReturned
¶
PreferenceRawFoods¶
-
class
diet_optimizer_website.models.
PreferenceRawFoods
(*args, **kwargs)¶ Class representing the raw food the user prefer.
Parameters: - userdb – The user whose the raw food preference it is. This is a ForeignKey relation, thus this is an UserDB object.
- cuisine_name – The name of the preference that the user has.
Note
This class is used to store the raw food preferences in order to pre fill the form when the user wants to get recipes. The user can change his preferences in the diet settings page. There is a row per user and per raw food preference. For instance if a user has 2 raw food preferences, there’ll be 2 rows in the db, with the reference to the user and the name of each raw food preference.
-
exception
DoesNotExist
¶
-
exception
MultipleObjectsReturned
¶
USDAfoods¶
-
class
diet_optimizer_website.models.
USDAfoods
(*args, **kwargs)¶ Class representing the different raw foods.
Parameters: - NDB_No – Automatic ID representing the number of the food in the database.
- desc – Description of the food.
- calorie – The number of calories a portion of this food provides.
- protein – The number of protein a portion of this food provides (in g).
- fat – The number of fat a portion of this food provides (in g).
- carb – The number of carbohydrates a portion of this food provides (in g).
- group_code – The code number of the group this food belongs to.
- group_name – The name of the group this food belongs to.
Note
Below are other fields used to enable food popularity.
param likes: The number of likes this food got. param dislikes_no_opinion: the number of dislikes or no opinion that this food got. param percent: The percentage of likes this food got comparend to the total number of votes it got. -
exception
DoesNotExist
¶
-
exception
MultipleObjectsReturned
¶
FeedbackRawFood¶
-
class
diet_optimizer_website.models.
FeedbackRawFood
(*args, **kwargs)¶ Class representing a Feedback from an user for a raw food.
Parameters: - food – The raw food concerned by the feedback. This is a ForeignKey relation, thus this is a USDAfoods object.
- user – The user whose feedback it is. This is a ForeignKey relation, thus this is an UserDB object.
- mark – The mark that the user gave for the raw food’s feedback. mark = 1 means that the user liked it, mark = 2 means that the user disliked it, mark = 3 means that the user has no opinion, mark = 4 means that the user didn’t try it yet.
- title – The feedback’s title. It’s equal to the raw food’s title that is linked to the feedback, so the feedback’s title is not unique.
-
exception
DoesNotExist
¶
-
exception
MultipleObjectsReturned
¶
UserData¶
-
class
diet_optimizer_website.models.
UserData
(user)¶ This class represents various data about the user that he didn’t enter himself.
For that it will use the information it knows about the user to calculate new data. This class has 6 fields:
Parameters: - age – The age of the user, calculated thanks to his birth date.
- gender – The user’s gender.
- weight – The user’s weight.
- height – The user’s height.
- exercise_level – The user’s exercise level.
- daily_nutrients – A dictionnary containing the amount of nutrients the user should consume daily in general.
-
get_BMI
()¶ This function calculate’s the BMI of the user.
Returns: A float, the user’s BMI.
-
get_PA
()¶ This function will calculate a number representing the user’s physical activity.
Returns: An arbitrary float representing the user’s physical activity.
-
get_calorie
()¶ This function will calculate the user’s physical activity and calculate accordingly the number of calories the user should take daily, also considering his age and gender.
Returns: A float, representing the number of calories the user should take daily.
-
get_carb_lower
(calories)¶ This function calculates the minimum amount of carbohydrates the user should consume per day.
Parameters: calories – The amount of calories the user should take daily. Returns: A float, minimum number of carbs the user should have per day.
-
get_carb_upper
(calories)¶ This function calculates the maximum amount of carbohydrates the user should consume per day.
Parameters: calories – The amount of calories the user should take daily. Returns: A float, maximum number of carbs the user should have per day.
-
get_daily_nutrients
()¶ This function calculates the minimum and maximum amount of each nutrients the user should take daily.
Returns: A dictionnary, containing all these nutrient information in addition to the user’s BMI.
-
get_fat_lower
(calories)¶ This function calculates the minimum amount of fat the user should consume per day.
Parameters: calories – The amount of calories the user should take daily. Returns: A float, minimum number of fat the user should have per day.
-
get_fat_upper
(calories)¶ This function calculates the maximum amount of fat the user should consume per day.
Parameters: calories – The amount of calories the user should take daily. Returns: A float, maximum number of fat the user should have per day.
-
get_protein_lower
(calories)¶ This function calculates the minimum amount of proteins the user should consume per day.
Parameters: calories – The amount of calories the user should take daily. Returns: A float, minimum number of proteins the user should have per day.
-
get_protein_upper
(calories)¶ This function calculates the maximum amount of proteins the user should consume per day.
Parameters: calories – The amount of calories the user should take daily. Returns: A float, maximum number of proteins the user should have per day.
RecipeHandler¶
-
class
diet_optimizer_website.models.
RecipeHandler
(userDB, user_daily_nutrients, cuisine, diet, intolerances, exclude_ingredients, recipe_types)¶ The RecipeHandler class is the one making sure the user will only be provided recipes that match what he is searching for.
-
get_URL
(recipe_type, offset)¶ Function used to get the url for spoonacular.
Parameters: recipe_type – The type of recipe we want our url to find. Returns: A string. The URL that will be sent to spoonacular. Note
offset is also a parameter but we have no idea what it stands for. It is just part of the URL for spoonacular.
-
get_recipes
()¶ Function used to get the list of the recipes usable with the user’s request.
Returns: A dictionnary filled with other dictionnarys containing various information about the recipes foud that satisfy the user’s needs.
-
LinearProgrammingSolver¶
-
class
diet_optimizer_website.models.
LinearProgrammingSolver
(obj, obj_nut, dict_prot, dict_fat, dict_cal, dict_carb, dict_title, dict_price, dict_time, recipe_types, daily_nutrients, max_time, asked_recipe_nutrients)¶ The LinearProgrammingSolver class will take every recipes found by the RecipeHandler as well as what the user is searching to optimize in order to find the optimal set of recipes responding to the user’s needs.
-
func_lp
()¶ This functions tries to returns the optimal list of recipes the user can cook to have the nutrients he asked for.
Returns: A list of the IDs of the recipes the user should try.
-
get_lp_output
(suggested_recipes)¶ Function used to get the spoonacular output concerning the recipes suggested by the website.
Returns: a dictionnary in Json format having all the data about the recipes the user should try.
-