Assignment
Assignment
2024-07-19
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
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()
Data Visualization
sns.heatmap(chicken.corr(), annot=True, cmap='coolwarm')
plt.title('Correlation Heatmap')
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:
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:
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()
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.
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).
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
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:
Non-Peak Hours:
17