Webserver_Dashboard and basic functionality #1
|
@ -12,8 +12,8 @@ class ZoneManager:
|
||||||
self.zones = fileIO.loadZones()
|
self.zones = fileIO.loadZones()
|
||||||
for zone in self.zones:
|
for zone in self.zones:
|
||||||
zone.setZoneManager(self)
|
zone.setZoneManager(self)
|
||||||
self.pipeLine = [] #todo Thread Synchron
|
self.pipeLine = []
|
||||||
#self.lock = threading.Lock()
|
self.piplineMutexLock = threading.Lock()
|
||||||
|
|
||||||
def getZone(self, number):
|
def getZone(self, number):
|
||||||
for zone in self.zones:
|
for zone in self.zones:
|
||||||
|
@ -21,22 +21,23 @@ class ZoneManager:
|
||||||
return zone
|
return zone
|
||||||
|
|
||||||
def addIrrigationJob(self, job):
|
def addIrrigationJob(self, job):
|
||||||
#with self.lock:
|
with self.piplineMutexLock:
|
||||||
self.pipeLine.append(job)
|
self.pipeLine.append(job)
|
||||||
|
|
||||||
def deleteIrrigationJobByID(self, id):
|
def deleteIrrigationJobByID(self, id):
|
||||||
#with self.lock:
|
i = 0
|
||||||
i = 0
|
with self.piplineMutexLock:
|
||||||
while i < (len(self.pipeLine)):
|
while i < (len(self.pipeLine)):
|
||||||
irrigationJob = self.pipeLine[i]
|
irrigationJob = self.pipeLine[i]
|
||||||
if(irrigationJob.id == id):
|
if(irrigationJob.id == id):
|
||||||
self.pipeLine.pop(i)
|
self.pipeLine.pop(i)
|
||||||
|
break
|
||||||
else:
|
else:
|
||||||
i = i + 1
|
i = i + 1
|
||||||
|
|
||||||
def deleteIrrigationJobsForZone(self, zone):
|
def deleteIrrigationJobsForZone(self, zone):
|
||||||
#with self.lock:
|
i = 0
|
||||||
i = 0
|
with self.piplineMutexLock:
|
||||||
while i < (len(self.pipeLine)):
|
while i < (len(self.pipeLine)):
|
||||||
irrigationJob = self.pipeLine[i]
|
irrigationJob = self.pipeLine[i]
|
||||||
if (irrigationJob.zone == zone):
|
if (irrigationJob.zone == zone):
|
||||||
|
@ -62,10 +63,10 @@ class ZoneManager:
|
||||||
|
|
||||||
def getPlanedDurationForZone(self, zone):
|
def getPlanedDurationForZone(self, zone):
|
||||||
totalDuration = 0
|
totalDuration = 0
|
||||||
#with self.lock:
|
with self.piplineMutexLock:
|
||||||
for irrigationJob in self.pipeLine:
|
for irrigationJob in self.pipeLine:
|
||||||
if(irrigationJob.zone == zone):
|
if(irrigationJob.zone == zone):
|
||||||
totalDuration = totalDuration + irrigationJob.duration
|
totalDuration = totalDuration + irrigationJob.duration
|
||||||
return totalDuration
|
return totalDuration
|
||||||
|
|
||||||
def refreshStates(self):
|
def refreshStates(self):
|
||||||
|
@ -73,16 +74,21 @@ class ZoneManager:
|
||||||
zone.refreshState()
|
zone.refreshState()
|
||||||
|
|
||||||
def processPipeline(self):
|
def processPipeline(self):
|
||||||
#with self.lock:
|
self.piplineMutexLock.acquire()
|
||||||
if(len(self.pipeLine) > 0 and (not self.isAnyZoneBusy())):
|
if(len(self.pipeLine) > 0 and (not self.isAnyZoneBusy())):
|
||||||
irrigationJob = self.pipeLine[0]
|
irrigationJob = self.pipeLine[0]
|
||||||
irrigationJob.process()
|
self.pipeLine.pop(0)
|
||||||
self.pipeLine.pop(0)
|
self.piplineMutexLock.release()
|
||||||
|
irrigationJob.process()
|
||||||
|
else:
|
||||||
|
self.piplineMutexLock.release()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def cronJobs(self):
|
def cronJobs(self):
|
||||||
self.refreshStates()
|
self.refreshStates()
|
||||||
self.processPipeline()
|
self.processPipeline()
|
||||||
print("Executed Cron Jobs of ZoneManager.\nactual Time: " + str(time()))
|
print("Executed Cron Jobs of ZoneManager.")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
3
main.py
3
main.py
|
@ -13,8 +13,9 @@ webserver = Webserver(zoneManager=zoneManager, port=80)
|
||||||
|
|
||||||
def cronJobs():
|
def cronJobs():
|
||||||
while True:
|
while True:
|
||||||
time.sleep(0.5)
|
|
||||||
zoneManager.cronJobs()
|
zoneManager.cronJobs()
|
||||||
|
print("Cronjobs done\nactual Time: " + str(time.time()))
|
||||||
|
time.sleep(0.5)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
cronjob_Thread = threading.Thread(target=cronJobs)
|
cronjob_Thread = threading.Thread(target=cronJobs)
|
||||||
|
|
Loading…
Reference in New Issue