0% found this document useful (0 votes)
3 views

Assignment

Code for python

Uploaded by

gotohell4907
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Assignment

Code for python

Uploaded by

gotohell4907
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

FoodNest Internship Assignment

Divyanshu Srivastava Gmail: [email protected]

2024-07-19

Case 1: Correlations between various variables in dish prep


Dataset
Link- https://data.mendeley.com/datasets/xsphgmmh7b/1 This dataset was scraped from the web-
site https://www.archanaskitchen.com On this website there is whole reciepe of the food with
‘RecipeName’, ‘TranslatedRecipeName’, ‘Ingredients’, ‘TranslatedIngredients’, ‘Prep’, ‘Cook’, ‘To-
tal’, ‘Servings’, ‘Cuisine’, ‘Course’, ‘Diet’, ‘Instructions’, ‘TranslatedInstructions’. This dataset is
suitable for our project because it contains all the variables needed for correlation.

Python Library
import pandas as pd
import re
import matplotlib.pyplot as plt
import seaborn as sns
import warnings
warnings.simplefilter("ignore")

Data Preprocessing
df=pd.read_csv('IndianFoodDatasetCSV.csv')
task1=df[['TranslatedRecipeName','TranslatedIngredients',
'PrepTimeInMins','CookTimeInMins','TotalTimeInMins','Cuisine']]
#find the quantity of the food
pattern = r'(\d+(?:-\d+/\d+|\s?\d*/*\d*)?\s?(?:grams|g|ml))'
task1['Quantity'] =
df['TranslatedIngredients'].str.extractall(pattern).groupby(level=0).agg(',
'.join)
task1.dropna(inplace=True)
#sumup the total quantity
def sum_quantities(quantities):
total = 0
for quantity in quantities.split(', '):
numbers = re.findall(r'\d+', quantity)
for number in numbers:

1
total += int(number)
return total

task1['Quantity'] = task1['Quantity'].apply(sum_quantities)
task1=task1[task1.Quantity>=250]
task1.head(5)

2
TranslatedRecipeName
Translate- PrepTi- Cook- Total- Cuisine Quantity
dIngredi- meInMins TimeIn- TimeIn-
ents Mins Mins
3 Gongura 500 grams 15 30 45 Andhra 500
Chicken Chicken,
Curry 2 Onion -
Recipe - chopped,
Andhra 1 Tomato
Style Go… -…
6 Udupi 500 grams 10 30 40 Udupi 530
Style AshVellai Poosanikai
Gourd (Ash
Coconut gourd/
Curry White P…
Recipe
10 Home- 250 grams 60 60 120 Fusion 750
made Dry beans
Baked - (such as
Beans cannellini
Recipe or s…
(Whole-
some &
Healthy)
13 And fish 600 grams 5 15 20 Bengali 600
soup Aar Recipes
recipe - Maach
Bengali (fish) -
style fish rohu/
in t… katla fish

29 Asian 300 grams 10 15 25 Thai 300
Style Green
Sweet beans
& Spicy (French
Green Beans) -
Beans cut int…
Recipe

Example 1: Chicken(Gravy Dish)


Here are the 8 dishes of Chicken

3
chicken_recipes = task1[task1['TranslatedRecipeName'].str.contains("Chicken",
case=False)]
# Sort the filtered DataFrame by the Quantity column in descending order
chicken_recipes_sorted = chicken_recipes.sort_values('Quantity',
ascending=False)
chicken = chicken_recipes_sorted.loc[[6509, 5233,5764,454,373,6802,3751,1618]]
chicken['PackingTime'] = chicken['Quantity'].apply(lambda x: 1 if x <= 500 else
2)
chicken.drop(['TranslatedIngredients','Cuisine'],axis=1,inplace=True)
chicken.head(10)

4
TranslatedRecipeName
PrepTimeIn- Cook- Total- Quantity Packing-
Mins TimeInMins TimeInMins Time
6509 Chicken Jal- 20 35 55 250 1
frezi Recipe
- Chicken
And Bell
Pep…
5233 Sri Lankan 15 40 55 500 1
Chicken
Curry
Recipe
5764 Classic 10 60 70 600 2
Andhra
Style
Chicken
Curry
Recipe
454 Kashmiri 30 40 70 750 2
Kokur
T Nadir
Recipe-
Chicken and
Lotu…
373 Chicken 20 45 65 800 2
and Mush-
room Pot Pie
Recipe
6802 Pumpkin 10 60 70 900 2
Curry With
Chicken
Recipe
3751 Cheesy 60 15 75 1000 2
Chicken
Tikka
Recipe
1618 Chicken 10 90 100 1250 2
Tomato
Macaroni
Recipe-
Pasta with
Ind…
5
Correlation
chicken.drop(['TranslatedRecipeName'],axis=1,inplace=True)
chicken.corr()

PrepTimeIn- CookTimeIn- TotalTimeIn- Quantity PackingTime


Mins Mins Mins
PrepTimeIn- 1.000000 −0.770666 −0.014952 0.168033 0.159877
Mins
CookTimeIn- −0.770666 1.000000 0.648691 0.438224 0.295529
Mins
TotalTimeIn- −0.014952 0.648691 1.000000 0.888295 0.654654
Mins
Quantity 0.168033 0.438224 0.888295 1.000000 0.759362
PackingTime 0.159877 0.295529 0.654654 0.759362 1.000000

Data Visualization
sns.heatmap(chicken.corr(), annot=True, cmap='coolwarm')
plt.title('Correlation Heatmap')
plt.show()

# Scatter plot for Quantity vs Preparation_Time with a line


plt.scatter(chicken['Quantity'], chicken['PrepTimeInMins'], label='Data
Points')
plt.plot(chicken['Quantity'], chicken['PrepTimeInMins'], linestyle='-',
color='orange', label='Connecting Line')
plt.title('Quantity vs Preparation Time')
plt.xlabel('Quantity')
plt.ylabel('Preparation Time')
plt.legend()
plt.show()

# Scatter plot for Quantity vs Cooking_Time with a line


plt.scatter(chicken['Quantity'], chicken['CookTimeInMins'], label='Data
Points')
plt.plot(chicken['Quantity'], chicken['CookTimeInMins'], linestyle='-',
color='orange', label='Connecting Line')
plt.title('Quantity vs Cooking Time')
plt.xlabel('Quantity')
plt.ylabel('Cooking Time')
plt.legend()
plt.show()

6
# Scatter plot for Quantity vs Total_Cooking_Time with a line
plt.scatter(chicken['Quantity'], chicken['TotalTimeInMins'], label='Data
Points')
plt.plot(chicken['Quantity'], chicken['TotalTimeInMins'], linestyle='-',
color='orange', label='Connecting Line')
plt.title('Quantity vs Total Cooking Time')
plt.xlabel('Quantity')
plt.ylabel('Total Cooking Time')
plt.legend()
plt.show()

7
8
Analysis on the results:
1. Variables Needed
To analyze the correlations between different aspects of cooking and preparation, the following
variables are needed:

• Preparation Time (PrepTimeInMins): Time taken to prepare the ingredients and


dish before cooking.
• Cooking Time (CookTimeInMins): Time taken to cook the dish.
• Total Time (TotalTimeInMins): Combined time of preparation, cooking, and
packaging.
• Quantity: Amount of the dish being prepared.
• Packing Time (PackingTime): Time taken to package the dish after cooking.

2. Mathematical/Statistical Methods Needed


To establish correlations and analyze the relationships between the variables, the following math-
ematical and statistical methods are required:

1. Pearson Correlation Coefficient:


• This measures the linear correlation between two variables, providing a value
between -1 and 1.
• A value closer to 1 indicates a strong positive correlation, while a value
closer to -1 indicates a strong negative correlation.
• Formula: r = \frac{\sum (X_i - \overline{X})(Y_i - \overline{Y})}{\sqrt{\sum
(X_i - \overline{X})^2 \sum (Y_i - \overline{Y})^2}}

9
2. Scatter Plots:
• Visual representations to identify the relationship and potential correlation
between two variables.
• Plotting Quantity vs Preparation Time, Quantity vs Cooking Time, etc.
3. Correlation Matrix:
• A table showing the correlation coefficients between multiple variables to
understand the relationships collectively.

3. Correlation between Cooking Time and Preparation Time with Different Quantities
of Chicken
Based on the correlation matrix, we can infer the following about the relationship between Cook-
ing Time and Preparation Time for different quantities:

•Correlation between Cooking Time and Preparation Time: -0.771


•This strong negative correlation indicates that as the preparation time
increases, the cooking time tends to decrease. Conversely, shorter preparation
times are associated with longer cooking times. This suggests a possible trade-
off between the time spent preparing the dish and the time needed to cook it.

4. Correlation Between Quantity, Preparation, Cooking, and Packaging Time


• Correlation between Quantity and Preparation Time: 0.168 A weak positive correlation indicates
a slight increase in preparation time as the quantity increases.
• Correlation between Quantity and Cooking Time: 0.438 A moderate positive correlation sug-
gests that as the quantity increases, the cooking time tends to increase as well.
• Correlation between Quantity and Total Time: 0.888 A strong positive correlation shows that as
the quantity of the dish increases, the total time required (which includes preparation, cooking,
and packaging) increases significantly.
• Correlation between Quantity and Packing Time: 0.759 A strong positive correlation indicates
that larger quantities are associated with longer packaging times.

5. Summary and Insights from Graphs:

Preparation Time vs Quantity: There is no clear linear relationship. Preparation


time fluctuates with varying quantities, which could be due to different
preparation requirements for different quantities.
Cooking Time vs Quantity: Cooking time also shows fluctuations with varying
quantities, indicating that different quantities might require different cooking
processes or techniques.
Total Cooking Time vs Quantity: There is a clearer upward trend in total cooking
time with increasing quantities, suggesting that larger quantities generally
require more total cooking time.

10
Example 2: Paneer
Here are the 5 dishes of Paneer

paneer_recipes = task1[task1['TranslatedRecipeName'].str.contains("Paneer",
case=False)]
paneer_recipes_sorted = paneer_recipes.sort_values('Quantity', ascending=False)
paneer = paneer_recipes_sorted.loc[[2776,5840,5492,386,1078]]
paneer['PackingTime'] = paneer['Quantity'].apply(lambda x: 1 if x <= 500 else
2)
paneer.head()
paneer.drop(['TranslatedIngredients','Cuisine'],axis=1,inplace=True)
paneer.head(10)

TranslatedRecipeName
PrepTimeIn- Cook- Total- Quantity Packing-
Mins TimeInMins TimeInMins Time
2776 Achari Pa- 15 15 30 250 1
neer Masala
Recipe
5840 Aloo Matar 10 45 55 500 1
Paneer
Curry
Recipe
5492 Orio Pa- 35 10 45 575 2
neer Modak
Recipe
386 Palak Pa- 20 40 60 750 2
neer Recipe -
Palak Paneer
Recipe
1078 Spicy Lemon 20 20 40 800 2
Chilli Pa-
neer Tart
With Curry
Leav…

Correlation
paneer.drop(['TranslatedRecipeName'],axis=1,inplace=True)
paneer.corr()

11
PrepTimeIn- CookTimeIn- TotalTimeIn- Quantity PackingTime
Mins Mins Mins
PrepTimeIn- 1.000000 −0.643593 −0.055972 0.289344 0.731925
Mins
CookTimeIn- −0.643593 1.000000 0.800191 0.237838 −0.234484
Mins
TotalTimeIn- −0.055972 0.800191 1.000000 0.536994 0.267652
Mins
Quantity 0.289344 0.237838 0.536994 1.000000 0.832250
PackingTime 0.731925 −0.234484 0.267652 0.832250 1.000000

Data Visualization
sns.heatmap(paneer.corr(), annot=True, cmap='coolwarm')
plt.title('Correlation Heatmap')
plt.show()

# Scatter plot for Quantity vs Preparation_Time with a line


plt.scatter(paneer['Quantity'], paneer['PrepTimeInMins'], label='Data Points')
plt.plot(paneer['Quantity'], paneer['PrepTimeInMins'], linestyle='-',
color='orange', label='Connecting Line')
plt.title('Quantity vs Preparation Time')
plt.xlabel('Quantity')
plt.ylabel('Preparation Time')
plt.legend()
plt.show()

# Scatter plot for Quantity vs Cooking_Time with a line


plt.scatter(paneer['Quantity'], paneer['CookTimeInMins'], label='Data Points')
plt.plot(paneer['Quantity'], paneer['CookTimeInMins'], linestyle='-',
color='orange', label='Connecting Line')
plt.title('Quantity vs Cooking Time')
plt.xlabel('Quantity')
plt.ylabel('Cooking Time')
plt.legend()
plt.show()

# Scatter plot for Quantity vs Total_Cooking_Time with a line


plt.scatter(paneer['Quantity'], paneer['TotalTimeInMins'], label='Data Points')
plt.plot(paneer['Quantity'], paneer['TotalTimeInMins'], linestyle='-',
color='orange', label='Connecting Line')
plt.title('Quantity vs Total Cooking Time')
plt.xlabel('Quantity')

12
plt.ylabel('Total Cooking Time')
plt.legend()
plt.show()

13
14
Analysis on the results:
1. Correlation between Cooking Time and Preparation Time with Different Quantities
of Paneer
Based on the correlation matrix, we can infer the following about the relationship between Cook-
ing Time and Preparation Time for different quantities:
Correlation between Cooking Time and Preparation Time: −0.643 • This moderate negative cor-
relation suggests that as the preparation time increases, the cooking time tends to decrease. Con-
versely, shorter preparation times are associated with longer cooking times. This indicates a trade-
off between preparation and cooking time.

2. Correlation Between Quantity, Preparation, Cooking, and Packaging Time


• Correlation between Quantity and Preparation Time: 0.289 A weak positive correlation indicates
a slight increase in preparation time as the quantity increases.
• Correlation between Quantity and Cooking Time: 0.238 A weak positive correlation suggests
that as the quantity increases, the cooking time slightly increases.
• Correlation between Quantity and Total Time: 0.537 A moderate positive correlation indicates
that as the quantity increases, the total time required (preparation + cooking + packaging) tends
to increase.
• Correlation between Quantity and Packing Time: 0.832 A strong positive correlation shows that
as the quantity increases, the packing time increases significantly.

15
3. Summary and Insights from Graphs:
Quantity vs Preparation Time • The data points indicate that there is some variability in prepa-
ration time with respect to the quantity. • As seen in the plot, there are fluctuations, but overall,
there is a weak positive correlation (0.289).
Quantity vs Cooking Time • The data points indicate variability, but there is a general trend of
increasing cooking time with increasing quantity. • The correlation is weakly positive (0.238).
Total Cooking Time vs Quantity • The data points indicate variability, but there is a general trend
of increasing cooking time with increasing quantity. • The correlation is partialy positive (0.54).

Case 2: Order Passing Approach to the Kitchen


Peak and Non-Peak Hours
Peak Hours: • Breakfast: 8:30-10:30 AM • Lunch: 12:30-2:30 PM • Dinner: 8:00-11:00 PM
Non-Peak Hours: All operating hours of the restaurant other than peak hours.

Asynchronous Approach
Characteristics
• Orders are passed to the kitchen once a specific order volume is reached.
• Utilizes 100% capacity of the kitchen.
• Example: - Slot Time: 2 mins - Orders Received: 20 - Kitchen Capacity: 20 orders at a time -
Order Received: - Paneer Butter Masala: - Half (500ML) – 4 orders - Qtr (250ML) – 4 orders - Full
(1000ML) – 2 orders
Analysis

Total Orders in Base Quantity:


Half (500ML) – 4 orders = 4 * 2 = 8 base orders
Qtr (250ML) – 4 orders = 4 * 1 = 4 base orders
Full (1000ML) – 2 orders = 2 * 4 = 8 base orders
Total Base Orders: 8 + 4 + 8 = 20 base orders
Since the total base orders (20) match the kitchen capacity (20), no orders will
be missed.

Conclusion

• Asynchronous Approach ensures that no orders get missed as long as the total
order volume matches the kitchen capacity.
• This approach is efficient during non-peak hours when order volumes are more
predictable and can be batched effectively.

Synchronous Approach
Characteristics

16
• Orders are passed to the kitchen within a specific time window.
• Orders are passed irrespective of whether the order volume utilizes the full capacity of the
kitchen. • Example: - Slot Window: 5 mins - Kitchen Capacity: 20 orders of base order quantity
(250 ML) in one go - Order Received: - Paneer Butter Masala: - Half (500 ML) – 2 orders = 4 base
orders - Full (1000ML) – 2 orders = 8 base orders - Qtr (250ML) – 4 orders = 4 base orders - Total
Base Orders: 4 + 8 + 4 = 16 base orders
Analysis

The total base orders (16) are less than the kitchen capacity (20).
Therefore, no orders will be missed.

Conclusion

• Synchronous Approach is suitable for peak hours when order volumes are high
and need to be processed in a timely manner to ensure quick service.

Answer
Peak Hours:

• Use the Synchronous Approach:


• Ensures timely processing of orders.
• Helps manage high volumes of orders efficiently.
• Orders are passed in fixed time windows, ensuring no delays in processing.

Non-Peak Hours:

• Use the Asynchronous Approach:


• Efficiently utilizes kitchen capacity.
• Orders are passed when the kitchen can handle them, ensuring no
underutilization of resources.
• Suitable for periods with unpredictable or lower order volumes.

17

You might also like