SZI_PROJEKT_GR1_TRAKTOR/Tree1.py
2019-06-10 11:26:22 +02:00

148 lines
5.1 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 = []
with open('dane.txt') as data:
for line in data:
elements = line.split(", ")
if elements[1] == "True":
elements[1] = 1
if elements[1] == "False":
elements[1] = 0
features.append(elements)
labels = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
5, 5, 5, 5, 5, 5,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 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
#file = open("features.txt", 'r').read()
#com = file.split("\n")
#print(com)
#for i, el in enumerate(com):
# com[i]=el+"."
# 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()
"""