passing and receiving orders from kitchen

This commit is contained in:
= 2020-05-13 01:59:34 +02:00
parent a2e474d520
commit be49eb4d00
9 changed files with 108 additions and 58 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 196 KiB

View File

@ -10,12 +10,12 @@ from kelner.src.managers.WaiterManager import WaiterManager
from kelner.src.algorithms.DecisionTree import Tree_Builder
# create screen consts
Scale = 2 # scale for all images used within project
CellSize = round(50 * Scale) # pixel size of 1 square cell in the grid
PaintOffset = CellSize # pixel size of paint offset for all drawables
GridCountX = 15 # number of columns in grid
GridCountY = 9 # number of rows in grid
ScreenWidth = CellSize * GridCountX + 2 * PaintOffset # screen width in pixels
Scale = 2 # scale for all images used within project
CellSize = round(50 * Scale) # pixel size of 1 square cell in the grid
PaintOffset = CellSize # pixel size of paint offset for all drawables
GridCountX = 15 # number of columns in grid
GridCountY = 9 # number of rows in grid
ScreenWidth = CellSize * GridCountX + 2 * PaintOffset # screen width in pixels
ScreenHeight = CellSize * GridCountY + 2 * PaintOffset # screen height in pixels
# initialize background
@ -28,7 +28,7 @@ drawableManager = DrawableCollection()
menuManager = MenuManager()
##TESTING THE DECISION TREE
#Testing Data
# Testing Data
testing_db = [
[1, 0, 0, 0, "Kurczak"],
[0, 1, 0, 0, "Piwo"],
@ -37,10 +37,10 @@ testing_db = [
]
#Building a decision tree
# Building a decision tree
Test_Tree = Tree_Builder.build_tree(testing_db)
#Testing the tree
# Testing the tree
if Tree_Builder.zgadnij(testing_db[0], Test_Tree) == "Kurczak":
print("test1: passed")
else:
@ -61,7 +61,6 @@ if Tree_Builder.zgadnij(testing_db[3], Test_Tree) == "Salad":
else:
print("test4: fail")
# initialize waiter component
waiter1 = Waiter(0, 0, 0, GridCountX - 1, 0, GridCountY - 1, CellSize, PaintOffset)
# waiter2 = Waiter(0, GridCountY - 1, 0, GridCountX - 1, 0, GridCountY - 1, CellSize, PaintOffset)
@ -77,10 +76,10 @@ drawableManager.add(waiter1)
# TODO: create kitchen
kitchen = Kitchen(5, GridCountX-5, 5, GridCountY-5, CellSize, PaintOffset)
kitchen = Kitchen(5, GridCountX - 5, 5, GridCountY - 5, CellSize, PaintOffset)
drawableManager.add(kitchen)
#My comment
# My comment
# initialize a number of tables given in range
for i in range(0, 40):
table = Table(1, GridCountX - 2, 1, GridCountY - 2, CellSize, PaintOffset)

View File

@ -12,13 +12,28 @@ class Kitchen(Drawable):
# call base class constructor
super().__init__(14, 0, minX, maxX, minY, maxY, cellSize, offset)
self._preparing_orders = []
self._ready_orders = []
self._ready_orders = None
self._photos_path = os.path.join(os.getcwd(), 'foodImages')
def get_new_orders(self, orders):
pass
def pass_new_orders(self, orders):
for table, order in orders.items():
self._preparing_orders.append((table, order))
# print("Orders prepared in kitchen: {}".format(self._preparing_orders))
def get_ready_orders(self):
if self._ready_orders:
out = self._ready_orders[:]
self._ready_orders.clear()
self._ready_orders = self._preparing_orders
return out
else:
self._ready_orders = self._preparing_orders
return []
def clear_preparing_orders(self):
self._preparing_orders.clear()
def draw(self, screen):
xBase = self.getX() * self.getCellSize() + self.getOffset()
yBase = self.getY() * self.getCellSize() + self.getOffset()
@ -29,5 +44,3 @@ class Kitchen(Drawable):
def drawAux(self, screen):
pass

View File

@ -24,6 +24,7 @@ class Table(Drawable):
self.__tableLock = Lock()
self.__zainteresowania = []
# Build a Decision Tree
self.Decision_Tree = Tree_Builder.build_tree(Tree_Builder.training_db)
@ -68,20 +69,25 @@ class Table(Drawable):
# return order
# waiter collects orders from table
def getOrder(self):
order = None
if self.__tableLock.acquire(False):
try:
if self.isStatus(Status.Ready) and self.hasOrder():
# Generates order
order = []
for a in range(0,len(self.__guests)):
order.append(Tree_Builder.zgadnij(self.__zainteresowania[a], self.Decision_Tree))
print("Zamowienie: " + str(order))
self.setOrder([])
finally:
self.__tableLock.release()
return order
# def getOrder(self):
# order = None
# if self.__tableLock.acquire(False):
# try:
# if self.isStatus(Status.Ready) and self.hasOrder():
# # Generates order
# order = []
# for a in range(0,len(self.__guests)):
# order.append(Tree_Builder.zgadnij(self.__zainteresowania[a], self.Decision_Tree))
# print("Zamowienie: " + str(order))
# self.setOrder([])
# finally:
# self.__tableLock.release()
# return order
def get_order(self):
return self.__order
#def getOrder(self):
# order = None

View File

@ -131,6 +131,8 @@ class Waiter(Drawable):
def get_state(self):
return self._ready
def clear_accepted_orders(self):
self.__acceptedOrders.clear()
def draw(self, screen):

View File

@ -12,6 +12,25 @@ class KitchenManager():
def prepare_dish(self):
pass
def receive_orders(self, orders, kitchen):
kitchen.get_new_orders(orders)
def pass_orders(self, orders, kitchen):
kitchen.pass_new_orders(orders)
def get_ready_orders(self, kitchen):
return kitchen.get_ready_orders()
def draw_orders(self, kitchen):
orders_to_print = kitchen.get_ready_orders()
dishes = []
if orders_to_print:
for order in orders_to_print:
dishes.append(order[1])
print(order[0])
kitchen.clear_preparing_orders()
print(orders_to_print)
print(dishes)

View File

@ -3,28 +3,13 @@ import random
# contains all dishes and generates random order for the table
class MenuManager:
# consts, min and max dishes ordered by the people sitting by the same table
__MinDishes = 1
__MaxDishes = 3
def __init__(self):
self.__menuCard = ["PORK",
"FRENCH FRIES",
"PIZZA",
"CHICKEN",
"RIBS",
"FISH",
"SPAGHETTI",
"BEEF",
"STEAK",
"SALAD",
"GRILLED VEGETABLES",
"VEAL",
"CHOPS",
"EMPTY PLATE",
"BEER",
"CAKE"]
self.__menuCard = ['pizza', 'apple_pie', 'donuts', 'sushi', 'omelette', 'nachos', 'tiramisu', 'pho',
'carrot_cake', 'mussels', 'waffles', 'hot_dog', 'hamburger']
# generator
def generateOrder(self):
@ -33,3 +18,4 @@ class MenuManager:
for _ in range(0, count):
order += [(self.__menuCard[random.randint(0, len(self.__menuCard) - 1)])]
return order

View File

@ -5,7 +5,7 @@ from kelner.src.components.Table import Status
# creates new thread
class TableManager (threading.Thread):
class TableManager(threading.Thread):
def __init__(self, drawableManager, menuManager):
super().__init__()

View File

@ -6,8 +6,9 @@ from kelner.src.algorithms.AStar.Finder import Finder
from kelner.src.algorithms.BFS.BFS import BFS
from kelner.src.managers.KitchenManager import KitchenManager
# creates new thread
class WaiterManager (threading.Thread):
class WaiterManager(threading.Thread):
def __init__(self, drawableManager, waiters):
super().__init__()
@ -16,7 +17,6 @@ class WaiterManager (threading.Thread):
self.__runThread = True
self._kitchen_manager = KitchenManager(drawableManager)
def __getNearestTargetPath(self, waiter, target):
distance = sys.maxsize
nearestTargetPath = None
@ -27,6 +27,8 @@ class WaiterManager (threading.Thread):
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:
for table in tables:
if table.hasOrder():
@ -71,12 +73,14 @@ class WaiterManager (threading.Thread):
turns = result
lessTurnsTable = table
if lessTurnsTable is not None:
tables.remove(lessTurnsTable)
self.__changeWaiterDirection(waiter, lessTurnsTable.getX(), lessTurnsTable.getY())
order = lessTurnsTable.getOrder()
if order is not None:
# order = lessTurnsTable.getOrder()
order = lessTurnsTable.get_order()
if order is not None and waiter.get_state:
waiter.addOrder(lessTurnsTable, order)
time.sleep(2)
lessTurnsTable.setStatus(Status.Waiting)
@ -85,7 +89,22 @@ class WaiterManager (threading.Thread):
def pass_orders_to_kitchen(self, orders):
kitchen = self.__drawableManager.get_kitchen()
self._kitchen_manager.receive_orders(orders, kitchen)
self._kitchen_manager.pass_orders(orders, kitchen)
def receive_ready_orders(self, waiter):
kitchen = self.__drawableManager.get_kitchen()
try:
ready_orders = kitchen.get_ready_orders()
for dish in ready_orders:
print("Orders ready to take", end=" ")
print(dish[1])
except IndexError as e:
print("No orders")
waiter.make_ready()
waiter.clear_accepted_orders()
print("Ready to go")
# changes the status of a random table from NotReady to Ready
@ -109,8 +128,14 @@ class WaiterManager (threading.Thread):
self.__moveWaiter(waiter, step[0], step[1])
if len(waiter.get_current_path()) == 0 and target == 'kitchen':
self.pass_orders_to_kitchen(waiter.getAcceptedOrders)
print(waiter.getAcceptedOrders())
kitchen = self.__drawableManager.get_kitchen()
self.pass_orders_to_kitchen(waiter.getAcceptedOrders())
# print(waiter.getAcceptedOrders())
if self.receive_ready_orders(waiter):
self._kitchen_manager.draw_orders(kitchen)
target = 'table'
print(1)
else:
self.__collectOrder(waiter)