import numpy as np
import pandas as pd
import streamlit as st
from analyzed_plots import *
from pyairtable_funcs import *
from class_client import *
from creds import *
import matplotlib.pyplot as plt
import seaborn as sns
import plotly.express as px
from wordcloud import WordCloud, STOPWORDS
import pandas as pd
import numpy as np
from pyairtable_funcs import *
from PIL import Image
from pyairtable import Table
import ast
import numpy as np
import requests
import json
import pandas as pd
from IPython.display import display
from creds import *
The API-Keys used are private and belong to Airtable
and Spoonacular
. To use them, you will need to create a creds.py
with the following code:
api_key = #YOUR-API-KEY
base_id = #YOUR-BASE-ID
table_name = #YOUR-TABLE-NAME
rapid_api_key = #YOUR-RAPID-API-KEY
You can obtain here your rapid_api_key
, and your Airtable
needs are specified below, under the Airtable functions title.
This is made to create instances of a client, with the attributes required to make for him:
- Calendar menu.
- Shopping list.
- Nutrition lists.
def __init__(self,name,surname,kcal,menudays,diet, exclude, address, client_id):
- Name: String with the name of our client
- Surname: String with the surname of our client
- Kcal: String with the desired calories for each day of the menu
- Menudays: List of strings with the days that the client wants to receive menu
- Diet: String with the dietary restrictions of our client. In case it has none, the string should be “ “
- Exclude: String with the ingredients the client wants to exclude from the diet, separated with commas. As with diet, if none, enter a space.
- Address: String with the address of the client.
- Client_id: String with our client ID. Optional. This is used in case that we want to upload our client to Airtable. In that case, the ID should be obtained based on the current maximum ID in the clients database.
Example:
myclient = client("Jacob","Bamio","2000",["Monday","Tuesday","Wednesday","Thursday","Friday"],"vegan","peanuts, raisins","Somewhere","159")
Prints our client info (without the ID), and returns a list with each attribute.
myclient.display_info()
Replaces the client name with the one provided, and prints the change you’ve made.
myclient.edit_name("Jake")
Replaces the client surname with the one provided, and prints the change you’ve made.
myclient.edit_surname("Bam")
Replaces the client menu days of the week with the ones provided, and prints the change you’ve made.
myclient.edit_menudays(["Friday","Saturday","Sunday"])
Replaces the client dietary restriction with the one provided, and prints the change you’ve made.
myclient.edit_diet("vegetarian")
Replaces the client excluded ingredients with the one-s provided, and prints the change you’ve made.
myclient.edit_exclude("chicken, meat")
Replaces the client address with the one provided, and prints the change you’ve made.
myclient.edit_address("Somewhere 2")
Makes a request
to Spoonacular API and creates a dataframe
with [“Breakfast", "Lunch","Dinner”]
as index, and the menudays
of this client as columns.
When it’s done, it prints “Calendar menu created!”
.
myclient.create_calendar_menu()
Returns the dataframe
created in create_calendar_menu()
.
myclient.return_calendar_menu()
Displays the dataframe
created in create_calendar_menu()
.
myclient.display_calendar_menu()
Returns a list of strings
with the ids
of each recipe in the calendar menu.
myclient.return_recipes_ids()
Makes a request
to Spoonacular API and creates a list
with the information of each recipe in the menu.
After, it loops over the list
to create:
- List with the ingredient names of every recipe.
- List with the ingredient amounts of every recipe.
- List with the ingredient units of every recipe.
In the end, creates a dataframe
with lists
as columns, and prints “Shopping list created!”
.
myclient.create_shopping_list()
Returns the dataframe
created in create_shopping_list()
.
myclient.return_shopping_list()
Displays the dataframe
created in create_shopping_list()
.
myclient.display_shopping_list()
Returns the list
with all the recipes info.
myclient.return_recipe_info()
Returns a dictionary
with recipes as keys
and a list of strings
with each step for the recipe.
myclient.return_recipes_instructions()
Prints each step of every recipe in the created menu.
myclient.display_recipes_instructions()
Creates the following lists and dataframes:
- Lists:
- Nutrient names.
- Nutrient amounts.
- Nutrient units.
- Nutrient PDN (Percentage of Daily Needs).
- Properties names.
- Properties amounts.
- Properties units.
- Dataframes:
- Nutrients.
- Properties.
When it finishes, prints: “Nutrition lists created!”
.
Returns nutrients dataframe
created in create_nutrition_lists()
myclient.return_nutrients_list()
Displays nutrients dataframe
created in create_nutrition_lists()
myclient.display_nutrients_list()
Returns properties dataframe
created in create_nutrition_lists()
myclient.return_properties_list()
Displays properties dataframe
created in create_nutrition_lists()
myclient.return_nutrients_list()
These are made to interact with the Airtable clients database, using pyairtable.
The structure of the database model for this app looks like this:
Name | Surname | Calories | Days of the menu | Diet | Excluded ingredients | Address | ID |
---|---|---|---|---|---|---|---|
STR | STR | STR | STR | STR | STR | STR | STR |
Loads a list
of clients to Airtable
clients = [
["Jake","Bam","2000",["Monday","Tuesday","Wednesday","Thursday","Friday"],"vegan","peanuts, raisins","Somewhere 1","159"],
["Jacob","Bamio","2500",["Monday","Tuesday","Wednesday","Thursday","Friday"]," ","raisins","Somewhere 2","160"]
]
load_list_of_clients_to_airtable(clients,api_key, base_id, table_name):
Loads one client to Airtable.
myclient = ["Jacob","Bamio","2000",["Monday","Tuesday","Wednesday","Thursday","Friday"],"vegan","peanuts, raisins","Somewhere in Madrid","159"]
load_client_to_airtable(myclient,api_key, base_id, table_name)
Returns a list
with all the clients in the Airtable database.
airtable_clients = extract_all_clients_from_airtable(api_key, base_id, table_name)
Returns the client from Airtable that matches the client_id
passed to the function.
myclient = extract_client_from_airtable("159",api_key, base_id, table_name)
Returns the higher ID in the entire Airtable database, in order to give the next to a new client.
max_id = return_max_id(api_key, base_id, table_name)
Deletes all the records in the Airtable database. Just used in case it’s needed for any test.
delete_all_records(api_key, base_id, table_name)
These are made show our client interesting data allocated in the app.
Returns a figure
with a comparative between the dietary restrictions of our clients, made with matplotlib
.
fig = return_pie_diets(api_key,base_id,table_name)
Returns a figure
with a wordcloud
that shows the main ingredients in our client menu. It requires a shopping list
to extract the ingredients, that can be obtained with return_shopping_list()
.
fig = return_wordcloud_graph(myclient.return_shopping_list())
Returns a figure
with a sunburst
from plotly
that shows the mean PDN of the nutrients in our client menu. It requires a nutrients list
to extract the values, that can be obtained with return_nutrients_list()
.
fig = return_sunburst_graph(myclient.return_nutrients_list())
Returns a figure
with a seaborn bar plot
that shows the mean PDN of the macronutrients in our client menu. It requires a nutrients list
to extract the values, that can be obtained with return_nutrients_list()
.
fig = return_macronutrients_graph(myclient.return_nutrients_list())
Returns a figure
with a seaborn bar plot
that shows the mean PDN of the micronutrients in our client menu. It requires a nutrients list
to extract the values, that can be obtained with return_nutrients_list()
.
fig = return_micronutrients_graph(myclient.return_nutrients_list())