waiter recognizes images, checks prediction, serves dish with correlated table

This commit is contained in:
= 2020-05-17 02:22:51 +02:00
parent 723568cf31
commit 23b85d2549
8 changed files with 167 additions and 97 deletions

View File

@ -34,7 +34,6 @@ load_model_thread.start()
# joining this thread to main thread. Man thread will be started after this finish
load_model_thread.join()
# initialize drawable objects manager
drawableManager = DrawableCollection()

View File

@ -5,7 +5,6 @@ import numpy as np
import kelner.src.settings as settings
class Predictor:
def __init__(self, food_list):
self._food_list = food_list
@ -26,7 +25,6 @@ class Predictor:
print("THIS IS A:{}".format(pred_value))
def predict_class(self, img):
img = image.load_img(img, target_size=(224, 224))
img = image.img_to_array(img)
img = np.expand_dims(img, axis=0)
@ -38,3 +36,4 @@ class Predictor:
pred_value = self._food_list[index]
# print("Pred: {}, index: {}, pred_value:{}".format(pred, index, pred_value))
print("THIS IS A:{}".format(pred_value))
return pred_value

View File

@ -36,6 +36,9 @@ class Drawable:
def getY(self):
return self.__y
def get_posistion(self):
return self.getX(), self.getY()
def getMinX(self):
return self.__minX

View File

@ -5,6 +5,7 @@ from kelner.src.components.Drawable import Drawable
from kelner.src.managers.ImageCache import ImageCache, Images
from kelner.src.algorithms.DecisionTree import Tree_Builder
# status of the table
class Status(Enum):
NotReady = 0
@ -24,7 +25,6 @@ class Table(Drawable):
self.__tableLock = Lock()
self.__zainteresowania = []
# Build a Decision Tree
self.Decision_Tree = Tree_Builder.build_tree(Tree_Builder.training_db)
@ -87,8 +87,6 @@ class Table(Drawable):
def get_order(self):
return self.__order
# def getOrder(self):
# order = None
# if self.__tableLock.acquire(False):

View File

@ -25,6 +25,8 @@ class Waiter(Drawable):
self.__currentPath = []
self._ready = True
self._target = 'table'
self._remaining_targets = []
self._remaining_positions = []
def moveUp(self):
if self.getY() > self.getMinY():
@ -77,7 +79,6 @@ class Waiter(Drawable):
def getDirection(self):
return self.__dx, self.__dy
def setDirection(self, dx, dy):
self.__dx = dx
self.__dy = dy
@ -135,7 +136,6 @@ class Waiter(Drawable):
def clear_accepted_orders(self):
self.__acceptedOrders.clear()
def draw(self, screen):
direction = self.getDirection()
imageKind = None
@ -186,3 +186,15 @@ class Waiter(Drawable):
def set_target(self, target):
self._target = target
def add_remaining_target(self, target):
self._remaining_targets.append(target)
def get_remaining_targets(self):
return self._remaining_targets
def add_remaining_position(self, target):
self._remaining_positions.append(target)
def get_remaining_positions(self):
return self._remaining_positions

View File

@ -12,21 +12,31 @@ class TableManager(threading.Thread):
self.__drawableManager = drawableManager
self.__menuManager = menuManager
self.__runThread = True
self._active = True
# changes the status of a random table from NotReady to Ready
def run(self):
while self.__runThread:
tables = self.__drawableManager.getTables(Status.NotReady)
if not self._active:
time.sleep(5)
else:
if tables:
tableIndex = random.randint(0, len(tables) - 1)
table = tables[tableIndex]
time.sleep(5)
time.sleep(7)
table.setOrder(self.__menuManager.generateOrder())
table.setStatus(Status.Ready)
self.__drawableManager.forceRepaint()
def stop(self):
self.__runThread = False
def get_table(self, position):
tables = self.__drawableManager.getTables(Status.Waiting)
for table in tables:
if (table.getX(), table.getY()) == position:
return table
def pause(self):
self._active = False
def resume(self):
self.__runThread = True
self._active = True

View File

