本文整理汇总了Python中PyExpLabSys.common.database_saver.ContinuousDataSaver.save_point方法的典型用法代码示例。如果您正苦于以下问题:Python ContinuousDataSaver.save_point方法的具体用法?Python ContinuousDataSaver.save_point怎么用?Python ContinuousDataSaver.save_point使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyExpLabSys.common.database_saver.ContinuousDataSaver
的用法示例。
在下文中一共展示了ContinuousDataSaver.save_point方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_enqueue_point
# 需要导入模块: from PyExpLabSys.common.database_saver import ContinuousDataSaver [as 别名]
# 或者: from PyExpLabSys.common.database_saver.ContinuousDataSaver import save_point [as 别名]
def test_enqueue_point(self):
"""Test the continous logger by sending data with timestamps"""
# Make timestamps to use
number_of_points = 10
start = time.time()
times = [start + increment for increment in range(number_of_points)]
# Form the lists for local storage of data, for tests
data1 = []
data2 = []
# Init the db_saver
db_saver = ContinuousDataSaver("dateplots_dummy", "dummy", "dummy", ["dummy_sine_one", "dummy_sine_two"])
db_saver.start()
# Save the points
for now in times:
value = math.sin(now)
data1.append([now, value])
db_saver.save_point("dummy_sine_one", (now, value))
value = math.sin(now + math.pi)
data2.append([now, value])
db_saver.save_point("dummy_sine_two", (now, value))
# Make sure the queue has been cleared
while db_saver.sql_saver.queue.qsize() > 0:
time.sleep(0.01)
# Get the measurement code numbers from the logger
codes = (db_saver.codename_translation["dummy_sine_one"], db_saver.codename_translation["dummy_sine_two"])
# Check if the data has been properly written to the db
for data, code in zip((data1, data2), codes):
query = (
"SELECT UNIX_TIMESTAMP(time), value FROM dateplots_dummy "
"WHERE type={} ORDER BY id DESC LIMIT {}".format(code, number_of_points)
)
CURSOR.execute(query)
fetched = reversed(CURSOR.fetchall())
for point_original, point_control in zip(data, fetched):
# Time is rounded, so it is only correct to within ~0.51 s
assert np.isclose(point_original[0], point_control[0], atol=0.51)
assert np.isclose(point_original[1], point_control[1])
db_saver.stop()
示例2: GasAlarmMonitor
# 需要导入模块: from PyExpLabSys.common.database_saver import ContinuousDataSaver [as 别名]
# 或者: from PyExpLabSys.common.database_saver.ContinuousDataSaver import save_point [as 别名]
#.........这里部分代码省略.........
return CONF_TO_NAME[conf]
def main(self):
"""Main monitoring and logging loop"""
# Each iteration takes about 5 sec
while True:
# Log detectors
for detector_num in self.detector_numbers:
self.log_detector(detector_num)
# Log Vortex unit status (force log every 24 hours)
self.log_central_unit()
def log_detector(self, detector_num):
"""Get the levels from one detector and log if required"""
# Get detector info and levels for this detector
conf = self.detector_info[detector_num]
codename = self.conf_to_codename(conf)
LOGGER.debug('Use detector {} \'{}\''.format(detector_num, codename))
levels = self.vortex.get_detector_levels(detector_num)
LOGGER.debug('Levels read: {}'.format(levels))
# Detector level
now = time.time()
# Always send to live socket
self.live_socket.set_point_now(codename, levels.level)
# Force log every 10 m
time_condition = now - self.detector_levels_last_times[detector_num] > 600
value_condition = abs(self.detector_levels_last_values[detector_num] - levels.level)\
>= self.trip_levels[detector_num]
if time_condition or value_condition:
LOGGER.debug('Send level to db trigged in time: {} or value: '
'{}'.format(time_condition, value_condition))
self.db_saver.save_point(codename, (now, levels.level))
# Update last values
self.detector_levels_last_values[detector_num] = levels.level
self.detector_levels_last_times[detector_num] = now
else:
LOGGER.debug('Level logging condition false')
self.log_detector_status(detector_num, levels, conf)
def log_detector_status(self, detector_num, levels, conf):
"""Sub function to log single detector status"""
now = time.time()
# Force log every 24 hours
time_condition = now - self.detector_status_last_times[detector_num] > 86400
status = {'inhibit': levels.inhibit, 'status': levels.status, 'codename': conf.identity}
value_condition = (status != self.detector_status_last_values[detector_num])
# Check if we should log
if time_condition or value_condition:
check_in = time_condition and not value_condition
LOGGER.info('Send detector status to db trigged on time: {} or '
'value: {}'.format(time_condition, value_condition))
query = 'INSERT INTO status_b312gasalarm '\
'(time, device, status, check_in) '\
'VALUES (FROM_UNIXTIME(%s), %s, %s, %s);'
values = (now, detector_num, json.dumps(status), check_in)
self._wake_mysql()
self.db_cursor.execute(query, values)
# Update last values
self.detector_status_last_times[detector_num] = now
self.detector_status_last_values[detector_num] = status
else:
LOGGER.debug('Detector status logging condition false')