English 中文(简体)
F#
原标题:Replay Recorded Data Stream in F#

我在一份包含以下领域的数据库中记录了实时存货:<代码>Id、、Last。 最后是目前的股票价格(翻一番),在记录价格变动时,<编码> 日标准/代码>为<日码>。

I would like to replay this stream in the same way it came in, meaning if a price change was originally 12 seconds apart then the price change event firing (or something similar) should be 12 seconds apart.

在C# I中,可能产生一种收集,按<代码>Datetime分类,然后使用时间差异引发一场事件,以知道何时发生火灾,以抵消下一个价格变化。 我认识到“F#”与事件有关的许多冷却的新障碍,但我不知道我会如何在F#中开始这样做。 关于我如何这样做的任何想法/编码信条/有益联系?

最佳回答

我认为你热爱“F#”解决办法:-。

为了保持这一榜样的简单性,我把价格和时间序列储存在包含标记的清单中(第一个要素是从最后更新中推延第二个要素是价格)。 很难将你的输入数据输入这一格式。 例如:

let prices = [ (0, 10.0); (1000, 10.5); (500, 9.5); (2500, 8.5) ]

现在,我们可以创造新的活动,用于重新开展这一进程。 在创立后,我们立即附上一些手稿,以印刷价格更新:

let evt = new Event<float>()
evt.Publish.Add(printfn "Price updated: %f")

最后一个步骤是实施这种再演——这可以采用对价值观的不同步工作流程,不时地等到规定的时间,然后引发事件:

async { for delay, price in prices do
          do! Async.Sleep(delay)
          evt.Trigger(price) }
|> Async.StartImmediate

采用<条码>StartImmediate开始工作,这意味着工作将按目前思路进行(等候时间是同步的,因此不会阻碍铺面)。 保持所有单一版本,就更加简单(例如,你可以安全地获得全球倡议的控制)。

http://www.ohchr.org。 为了从申请的其他部分中总结某些部分的功能,你可以确定这样的类型:

type ReplyDataStream(prices) =
  let evt = new Event<float>()
  member x.Reply() = 
    // Start the asynchronous workflow here
  member x.PriceChanged = 
    evt.Publish

然后,用户可以通过<代码>stream.PriceChanged.Add.(......)对所记录的变化进行重新分析,然后开始使用<代码>Reply(。

问题回答

暂无回答




相关问题
what is wrong with this mysql code

$db_user="root"; $db_host="localhost"; $db_password="root"; $db_name = "fayer"; $conn = mysqli_connect($db_host,$db_user,$db_password,$db_name) or die ("couldn t connect to server"); // perform query ...

Users asking for denormalized database

I am in the early stages of developing a database-driven system and the largest part of the system revolves around an inheritance type of relationship. There is a parent entity with about 10 columns ...

Easiest way to deal with sample data in Java web apps?

I m writing a Java web app in my free time to learn more about development. I m using the Stripes framework and eventually intend to use hibernate and MySQL For the moment, whilst creating the pages ...

join across databases with nhibernate

I am trying to join two tables that reside in two different databases. Every time, I try to join I get the following error: An association from the table xxx refers to an unmapped class. If the ...

How can I know if such value exists in database? (ADO.NET)

For example, I have a table, and there is a column named Tags . I want to know if value programming exists in this column. How can I do this in ADO.NET? I did this: OleDbCommand cmd = new ...

Convert date to string upon saving a doctrine record

I m trying to migrate one of my PHP projects to Doctrine. I ve never used it before so there are a few things I don t understand. In my current code, I have a class similar to this: class ...

热门标签