205 lines
7.0 KiB
Python
205 lines
7.0 KiB
Python
|
|
from sklearn import tree
|
|
|
|
class TreeClass:
|
|
#file = open("probne.pl", 'r').read()
|
|
#text = ""
|
|
#for line in file:
|
|
# text += line
|
|
|
|
|
|
#com = file.replace("\n", "").split(".")
|
|
#for i, el in enumerate(com):
|
|
# com[i]=el+"."
|
|
#com.pop()
|
|
|
|
|
|
#features = {"key1": 4,
|
|
# "key2": [4, 6],
|
|
# "key3": {"k": [ 1, 4]}}
|
|
|
|
#features["key4"] = [1, 4, 3]
|
|
#features.update({"key5": "text"})
|
|
|
|
#symbol, is_alive, ttl, hydration, soil_level, ready
|
|
|
|
#print(com)
|
|
|
|
def make_tree(self, plant, pl_stats):
|
|
features = [
|
|
[1, True, 199, 900, 950],
|
|
[1, True, 150, 840, 880],
|
|
[1, True, 149, 780, 770],
|
|
[1, True, 133, 630, 680],
|
|
[1, True, 185, 540, 590],
|
|
[1, True, 123, 310, 620],
|
|
|
|
[1, True, 3800, 450, 490],
|
|
[1, True, 290, 240, 740],
|
|
[1, True, 240, 490, 550],
|
|
[1, True, 350, 350, 850],
|
|
[1, True, 230, 349, 400],
|
|
[1, True, 260, 410, 400],
|
|
|
|
[1, True, 260, 510, 399],
|
|
[1, True, 210, 550, 320],
|
|
[1, True, 490, 740, 280],
|
|
[1, True, 640, 500, 140],
|
|
[1, True, 840, 867, 80],
|
|
[1, True, 6789, 555, 159],
|
|
|
|
[1, True, 37812, 489, 368],
|
|
[1, True, 3728, 387, 278],
|
|
[1, True, 1934, 134, 334],
|
|
[1, True, 13562, 499, 233],
|
|
[1, True, 1789, 289, 399],
|
|
[1, True, 201, 478, 340],
|
|
|
|
[1, True, 1892, 996, 865],
|
|
[1, True, 6789, 555, 459],
|
|
[1, True, 37812, 789, 768],
|
|
[1, True, 3728, 987, 678],
|
|
[1, True, 199, 500, 555],
|
|
[1, True, 1892, 502, 400],
|
|
|
|
[1, False, 6789, 672, 405],
|
|
[1, False, 37812, 589, 420],
|
|
[1, False, 3728, 890, 778],
|
|
[1, False, 799, 734, 634],
|
|
[1, False, 799, 734, 634],
|
|
[1, False, 799, 734, 634],
|
|
|
|
|
|
[0, True, 299, 890, 840],
|
|
[0, True, 134, 910, 950],
|
|
[0, True, 256, 720, 710],
|
|
[0, True, 87, 640, 680],
|
|
[0, True, 189, 540, 590],
|
|
[0, True, 222, 420, 460],
|
|
|
|
[0, True, 300, 310, 620],
|
|
[0, True, 4580, 550, 590],
|
|
[0, True, 1290, 240, 740],
|
|
[0, True, 340, 290, 650],
|
|
[0, True, 7650, 120, 850],
|
|
[0, True, 3455, 599, 501],
|
|
|
|
[0, True, 3040, 680, 360],
|
|
[0, True, 410, 740, 220],
|
|
[0, True, 340, 880, 360],
|
|
[0, True, 740, 960, 499],
|
|
[0, True, 840, 601, 190],
|
|
[0, True, 950, 765, 400],
|
|
|
|
[0, True, 3400, 550, 360],
|
|
[0, True, 740, 260, 230],
|
|
[0, True, 840, 300, 190],
|
|
[0, True, 950, 199, 100],
|
|
[0, True, 340, 380, 460],
|
|
[0, True, 740, 560, 499],
|
|
|
|
[0, True, 840, 690, 790],
|
|
[0, True, 950, 800, 550],
|
|
[0, True, 340, 799, 599],
|
|
[0, True, 740, 900, 501],
|
|
[0, True, 840, 645, 785],
|
|
[0, True, 950, 700, 650],
|
|
|
|
[0, False, 190, 240, 740],
|
|
[0, False, 240, 690, 250],
|
|
[0, False, 150, 120, 850],
|
|
[0, False, 230, 850, 180],
|
|
[0, False, 2345, 21, 342],
|
|
[0, False, 2561, 244, 532]
|
|
]
|
|
|
|
labels = [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5]
|
|
#utwórz drzewo decyzyjne
|
|
t = tree.DecisionTreeClassifier()
|
|
|
|
#znajdź wzór na podstawie danych
|
|
t = t.fit(features, labels)#jakieś cechy w środku i decyzje jakie ma podjąć
|
|
|
|
#użyj modelu aby dopasować(podjąć decyzję)
|
|
#p = tree.predict([["Cucumber", True, 38, 26, 51]])
|
|
p = t.predict([[pl_stats["name"], pl_stats["is_alive"], pl_stats["ttl"], pl_stats["hydration"], pl_stats["soil_level"]]])
|
|
|
|
return p
|
|
|
|
# if p == 0:
|
|
# print("Ready to cut")
|
|
# return 0
|
|
# # t.Harvest()
|
|
# elif p == 1:
|
|
# plant.increase_hydration(plant.max_hydration_lvl - plant.hydration)
|
|
# elif p == 2:
|
|
# plant.increase_soillevel(plant.max_soil_lvl - plant.soil_level)
|
|
# elif p == 3:
|
|
# plant.increase_hydration(plant.max_hydration_lvl - plant.hydration)
|
|
# plant.increase_soillevel(plant.max_soil_lvl - plant.soil_level)
|
|
|
|
#wyświetlamy dopasowaną wartość
|
|
# print(p)
|
|
|
|
T = TreeClass()
|
|
|
|
#pass
|
|
"""
|
|
is_life = bool
|
|
type = "POop"
|
|
Timer = 20
|
|
hydration = (0,40)
|
|
soil_level = (0,40)
|
|
water_tank = (0,200)
|
|
soil_tank = (0,100)
|
|
def Harvest():
|
|
pass
|
|
def increase_soil_level():
|
|
pass
|
|
def increase_hydration():
|
|
pass
|
|
|
|
if is_life == False:
|
|
print("Roślina uschła")
|
|
else:
|
|
if type == 'P' or type == "O":
|
|
if Timer == 0:
|
|
print("Warzywa nie nadają się już do zbioru")
|
|
elif Timer > 0 and Timer <= 20:
|
|
Harvest()#Zbierz plon
|
|
elif type == 'p':
|
|
if hydration > 20 and soil_level > 20:
|
|
type == 'P'#zmiana literki
|
|
#if Timer == 0:
|
|
# print("Warzywa nie nadają się do zbioru")
|
|
#elif Timer > 0 and Timer <= 20:
|
|
# Harvest()#Zbierz plon
|
|
elif hydration > 20 and (soil_level > 0 and soil_level <= 20):
|
|
if soil_tank > 0:
|
|
increase_soil_level()
|
|
elif (hydration > 0 and hydration <= 20) and soil_level > 20:
|
|
if water_tank > 0:
|
|
increase_hydration()
|
|
elif (hydration > 0 and hydration <= 20) and (soil_level > 0 and soil_level <= 20):
|
|
if water_tank > 0 and soil_tank > 0:
|
|
increase_hydration()
|
|
increase_soil_level()
|
|
elif type == 'o':
|
|
if hydration > 30 and soil_level > 30:
|
|
type == 'O'#zmiana literki
|
|
#if Timer == 0:
|
|
# print("Warzywa nie nadają się do zbioru")
|
|
#elif Timer > 0 and Timer <= 20:
|
|
# Harvest()#Zbierz plon
|
|
elif hydration > 30 and (soil_level > 0 and soil_level <= 30):
|
|
if soil_tank > 0:
|
|
increase_soil_level()
|
|
elif (hydration > 0 and hydration <= 30) and soil_level > 20:
|
|
if water_tank > 0:
|
|
increase_hydration()
|
|
elif (hydration > 0 and hydration <= 30) and (soil_level > 0 and soil_level <= 30):
|
|
if water_tank > 0 and soil_tank > 0:
|
|
increase_hydration()
|
|
increase_soil_level()
|
|
"""
|