AdamT_Podprojekt_Final

This commit is contained in:
s444496 2020-05-10 00:04:33 +02:00
parent 56689faa23
commit 172f97bc8c
3 changed files with 91 additions and 30 deletions

View File

@ -6,7 +6,7 @@ from kelner.src.managers.DrawableCollection import DrawableCollection
from kelner.src.managers.MenuManager import MenuManager 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
# create screen consts # create screen consts
Scale = 2 # scale for all images used within project Scale = 2 # scale for all images used within project
@ -26,6 +26,40 @@ drawableManager = DrawableCollection()
# initialize menu manager # initialize menu manager
menuManager = MenuManager() 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 # initialize waiter component

View File

@ -1,18 +1,18 @@
import random import random
training_db = [ training_db = [
[1, 0, 0, 'A'], [1, 0, 0, 1, "Kurczak"],
[1, 1, 0,'B'], [1, 1, 0, 0, "Piwo"],
[0, 1, 0, 'C'], [0, 1, 0, 0, "Pizza"],
[0, 1, 1, 'B'], [0, 1, 1, 1, "Pizza"],
[0, 0, 1, 'D'], [0, 0, 1, 0, "Salad"],
[1, 1, 0, 'B'], [1, 1, 0, 1, "Cake"],
] ]
kolumny = ["sport", "czytanie", "lucznictwo", "jedzenie"] kolumny = ["sport", "czytanie", "lucznictwo", "boks", "jedzenie"]
def kolumny_wartosci(rows, col): def kolumny_wartosci(rows, col):
@ -124,9 +124,6 @@ def build_tree(rows):
print(spacing + '--> False:')
print_tree(node.false_branch, spacing + " ")
def zgadnij(row, node): def zgadnij(row, node):
if isinstance(node, Leaf): if isinstance(node, Leaf):

View File

@ -32,16 +32,16 @@ class Table(Drawable):
sport = random.randint(0,1) sport = random.randint(0,1)
czytanie = random.randint(0,1) czytanie = random.randint(0,1)
lucznictwo = random.randint(0,1) lucznictwo = random.randint(0,1)
jedzenie = random.randint(0,1) boks = random.randint(0,1)
self.__zainteresowania.append([sport,czytanie,lucznictwo,jedzenie, "A"]) self.__zainteresowania.append([sport,czytanie,lucznictwo,boks, "A"])
def getOrder(self): ##def getOrder(self):
# Generates order ## # Generates order
order = [] ## order = []
for a in range(0,len(self.__guests)): ## for a in range(0,len(self.__guests)):
order.append(Tree_Builder.zgadnij(self.__zainteresowania[a], self.Decision_Tree)) ## order.append(Tree_Builder.zgadnij(self.__zainteresowania[a], self.Decision_Tree))
print("Zamowienie: " + str(order)) ## print("Zamowienie: " + str(order))
return order ## return order
@staticmethod @staticmethod
def __getRandomGuests(): def __getRandomGuests():
@ -53,16 +53,46 @@ class Table(Drawable):
return guests return guests
# waiter collects orders from table # waiter collects orders from table
##def getOrder(self): #def getOrder(self):
## order = None # order = None
## if self.__tableLock.acquire(False): # if self.__tableLock.acquire(False):
## try: # try:
## if self.isStatus(Status.Ready) and self.hasOrder(): # if self.isStatus(Status.Ready):
## order = self.__order # # Generates order
## self.setOrder([]) # order = []
## finally: # for a in range(0,len(self.__guests)):
## self.__tableLock.release() # order.append(Tree_Builder.zgadnij(self.__zainteresowania[a], self.Decision_Tree))
## return order # print("Zamowienie: " + str(order))
# finally:
# self.__tableLock.release()
# 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():
# order = self.__order
# self.setOrder([])
# finally:
# self.__tableLock.release()
# return order
def setOrder(self, order): def setOrder(self, order):
self.__order = order self.__order = order