Helllo,我想在python和进程之间共享少量数据(<1K).数据是物理pc/104 IO数据,它们经常快速变化(24x7x365).将有一个"服务器"写入数据,多个客户端读取它的一部分.这将运行的系统使用闪存(CF卡)而不是硬盘驱动器,所以我担心使用基于文件的方案磨损闪存.我也希望使用更少的功率(处理器时间),因为我们100%太阳能供电.
谢谢
更新:我们将最大数据更新速率降低到大约10 Hz,但更典型的是1 Hz.客户端仅在值更改时通知,而不是以不断更新的速率通知.我们已经进入了多服务器/多客户端模型,其中每个服务器都专注于某种类型的仪器或功能.由于事实证明大部分编程都是由Java程序员完成的,我们最终使用的是JSON-RPC over TCP.服务器将用Java编写,但我仍然希望用Python编写主客户端并调查JSON-RPC实现.
我需要做一些实时数据分析来监控操作错误.更具体地说,我正在控制一个浮标上的绞盘,这个浮标将仪器包降低到水中.我需要检测它是否已触及底部,如果有,则将其停止.我有以下数据:传感器的深度,绞车解开的速度.我得到1Hz的更新,整个过程持续约5分钟.如果传感器撞到底部,深度值通常会急剧减慢并最终停止可以假设在理想情况下下降速率是线性的,但由于波浪,可能会有相当多的噪声.
我想出了这个方法:
'''
The variables sensor_depth, winch_velocity and sample_time are assumed to be updated in the background
by another thread.
'''
import numpy as np
from time import sleep
x_data = []
y_data = []
running_size = 10
while winch_is_running():
if new_sample():
x_data.append(sample_time)
y_data.append(sensor_depth)
# Get the slope for the entire procedure
A = np.vstack([x_data,np.ones(len(x_data))])
overall_slope,offset = np.linalg.lstsq(A,y_data)[0]
# Get the slope for a recent set of samples
A = np.vstack([x_data[-1*running_size],np.ones(running_size)])
recent_slope,offset = np.linalg.lstsq(A,y_data[-1*running_size])[0]
if overall_slope - recent_slope > allowed_slope_error: …Run Code Online (Sandbox Code Playgroud) 这可能是一个基本的面向对象问题:我正在尝试使用 cmd 制作一个嵌套控制台菜单,效果很好。我还希望所有子控制台都可以访问相同的对象。这进展并不顺利。
我的简单例子:
import cmd
class MainConsole(cmd.Cmd):
def __init__(self,obj1,obj2):
cmd.Cmd.__init__(self)
self.prompt = ">"
self.obj1 = obj1 # The objects I want access to in all my consoles.
self.obj2 = obj2
self.menu1 = SubConsole1() # I could pass in the objects here as arguments
self.menu2 = SubConsole2() # but there should be a better way.
def do_menu1(self,args):
self.menu1.cmdloop()
def do_menu2(self,args):
self.menu2.cmdloop()
def do_info(self,args):
self.menu1.do_info(args)
self.menu2.do_info(args)
def do_exit(self,args):
return -1
class SubConsole1(cmd.Cmd,MainConsole):
def __init__(self):
cmd.Cmd.__init__(self)
self.prompt = "1>"
def do_action(self,args):
print …Run Code Online (Sandbox Code Playgroud) 我有一个表功能,有一个名为sample_time的datetimetz字段和一个名为amp_hours的列.
amp_hours字段大约每两分钟获得一次记录,并在午夜每晚重置.
我想看看每天最后一条记录的sample_time和amp_hours.
我对SQL很新,所以我可能会忽略一个明显的答案.
我看到这篇关于如何选择组的最后一条记录的帖子,但我对SQL不熟悉以使其在日期时间内工作:
我想使用lead()或lag()比较记录的日期和下一条记录,但我使用postgresql 8.3,我认为窗口是在8.4中引入的.