本文整理汇总了Python中Data.dataAccess.DataAccess.saveSensorLog方法的典型用法代码示例。如果您正苦于以下问题:Python DataAccess.saveSensorLog方法的具体用法?Python DataAccess.saveSensorLog怎么用?Python DataAccess.saveSensorLog使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Data.dataAccess.DataAccess
的用法示例。
在下文中一共展示了DataAccess.saveSensorLog方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SensorLog
# 需要导入模块: from Data.dataAccess import DataAccess [as 别名]
# 或者: from Data.dataAccess.DataAccess import saveSensorLog [as 别名]
class SensorLog(PollingProcessor):
""" Handles updating sensors of all types to the database """
def __init__ (self, channels, name=''):
super(SensorLog, self).__init__()
self._dao = DataAccess().sensors
self._channels = channels
self._logCache = {}
self._name = name
def start(self):
""" Begin asynchronously updating changes in sensors """
if self._name != '':
print "Started updating database for %s sensor changes" % (self._name)
else:
print "Started updating database for [unknown] sensor changes"
self._addPollingProcessor('sensorHistory', self.checkUpdateSensors, (self._channels,), 0.01)
def stop(self):
""" Stop updating the sensor table """
if self._name != '':
print "Stopped updating database for %s sensor changes" % (self._name)
else:
print "Stopped updating database for [unknown] sensor changes"
self._removePollingProcessor('sensorHistory')
def checkUpdateSensors(self, channels):
""" Check the specified channels and update the database whenever changes are detected to the 'value' or 'status'"""
for uuid, sensor in channels.items():
if not self._logCache.has_key(uuid):
current = self._dao.getSensor(sensor['id'])
self._logCache[uuid] = { 'value': current['value'], 'status': current['status']}
status = str(sensor['status']).capitalize()
if self._logCache[uuid]['status'] != status or self._logCache[uuid]['value'] != sensor['value']:
val = sensor['value'] if len(sensor['value']) > 1 else sensor['value'][0]
timestamp = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
success = self._dao.saveSensorLog(
sensor['id'],
val,
status,
timestamp,
sensor['room'],
sensor['channel'])
if success:
print "%(time)s: Updated sensor log for %(id)s to %(status)s (%(value)s)" % {
'time':timestamp,
'id':sensor['channel'],
'status': status,
'value': val,
}
self._logCache[uuid]['value'] = sensor['value']
self._logCache[uuid]['status'] = status
示例2: SensorLog
# 需要导入模块: from Data.dataAccess import DataAccess [as 别名]
# 或者: from Data.dataAccess.DataAccess import saveSensorLog [as 别名]
class SensorLog(PollingProcessor):
def __init__ (self, channels, name=''):
super(SensorLog, self).__init__()
self._dao = DataAccess().sensors
self._channels = channels
self._logCache = {}
self._name = name
def start(self):
if self._name != '':
print "Started updating database for %s sensor changes" % (self._name)
else:
print "Started updating database for [unknown] sensor changes"
self._addPollingProcessor('sensorHistory', self.checkUpdateSensors, (self._channels,), 0.01)
def stop(self):
if self._name != '':
print "Stopped updating database for %s sensor changes" % (self._name)
else:
print "Stopped updating database for [unknown] sensor changes"
self._removePollingProcessor('sensorHistory')
def checkUpdateSensors(self, channels):
for uuid, sensor in channels.items():
if not self._logCache.has_key(uuid):
current = self._dao.getSensor(sensor['id'])
self._logCache[uuid] = { 'value': current['value'], 'status': current['status']}
status = str(sensor['status']).capitalize()
if self._logCache[uuid]['status'] != status:
timestamp = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
success = self._dao.saveSensorLog(
sensor['id'],
sensor['value'],
status,
timestamp,
sensor['room'],
sensor['channel'])
if success:
print "Updated sensor log for %(id)s to %(status)s" % {
'id':sensor['channel'],
'status': status
}
self._logCache[uuid]['value'] = sensor['value']
self._logCache[uuid]['status'] = status
示例3: SensorLog
# 需要导入模块: from Data.dataAccess import DataAccess [as 别名]
# 或者: from Data.dataAccess.DataAccess import saveSensorLog [as 别名]
class SensorLog(PollingProcessor):
def __init__ (self, channels, name=''):
super(SensorLog, self).__init__()
self._dao = DataAccess().sensors
self._channels = channels
self._logCache = {}
self._name = name
def start(self):
if self._name != '':
print "Started polling sensor changes for %s" % (self._name)
else:
print "Started polling sensor changes"
self._addPollingProcessor('sensorHistory', self.checkUpdateSensors, (self._channels, ), 0.01)
def stop(self):
if self._name != '':
print "Stopped polling sensor changes for %s" % (self._name)
else:
print "Stopped polling sensor changes"
self._removePollingProcessor('sensorHistory')
def checkUpdateSensors(self, channels):
for k in channels.keys():
if not self._logCache.has_key(k):
current = self._dao.getSensor(channels[k]['id'])
self._logCache.setdefault(k, { 'value': current['value'], 'status': current['status']})
if self._logCache[k]['status'] != channels[k]['status']:
timestamp = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
success = self._dao.saveSensorLog(
channels[k]['id'],
channels[k]['value'],
channels[k]['status'],
timestamp,
channels[k]['room'],
channels[k]['channel'])
if success:
print "Updated sensor log for %(id)s to %(status)s" % {
'id':channels[k]['channel'],
'status': channels[k]['status']
}
self._logCache[k]['value'] = channels[k]['value']
self._logCache[k]['status'] = channels[k]['status']