1
0
forked from s444417/ProjektAI

kitchen prints images, stopping threads

This commit is contained in:
= 2020-05-14 23:22:30 +02:00
parent be49eb4d00
commit 87483f5838
75 changed files with 199 additions and 55 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 196 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 67 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

View File

@ -8,6 +8,7 @@ from kelner.src.managers.MenuManager import MenuManager
from kelner.src.managers.TableManager import TableManager from kelner.src.managers.TableManager import TableManager
from kelner.src.managers.WaiterManager import WaiterManager from kelner.src.managers.WaiterManager import WaiterManager
from kelner.src.algorithms.DecisionTree import Tree_Builder from kelner.src.algorithms.DecisionTree import Tree_Builder
from kelner.src.managers.KitchenManager import KitchenManager
# create screen consts # create screen consts
Scale = 2 # scale for all images used within project Scale = 2 # scale for all images used within project
@ -78,6 +79,8 @@ drawableManager.add(waiter1)
# TODO: create kitchen # 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) drawableManager.add(kitchen)
kitchenManager = KitchenManager(drawableManager, gridBoard)
# My comment # My comment
# initialize a number of tables given in range # initialize a number of tables given in range
@ -91,7 +94,7 @@ tableTask = TableManager(drawableManager, menuManager)
tableTask.start() tableTask.start()
# new thread controlling waiter # new thread controlling waiter
waiter1Task = WaiterManager(drawableManager, [waiter1]) waiter1Task = WaiterManager(drawableManager, [waiter1], kitchenManager)
waiter1Task.start() waiter1Task.start()
# waiter2Task = WaiterManager(drawableManager, [waiter2]) # waiter2Task = WaiterManager(drawableManager, [waiter2])
@ -160,6 +163,7 @@ while running:
# repaints all objects to the screen # repaints all objects to the screen
# is set only on initial paint or after keyboard event or call to forceRepaint() # is set only on initial paint or after keyboard event or call to forceRepaint()
if drawableManager.mustRepaint(): if drawableManager.mustRepaint():
gridBoard.reinitialize() if not kitchenManager.is_running():
gridBoard.draw(drawableManager) gridBoard.reinitialize()
gridBoard.udpdate() gridBoard.draw(drawableManager)
gridBoard.udpdate()

View File

@ -60,11 +60,14 @@ class Drawable:
def drawAux(self, screen): def drawAux(self, screen):
pass pass
def getImage(self, imageKind): def getImage(self, imageKind, img_path=None):
if imageKind in [Images.Guest1, Images.Guest2, Images.Guest3, Images.Plate]: if imageKind in [Images.Guest1, Images.Guest2, Images.Guest3, Images.Plate]:
size = int(self.getCellSize() / 3) size = int(self.getCellSize() / 3)
elif imageKind in [Images.Kitchen]: elif imageKind in [Images.Kitchen, Images.Dishes]:
size = int(self.getCellSize()) size = int(self.getCellSize())
else: else:
size = int(1.4 * self.getCellSize()) size = int(1.4 * self.getCellSize())
return ImageCache.getInstance().getImage(imageKind, size, size) if img_path:
return ImageCache.getInstance().getImage(imageKind, size, size, img_path)
else:
return ImageCache.getInstance().getImage(imageKind, size, size)

View File

@ -1,6 +1,6 @@
import pygame import pygame
from kelner.src.managers.ImageCache import ImageCache, Images from kelner.src.managers.ImageCache import ImageCache, Images
import time
class GridBoard: class GridBoard:
@ -30,3 +30,10 @@ class GridBoard:
# updates screen # updates screen
def udpdate(self): def udpdate(self):
pygame.display.update() pygame.display.update()
def update_and_sleep(self, sec):
pygame.display.update()
time.sleep(sec)
def get_screen(self):
return self.__screen

View File