@ -23,16 +23,16 @@ class WaiterManager(threading.Thread):
def __getNearestTargetPath(self, waiter, target):
distance = sys.maxsize
nearestTargetPath = None
tables = self.__drawableManager.getTables(Status.Ready)
if tables:
reservedPlaces = self.__drawableManager.getReservedPlaces(waiter)
tables = self.__drawableManager.getTables(Status.Ready)
finder = Finder(reservedPlaces)
origin = (waiter.getX(), waiter.getY())
if target == 'kitchen':
path = finder.getPath(origin, (14, 1), True)
path2 = finder.getPath(origin, (13, 0), True)
path = path2 if len(path) > len(path2) else path
else:
return path
if tables:
for table in tables:
if table.hasOrder():
targets = finder.getNeighbours((table.getX(), table.getY()), False)
@ -44,8 +44,20 @@ class WaiterManager(threading.Thread):
if result < distance:
distance = result
nearestTargetPath = path
return nearestTargetPath
def get_specified_path(self, waiter, table):
reserved_places = self.__drawableManager.getReservedPlaces(waiter)
finder = Finder(reserved_places)
origin = (waiter.getX(), waiter.getY())
targets = finder.getNeighbours((table[0], table[1]), False)
for target in targets:
if target is not None:
path = finder.getPath(origin, target, True)
if path:
return path
def __changeWaiterDirection(self, waiter, x, y):
targetDirection = x - waiter.getX(), y - waiter.getY()
originDirection = waiter.getDirection()
@ -107,22 +119,74 @@ class WaiterManager(threading.Thread):
print("Ready to go")
return ready_orders
def predict_orders(self, orders, waiter):
pass
def predict_order(self, order, kitchen):
food_list = self._menu_manager.get_menu()
image_predictor = Predictor(food_list)
paths = self._kitchen_manager.draw_single_order(order, kitchen)
predicted_dishes = []
self._kitchen_manager.run()
self._table_manager.pause()
# print("Printed images paths: {}".format(paths))
if paths is not None:
for img_path in paths:
predicted_dish = image_predictor.predict_class(img_path)
predicted_dishes.append(predicted_dish)
self.__drawableManager.forceRepaint()
return predicted_dishes
def match_predicted_orders(self, predicted_orders):
all_tables = self.__drawableManager.getTables(Status.Waiting)
located_orders = dict()
for p_order in predicted_orders:
p_order.sort()
for table in all_tables:
table_dishes = table.get_order()
table_dishes.sort()
if p_order == table_dishes:
located_orders[table] = p_order
return located_orders
def get_order_targets(self, orders):
targets = dict()
for table, dishes in orders.items():
targets[table.get_posistion()] = dishes
return targets
def set_next_waiter_targets(self, waiter, matched_targets):
for table in matched_targets.keys():
path = self.get_specified_path(waiter, table)
waiter.add_remaining_target(path)
def set_next_waiter_positions(self, waiter, matched_positions):
for position in matched_positions.keys():
waiter.add_remaining_position(position)
# changes the status of a random table from NotReady to Ready
def run(self):
while self.__runThread:
if self.__waiters:
for waiter in self.__waiters:
if len(waiter.getAcceptedOrders()) > 0:
if len(waiter.getAcceptedOrders()) > 1:
waiter.set_target('kitchen')
path = self.__getNearestTargetPath(waiter, target=waiter.get_target())
waiter.make_busy()
else:
if waiter.get_target() == 'return_order' and waiter.isPathEmpty():
print("Order returned")
table = self._table_manager.get_table(waiter.get_remaining_positions()[0])
table.setStatus(Status.Served)
waiter.get_remaining_positions().pop(0)
if not waiter.get_remaining_positions() == []:
waiter.set_target('return_order')
path = self.get_specified_path(waiter, waiter.get_remaining_positions()[0])
else:
waiter.set_target('table')
path = self.__getNearestTargetPath(waiter, target='table')
waiter.setPath([] if path is None else path)
if not waiter.isPathEmpty():
@ -133,51 +197,36 @@ class WaiterManager(threading.Thread):
# check if waiter is near kitchen
if (waiter.getX(), waiter.getY()) == (14, 1) or (waiter.getX(), waiter.getY()) == (13, 0):
if waiter.get_target() == 'kitchen':
self._table_manager.pause()
kitchen = self.__drawableManager.get_kitchen()
waiter_orders = waiter.getAcceptedOrders()
print("Waiter near kitchen. Collected orders: {}".format(waiter_orders))
# print("Waiter near kitchen. Collected orders: {}".format(waiter_orders))
kitchen.add_orders(waiter_orders)
received_orders = kitchen.get_ready_orders()
waiter.clear_accepted_orders()
if received_orders:
# self._kitchen_manager.draw_orders(received_orders)
# paths = self._kitchen_manager.draw_orders(received_orders, kitchen)
food_list = self._menu_manager.get_menu()
ImagePredictor = Predictor(food_list)
predicted_orders = []
for order in received_orders:
paths = self._kitchen_manager.draw_single_order(order, kitchen)
self._kitchen_manager.run()
self._table_manager.stop()
# print("Printed images paths: {}".format(paths))
if paths is not None:
for img_path in paths:
ImagePredictor.predict_class(img_path)
self.__drawableManager.forceRepaint()
# get predicted dishes
predicted_dishes = self.predict_order(order, kitchen)
predicted_orders.append(predicted_dishes)
# check if all predicted orders were really ordered
matched_targets = self.match_predicted_orders(predicted_orders)
# get positions to matched orders (X,Y): dish
order_positions = self.get_order_targets(matched_targets)
self.set_next_waiter_positions(waiter, order_positions)
# set new ready paths to waiter
# self.set_next_waiter_targets(waiter, matched_targets)
self._kitchen_manager.stop()
self._table_manager.resume()
self._table_manager.join()
# TODO: recognize images
all_tables = self.__drawableManager.getTables(Status.Waiting)
for table in all_tables:
# order = table.get_order()
# print("Table: {}\norder: {}".format(table, order))
pass
# TODO: choose proper tableo
# TODO: set path to tables, another target
time.sleep(5)
self._kitchen_manager.stop()
kitchen.clear_orders()
waiter.make_ready()
waiter.set_target('table')
else:
elif waiter.get_target() not in ['return_order', 'check']:
self.__collectOrder(waiter)
def stop(self):