Compare commits

..

No commits in common. "0b494d694d5cdcb6b81c533c561f7a2daeaacbee" and "7a14a94b1ed2e6b14f1a193a1d843dd6135e8cbb" have entirely different histories.

6 changed files with 22 additions and 35 deletions

6
App.py

File diff suppressed because one or more lines are too long

View File

@ -44,4 +44,4 @@ class Condition:
def getCondition(self):
return ([Climate.temperature[self.temperature],Climate.rain[self.rain],Climate.seasons[self.season],Climate.time[self.currentTime]])
print(f"Aktualny czas: {Climate.time[self.currentTime]},opady: {Climate.rain[self.rain]},temperatura: {Climate.temperature[self.temperature]}, pora roku: {Climate.seasons[self.season]}")

View File

@ -15,14 +15,14 @@ class Drzewo:
self.tree=self.tree.fit(x.values,decision)
def plotTree(self):
plt.figure(figsize=(10,15))
plt.figure()
skltree.plot_tree(self.tree,filled=True,feature_names=atributes)
plt.title("Drzewo decyzyjne wytrenowane na przygotowanych danych")
plt.savefig('tree.png')
#plt.show()
# plt.show()
def makeDecision(self,values):
action=self.tree.predict([values]) #0- nie podlewac, 1-podlewac
if(action==[0]):
return "Nie"
return "Nie podlewac"
if(action==[1]):
return "Tak"
return "Podlewac"

View File

@ -117,7 +117,4 @@ class Roslina:
return self.stan.return_hydrate()
def report_status(self):
return f"Nazwa rosliny: {self.nazwa} "+self.stan.report_all()
def return_status_tree(self):
return self.stan.return_stan_for_tree()
return f"Nazwa rosliny: {self.nazwa} "+self.stan.report_all()

View File

@ -62,5 +62,4 @@ class Stan:
return [self.nawodnienie,self.wzrost,self.choroba,self.zyznosc]
def report_all(self):
return f"Nawodnienie: {self.nawodnienie} Zyznosc: {self.zyznosc} Wzrost: {self.wzrost} Choroba: {self.return_disease_as_string()}"
return f"Nawodnienie: {self.nawodnienie} Zyznosc: {self.zyznosc} Wzrost: {self.wzrost} Choroba: {self.return_disease_as_string()}"

View File

@ -13,8 +13,6 @@ import Drzewo
condition=Condition.Condition()
drzewo=Drzewo.Drzewo()
format_string = "{:<25}{:<25}{:<25}{:<10}{:<10}{:<10}{:<25}{:<15}{:<20}{:<10}{:<15}"
tab = [-1, 0, 0, 0, 0, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 0, 1, 0, 1, 1,
@ -67,22 +65,17 @@ class Tractor:
def tree_move(self, pole):
drzewo.treeLearn()
print("test")
drzewo.plotTree()
self.snake_move_irrigation(pole, drzewo)
def get_attributes(self):
slot_attributes=self.slot.return_stan_for_tree()
climate_attributes=condition.return_condition()
attributes=[]
attributes=attributes+slot_attributes+[self.waterLevel]+climate_attributes
return attributes
def get_attributes_for_print(self):
slot_attributes=self.slot.return_plant().return_status_tree()
climate_attributes=condition.getCondition()
slot_attributes=slot_attributes+[self.waterLevel]
return slot_attributes+climate_attributes
print("Decyzja czy podlac:",drzewo.makeDecision(attributes),"Atrybuty tego stanu to:",attributes)
self.snake_move_irrigation(pole, drzewo)
#TODO SNAKE MOVE AND USING drzewo.makeDecision(attributes)for each slot. Also we need to cycle climate for each slot change
#condition.cycle()
#condition.getCondition()
def turn_right(self):
# zmiana kierunku w prawo
direction_map = {
@ -164,15 +157,16 @@ class Tractor:
def snake_move_irrigation(self, pole, drzewo):
headers=['Wspolrzedne','Czy podlac','Poziom nawodnienia','Wzrost','Choroba','Zyznosc','Poziom wody w traktorze','Temperatura','Opady','Pora Roku','Aktualny czas']
print(format_string.format(*headers))
initPos = (self.slot.x_axis, self.slot.y_axis)
counter = 0
for i in range(initPos[1], dCon.NUM_Y):
for j in range(initPos[0], dCon.NUM_X):
attributes=self.get_attributes()
slot_attributes=self.slot.return_stan_for_tree()
climate_attributes=condition.return_condition()
attributes=[]
attributes=attributes+slot_attributes+[self.waterLevel]+climate_attributes
decision = drzewo.makeDecision(attributes)
self.pretty_print_tree([str("({:02d}, {:02d})").format(self.slot.x_axis, self.slot.y_axis),decision,*self.get_attributes_for_print()])
print("Slot:", str("({:02d}, {:02d})").format(self.slot.x_axis, self.slot.y_axis),"Decyzja czy podlac:",decision,"Atrybuty slotu:",attributes)
if decision == "Podlewac":
self.slot.irrigatePlant()
counter += 1
@ -187,7 +181,6 @@ class Tractor:
self.turn_left()
self.move_forward(pole, False)
self.turn_left()
pygame.time.delay(50)
print("podlanych slotów: ", str(counter))
def snake_move(self,pole,x,y):
@ -234,11 +227,9 @@ class Tractor:
print("- Typ:", akcja.typ)
else:
print("Brak akcji przypisanych do tego sprzętu.")
def pretty_print_tree(self,attributes):
print(format_string.format(*attributes))
def irrigateSlot(self):
try:
self.slot.irrigatePlant()
except:
pass