@ -5,34 +5,95 @@ from kelner.src.components.Drawable import Drawable
from kelner.src.managers.ImageCache import ImageCache, Images from kelner.src.managers.ImageCache import ImageCache, Images
from kelner.src.algorithms.DecisionTree import Tree_Builder from kelner.src.algorithms.DecisionTree import Tree_Builder
import os import os
import copy
import time
import pygame
class Kitchen(Drawable): class Kitchen(Drawable):
def __init__(self, minX, maxX, minY, maxY, cellSize, offset): def __init__(self, minX, maxX, minY, maxY, cellSize, offset):
# call base class constructor # call base class constructor
super().__init__(14, 0, minX, maxX, minY, maxY, cellSize, offset) super().__init__(14, 0, minX, maxX, minY, maxY, cellSize, offset)
self._preparing_orders = [] self._preparing_orders = None
self._ready_orders = None self._ready_orders = None
self._photos_path = os.path.join(os.getcwd(), 'foodImages') self._photos_path = os.path.join(os.getcwd(), 'foodImages')
def pass_new_orders(self, orders): def add_orders(self, orders):
for table, order in orders.items(): if not self._preparing_orders:
self._preparing_orders.append((table, order)) self._preparing_orders = []
# print("Orders prepared in kitchen: {}".format(self._preparing_orders)) for order in orders.items():
self._preparing_orders.append(order)
print("Added {} to kitchen".format(order))
def get_ready_orders(self): def get_ready_orders(self):
print("Ready orders on kitchen: {}".format(self._ready_orders))
if self._ready_orders: if self._ready_orders:
out = self._ready_orders[:] out = self._ready_orders[:]
self._ready_orders.clear() self._ready_orders = None
self._ready_orders = self._preparing_orders if self._preparing_orders:
self._ready_orders = self._preparing_orders[:]
return out return out
else: else:
self._ready_orders = self._preparing_orders self._ready_orders = self.get_prepairing_orders()
return [] return None
def only_get_ready_orders(self):
return self._ready_orders
def get_prepairing_orders(self):
return self._preparing_orders
# def pick_ready_orders(self):
# return self._ready_orders
#
#
#
# def pass_and_return_order(self, orders):
# for table, dish in orders:
# self._preparing_orders.append((table, dish))
#
# if not 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
#
# def pass_new_orders(self, orders):
# for table, dish in orders:
# self._preparing_orders.append((table, dish))
#
def clear_orders(self):
if self._preparing_orders:
self._ready_orders = self._preparing_orders[:]
self._preparing_orders = None
#
# def clear_preparing_orders(self):
# self._preparing_orders.clear()
def draw_order(self, dishes, screen):
draw_screen = screen.get_screen()
for i, dish in enumerate(dishes):
img_path = str(dish) + '/' + str(random.randint(0, 4)) + '.jpg'
print("Image drawing: {}".format(img_path))
image = self.getImage(Images.Dishes, img_path)
size = int(self.getCellSize())
print(os.getcwd())
image = pygame.transform.scale((pygame.image.load(os.path.join(os.getcwd(), 'images', 'testDishes', img_path))), (size, size))
print((13 - i) * self.getCellSize(), 1 * self.getCellSize())
draw_screen.blit(image, ((13 - i) * self.getCellSize(), 1 * self.getCellSize()))
screen.udpdate()
# screen.update_and_sleep(5)
def clear_preparing_orders(self):
self._preparing_orders.clear()
def draw(self, screen): def draw(self, screen):
xBase = self.getX() * self.getCellSize() + self.getOffset() xBase = self.getX() * self.getCellSize() + self.getOffset()
@ -43,4 +104,17 @@ class Kitchen(Drawable):
screen.blit(image, (xBase - tableXYOffset, yBase - tableXYOffset)) screen.blit(image, (xBase - tableXYOffset, yBase - tableXYOffset))
def drawAux(self, screen): def drawAux(self, screen):
# orders = self.only_get_ready_orders()
# if orders:
# for order in orders:
# dishes = order[1]
# if dishes:
# for i, dish in enumerate(dishes):
# img_path = str(dish) + '/' + str(random.randint(0, 4)) + '.jpg'
# image = self.getImage(Images.Dishes, img_path)
# print((13 - i) * self.getCellSize(), 1 * self.getCellSize())
# print((13 - i) * self.getCellSize(), 1 * self.getCellSize())
# screen.blit(image, ((13 - i) * self.getCellSize(), 1 * self.getCellSize()))
pass pass

View File

