1
0
forked from s444417/ProjektAI
ProjektAI/kelner/main.py

109 lines
3.5 KiB
Python

import pygame
from kelner.src.components.GridBoard import GridBoard
from kelner.src.components.Waiter import Waiter
from kelner.src.components.Kitchen import Kitchen
from kelner.src.managers.DrawableCollection import DrawableCollection
# create screen consts
from kelner.src.managers.MenuManager import MenuManager
from kelner.src.managers.TableGenerator import TableGenerator
from kelner.src.algorithms.DecisionTree import Tree_Builder
from kelner.src.managers.KitchenManager import KitchenManager
from kelner.src.algorithms.CNN.PrepareData import LoadModelThread
from kelner.src.algorithms.FoodNet import classify
import kelner.src.settings as settings
Scale = 1.5 # 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
running_tasks = {'table': [], 'waiter': []}
# initialize background
gridBoard = GridBoard(ScreenWidth, ScreenHeight)
classify.join('/src/algorithms/FoodNet/classify.py')
# start loading prediction model
settings.init()
load_model_thread = LoadModelThread()
load_model_thread.start()
# joining this thread to main thread. Man thread will be started after this finish
load_model_thread.join()
kitchenManager = KitchenManager(gridBoard)
# initialize drawable objects manager
drawableManager = DrawableCollection(kitchenManager)
# initialize menu manager
menuManager = MenuManager()
##TESTING THE DECISION TREE
# Testing Data
testing_db = [
[1, 0, 0, 0, "Kurczak"],
[0, 1, 0, 0, "Piwo"],
[0, 0, 1, 0, "Pizza"],
[0, 0, 0, 1, "Salad"],
]
# Building a decision tree
Test_Tree = Tree_Builder.build_tree(testing_db)
# Testing the tree
if Tree_Builder.zgadnij(testing_db[0], Test_Tree) == "Kurczak":
print("test1: passed")
else:
print("test1: fail")
if Tree_Builder.zgadnij(testing_db[1], Test_Tree) == "Piwo":
print("test2: passed")
else:
print("test2: fail")
if Tree_Builder.zgadnij(testing_db[2], Test_Tree) == "Pizza":
print("test3: passed")
else:
print("test3: fail")
if Tree_Builder.zgadnij(testing_db[3], Test_Tree) == "Salad":
print("test4: passed")
else:
print("test4: fail")
# initialize waiter component
waiter1 = Waiter(7, 4, 0, GridCountX - 1, 0, GridCountY - 1, CellSize, PaintOffset)
# adds waiter to drawable collection
drawableManager.add(waiter1)
kitchen = Kitchen(14, 0, 5, GridCountX - 5, 5, GridCountY - 5, CellSize, PaintOffset)
drawableManager.add(kitchen)
tableGenerator = TableGenerator(GridCountX, GridCountY, 1, GridCountX - 2, 1, GridCountY - 2, CellSize, PaintOffset, drawableManager)
tableGenerator.start()
# main loop
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
tableGenerator.stop()
drawableManager.stop()
running = False
# repaints all objects to the screen
# is set only on initial paint or call to forceRepaint()
if drawableManager.mustRepaint():
if not kitchenManager.is_running():
gridBoard.reinitialize()
gridBoard.draw(drawableManager)
gridBoard.udpdate()