I have a list of objects of the following class:
public class CounterData
{
public DateTime counterTime { get; set; }
public int counterName { get; set; }
public int count { get; set; }
}
For example I have the following list of data in the format {counterTime, counterName, count}
:
{"Aug 8 2016 9:00AM","counter1",11}
{"Aug 8 2016 9:05AM","counter2",12}
{"Aug 8 2016 9:11AM","counter3",47}
{"Aug 8 2016 9:12AM","counter3",20}
{"Aug 8 2016 9:13AM","counter1",12}
{"Aug 8 2016 9:30AM","counter3",61}
{"Aug 8 2016 9:35AM","counter2",35}
{"Aug 8 2016 9:39AM","counter1",16}
{"Aug 8 2016 9:40AM","counter1",92}
{"Aug 8 2016 9:53AM","counter2",19}
And I want to group the counters by counterName
and counterTime
aggregated for every 15 minute interval. For the above example the resultant list should be:
{"Aug 8 2016 9:00AM","counter1",23}
{"Aug 8 2016 9:00AM","counter2",12}
{"Aug 8 2016 9:00AM","counter3",67}
{"Aug 8 2016 9:30AM","counter3",61}
{"Aug 8 2016 9:30AM","counter2",35}
{"Aug 8 2016 9:30AM","counter1",108}
{"Aug 8 2016 9:45AM","counter2",19}
From 9:00AM-9:15AM, there were 2 entries of counter1
. So the count
value is a sum of the entries. Similarly for other counters.
Can we use LINQ GroupBy to solve this? If so then how?