永无止境的列表上的连续聚合 [英] Continuous aggregation on never ending list

查看:67
本文介绍了永无止境的列表上的连续聚合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我们的  < span style ="font-family:Calibri,sans-serif; line-height:normal; margin:0px; padding:0px; border:0px; vertical-align:baseline; font-size:11pt"> application business
层有一个modelList集合,它接收  连续  数据
关于从WCF服务购买的车辆。此数据已汇总 
购买日期  进入
另一个名为list1的集合。因此,聚合集合(list1)具有为每个日期购买的车辆的数量。以下代码用于汇总




 



  var   list1 = modelList.GroupBy((x)=> x.PurchaseDate).Select(( y)=>  new   DateVehicleCountViewMod el ()
{Date = y.Key,Count = y.Cou nt()})。ToList();





我们无法找出更新聚合计数的确切机制  特别   date
in list1。一些 
< span style ="margin:0px;填充:0像素;边框:0像素;垂直对齐:基线; FONT-FAMILY:宋体,无衬线; font-size:11pt">可能
接近 可以是:





1)处理modeList的collectionchanged事件。将新项目分组并合并到原始集合(list1)。即我们想以这样的方式合并这两个列表:如果list1中存在相同的日期,那么count将从list2添加到list1&
的相同项目,如果list1中不存在日期,那么新项目将被插入list1。实现此目的的语法应该是什么?



2)我们可以使用类似于CreateDerivedCollection的东西但是它会作用于永不结束的列表吗?



任意
帮助或 
指南  高度为
 
赞赏

解决方案

您好Sanjeev。您当前的代码使用的是LINQ运算符,例如GroupBy和Select ,以及.Count / .ToList等扩展,但实际上并没有以任何方式使用Reactive Extensions(Rx)。你仍然在编写LINQ查询,这些查询在
看来是一个集合,而不是比一个可观察的流(例如< IObservable< Purchases>)。


你的'modelList'集合如何接收其连续数据?你是从.NET事件开始,然后保持重新评估'list1'?你真的想在新项目到达时更新本地词典(并保持适当的分组)吗?
例如


我想我们可能需要更多信息,但你会想尝试使用一系列购买,而不是试图在一个集合上使用LINQ。每次购买时都不会创建一个新的集合,我很确定你好u
只需更新您当前的集合即可在没有RX的情况下执行此操作。


一旦您完成此工作,请使用.GroupBy和.Scan的组合在论坛上查找其他示例,所以你可以在你投影的每个组内进行扫描,以便输出'DateTime'和'ItemCount'的元组。


这不是一百万英里之外(但总结为'价值',而不仅仅是增加一个柜台):


http://social.msdn.microsoft.com/Forums/en-US/rx/thread/e1c1d590-4189-4566- a5e2-7e6afde96348


Hi,

Our application business layer has a modelList collection which receives continuous data about vehicle purchased from a WCF service. This data is aggregated on purchase date into another collection called list1. Thus the  aggregated collection (list1) has count of vehicle purchased for each date. Following code is used for aggregation

 

 var list1 = modelList.GroupBy((x) => x.PurchaseDate).Select((y) => new DateVehicleCountViewModel() { Date = y.Key, Count = y.Count() }).ToList();

We are not able to figure out the exact mechanism to update the aggregated count for a particular date in list1 when new records are added in  modelList  (for a new date or existing date). Some of the possible approaches  can be:

1) Handle the collectionchanged event of modeList. Group the new items and merge into original collection (list1). i.e. we want to merge these two lists in such way that if same date exists in list1 then count will add from list2 to the same item of list1 & if date doesn’t exist in list1 then new item get inserted in list1. What should be the syntax for achieving this?

2) Can we use something similar to CreateDerivedCollection but which acts on never ending list?

Any help or guidance is highly appreciated.

解决方案

Hi Sanjeev. Your current code uses LINQ operators such as GroupBy and Select, as well as extensions such as .Count/.ToList etc, but isn't actually using Reactive Extensions (Rx) in any way. You are still writing LINQ queries which operate over what appears to be a collection, rather than an observable stream (e.g.  IObservable<Purchases>).

How does your 'modelList' collection receive its continuous data? Do you start off with a .NET event, and then keep re-evaluating the 'list1'? Do you really want to just update a local dictionary as a new item arrives (and keep it grouped appropriately)? e.g.

I think we probably need more info, but you'll want to try and work with a stream of Purchases, rather than trying to use LINQ over a collection. It doesn't seem right to be creating a fresh collection each time there is a new purchase, and I'm sure you could do this without RX by just updating your current collection.

Once you have this working, look for other examples on the forum using a combination of .GroupBy and .Scan, so you can scan within each group you project in order to output a Tuple of 'DateTime' and 'ItemCount'.

This isn't a million miles away (but is summing a 'Value', rather than just incrementing a counter):

http://social.msdn.microsoft.com/Forums/en-US/rx/thread/e1c1d590-4189-4566-a5e2-7e6afde96348


这篇关于永无止境的列表上的连续聚合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