how to group by specific timestamp interval like 15 min?????
-
Yeah, thats nice and easy (when you know how). A little test code for you.
List listTicks = new List();
listTicks.Add(new DateTime(2009, 3, 5, 8, 0, 0));
listTicks.Add(new DateTime(2009, 3, 5, 8, 1, 0));
listTicks.Add(new DateTime(2009, 3, 5, 8, 7, 0));
listTicks.Add(new DateTime(2009, 3, 5, 8, 15, 0));
listTicks.Add(new DateTime(2009, 3, 5, 8, 17, 0));
listTicks.Add(new DateTime(2009, 3, 5, 8, 19, 0));
listTicks.Add(new DateTime(2009, 3, 5, 8, 22, 0));
listTicks.Add(new DateTime(2009, 3, 5, 8, 35, 0));
listTicks.Add(new DateTime(2009, 3, 5, 8, 37, 0));
listTicks.Add(new DateTime(2009, 3, 5, 8, 47, 0));
listTicks.Add(new DateTime(2009, 3, 5, 9, 15, 0));
listTicks.Add(new DateTime(2009, 3, 5, 9, 44, 0));
listTicks.Add(new DateTime(2009, 3, 5, 9, 59, 0));var result = from tick in listTicks
group tick by new { Hour=tick.Hour ,QuarterHour=(15*Math.Floor(((double)(tick.Minute/15)))) } into g
select new
{
Count = g.Count(),
Key = g.Key,
Items = g
};
foreach (var item in result)
{
Console.WriteLine("There are {0} items in the group starting {1:00}:{2:00}:00",
item.Count,item.Key.Hour,item.Key.QuarterHour);
foreach (var x in item.Items)
Console.WriteLine("\t{0}",x );
}Output is:
There are 3 items in the group starting 08:00:00
05/03/2009 08:00:00
05/03/2009 08:01:00
05/03/2009 08:07:00
There are 4 items in the group starting 08:15:00
05/03/2009 08:15:00
05/03/2009 08:17:00
05/03/2009 08:19:00
05/03/2009 08:22:00
There are 2 items in the group starting 08:30:00
05/03/2009 08:35:00
05/03/2009 08:37:00
There are 1 items in the group starting 08:45:00
05/03/2009 08:47:00
There are 1 items in the group starting 09:15:00
05/03/2009 09:15:00
There are 1 items in the group starting 09:30:00
05/03/2009 09:44:00
There are 1 items in the group starting 09:45:00
05/03/2009 09:59:00The crux of the matter is in the grouping in LINQ, I have group by a
new
anonymous class that contains the Hour and the Minute based to the previous quarter hour mark:QuarterHour=(15*Math.Floor(((double)(tick.Minute/15))))
breaking that down you get 1) tick.Minute/15 - to reduce the minute to its previous quarter 2) Cast it to a double so it can be passed toIf I have data from 8-22 each day and i want to separate it to 3 h he separate this way:
var result = from tick in listTicks group tick by new { Hour=tick.Day ,ThreeHours=( ??? ) } into g select new { Count = g.Count(), Key = g.Key, Items = g };
normally it will seperated this way 0-2;3-5;6-8;9-11,... , but i want it 8-10;11-13;14-16;17-19;20-22 how can i this manage...? -
If I have data from 8-22 each day and i want to separate it to 3 h he separate this way:
var result = from tick in listTicks group tick by new { Hour=tick.Day ,ThreeHours=( ??? ) } into g select new { Count = g.Count(), Key = g.Key, Items = g };
normally it will seperated this way 0-2;3-5;6-8;9-11,... , but i want it 8-10;11-13;14-16;17-19;20-22 how can i this manage...?Im a bit exasperated you couldn't figure this out yourself with the help already given, however your problem is a simple one still. Group by the number of hours past 8 in blocks of 3 hours.
var result = from tick in listTicks
group tick by new { HoursPastEight = (3*Math.Floor((double)((tick.Hour-8) / 3))) } into g
select new
{
Count = g.Count(),
Key = g.Key,
Items = g
}; -
Im a bit exasperated you couldn't figure this out yourself with the help already given, however your problem is a simple one still. Group by the number of hours past 8 in blocks of 3 hours.
var result = from tick in listTicks
group tick by new { HoursPastEight = (3*Math.Floor((double)((tick.Hour-8) / 3))) } into g
select new
{
Count = g.Count(),
Key = g.Key,
Items = g
}; -
is it possible to have access to the last g during creating the select new { } i want to check an actual value withe one from the last g
Ive now provided you the very best help you're ever likely to get, and you've not even seen fit to type the words "thank you" even once, im now done helping you. You're not going to get spoon-fed in this industry, I provided you some workable examples hoping you would have a little play around yourself. Youve not. You've simply asked another mindless question. Good day sir.
-
Yeah, thats nice and easy (when you know how). A little test code for you.
List listTicks = new List();
listTicks.Add(new DateTime(2009, 3, 5, 8, 0, 0));
listTicks.Add(new DateTime(2009, 3, 5, 8, 1, 0));
listTicks.Add(new DateTime(2009, 3, 5, 8, 7, 0));
listTicks.Add(new DateTime(2009, 3, 5, 8, 15, 0));
listTicks.Add(new DateTime(2009, 3, 5, 8, 17, 0));
listTicks.Add(new DateTime(2009, 3, 5, 8, 19, 0));
listTicks.Add(new DateTime(2009, 3, 5, 8, 22, 0));
listTicks.Add(new DateTime(2009, 3, 5, 8, 35, 0));
listTicks.Add(new DateTime(2009, 3, 5, 8, 37, 0));
listTicks.Add(new DateTime(2009, 3, 5, 8, 47, 0));
listTicks.Add(new DateTime(2009, 3, 5, 9, 15, 0));
listTicks.Add(new DateTime(2009, 3, 5, 9, 44, 0));
listTicks.Add(new DateTime(2009, 3, 5, 9, 59, 0));var result = from tick in listTicks
group tick by new { Hour=tick.Hour ,QuarterHour=(15*Math.Floor(((double)(tick.Minute/15)))) } into g
select new
{
Count = g.Count(),
Key = g.Key,
Items = g
};
foreach (var item in result)
{
Console.WriteLine("There are {0} items in the group starting {1:00}:{2:00}:00",
item.Count,item.Key.Hour,item.Key.QuarterHour);
foreach (var x in item.Items)
Console.WriteLine("\t{0}",x );
}Output is:
There are 3 items in the group starting 08:00:00
05/03/2009 08:00:00
05/03/2009 08:01:00
05/03/2009 08:07:00
There are 4 items in the group starting 08:15:00
05/03/2009 08:15:00
05/03/2009 08:17:00
05/03/2009 08:19:00
05/03/2009 08:22:00
There are 2 items in the group starting 08:30:00
05/03/2009 08:35:00
05/03/2009 08:37:00
There are 1 items in the group starting 08:45:00
05/03/2009 08:47:00
There are 1 items in the group starting 09:15:00
05/03/2009 09:15:00
There are 1 items in the group starting 09:30:00
05/03/2009 09:44:00
There are 1 items in the group starting 09:45:00
05/03/2009 09:59:00The crux of the matter is in the grouping in LINQ, I have group by a
new
anonymous class that contains the Hour and the Minute based to the previous quarter hour mark:QuarterHour=(15*Math.Floor(((double)(tick.Minute/15))))
breaking that down you get 1) tick.Minute/15 - to reduce the minute to its previous quarter 2) Cast it to a double so it can be passed to -
Ive now provided you the very best help you're ever likely to get, and you've not even seen fit to type the words "thank you" even once, im now done helping you. You're not going to get spoon-fed in this industry, I provided you some workable examples hoping you would have a little play around yourself. Youve not. You've simply asked another mindless question. Good day sir.
hey i only can say thank you... thatsy why i pushed shortly directly on the first answer a positive reputation... i voted positive and thoughty thats what i have to do... sry that i dont said it directly... but your help was undoubtedly great! anyway do you know something about teh access?
-
hey i only can say thank you... thatsy why i pushed shortly directly on the first answer a positive reputation... i voted positive and thoughty thats what i have to do... sry that i dont said it directly... but your help was undoubtedly great! anyway do you know something about teh access?
-
Well, how about you have a try at solving your problem, and if you get stuck post the code you're up to.
var result3 = (from tick in listTicks group tick by new { Day = tick.timestamp.Day, HoursPastEight = (3 \* Math.Floor(Convert.ToDouble((tick.timestamp.Hour - 8) / 3))) } into g select g).Select(g => { // Create your object with the last timestamp var runtimeResult = new { Count = g.Count(), //Key = g.Key, Items = g, Timestamp = g.First().timestamp, LastTimestamp = lastTimestamp }; // Set last timestamp for next iteration lastTimestamp = runtimeResult.Timestamp; // Return your object return result; });
but this wont't work because in debug i dont find Count , Items, Timestamp, LastTimestamp etc...
-
var result3 = (from tick in listTicks group tick by new { Day = tick.timestamp.Day, HoursPastEight = (3 \* Math.Floor(Convert.ToDouble((tick.timestamp.Hour - 8) / 3))) } into g select g).Select(g => { // Create your object with the last timestamp var runtimeResult = new { Count = g.Count(), //Key = g.Key, Items = g, Timestamp = g.First().timestamp, LastTimestamp = lastTimestamp }; // Set last timestamp for next iteration lastTimestamp = runtimeResult.Timestamp; // Return your object return result; });
but this wont't work because in debug i dont find Count , Items, Timestamp, LastTimestamp etc...