问题描述
我是一名机械工程研究生,我的顾问刚要我为我们的一个传感器项目编写数据可视化工具。由于是夏天,他希望我可以带上一些乐趣,所以我认为这将是学习科学计算语言的好时机,所以我继续前进,并投入到F#中。由于我是功能性编程范式的新手,我在正确构建程序时遇到了一些困难,尤其是考虑到可以轻松地将FO中的OO / FP组合起来。我的任务如下:
- 我们有数十个传感器不断报告数据(每隔几秒钟一次)。
- 我需要同时连接所有传感器,创建每个传感器输出的内存时间序列,然后实时计算这些时间序列的各种统计数据。
- 每隔几个小时我需要将数据刷新到二进制文件中进行记录。
我应该如何设计我的应用程序?我想过这样的事情:
1.我打算连接到每个传感器以开始接收数据,然后将这些数据转储到消息队列中。
2.我有一个事件驱动的处理函数接收队列中的数据。当收到数据时,会确定数据来自哪个传感器,然后将数据放入相应传感器的时间序列对象中。
3.每次添加传感器数据时间序列对象时,我都可以触发事件并让我的统计功能为传感器收集新数据。
显然我需要在这个应用程序中保持某种状态。所以我会添加下面的可变数据结构。我将使用一个通用的.NET可调整大小的List来存储我的时间序列数据,并实现一个新的衍生工具来触发数据添加事件。我可以在一个Dictionary中存储sensorid和实际时间序列容器之间的映射(当数据从队列中弹出时,我可以读取sensorid字段,获取该sensorid的时间序列容器,然后轻松添加新数据)。我还可以有第二个字典来存储sensorid和各个时间序列之间的映射,这些时间序列包含感知时间序列的统计信息)。当添加主传感器时间序列时,它会触发一个事件来调用所有的统计函数来运行新数据,并将它们的信息存储在该sensorid的适当字典中。
我还没有想过如何保存数据,但我想我可以用数据写出二进制文件。
感谢:)
在这个问题上我可能完全错了,这不是对你的问题的回答,所以请按照意愿投票给我,但是我的'感觉'来自于我的'感觉'对F#的兴趣刚刚超过一年,在科学/技术环境中使用F#有很多经验(我知道 异常 b
$ b
这可能是微软将他们的努力集中在金融界的F#推广上 - 相当不幸的是回顾过去的时机!
这并不意味着你不会为你的具体问题得到很好的答案,你只是不可能得到哦,是的,我上周做了类似的事情,小心这个p roblem等等。
另外,您是否知道 F#中的度量单位?非常有趣的功能与技术相关的任何事情。
I'm a mechanical engineering grad student and my adviser has just asked me to write a data visualization utility for one of our sensor projects. As it's summer and he wants me to have some fun with it, I thought this would be a great time to learn a language adept at scientific computing, so I went ahead and plowed right into F#.
As I'm new to the functional programming paradigm I'm having a little difficulty structuring my program properly, especially given the possibility of easily combining OO/FP in F#. My task is the following:
- We have dozens of sensors constantly reporting data (once every few seconds).
- I need to connect to all sensors simultaneously, create an in-memory timeseries of each sensor's output, and then calculate in real time various statistics on these timeseries.
- Every few hours I need to flush the data into a binary file for logging purposes.
How should I be designing my application? I've thought about something like this:1. I was planning on connecting to each sensor to start receiving data and then dump this data onto a message queue.2. I'd have an event-driven processing function receives data on the queue. When data is received, it is determined which sensor the data came from, and then the data is placed into the timeseries object of the corresponding sensor.3. Every time a sensor data timeseries object is added to, I could fire an Event and have my statistics functions crunch new data for the sensor.
Obviously I need to maintain some kind of state in this application. So I'd add the following mutable data structures. I would use a generic .NET resizable List for storing my timeseries data and implement a new derivative to fire on data add events. I could store the mappings between sensorid and the actual timeseries container in a Dictionary (when data is popped off the queue, I can read the sensorid field, grab the timeseries container for that sensorid, and then easily add new data). I could also have a second dictionary to store mappings between sensorid and the various timeseries containing statistics for that sensorid timeseries). When a main sensor timeseries is added to, it fires an event to call all of the statistics functions to run themselves on the new data and store their information in the appropriate dictionary for that sensorid.
I haven't thought about how to save the data much yet, but I figured I could just write out binary files with the data.
Any advice, ideas, or references are appreciated.
Thanks :)
I may be totally wrong on this, and it isn't an answer to your question, so vote me down at will, but my 'feeling' from just over a year's interest in F# is that there aren't that many people out there (or 'in here') with much experience using F# in scientific/technical environments (I know of one exception).
It may be that Microsoft focused their efforts on F# outreach to the financial community - rather unfortunate timing in retrospect!
Which doesn't mean that you won't get good answers for your specific question, you just aren't likely to get a "oh yeah, I did something like that last week, watch out for this problem" etc...
As an aside, are you aware of units of measure in F#? Very interesting feature for anything technical-related.
这篇关于你如何在F#中解决这个问题? (高频传感器数据)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!