In this section, the detailed structure of the system will be illustrated. To simplify the explanation, we illustrated the structure with 4 parts: placing order, delivering & picking up, updating rating and cleaning.
Placing Order
The first part we are going to talk about is placing order, as illustrated in the figure below. When an order is generated by iOS app, it will firstly be populated to our 'Order Table' in AWS DynamoDB. At the same time, this event will trigger our 'Order Predict' function in AWS Lambda, which then deliver the new order record to AWS Machine Learning to compute an estimated cooking and delivering time for this order in order to save heating energy in the box and keep the food fresh. When the regression algorithm is finished, the result will be sent back to Lambda, which takes over and populate the Order-Storage table in DynamoDB with the new order record. At the same time, Lambda also inform user about the estimated delivery time through AWS SNS. We built a Python server running on one of our AWS ec2 instance. It intermittently scan the Order-Storage table in DynamoDB and notify the restaurant about the order with a push notification when the predicted notifying time comes.
Machine learning for delivery time prediction
1) Model Structure
The machine learning model for delivery time prediction is to predict the time interval between the restaurant receiving the order and food arriving at the box, based on the type of food, the distance between the restaurant and our box, the restaurant’s particularity and the order-placing time. Taking the machine learning prediction and the customer’s required delivery time into consideration, the time for our system to place order to restaurant is decided.
The time interval can be separated into two parts. One is the food preparation time and the other is food delivery time.
The type of the food to deliver is essential to the food preparation time because different type of food require different duration to prepare. For example, a Coke only require 1 minute for preparation. However, a fried chicken may take 5 minutes to cook and pack. Our model divide food into three categories, hot food, cold food and drink.
The food preparation time also depend on the restaurant itself. The quality of staff training, the condition of machine and many other restaurant-related factors affect the food preparation time. So we take the restaurant itself into the training input.
The food delivery time is related to the distance between restaurant and our box. The larger distance will for sure increase the food delivery time.
The order-placing time affects both food preparation time and food delivery time. For instance, the rush hour not only jam the traffic, increasing the food delivery time but also increase food preparation time because at that time, more people order food.
2) Data Generation
Due to there is no existing API providing all data we need, we generate the data ourselves on two restaurants. For each restaurant, two Gaussian model are introduced. One is for ordinary time and the other is for rush hour. Compared to the model for ordinary time, the model used for rush hour has larger mean for preparation time of each kind of food, and the mean time for distance-based food delivery time is larger. The rush hour is defined form 8AM to 9:30AM, from 11AM to 1PM and form 5PM to 7PM.
The mean of each kind of food is different. Hot food is generally considered to have a larger preparation time than cold food and cold food require more time than drink. As a result, the mean of each kind of food in decreasing order is hot food, cold food and drink.
3) Training and Evaluation
We use regression method in AWS Machine Learning Service to train the model. The evaluation on our model is shown in the figure below, which illustrates The RMSE compared with RMSE baseline shows that our model is good for prediction.
The machine learning model for delivery time prediction is to predict the time interval between the restaurant receiving the order and food arriving at the box, based on the type of food, the distance between the restaurant and our box, the restaurant’s particularity and the order-placing time. Taking the machine learning prediction and the customer’s required delivery time into consideration, the time for our system to place order to restaurant is decided.
The time interval can be separated into two parts. One is the food preparation time and the other is food delivery time.
The type of the food to deliver is essential to the food preparation time because different type of food require different duration to prepare. For example, a Coke only require 1 minute for preparation. However, a fried chicken may take 5 minutes to cook and pack. Our model divide food into three categories, hot food, cold food and drink.
The food preparation time also depend on the restaurant itself. The quality of staff training, the condition of machine and many other restaurant-related factors affect the food preparation time. So we take the restaurant itself into the training input.
The food delivery time is related to the distance between restaurant and our box. The larger distance will for sure increase the food delivery time.
The order-placing time affects both food preparation time and food delivery time. For instance, the rush hour not only jam the traffic, increasing the food delivery time but also increase food preparation time because at that time, more people order food.
2) Data Generation
Due to there is no existing API providing all data we need, we generate the data ourselves on two restaurants. For each restaurant, two Gaussian model are introduced. One is for ordinary time and the other is for rush hour. Compared to the model for ordinary time, the model used for rush hour has larger mean for preparation time of each kind of food, and the mean time for distance-based food delivery time is larger. The rush hour is defined form 8AM to 9:30AM, from 11AM to 1PM and form 5PM to 7PM.
The mean of each kind of food is different. Hot food is generally considered to have a larger preparation time than cold food and cold food require more time than drink. As a result, the mean of each kind of food in decreasing order is hot food, cold food and drink.
3) Training and Evaluation
We use regression method in AWS Machine Learning Service to train the model. The evaluation on our model is shown in the figure below, which illustrates The RMSE compared with RMSE baseline shows that our model is good for prediction.
4) Algorithm for search order-placing time
Since we now have both the time customer’s required delivery time, and the predicted time between order placement and food arrival from out machine learning model. We need to search the order-placing time in order to place order to the restaurant in time.
Initialization: compare the current time and the time an hour ahead of the desire arrival time. Choose the closer to the required delivery time as the start of search. The maximum iteration number is 5.
For every iteration, based on the current searching order-placing time, use the model to predict the time interval. Add the time interval to the current searching time as the predicted arrival time. If the predicted arrival time is within 5 minutes before desire arrival time, stop iteration and store the result. Otherwise, the algorithm moves the search time with the difference between predict arrival time and desire arrival time and keep the iteration going.
Since we now have both the time customer’s required delivery time, and the predicted time between order placement and food arrival from out machine learning model. We need to search the order-placing time in order to place order to the restaurant in time.
Initialization: compare the current time and the time an hour ahead of the desire arrival time. Choose the closer to the required delivery time as the start of search. The maximum iteration number is 5.
For every iteration, based on the current searching order-placing time, use the model to predict the time interval. Add the time interval to the current searching time as the predicted arrival time. If the predicted arrival time is within 5 minutes before desire arrival time, stop iteration and store the result. Otherwise, the algorithm moves the search time with the difference between predict arrival time and desire arrival time and keep the iteration going.
Delivering & Picking Up
When a new order arrived, the restaurant will receive a "open box" button along with the push notification. When the delivery guy arrived at the smart food delivery boxes, he can click on the button and one of the available boxes will open. This is managed by a Python Flask server running on the Raspberry Pi attached to the boxes. When the button is clicked, a HTTP POST request was sent to the Flask server by our iOS app, and this event will trigger the Flask server to look into the "Order" table in AWS DynamoDB. If an order with the corresponding order number was found in the table, the server will go ahead and open one of the available boxes. After the food is put in the box, the user will receive a push notification telling him/her "your food has arrived!" so he/she can pick it up. At the same time, the Flask server will record down the order number with the number of the box storing it.
The detailed illustration of the process is in the figure below.
The detailed illustration of the process is in the figure below.
When the user come to the boxes, he can use the button under the QR code on his/her iOS app, and the box containing his/her food will open. This is done with similar method as delivery. When clicking on the button, the iOS app will send a HTTP POST request to the Flask server on Raspberry Pi. When the server received the order number, it search through all of the order number it currently have, and if found, the corresponding box will open by giving a digital high output to the corresponding relay. After the picking up process has completed, the box will discard this particular order number. This will prevent some "naughty" user from trying to use an overdue order number and open the box for the second time.
Update Rating
After the user picked up his/her food, he/she can rate the restaurant. This rating updating process is illustrated in the figure below. After user submitted a rating in his/her iOS app, the rating goes to a DynamoDB table called 'Order Table', which keeps track of the order information. This event then triggered Lambda function 'Order Predict', and update the rating in the DynamoDB table.
Cleaning
After user has picked up his/her food, the job of the smart food delivery box is not finished yet. It will automatically detect if the box is clean or needs cleaning (i.e. with spilled soup inside). This process is illustrated in the figure below. After picking up, the humidity sensors inside and outside the box will start measuring the humidity difference between them, and populate the series of measurements into 'Cleaner Table' in DynamoDB. This will trigger a Lambda function 'cleaner predict', and call Machine Learning to do a classification in terms whether the box needs cleaning or not. Depends on the result returned, our system will inform a cleaner using SNS, or put the box back to a waiting status.
Machine learning for cleaning
1) Introduction
It is inevitable for our box to have some leaked or spilled liquid inside due to the carelessness of users. If the users fail to report the leak, we need some methods to maintain hygiene in our box. According to the vaporization of the liquid, the leaked liquid will cause different pattern in terms of the decreasing rate in humidity inside box. With remaining liquid inside, the decreasing of humidity will be slower than boxes without remaining liquid. By monitoring the decrease in humidity inside box and machine learning, leaked and spilled liquid is detectable.
2) Model Structure
The model is a binary classification model representing whether there is a spill. The input is the humidity difference inside and outside the box, with a detection frequency of one data point per second, and last for 300 seconds. The measuring time period is long enough to detect the different decrease pattern.
3) Data Collection (Experiments)
To get the training data, we design an experiment in our box.
Step 1: place 50ml hot water inside our box until the humidity difference inside and outside box is stable, representing the increase in humidity when food is stored in the box.
Step 2: remove the hot water, place 5ml hot water inside our box to represent there is leak liquid or nothing to represent there is no leak.
Step 3: measure the difference inside and outside box once per second for 300 second.
The figure below shows our collection result, which shows that the difference in the pattern is obvious..
It is inevitable for our box to have some leaked or spilled liquid inside due to the carelessness of users. If the users fail to report the leak, we need some methods to maintain hygiene in our box. According to the vaporization of the liquid, the leaked liquid will cause different pattern in terms of the decreasing rate in humidity inside box. With remaining liquid inside, the decreasing of humidity will be slower than boxes without remaining liquid. By monitoring the decrease in humidity inside box and machine learning, leaked and spilled liquid is detectable.
2) Model Structure
The model is a binary classification model representing whether there is a spill. The input is the humidity difference inside and outside the box, with a detection frequency of one data point per second, and last for 300 seconds. The measuring time period is long enough to detect the different decrease pattern.
3) Data Collection (Experiments)
To get the training data, we design an experiment in our box.
Step 1: place 50ml hot water inside our box until the humidity difference inside and outside box is stable, representing the increase in humidity when food is stored in the box.
Step 2: remove the hot water, place 5ml hot water inside our box to represent there is leak liquid or nothing to represent there is no leak.
Step 3: measure the difference inside and outside box once per second for 300 second.
The figure below shows our collection result, which shows that the difference in the pattern is obvious..
4) Training and evaluation
We use binary classification method in AWS Machine Learning Service to train the model. The evaluation shows the result is accurate.
5) Result notification
Based on the prediction of the model we train, we use AWS SNS Service to inform the cleaner if the box needs cleaning.
We use binary classification method in AWS Machine Learning Service to train the model. The evaluation shows the result is accurate.
5) Result notification
Based on the prediction of the model we train, we use AWS SNS Service to inform the cleaner if the box needs cleaning.