Usuń 'Tree1.py'

This commit is contained in:
Adam Świnka 2019-06-09 19:08:29 +00:00
parent ad33c1f01a
commit 07bf069a28

425
Tree1.py
View File

@ -1,425 +0,0 @@
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, 125, 555, 567],
[1, True, 112, 920, 834],
[1, True, 173, 947, 736],
[1, True, 143, 934, 642],
[1, True, 126, 928, 521],
[1, True, 136, 842, 756],
[1, True, 174, 860, 641],
[1, True, 186, 826, 531],
[1, True, 163, 769, 695],
[1, True, 176, 728, 543],
[1, True, 146, 684, 528],
[1, True, 158, 853, 964],
[1, True, 176, 746, 935],
[1, True, 169, 661, 961],
[1, True, 129, 584, 935],
[1, True, 187, 755, 812],
[1, True, 194, 642, 836],
[1, True, 173, 583, 861],
[1, True, 115, 628, 716],
[1, True, 123, 592, 756],
[1, True, 165, 584, 614],
[1, True, 3800, 450, 941],
[1, True, 290, 340, 958],
[1, True, 240, 290, 914],
[1, True, 350, 140, 980],
[1, True, 451, 68, 926],
[1, True, 230, 479, 856],
[1, True, 260, 310, 824],
[1, True, 568, 256, 834],
[1, True, 427, 149, 873],
[1, True, 237, 46, 831],
[1, True, 341, 416, 784],
[1, True, 413, 369, 716],
[1, True, 689, 251, 761],
[1, True, 746, 183, 743],
[1, True, 856, 45, 736],
[1, True, 652, 415, 641],
[1, True, 931, 346, 694],
[1, True, 347, 258, 623],
[1, True, 248, 149, 684],
[1, True, 354, 24, 617],
[1, True, 619, 416, 518],
[1, True, 746, 352, 585],
[1, True, 456, 271, 544],
[1, True, 746, 164, 572],
[1, True, 620, 38, 565],
[1, True, 321, 920, 412],
[1, True, 520, 935, 348],
[1, True, 364, 961, 259],
[1, True, 206, 946, 148],
[1, True, 402, 916, 62],
[1, True, 660, 850, 461],
[1, True, 542, 827, 320],
[1, True, 490, 886, 280],
[1, True, 640, 851, 140],
[1, True, 840, 867, 80],
[1, True, 746, 716, 486],
[1, True, 142, 769, 364],
[1, True, 246, 784, 249],
[1, True, 368, 751, 165],
[1, True, 6789, 755, 16],
[1, True, 1203, 649, 426],
[1, True, 924, 685, 310],
[1, True, 864, 694, 267],
[1, True, 592, 628, 128],
[1, True, 482, 673, 38],
[1, True, 235, 542, 461],
[1, True, 357, 549, 364],
[1, True, 751, 502, 288],
[1, True, 1452, 589, 176],
[1, True, 845, 516, 67],
[1, True, 37812, 489, 468],
[1, True, 3728, 387, 328],
[1, True, 1934, 234, 264],
[1, True, 13562, 149, 168],
[1, True, 698, 84, 61],
[1, True, 1789, 475, 386],
[1, True, 201, 425, 235],
[1, True, 358, 467, 147],
[1, True, 942, 491, 37],
[1, True, 1056, 367, 241],
[1, True, 846, 352, 130],
[1, True, 754, 312, 75],
[1, True, 564, 210, 138],
[1, True, 416, 289, 62],
[1, True, 256, 139, 67],
[1, True, 1365, 371, 492],
[1, True, 954, 254, 452],
[1, True, 821, 185, 449],
[1, True, 564, 76, 421],
[1, True, 648, 276, 305],
[1, True, 246, 123, 368],
[1, True, 461, 43, 378],
[1, True, 368, 185, 249],
[1, True, 597, 54, 294],
[1, True, 694, 73, 165],
[1, True, 1454, 948, 921],
[1, True, 1888, 838, 868],
[1, True, 1126, 741, 756],
[1, True, 895, 634, 627],
[1, True, 738, 565, 528],
[1, True, 814, 974, 842],
[1, True, 1413, 961, 751],
[1, True, 3628, 958, 657],
[1, True, 364, 948, 556],
[1, True, 6729, 863, 748],
[1, True, 258, 854, 618],
[1, True, 352, 814, 550],
[1, True, 37822, 779, 670],
[1, True, 4315, 752, 546],
[1, True, 288, 635, 558],
[1, True, 384, 857, 943],
[1, True, 476, 741, 938],
[1, True, 376, 638, 976],
[1, True, 228, 534, 936],
[1, True, 534, 749, 855],
[1, True, 684, 651, 835],
[1, True, 854, 536, 827],
[1, True, 1526, 628, 756],
[1, True, 924, 524, 712],
[1, True, 846, 514, 638],
[1, True, 1872, 547, 501],
[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, 134, 910, 950],
[0, True, 254, 890, 840],
[0, True, 124, 763, 746],
[0, True, 168, 667, 641],
[0, True, 148, 546, 531],
[0, True, 261, 916, 843],
[0, True, 284, 951, 762],
[0, True, 256, 922, 610],
[0, True, 123, 956, 552],
[0, True, 87, 840, 781],
[0, True, 189, 820, 690],
[0, True, 222, 813, 560],
[0, True, 168, 746, 635],
[0, True, 234, 768, 523],
[0, True, 155, 624, 516],
[0, True, 278, 846, 962],
[0, True, 226, 769, 931],
[0, True, 184, 647, 951],
[0, True, 124, 563, 947],
[0, True, 156, 761, 854],
[0, True, 178, 632, 846],
[0, True, 98, 589, 812],
[0, True, 134, 658, 715],
[0, True, 169, 528, 762],
[0, True, 234, 553, 674],
[0, True, 300, 450, 920],
[0, True, 4580, 350, 961],
[0, True, 1290, 240, 923],
[0, True, 340, 170, 974],
[0, True, 7650, 28, 945],
[0, True, 3455, 429, 801],
[0, True, 684, 358, 826],
[0, True, 569, 214, 836],
[0, True, 469, 148, 853],
[0, True, 396, 61, 816],
[0, True, 769, 462, 756],
[0, True, 1584, 367, 761],
[0, True, 648, 231, 752],
[0, True, 1147, 182, 726],
[0, True, 685, 58, 795],
[0, True, 596, 486, 634],
[0, True, 1462, 368, 614],
[0, True, 1062, 245, 658],
[0, True, 482, 156, 674],
[0, True, 584, 84, 623],
[0, True, 469, 421, 574],
[0, True, 657, 345, 563],
[0, True, 846, 215, 587],
[0, True, 769, 156, 532],
[0, True, 845, 34, 542],
[0, True, 358, 941, 468],
[0, True, 1354, 932, 394],
[0, True, 458, 954, 265],
[0, True, 369, 914, 178],
[0, True, 946, 954, 62],
[0, True, 746, 821, 428],
[0, True, 340, 880, 360],
[0, True, 410, 812, 220],
[0, True, 386, 856, 148],
[0, True, 589, 816, 75],
[0, True, 950, 765, 420],
[0, True, 869, 715, 362],
[0, True, 1304, 763, 296],
[0, True, 746, 736, 162],
[0, True, 684, 712, 84],
[0, True, 935, 622, 413],
[0, True, 3040, 680, 360],
[0, True, 840, 601, 280],
[0, True, 765, 682, 164],
[0, True, 568, 624, 72],
[0, True, 485, 563, 426],
[0, True, 385, 531, 368],
[0, True, 934, 546, 235],
[0, True, 312, 574, 163],
[0, True, 468, 513, 63],
[0, True, 1024, 536, 542],
[0, True, 478, 468, 413],
[0, True, 369, 345, 368],
[0, True, 562, 248, 267],
[0, True, 836, 186, 148],
[0, True, 745, 54, 36],
[0, True, 3400, 550, 460],
[0, True, 562, 532, 368],
[0, True, 765, 589, 241],
[0, True, 1628, 518, 160],
[0, True, 740, 560, 49],
[0, True, 698, 415, 345],
[0, True, 528, 464, 231],
[0, True, 694, 432, 184],
[0, True, 746, 413, 46],
[0, True, 340, 380, 260],
[0, True, 840, 300, 190],
[0, True, 740, 360, 35],
[0, True, 489, 232, 154],
[0, True, 568, 254, 63],
[0, True, 950, 189, 92],
[0, True, 368, 436, 584],
[0, True, 465, 381, 523],
[0, True, 649, 225, 548],
[0, True, 968, 145, 568],
[0, True, 1205, 29, 519],
[0, True, 382, 365, 492],
[0, True, 594, 237, 459],
[0, True, 846, 164, 425],
[0, True, 715, 56, 445],
[0, True, 1306, 284, 364],
[0, True, 563, 134, 385],
[0, True, 469, 72, 318],
[0, True, 746, 164, 296],
[0, True, 528, 64, 205],
[0, True, 674, 58, 169],
[0, True, 1524, 924, 938],
[0, True, 1892, 896, 865],
[0, True, 1246, 736, 762],
[0, True, 895, 648, 623],
[0, True, 726, 537, 584],
[0, True, 648, 934, 864],
[0, True, 1423, 922, 746],
[0, True, 3728, 987, 678],
[0, True, 458, 934, 514],
[0, True, 6789, 855, 759],
[0, True, 254, 843, 628],
[0, True, 367, 865, 564],
[0, True, 37812, 789, 668],
[0, True, 4365, 769, 534],
[0, True, 299, 630, 555],
[0, True, 368, 852, 937],
[0, True, 468, 716, 925],
[0, True, 374, 648, 986],
[0, True, 216, 526, 925],
[0, True, 528, 746, 851],
[0, True, 648, 632, 816],
[0, True, 846, 528, 853],
[0, True, 1506, 648, 731],
[0, True, 954, 520, 749],
[0, True, 846, 543, 616],
[0, True, 1892, 532, 500],
[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, 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()
"""