J'ai uploadé 2 nouveaux exemples dans le dépôt : l'un pour montrer comment faire une moyenne sur des températures, l'autre (pas encore testé) qui rejoue les dernières xx minutes de l'activité du bus (enfin, des GAD paramétrées dans le script)...
http://www.pknyx.org/browser/pknyx/examples
Moyenne :
http://www.pknyx.org/browser/pknyx/examp...erageFB.py
Replay :
http://www.pknyx.org/browser/pknyx/examp...eplayFB.py
Au passage, si on vire les logs et les commentaires, on voit qu'il ne reste pas grand chose :
http://www.pknyx.org/browser/pknyx/examples
Moyenne :
http://www.pknyx.org/browser/pknyx/examp...erageFB.py
Replay :
http://www.pknyx.org/browser/pknyx/examp...eplayFB.py
Au passage, si on vire les logs et les commentaires, on voit qu'il ne reste pas grand chose :
Code :
# -*- coding: utf-8 -*-
import time
import Queue
from pknyx.api import FunctionalBlock
from pknyx.api import logger, schedule, notify
class ReplayFB(FunctionalBlock):
DP_01 = dict(name="replay", access="input", dptId="1.011", default="Inactive")
DP_02 = dict(name="replay_period", access="input", dptId="7.006", default=1440) # min (= 24h)
DP_03 = dict(name="light_1", access="output", dptId="1.001", default="Off")
DP_04 = dict(name="light_2", access="output", dptId="1.001", default="Off")
DP_05 = dict(name="light_3", access="output", dptId="1.001", default="Off")
DP_06 = dict(name="light_4", access="output", dptId="1.001", default="Off")
DP_07 = dict(name="light_5", access="output", dptId="1.001", default="Off")
GO_01 = dict(dp="replay", flags="CRWU", priority="low")
GO_02 = dict(dp="replay_period", flags="CRWU", priority="low")
GO_03 = dict(dp="light_1", flags="CWTU", priority="low")
GO_04 = dict(dp="light_2", flags="CWTU", priority="low")
GO_05 = dict(dp="light_3", flags="CWTU", priority="low")
GO_06 = dict(dp="light_4", flags="CWTU", priority="low")
GO_07 = dict(dp="light_5", flags="CWTU", priority="low")
DESC = "Replay FB"
def init(self):
self._sequence = Queue.Queue(100)
@notify.datapoint(dp="light_1", condition="change")
@notify.datapoint(dp="light_2", condition="change")
@notify.datapoint(dp="light_3", condition="change")
@notify.datapoint(dp="light_4", condition="change")
@notify.datapoint(dp="light_5", condition="change")
def lightStateChanged(self, event):
dpName = event['dp']
newValue = event['newValue']
time_ = time.time()
try:
self._sequence.put_nowait({'dp': dpName, 'value': newValue, 'time': time_})
except Queue.Full:
logger.exception("%s: storage sequence is full; skipping..." % self.name, debug=True)
@schedule.every(seconds=1)
def processQueue(self):
try:
item = self._sequence.get_nowait()
except Queue.Empty:
logger.exception("%s: storage sequence is empty; skipping..." % self.name, debug=True)
delta = (time.time() - item['time']) / 60.
if self.dp['replay'].value == "Active" and delta > self.dp['replay_period'].value:
self.dp[item['dp']].value = item['value']