@ -24,6 +24,7 @@ class Waiter(Drawable):
self.__acceptedOrders = dict() self.__acceptedOrders = dict()
self.__currentPath = [] self.__currentPath = []
self._ready = True self._ready = True
self._target = 'table'
def moveUp(self): def moveUp(self):
if self.getY() > self.getMinY(): if self.getY() > self.getMinY():
@ -179,3 +180,9 @@ class Waiter(Drawable):
textXOffset = toolTipXOffset + int((toolTipWidth - textWidth) / 2) textXOffset = toolTipXOffset + int((toolTipWidth - textWidth) / 2)
textYOffset = toolTipYOffset + int((toolTipHeight - textHeight) / 2) textYOffset = toolTipYOffset + int((toolTipHeight - textHeight) / 2)
screen.blit(imageText, (self.__xBase + textXOffset, self.__yBase + textYOffset)) screen.blit(imageText, (self.__xBase + textXOffset, self.__yBase + textYOffset))
def get_target(self):
return self._target
def set_target(self, target):
self._target = target

View File

@ -125,6 +125,9 @@ class DrawableCollection:
def mustRepaint(self): def mustRepaint(self):
return self.__mustRepaint return self.__mustRepaint
def stopRepaint(self):
self.__mustRepaint = False
# draws all objects stored in collection # draws all objects stored in collection
def draw(self, screen): def draw(self, screen):
for item in self.__drawables: for item in self.__drawables:

View File

@ -22,6 +22,7 @@ class Images(Enum):
Guest3 = 15 Guest3 = 15
ToolTip = 16 ToolTip = 16
Kitchen = 17 Kitchen = 17
Dishes = 18
class ImageCache: class ImageCache:
@ -58,19 +59,25 @@ class ImageCache:
Images.Guest2: './images/wiking_rudy.png', Images.Guest2: './images/wiking_rudy.png',
Images.Guest3: './images/wiking_rudy2.png', Images.Guest3: './images/wiking_rudy2.png',
Images.ToolTip: './images/tooltip.png', Images.ToolTip: './images/tooltip.png',
Images.Kitchen: './images/kitchen.png'} Images.Kitchen: './images/kitchen.png',
Images.Dishes: './images/testDishes/'
}
def __getFont(self): def __getFont(self):
if self.__font is None: if self.__font is None:
self.__font = pygame.font.SysFont('comicsansms', 24, True) self.__font = pygame.font.SysFont('comicsansms', 24, True)
return self.__font return self.__font
def getImage(self, imageKind, width, height): def getImage(self, imageKind, width, height, img_path=None):
key = imageKind.name + ':' + str(width) + 'x' + str(height) key = imageKind.name + ':' + str(width) + 'x' + str(height)
image = self.__images.get(key, None) image = self.__images.get(key, None)
if image is None: if image is None:
image = pygame.transform.scale((pygame.image.load(self.__paths[imageKind])), (width, height)) if not img_path:
self.__images[key] = image image = pygame.transform.scale((pygame.image.load(self.__paths[imageKind])), (width, height))
self.__images[key] = image
else:
image = pygame.transform.scale((pygame.image.load(self.__paths[imageKind] + img_path)), (width, height))
self.__images[key] = image
return image return image
def getTextImage(self, text, color, height): def getTextImage(self, text, color, height):

View File

@ -4,10 +4,14 @@ import sys
# creates new thread # creates new thread
class KitchenManager(): class KitchenManager(threading.Thread):
def __init__(self, drawable_manager): def __init__(self, drawable_manager, gridboard):
super().__init__()
self._drawable_manager = drawable_manager self._drawable_manager = drawable_manager
self._gridboard = gridboard
self.__runThread = False
def prepare_dish(self): def prepare_dish(self):
pass pass
@ -16,21 +20,38 @@ class KitchenManager():
kitchen.pass_new_orders(orders) kitchen.pass_new_orders(orders)
def get_ready_orders(self, kitchen): def get_ready_orders(self, kitchen):
return kitchen.get_ready_orders() out = kitchen.get_ready_orders()
kitchen.clear_orders()
def draw_orders(self, kitchen): return out
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()
def pass_and_return_order(self, orders, kitchen):
return kitchen.pass_and_return_order(orders)
def draw_orders(self, orders, kitchen):
if orders:
for order in orders:
dishes = order[1]
if dishes:
kitchen.draw_order(dishes, self._gridboard)
def run(self, orders, kitchen):
self.__runThread = True
self.draw_orders(orders, kitchen)
time.sleep(10)
def stop(self):
self.__runThread = False
def is_running(self):
return self.__runThread
# def draw_orders(self, kitchen, orders, draw_manager):
# for order in orders:
# dishes = order[1]
# i = 0
# print("DISHES TO PRINT: {}".format(dishes))
print(orders_to_print)
print(dishes) # TODO: draw real images

