Merge old branches to refactor due to merge it with master #22

Merged
s481825 merged 20 commits from tree into refactor 2024-06-04 11:36:14 +02:00
6 changed files with 33 additions and 20 deletions
Showing only changes of commit 0b494d694d - Show all commits

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): def getCondition(self):
print(f"Aktualny czas: {Climate.time[self.currentTime]},opady: {Climate.rain[self.rain]},temperatura: {Climate.temperature[self.temperature]}, pora roku: {Climate.seasons[self.season]}") return ([Climate.temperature[self.temperature],Climate.rain[self.rain],Climate.seasons[self.season],Climate.time[self.currentTime]])

View File

@ -23,6 +23,6 @@ class Drzewo:
def makeDecision(self,values): def makeDecision(self,values):
action=self.tree.predict([values]) #0- nie podlewac, 1-podlewac action=self.tree.predict([values]) #0- nie podlewac, 1-podlewac
if(action==[0]): if(action==[0]):
return "Nie podlewac" return "Nie"
if(action==[1]): if(action==[1]):
return "Podlewac" return "Tak"

View File

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

View File

@ -62,4 +62,5 @@ class Stan:
return [self.nawodnienie,self.wzrost,self.choroba,self.zyznosc] return [self.nawodnienie,self.wzrost,self.choroba,self.zyznosc]
def report_all(self): 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,6 +13,8 @@ import Drzewo
condition=Condition.Condition() condition=Condition.Condition()
drzewo=Drzewo.Drzewo() 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, tab = [-1, 0, 0, 0, 0, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1,
@ -65,17 +67,22 @@ class Tractor:
def tree_move(self, pole): def tree_move(self, pole):
drzewo.treeLearn() drzewo.treeLearn()
print("test")
drzewo.plotTree() drzewo.plotTree()
self.snake_move_irrigation(pole, drzewo)
def get_attributes(self):
slot_attributes=self.slot.return_stan_for_tree() slot_attributes=self.slot.return_stan_for_tree()
climate_attributes=condition.return_condition() climate_attributes=condition.return_condition()
attributes=[] attributes=[]
attributes=attributes+slot_attributes+[self.waterLevel]+climate_attributes attributes=attributes+slot_attributes+[self.waterLevel]+climate_attributes
print("Decyzja czy podlac:",drzewo.makeDecision(attributes),"Atrybuty tego stanu to:",attributes) return 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 def get_attributes_for_print(self):
#condition.cycle() slot_attributes=self.slot.return_plant().return_status_tree()
#condition.getCondition() climate_attributes=condition.getCondition()
slot_attributes=slot_attributes+[self.waterLevel]
return slot_attributes+climate_attributes
def turn_right(self): def turn_right(self):
# zmiana kierunku w prawo # zmiana kierunku w prawo
direction_map = { direction_map = {
@ -157,16 +164,15 @@ class Tractor:
def snake_move_irrigation(self, pole, drzewo): 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) initPos = (self.slot.x_axis, self.slot.y_axis)
counter = 0 counter = 0
for i in range(initPos[1], dCon.NUM_Y): for i in range(initPos[1], dCon.NUM_Y):
for j in range(initPos[0], dCon.NUM_X): for j in range(initPos[0], dCon.NUM_X):
slot_attributes=self.slot.return_stan_for_tree() attributes=self.get_attributes()
climate_attributes=condition.return_condition()
attributes=[]
attributes=attributes+slot_attributes+[self.waterLevel]+climate_attributes
decision = drzewo.makeDecision(attributes) decision = drzewo.makeDecision(attributes)
print("Slot:", str("({:02d}, {:02d})").format(self.slot.x_axis, self.slot.y_axis),"Decyzja czy podlac:",decision,"Atrybuty slotu:",attributes) self.pretty_print_tree([str("({:02d}, {:02d})").format(self.slot.x_axis, self.slot.y_axis),decision,*self.get_attributes_for_print()])
if decision == "Podlewac": if decision == "Podlewac":
self.slot.irrigatePlant() self.slot.irrigatePlant()
counter += 1 counter += 1
@ -181,6 +187,7 @@ class Tractor:
self.turn_left() self.turn_left()
self.move_forward(pole, False) self.move_forward(pole, False)
self.turn_left() self.turn_left()
pygame.time.delay(50)
print("podlanych slotów: ", str(counter)) print("podlanych slotów: ", str(counter))
def snake_move(self,pole,x,y): def snake_move(self,pole,x,y):
@ -227,9 +234,11 @@ class Tractor:
print("- Typ:", akcja.typ) print("- Typ:", akcja.typ)
else: else:
print("Brak akcji przypisanych do tego sprzętu.") print("Brak akcji przypisanych do tego sprzętu.")
def pretty_print_tree(self,attributes):
print(format_string.format(*attributes))
def irrigateSlot(self): def irrigateSlot(self):
try: try:
self.slot.irrigatePlant() self.slot.irrigatePlant()
except: except:
pass pass