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 = [["Tomato", True, 60, 90, 95], ["Tomato", True, 60, 84, 88], ["Tomato", True, 50, 78, 77], ["Tomato", True, 45, 63, 68], ["Tomato", True, 37, 54, 59], ["Tomato", True, 20, 31, 62], ["Tomato", True, 18, 75, 39], ["Tomato", True, 19, 24, 74], ["Tomato", True, 24, 69, 25], ["Tomato", True, 15, 45, 85], ["Tomato", True, 23, 85, 48], ["Tomato", True, 26, 41, 45], ["Tomato", True, 21, 35, 32], ["Tomato", True, 49, 24, 28], ["Tomato", True, 64, 15, 14], ["Tomato", True, 84, 4, 8], ["Cucumber", True, 55, 89, 84], ["Cucumber", True, 76, 91, 95], ["Cucumber", True, 45, 72, 71], ["Cucumber", True, 37, 64, 68], ["Cucumber", True, 26, 54, 59], ["Cucumber", True, 58, 42, 46], ["Cucumber", True, 20, 31, 62], ["Cucumber", True, 18, 75, 39], ["Cucumber", True, 19, 24, 74], ["Cucumber", True, 24, 69, 25], ["Cucumber", True, 15, 12, 85], ["Cucumber", True, 23, 85, 18], ["Cucumber", True, 34, 38, 36], ["Cucumber", True, 41, 24, 22], ["Cucumber", True, 34, 38, 36], ["Cucumber", True, 74, 26, 23], ["Cucumber", True, 84, 14, 19], ["Cucumber", 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 = tree.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) 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() """