Webserver_Dashboard and basic functionality #1

Merged
Roman_Schenk merged 12 commits from Webserver_Layout into master 2022-08-23 20:28:05 +02:00
2 changed files with 25 additions and 18 deletions
Showing only changes of commit 6fda077f9b - Show all commits

View File

@ -12,8 +12,8 @@ class ZoneManager:
self.zones = fileIO.loadZones()
for zone in self.zones:
zone.setZoneManager(self)
self.pipeLine = [] #todo Thread Synchron
#self.lock = threading.Lock()
self.pipeLine = []
self.piplineMutexLock = threading.Lock()
def getZone(self, number):
for zone in self.zones:
@ -21,22 +21,23 @@ class ZoneManager:
return zone
def addIrrigationJob(self, job):
#with self.lock:
with self.piplineMutexLock:
self.pipeLine.append(job)
def deleteIrrigationJobByID(self, id):
#with self.lock:
i = 0
i = 0
with self.piplineMutexLock:
while i < (len(self.pipeLine)):
irrigationJob = self.pipeLine[i]
if(irrigationJob.id == id):
self.pipeLine.pop(i)
break
else:
i = i + 1
def deleteIrrigationJobsForZone(self, zone):
#with self.lock:
i = 0
i = 0
with self.piplineMutexLock:
while i < (len(self.pipeLine)):
irrigationJob = self.pipeLine[i]
if (irrigationJob.zone == zone):
@ -62,10 +63,10 @@ class ZoneManager:
def getPlanedDurationForZone(self, zone):
totalDuration = 0
#with self.lock:
for irrigationJob in self.pipeLine:
if(irrigationJob.zone == zone):
totalDuration = totalDuration + irrigationJob.duration
with self.piplineMutexLock:
for irrigationJob in self.pipeLine:
if(irrigationJob.zone == zone):
totalDuration = totalDuration + irrigationJob.duration
return totalDuration
def refreshStates(self):
@ -73,16 +74,21 @@ class ZoneManager:
zone.refreshState()
def processPipeline(self):
#with self.lock:
if(len(self.pipeLine) > 0 and (not self.isAnyZoneBusy())):
irrigationJob = self.pipeLine[0]
irrigationJob.process()
self.pipeLine.pop(0)
self.piplineMutexLock.acquire()
if(len(self.pipeLine) > 0 and (not self.isAnyZoneBusy())):
irrigationJob = self.pipeLine[0]
self.pipeLine.pop(0)
self.piplineMutexLock.release()
irrigationJob.process()
else:
self.piplineMutexLock.release()
def cronJobs(self):
self.refreshStates()
self.processPipeline()
print("Executed Cron Jobs of ZoneManager.\nactual Time: " + str(time()))
print("Executed Cron Jobs of ZoneManager.")

View File

@ -13,8 +13,9 @@ webserver = Webserver(zoneManager=zoneManager, port=80)
def cronJobs():
while True:
time.sleep(0.5)
zoneManager.cronJobs()
print("Cronjobs done\nactual Time: " + str(time.time()))
time.sleep(0.5)
if __name__ == "__main__":
cronjob_Thread = threading.Thread(target=cronJobs)