implemented pipeline
This commit is contained in:
parent
85ba8cb402
commit
503b87579b
|
@ -26,6 +26,12 @@ class Translater:
|
||||||
"switch to manual mode": "Auf Handbetrieb umstellen",
|
"switch to manual mode": "Auf Handbetrieb umstellen",
|
||||||
"switch to automatic mode": "Auf Automatikbetrieb umstellen",
|
"switch to automatic mode": "Auf Automatikbetrieb umstellen",
|
||||||
"minutes": "Minuten",
|
"minutes": "Minuten",
|
||||||
|
"until": "bis",
|
||||||
|
"irragation is planed for": "Bewässerung ist geplant für",
|
||||||
|
"planed irrigationjobs": "geplante Bewässerungsaufträge",
|
||||||
|
"planed duration": "geplante Dauer",
|
||||||
|
"cancel": "abbrechen",
|
||||||
|
"delete": "löschen",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ class Webserver:
|
||||||
self.zoneManager = zoneManager
|
self.zoneManager = zoneManager
|
||||||
self.translater_EN = Translater(Language.ENGLISH)
|
self.translater_EN = Translater(Language.ENGLISH)
|
||||||
self.translater_DE = Translater(Language.GERMAN)
|
self.translater_DE = Translater(Language.GERMAN)
|
||||||
self.translater = self.translater_EN
|
self.translater = self.translater_DE
|
||||||
|
|
||||||
def startWebserver(self):
|
def startWebserver(self):
|
||||||
app = Flask("Bewässerungssystem", template_folder="Webserver/templates", static_folder="Webserver/static")
|
app = Flask("Bewässerungssystem", template_folder="Webserver/templates", static_folder="Webserver/static")
|
||||||
|
@ -73,6 +73,14 @@ class Webserver:
|
||||||
zone = self.zoneManager.getZone(index)
|
zone = self.zoneManager.getZone(index)
|
||||||
zone.desiredHumidity = value
|
zone.desiredHumidity = value
|
||||||
sucess = True
|
sucess = True
|
||||||
|
case "delete_jobs_for_zone":
|
||||||
|
if (index):
|
||||||
|
zone = self.zoneManager.getZone(index)
|
||||||
|
self.zoneManager.deleteIrrigationJobsForZone(zone)
|
||||||
|
case "delete_job_by_id":
|
||||||
|
if (index):
|
||||||
|
self.zoneManager.deleteIrrigationJobByID(index)
|
||||||
|
|
||||||
|
|
||||||
return render_template('action.html', translater=self.translater, zones=self.zoneManager.zones, sucess=sucess)
|
return render_template('action.html', translater=self.translater, zones=self.zoneManager.zones, sucess=sucess)
|
||||||
|
|
||||||
|
|
13
Zone.py
13
Zone.py
|
@ -22,10 +22,11 @@ class Zone:
|
||||||
def refreshStateAutomode(self):
|
def refreshStateAutomode(self):
|
||||||
match self.setState:
|
match self.setState:
|
||||||
case 0:
|
case 0:
|
||||||
if(self.desiredHumidity > self.actualHumidity):
|
|
||||||
self.zoneManager.switchZoneState(zone=self, state=True, duration=self.zoneManager.systemSettings.defaultAutoIrrigationDuration, instant=False)
|
|
||||||
else:
|
|
||||||
self.state = False
|
self.state = False
|
||||||
|
if(self.planedDuration > 0):
|
||||||
|
self.setState = 3
|
||||||
|
elif(self.desiredHumidity > self.actualHumidity):
|
||||||
|
self.zoneManager.switchZoneState(zone=self, state=True, duration=self.zoneManager.systemSettings.defaultAutoIrrigationDuration, instant=False)
|
||||||
case 1:
|
case 1:
|
||||||
if(self.timeOver()):
|
if(self.timeOver()):
|
||||||
self.setState = 0
|
self.setState = 0
|
||||||
|
@ -45,6 +46,10 @@ class Zone:
|
||||||
def refreshStateManualmode(self):
|
def refreshStateManualmode(self):
|
||||||
if(self.setState > 0):
|
if(self.setState > 0):
|
||||||
match self.setState:
|
match self.setState:
|
||||||
|
case 0:
|
||||||
|
self.state = False
|
||||||
|
if (self.planedDuration > 0):
|
||||||
|
self.setState = 3
|
||||||
case 1:
|
case 1:
|
||||||
if(self.timeOver()):
|
if(self.timeOver()):
|
||||||
self.setState = 0
|
self.setState = 0
|
||||||
|
@ -60,6 +65,7 @@ class Zone:
|
||||||
|
|
||||||
|
|
||||||
def refreshState(self):
|
def refreshState(self):
|
||||||
|
self.planedDuration = self.zoneManager.getPlanedDurationForZone(zone=self)
|
||||||
if(self.autoMode):
|
if(self.autoMode):
|
||||||
self.refreshStateAutomode()
|
self.refreshStateAutomode()
|
||||||
else:
|
else:
|
||||||
|
@ -81,7 +87,6 @@ class Zone:
|
||||||
else:
|
else:
|
||||||
if(state):
|
if(state):
|
||||||
self.setState = 3
|
self.setState = 3
|
||||||
self.planedDuration = duration
|
|
||||||
self.refreshState()
|
self.refreshState()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,19 @@
|
||||||
|
import threading
|
||||||
|
from random import Random
|
||||||
|
from time import time
|
||||||
|
|
||||||
from FileIO import FileIO
|
from FileIO import FileIO
|
||||||
|
|
||||||
class ZoneManager:
|
class ZoneManager:
|
||||||
def __init__(self, systemSettings, fileIO):
|
def __init__(self, systemSettings, fileIO):
|
||||||
|
self.random = Random()
|
||||||
self.systemSettings = systemSettings
|
self.systemSettings = systemSettings
|
||||||
self.fileIO = FileIO
|
self.fileIO = FileIO
|
||||||
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 = []
|
self.pipeLine = [] #todo Thread Synchron
|
||||||
|
#self.lock = threading.Lock()
|
||||||
|
|
||||||
def getZone(self, number):
|
def getZone(self, number):
|
||||||
for zone in self.zones:
|
for zone in self.zones:
|
||||||
|
@ -15,8 +21,29 @@ class ZoneManager:
|
||||||
return zone
|
return zone
|
||||||
|
|
||||||
def addIrrigationJob(self, job):
|
def addIrrigationJob(self, job):
|
||||||
|
#with self.lock:
|
||||||
self.pipeLine.append(job)
|
self.pipeLine.append(job)
|
||||||
|
|
||||||
|
def deleteIrrigationJobByID(self, id):
|
||||||
|
#with self.lock:
|
||||||
|
i = 0
|
||||||
|
while i < (len(self.pipeLine)):
|
||||||
|
irrigationJob = self.pipeLine[i]
|
||||||
|
if(irrigationJob.id == id):
|
||||||
|
self.pipeLine.pop(i)
|
||||||
|
else:
|
||||||
|
i = i + 1
|
||||||
|
|
||||||
|
def deleteIrrigationJobsForZone(self, zone):
|
||||||
|
#with self.lock:
|
||||||
|
i = 0
|
||||||
|
while i < (len(self.pipeLine)):
|
||||||
|
irrigationJob = self.pipeLine[i]
|
||||||
|
if (irrigationJob.zone == zone):
|
||||||
|
self.pipeLine.pop(i)
|
||||||
|
else:
|
||||||
|
i = i + 1
|
||||||
|
|
||||||
def isAnyZoneBusy(self):
|
def isAnyZoneBusy(self):
|
||||||
for zone in self.zones:
|
for zone in self.zones:
|
||||||
if(zone.state):
|
if(zone.state):
|
||||||
|
@ -24,20 +51,29 @@ class ZoneManager:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def switchZoneState(self, zone, state, duration, instant=False):
|
def switchZoneState(self, zone, state, duration, instant=False):
|
||||||
if(instant or self.systemSettings.multiZoneIrrigation):
|
if(instant or self.systemSettings.multiZoneIrrigation or state==False or (not self.isAnyZoneBusy())):
|
||||||
zone.switchState(state=state, duration=duration, instant=True)
|
zone.switchState(state=state, duration=duration, instant=True)
|
||||||
else:
|
else:
|
||||||
self.addIrrigationJob(IrrigationJob(zone, duration))
|
self.addIrrigationJob(IrrigationJob(id=self.random.randint(a=100000000, b=999999999), zone=zone, duration=duration))
|
||||||
|
|
||||||
def switchZoneIndexState(self, zoneIndex, state, duration, instant=False):
|
def switchZoneIndexState(self, zoneIndex, state, duration, instant=False):
|
||||||
zone = self.getZone(zoneIndex)
|
zone = self.getZone(zoneIndex)
|
||||||
self.switchZoneState(zone, state, duration, instant)
|
self.switchZoneState(zone, state, duration, instant)
|
||||||
|
|
||||||
|
def getPlanedDurationForZone(self, zone):
|
||||||
|
totalDuration = 0
|
||||||
|
#with self.lock:
|
||||||
|
for irrigationJob in self.pipeLine:
|
||||||
|
if(irrigationJob.zone == zone):
|
||||||
|
totalDuration = totalDuration + irrigationJob.duration
|
||||||
|
return totalDuration
|
||||||
|
|
||||||
def refreshStates(self):
|
def refreshStates(self):
|
||||||
for zone in self.zones:
|
for zone in self.zones:
|
||||||
zone.refreshState()
|
zone.refreshState()
|
||||||
|
|
||||||
def processPipeline(self):
|
def processPipeline(self):
|
||||||
|
#with self.lock:
|
||||||
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()
|
irrigationJob.process()
|
||||||
|
@ -46,13 +82,14 @@ class ZoneManager:
|
||||||
def cronJobs(self):
|
def cronJobs(self):
|
||||||
self.refreshStates()
|
self.refreshStates()
|
||||||
self.processPipeline()
|
self.processPipeline()
|
||||||
print("Executed Cron Jobs of ZoneManager")
|
print("Executed Cron Jobs of ZoneManager.\nactual Time: " + str(time()))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class IrrigationJob:
|
class IrrigationJob:
|
||||||
def __init__(self, zone, duration=0):
|
def __init__(self, id, zone, duration=0):
|
||||||
|
self.id = id
|
||||||
self.zone = zone
|
self.zone = zone
|
||||||
self.duration = duration
|
self.duration = duration
|
||||||
self.zone.switchState(state=True, duration=duration, instant=False)
|
self.zone.switchState(state=True, duration=duration, instant=False)
|
||||||
|
|
2
main.py
2
main.py
|
@ -6,7 +6,7 @@ from ZoneManager import ZoneManager
|
||||||
from SystemSettings import SystemSettings
|
from SystemSettings import SystemSettings
|
||||||
from FileIO import FileIO
|
from FileIO import FileIO
|
||||||
|
|
||||||
systemSettings = SystemSettings(dataDir="/Data", multiZoneIrrigation=False, defaultAutoIrrigationDuration=10, defaultManualIrrigationDuration=10, defaultManualOffDuration=10, webDurationOptions=[5, 10, 15, 20, 25, 30, 45, 60])
|
systemSettings = SystemSettings(dataDir="/Data", multiZoneIrrigation=False, defaultAutoIrrigationDuration=10, defaultManualIrrigationDuration=10, defaultManualOffDuration=10, webDurationOptions=[1, 5, 10, 15, 20, 25, 30, 45, 60])
|
||||||
fileIO = FileIO(systemSettings)
|
fileIO = FileIO(systemSettings)
|
||||||
zoneManager = ZoneManager(systemSettings=systemSettings, fileIO=fileIO)
|
zoneManager = ZoneManager(systemSettings=systemSettings, fileIO=fileIO)
|
||||||
webserver = Webserver(zoneManager=zoneManager, port=80)
|
webserver = Webserver(zoneManager=zoneManager, port=80)
|
||||||
|
|
Loading…
Reference in New Issue