View File

@ -4,18 +4,17 @@ import sys
from kelner.src.components.Table import Status from kelner.src.components.Table import Status
from kelner.src.algorithms.AStar.Finder import Finder from kelner.src.algorithms.AStar.Finder import Finder
from kelner.src.algorithms.BFS.BFS import BFS from kelner.src.algorithms.BFS.BFS import BFS
from kelner.src.managers.KitchenManager import KitchenManager
# creates new thread # creates new thread
class WaiterManager(threading.Thread): class WaiterManager(threading.Thread):
def __init__(self, drawableManager, waiters): def __init__(self, drawableManager, waiters, kitchenManager):
super().__init__() super().__init__()
self.__drawableManager = drawableManager self.__drawableManager = drawableManager
self.__waiters = waiters self.__waiters = waiters
self.__runThread = True self.__runThread = True
self._kitchen_manager = KitchenManager(drawableManager) self._kitchen_manager = kitchenManager
def __getNearestTargetPath(self, waiter, target): def __getNearestTargetPath(self, waiter, target):
distance = sys.maxsize distance = sys.maxsize
@ -94,7 +93,7 @@ class WaiterManager(threading.Thread):
def receive_ready_orders(self, waiter): def receive_ready_orders(self, waiter):
kitchen = self.__drawableManager.get_kitchen() kitchen = self.__drawableManager.get_kitchen()
try: try:
ready_orders = kitchen.get_ready_orders() ready_orders = self._kitchen_manager.get_ready_orders(kitchen)
for dish in ready_orders: for dish in ready_orders:
print("Orders ready to take", end=" ") print("Orders ready to take", end=" ")
print(dish[1]) print(dish[1])
@ -103,6 +102,7 @@ class WaiterManager(threading.Thread):
waiter.make_ready() waiter.make_ready()
waiter.clear_accepted_orders() waiter.clear_accepted_orders()
print("Ready to go") print("Ready to go")
return ready_orders
@ -112,10 +112,9 @@ class WaiterManager(threading.Thread):
while self.__runThread: while self.__runThread:
if self.__waiters: if self.__waiters:
for waiter in self.__waiters: for waiter in self.__waiters:
target = 'table'
if len(waiter.getAcceptedOrders()) > 0: if len(waiter.getAcceptedOrders()) > 0:
target = 'kitchen' waiter.set_target('kitchen')
path = self.__getNearestTargetPath(waiter, target=target) path = self.__getNearestTargetPath(waiter, target=waiter.get_target())
waiter.make_busy() waiter.make_busy()
else: else:
@ -127,15 +126,34 @@ class WaiterManager(threading.Thread):
self.__changeWaiterDirection(waiter, step[0], step[1]) self.__changeWaiterDirection(waiter, step[0], step[1])
self.__moveWaiter(waiter, step[0], step[1]) self.__moveWaiter(waiter, step[0], step[1])
if len(waiter.get_current_path()) == 0 and target == 'kitchen': if (waiter.getX(), waiter.getY()) == (14, 1) or (waiter.getX(), waiter.getY()) == (13, 0):
kitchen = self.__drawableManager.get_kitchen() if waiter.get_target() == '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' kitchen = self.__drawableManager.get_kitchen()
print(1) waiter_orders = waiter.getAcceptedOrders()
print(type(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)
KM = self._kitchen_manager
KM.run(received_orders, kitchen)
KM.stop()
# TODO: recognize images
# TODO: choose proper tableo
# TODO: set path to tables, another target
print('should blit')
kitchen.clear_orders()
waiter.make_ready()
waiter.set_target('table')
else: else:
self.__collectOrder(waiter) self.__collectOrder(waiter)