Assume we have this records:
NID CId PushedAt
120 796 2015-09-04 18:00:53.6012627 +00:00
120 967 2015-09-04 18:00:51.9891748 +00:00
119 669 2015-09-04 17:45:56.8179094 +00:00
119 955 2015-09-04 17:45:55.2078154 +00:00
119 100 2015-09-04 17:45:53.5867187 +00:00
116 384 2015-09-04 17:01:01.5375630 +00:00
116 155 2015-09-04 17:00:59.9284665 +00:00
116 517 2015-09-04 17:00:58.3193725 +00:00
113 109 2015-09-04 16:00:53.5269438 +00:00
113 111 2015-09-04 16:00:51.9168442 +00:00
107 603 2015-09-04 13:45:59.9994496 +00:00
I want to group them by time-range (not a certain time). If I group them by time:
var grouped = list.GroupBy(t => new {
t.PushedAt.Year,
t.PushedAt.Month,
t.PushedAt.Day,
t.PushedAt.Hour,
t.PushedAt.Minute
});
then I'll miss groups wich have different Minute
, but actualy are in same group. For example, these rows:
116 384 2015-09-04 17:01:01.5375630 +00:00
116 155 2015-09-04 17:00:59.9284665 +00:00
116 517 2015-09-04 17:00:58.3193725 +00:00
will go to these groups:
// group 1:
116 384 2015-09-04 17:01:01.5375630 +00:00
// group 2:
116 155 2015-09-04 17:00:59.9284665 +00:00
116 517 2015-09-04 17:00:58.3193725 +00:00
But, what I'm looking for, is this group:
// group 1:
116 384 2015-09-04 17:01:01.5375630 +00:00
116 155 2015-09-04 17:00:59.9284665 +00:00
116 517 2015-09-04 17:00:58.3193725 +00:00
Means, these 3 rows should grouped together. Say, all rows which are in a 5 minutes range, should be grouped together. A full output would be something like this:
// group 1:
120 796 2015-09-04 18:00:53.6012627 +00:00
120 967 2015-09-04 18:00:51.9891748 +00:00
// group 2:
119 669 2015-09-04 17:45:56.8179094 +00:00
119 955 2015-09-04 17:45:55.2078154 +00:00
119 100 2015-09-04 17:45:53.5867187 +00:00
// group 3:
116 384 2015-09-04 17:01:01.5375630 +00:00
116 155 2015-09-04 17:00:59.9284665 +00:00
116 517 2015-09-04 17:00:58.3193725 +00:00
// group 4:
113 109 2015-09-04 16:00:53.5269438 +00:00
113 111 2015-09-04 16:00:51.9168442 +00:00
// group 5:
107 603 2015-09-04 13:45:59.9994496 +00:00
Do you have any idea?
Note: The NID
field is NOT group-able.
UPDATE:
I know I can solve the problem by iterating items (as juharr said in comment). But, I'm looking for a LINQ
solution, if there is any. Thanks.