def on_data(self, item):
curr_time = time.time()
value = item.data
if value is None or value == self.last_value:
return
# This is kind of a hack to correctly interpret UInt8MultiArray
# messages. There should be a better way to do this
if item._slot_types[item.__slots__.index('data')] == "uint8[]":
value = [ord(x) for x in value]
# Throttle updates by value only (not time)
if self.topic_type == Float64 and \
self.last_value is not None and \
self.last_value != 0.0:
delta_val = value - self.last_value
if abs(delta_val / self.last_value) <= 0.01:
return
# Save the data point
point = EnvironmentalDataPoint({
"environment": self.environment,
"variable": self.variable,
"is_desired": self.is_desired,
"value": value,
"timestamp": curr_time
})
point_id = gen_doc_id(curr_time)
self.db[point_id] = point
self.last_value = value
recipe_persistence.py 文件源码
python
阅读 17
收藏 0
点赞 0
评论 0
评论列表
文章目录