SZI_PROJEKT_GR1_TRAKTOR/Tree.py
Paulina J 66fe83073f nowe
2019-06-03 11:56:25 +02:00

154 lines
5.0 KiB
Python

from sklearn import tree
import collections
import subprocess
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 = [[0, True, 60, 90, 95],
[0, True, 60, 84, 88],
[0, True, 50, 78, 77],
[0, True, 45, 63, 68],
[0, True, 37, 54, 59],
[0, True, 20, 31, 62],
[0, True, 18, 75, 39],
[0, True, 19, 24, 74],
[0, True, 24, 69, 25],
[0, True, 15, 45, 85],
[0, True, 23, 85, 48],
[0, True, 26, 41, 45],
[0, True, 21, 35, 32],
[0, True, 49, 24, 28],
[0, True, 64, 15, 14],
[0, True, 84, 4, 8],
[1, True, 55, 89, 84],
[1, True, 76, 91, 95],
[1, True, 45, 72, 71],
[1, True, 37, 64, 68],
[1, True, 26, 54, 59],
[1, True, 58, 42, 46],
[1, True, 20, 31, 62],
[1, True, 18, 75, 39],
[1, True, 19, 24, 74],
[1, True, 24, 69, 25],
[1, True, 15, 12, 85],
[1, True, 23, 85, 18],
[1, True, 34, 38, 36],
[1, True, 41, 24, 22],
[1, True, 34, 38, 36],
[1, True, 74, 26, 23],
[1, True, 84, 14, 19],
[1, True, 95, 7, 4]
]
labels = [0, 0, 0, 0, 0, 1, 2, 1, 2, 1, 2, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 1, 2, 1, 2, 1, 2, 3, 3, 3, 3, 3, 3]
#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[0], pl_stats[1]], pl_stats[2], pl_stats[3], pl_stats[4])
if p == 0:
print("Ready to cut")
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()
"""