drzewo decyzyjne
This commit is contained in:
parent
a8b0c0f710
commit
d7d904a4be
57
dishes.json
57
dishes.json
@ -1,36 +1,40 @@
|
||||
[
|
||||
{
|
||||
"name": "margherita",
|
||||
"pos_in_card": 0,
|
||||
"price": 20,
|
||||
"spiciness": false,
|
||||
"vege": true,
|
||||
"size": 30,
|
||||
"allergens": "",
|
||||
"allergens": "none",
|
||||
"ingridients": [ "cheese" ],
|
||||
"drink_in": true
|
||||
},
|
||||
{
|
||||
"name": "hawajska",
|
||||
"pos_in_card": 1,
|
||||
"price": 22,
|
||||
"spiciness": false,
|
||||
"vege": false,
|
||||
"size": 50,
|
||||
"allergens": "",
|
||||
"allergens": "none",
|
||||
"ingridients": [ "cheese", "ham", "pineapple" ],
|
||||
"drink_in": true
|
||||
},
|
||||
{
|
||||
"name": "funghi",
|
||||
"pos_in_card": 2,
|
||||
"price": 22,
|
||||
"spiciness": false,
|
||||
"vege": true,
|
||||
"size": 30,
|
||||
"allergens": "",
|
||||
"allergens": "none",
|
||||
"ingridients": [ "cheese", "mushrooms" ],
|
||||
"drink_in": true
|
||||
},
|
||||
{
|
||||
"name": "light",
|
||||
"pos_in_card": 3,
|
||||
"price": 24,
|
||||
"spiciness": false,
|
||||
"vege": true,
|
||||
@ -41,36 +45,40 @@
|
||||
},
|
||||
{
|
||||
"name": "4 sery",
|
||||
"pos_in_card": 4,
|
||||
"price": 24,
|
||||
"spiciness": false,
|
||||
"vege": true,
|
||||
"size": 50,
|
||||
"allergens": "",
|
||||
"allergens": "none",
|
||||
"ingridients": [ "cheese", "mozzarella", "parmesan", "gorgonzola" ],
|
||||
"drink_in": true
|
||||
},
|
||||
{
|
||||
"name": "pepperoni",
|
||||
"pos_in_card": 5,
|
||||
"price": 25,
|
||||
"spiciness": true,
|
||||
"vege": false,
|
||||
"size": 50,
|
||||
"allergens": "",
|
||||
"allergens": "none",
|
||||
"ingridients": [ "cheese", "onion", "pepperoni" ],
|
||||
"drink_in": true
|
||||
},
|
||||
{
|
||||
"name": "salami",
|
||||
"pos_in_card": 6,
|
||||
"price": 25,
|
||||
"spiciness": false,
|
||||
"vege": false,
|
||||
"size": 30,
|
||||
"allergens": "",
|
||||
"allergens": "none",
|
||||
"ingridients": [ "cheese", "salami" ],
|
||||
"drink_in": true
|
||||
},
|
||||
{
|
||||
"name": "wegetarianska",
|
||||
"pos_in_card": 7,
|
||||
"price": 25,
|
||||
"spiciness": false,
|
||||
"vege": true,
|
||||
@ -81,6 +89,7 @@
|
||||
},
|
||||
{
|
||||
"name": "barbecue",
|
||||
"pos_in_card": 8,
|
||||
"price": 26,
|
||||
"spiciness": false,
|
||||
"vege": false,
|
||||
@ -91,16 +100,18 @@
|
||||
},
|
||||
{
|
||||
"name": "miesna",
|
||||
"pos_in_card": 9,
|
||||
"price": 27,
|
||||
"spiciness": false,
|
||||
"vege": false,
|
||||
"size": 30,
|
||||
"allergens": "",
|
||||
"allergens": "none",
|
||||
"ingridients": [ "cheese", "ham", "salami", "sausage", "bacon" ],
|
||||
"drink_in": false
|
||||
},
|
||||
{
|
||||
"name": "paprykowa",
|
||||
"pos_in_card": 10,
|
||||
"price": 27,
|
||||
"spiciness": true,
|
||||
"vege": true,
|
||||
@ -111,16 +122,18 @@
|
||||
},
|
||||
{
|
||||
"name": "jalapeno",
|
||||
"pos_in_card": 11,
|
||||
"price": 27,
|
||||
"spiciness": true,
|
||||
"vege": false,
|
||||
"size": 50,
|
||||
"allergens": "",
|
||||
"allergens": "none",
|
||||
"ingridients": [ "cheese", "bacon", "pepper", "onion", "jalapeno" ],
|
||||
"drink_in": false
|
||||
},
|
||||
{
|
||||
"name": "barbecue wege",
|
||||
"pos_in_card": 12,
|
||||
"price": 27,
|
||||
"spiciness": true,
|
||||
"vege": true,
|
||||
@ -131,6 +144,7 @@
|
||||
},
|
||||
{
|
||||
"name": "kebab",
|
||||
"pos_in_card": 13,
|
||||
"price": 32,
|
||||
"spiciness": false,
|
||||
"vege": false,
|
||||
@ -141,6 +155,7 @@
|
||||
},
|
||||
{
|
||||
"name": "grecka",
|
||||
"pos_in_card": 14,
|
||||
"price": 34,
|
||||
"spiciness": false,
|
||||
"vege": true,
|
||||
@ -151,6 +166,7 @@
|
||||
},
|
||||
{
|
||||
"name": "piekielna",
|
||||
"pos_in_card": 15,
|
||||
"price": 37,
|
||||
"spiciness": true,
|
||||
"vege": false,
|
||||
@ -161,6 +177,7 @@
|
||||
},
|
||||
{
|
||||
"name": "drwala",
|
||||
"pos_in_card": 16,
|
||||
"price": 37,
|
||||
"spiciness": true,
|
||||
"vege": false,
|
||||
@ -171,6 +188,7 @@
|
||||
},
|
||||
{
|
||||
"name": "grzybowa",
|
||||
"pos_in_card": 17,
|
||||
"price": 37,
|
||||
"spiciness": false,
|
||||
"vege": true,
|
||||
@ -181,16 +199,18 @@
|
||||
},
|
||||
{
|
||||
"name": "staropolska",
|
||||
"pos_in_card": 18,
|
||||
"price": 40,
|
||||
"spiciness": false,
|
||||
"vege": false,
|
||||
"size": 30,
|
||||
"allergens": "",
|
||||
"allergens": "none",
|
||||
"ingridients": [ "cheese", "chicken", "mushrooms", "sausage", "ham" ],
|
||||
"drink_in": true
|
||||
},
|
||||
{
|
||||
"name": "goralska",
|
||||
"pos_in_card": 19,
|
||||
"price": 42,
|
||||
"spiciness": false,
|
||||
"vege": false,
|
||||
@ -201,6 +221,7 @@
|
||||
},
|
||||
{
|
||||
"name": "prosciutto",
|
||||
"pos_in_card": 20,
|
||||
"price": 43,
|
||||
"spiciness": false,
|
||||
"vege": false,
|
||||
@ -211,6 +232,7 @@
|
||||
},
|
||||
{
|
||||
"name": "broccoli",
|
||||
"pos_in_card": 21,
|
||||
"price": 44,
|
||||
"spiciness": false,
|
||||
"vege": true,
|
||||
@ -221,26 +243,29 @@
|
||||
},
|
||||
{
|
||||
"name": "americana",
|
||||
"pos_in_card": 22,
|
||||
"price": 45,
|
||||
"spiciness": true,
|
||||
"vege": false,
|
||||
"size": 50,
|
||||
"allergens": "",
|
||||
"allergens": "none",
|
||||
"ingridients": [ "cheese", "salami", "papperoni", "onion", "corn" ],
|
||||
"drink_in": false
|
||||
"drink_in": true
|
||||
},
|
||||
{
|
||||
"name": "farmerska",
|
||||
"pos_in_card": 23,
|
||||
"price": 47,
|
||||
"spiciness": true,
|
||||
"vege": false,
|
||||
"size": 30,
|
||||
"allergens": "",
|
||||
"allergens": "none",
|
||||
"ingridients": [ "cheese", "sausage", "ham", "salami", "chicken", "pepperoni" ],
|
||||
"drink_in": false
|
||||
},
|
||||
{
|
||||
"name": "nachos",
|
||||
"pos_in_card": 24,
|
||||
"price": 48,
|
||||
"spiciness": true,
|
||||
"vege": false,
|
||||
@ -251,6 +276,7 @@
|
||||
},
|
||||
{
|
||||
"name": "texas",
|
||||
"pos_in_card": 25,
|
||||
"price": 48,
|
||||
"spiciness": true,
|
||||
"vege": false,
|
||||
@ -261,16 +287,18 @@
|
||||
},
|
||||
{
|
||||
"name": "kurczak",
|
||||
"pos_in_card": 26,
|
||||
"price": 49,
|
||||
"spiciness": false,
|
||||
"vege": false,
|
||||
"size": 50,
|
||||
"allergens": "tomato",
|
||||
"ingridients": [ "cheese", "chicken", "onion", "corn", "toamto" ],
|
||||
"drink_in": false
|
||||
"drink_in": true
|
||||
},
|
||||
{
|
||||
"name": "zielona",
|
||||
"pos_in_card": 27,
|
||||
"price": 50,
|
||||
"spiciness": false,
|
||||
"vege": true,
|
||||
@ -281,13 +309,14 @@
|
||||
},
|
||||
{
|
||||
"name": "mix",
|
||||
"pos_in_card": 28,
|
||||
"price": 50,
|
||||
"spiciness": true,
|
||||
"vege": false,
|
||||
"size": 50,
|
||||
"allergens": "feta",
|
||||
"ingridients": [ "cheese", "ham", "salami", "papperoni", "sausage", "mushrooms", "corn", "broccoli", "pineapple", "feta" ],
|
||||
"drink_in": false
|
||||
"drink_in": true
|
||||
}
|
||||
|
||||
]
|
135
tiles.py
135
tiles.py
@ -5,6 +5,10 @@ import pygame
|
||||
import pytmx
|
||||
from queue import Queue
|
||||
import math
|
||||
import pandas as pd
|
||||
from sklearn.model_selection import train_test_split
|
||||
from sklearn.tree import DecisionTreeClassifier
|
||||
import json
|
||||
|
||||
pygame.init()
|
||||
|
||||
@ -117,8 +121,9 @@ def check_collision_with_chair(x,y):
|
||||
|
||||
|
||||
class Food:
|
||||
def __init__(self, name, price, spiciness, vege, size, allergens, ingridients, drink_in):
|
||||
def __init__(self, name, pos_in_card, price, spiciness, vege, size, allergens, ingridients, drink_in):
|
||||
self.name = name
|
||||
self.pos_in_card = pos_in_card
|
||||
self.price = price
|
||||
self.spiciness = spiciness
|
||||
self.vege = vege
|
||||
@ -373,6 +378,7 @@ def astar(map, start, end):
|
||||
continue
|
||||
open_list.append(child)
|
||||
|
||||
|
||||
def tell_preferences():
|
||||
possibilities = [[30, 40 ,50, None],
|
||||
[True, False, None],
|
||||
@ -384,17 +390,110 @@ def tell_preferences():
|
||||
choices = []
|
||||
for i in possibilities:
|
||||
choices.append(random.choice(i))
|
||||
preferences = {
|
||||
"budget": choices[0],
|
||||
"spiciness": choices[1],
|
||||
"vege": choices[2],
|
||||
"level_of_hunger": choices[3],
|
||||
"allergy": choices[4],
|
||||
"favorite_ingridient": choices[5],
|
||||
"drink_in": choices[6]
|
||||
}
|
||||
return preferences
|
||||
|
||||
return choices
|
||||
|
||||
def evaluate_preferences(preferences):
|
||||
data = []
|
||||
if preferences[0] == 30:
|
||||
data.append(30)
|
||||
elif preferences[0] == 40:
|
||||
data.append(40)
|
||||
elif preferences[0] == 50:
|
||||
data.append(50)
|
||||
else:
|
||||
data.append(random.choice([30, 40, 50]))
|
||||
|
||||
if preferences[1] is True:
|
||||
data.append(1)
|
||||
elif preferences[1] is False:
|
||||
data.append(0)
|
||||
else:
|
||||
data.append(random.choice([1, 0]))
|
||||
|
||||
if preferences[2] is True:
|
||||
data.append(1)
|
||||
elif preferences[2] is False:
|
||||
data.append(0)
|
||||
else:
|
||||
data.append(random.choice([1, 0]))
|
||||
|
||||
if preferences[3] == 'low':
|
||||
data.append(30)
|
||||
elif preferences[3] == 'high':
|
||||
data.append(50)
|
||||
else:
|
||||
data.append(random.choice([30, 50]))
|
||||
|
||||
if preferences[4] == 'tomato':
|
||||
data.append(1)
|
||||
elif preferences[4] == 'olives':
|
||||
data.append(3)
|
||||
elif preferences[4] == 'feta':
|
||||
data.append(2)
|
||||
else:
|
||||
data.append(0)
|
||||
|
||||
if preferences[5] == 'salami':
|
||||
data.append(1)
|
||||
elif preferences[5] == 'mushrooms':
|
||||
data.append(2)
|
||||
elif preferences[5] == 'pineapple':
|
||||
data.append(3)
|
||||
elif preferences[5] == 'shrimps':
|
||||
data.append(4)
|
||||
elif preferences[5] == 'sausage':
|
||||
data.append(5)
|
||||
else:
|
||||
data.append(0)
|
||||
|
||||
if preferences[6] is True:
|
||||
data.append(1)
|
||||
elif preferences[6] is False:
|
||||
data.append(0)
|
||||
else:
|
||||
data.append(random.choice([1, 0]))
|
||||
|
||||
return data
|
||||
|
||||
def choose_pizza(prefernce):
|
||||
df = pd.read_excel("data.xlsx")
|
||||
|
||||
d = {'low': 30, 'high': 50}
|
||||
df['level of hunger'] = df['level of hunger'].map(d)
|
||||
|
||||
d = {'none': 0, 'tomato': 1, 'feta': 2, 'olives': 3}
|
||||
df['allergy'] = df['allergy'].map(d)
|
||||
|
||||
d = {'none': 0, 'salami': 1, 'mushrooms': 2, 'pineapple': 3, 'shrimps': 4, 'sausage': 5}
|
||||
df['favorite ingridient'] = df['favorite ingridient'].map(d)
|
||||
|
||||
d = {'margherita': 0, 'hawajska': 1, 'funghi': 2, 'light': 3, '4 sery': 4, 'pepperoni': 5,
|
||||
'salami': 6, 'wegetarianska': 7, 'barbecue': 8, 'miesna': 9, 'paprykowa': 10,
|
||||
'jalapeno': 11, 'barbecue wege': 12, 'kebab': 13, 'grecka': 14, 'piekielna': 15,
|
||||
'drwala': 16, 'grzybowa': 17, 'staropolska': 18, 'goralska': 19, 'prosciutto': 20,
|
||||
'broccoli': 21, 'americana': 22, 'farmerska': 23, 'nachos': 24, 'texas': 25,
|
||||
'kurczak': 26, 'zielona': 27, 'mix': 28}
|
||||
|
||||
df['pizza'] = df['pizza'].map(d)
|
||||
|
||||
features = ['budget', 'spiciness', 'vege', 'level of hunger', 'allergy', 'favorite ingridient', 'drink in']
|
||||
x = df[features]
|
||||
y = df['pizza']
|
||||
x_train, x_test, y_train, y_test = train_test_split(x, y)
|
||||
|
||||
clf = DecisionTreeClassifier(criterion='entropy')
|
||||
clf = clf.fit(x_train, y_train)
|
||||
|
||||
return clf.predict([prefernce])
|
||||
|
||||
def get_pizza(number):
|
||||
with open("dishes.json") as f:
|
||||
data = json.load(f)
|
||||
for i in data:
|
||||
if i["pos_in_card"] == int(number):
|
||||
food = Food(i['name'], i['pos_in_card'], i['price'], i['spiciness'], i['vege'], i['size'], i['allergens'], i['ingridients'], i['drink_in'])
|
||||
return food
|
||||
|
||||
map = Map()
|
||||
waiter = Waiter([32, 32])
|
||||
@ -454,11 +553,9 @@ def main():
|
||||
if y > 608 or y < 32 or x > 608 or x < 32 or check_collision_with_table(y,x) or check_collision_with_chair(y, x):
|
||||
print("I can't go there")
|
||||
break
|
||||
print(x,y)
|
||||
goal = (x // 32, y // 32)
|
||||
route = astar(map.get_arr(), (waiter.loc[1] // 32, waiter.loc[0] // 32), goal)
|
||||
direction = [(x[1] - y[1], x[0] - y[0]) for x, y in zip(route[1:], route)]
|
||||
print(waiter.loc)
|
||||
break
|
||||
elif middle:
|
||||
if client.loc[0] in [64, 128, 192, 256, 352, 416, 480, 544]:
|
||||
@ -478,8 +575,18 @@ def main():
|
||||
direction = [(x[1] - y[1], x[0] - y[0]) for x, y in zip(route[1:], route)]
|
||||
break
|
||||
print("Hello Sir, tell me yours preferences")
|
||||
print("Pass: 'budget', 'spiciness', 'vege', 'level_of_hunger', 'allergy', 'favorite_ingridient', 'drink_in'\n")
|
||||
print("Here is my list of preferences")
|
||||
print(tell_preferences())
|
||||
ingridients = tell_preferences()
|
||||
print(ingridients)
|
||||
print()
|
||||
evaluated_ingridients = evaluate_preferences(ingridients)
|
||||
number_of_pizza = choose_pizza(evaluated_ingridients)
|
||||
pizza = get_pizza(number_of_pizza)
|
||||
print("In case we don't offer pizza with identical ingredients, we offer:")
|
||||
print("Name = {}, pos_in_card - {}, price = {}, spiciness = {}, vege = {}, size = {}, allergens = {}, ingridients = {}, drink_in = {}\n"
|
||||
.format(pizza.name,pizza.pos_in_card,pizza.price, pizza.spiciness,pizza.vege,pizza.size,pizza.allergens,pizza.ingridients,pizza.drink_in))
|
||||
|
||||
|
||||
if len(direction) > 0:
|
||||
d = direction.pop(0)
|
||||
|
Loading…
Reference in New Issue
Block a user