c# - Average int Array elements with a GroupBy -



c# - Average int Array elements with a GroupBy -

i have list of items so:

where each element in list follows same structure. each y property int[] has 3 values.

i doing groupby on list split info 60 sec periods:

var newchart = chart.groupby(x => x.dateadded.roundup(timespan.fromseconds(60)));

roundup extension method got here: how can round time nearest x minutes?

this creates list so, values grouped minute, i'd expect:

so illustration min 20:18 there 5 entries, value may change, may 6 entries, 1 entry , forth.

so question is, how can cast new grouped list type of original list y values has average of entries in grouping by. i've tried next y values contain more 3 entries:

var newchart = chart.groupby(x => x.dateadded.roundup(timespan.fromseconds(60))) .select(x => new chartpoint { dateadded = x.key, x = x.key.tostring(@"hh:mm:ss"), y = x.select(y => (int)math.round(y.y.average(z => z), 0, midpointrounding.awayfromzero)).toarray() });

so example, if entry @ 20:18 had 2 entries, , y values entry 1 was: 3, 4, 5 , values entry 2 were: 5, 10, 11. expect entry @ 20:18 y in new list follows: 4, 7, 8 because: (3+5)/2 = 4, (4+10)/2 = 7, (5+11)/2 = 8

instead of getting average each array in group, create range length of arrays , average corresponding item each array:

var newchart = chart.groupby(x => x.dateadded.roundup(timespan.fromseconds(60))) .select(x => new chartpoint { dateadded = x.key, x = x.key.tostring(@"hh:mm:ss"), y = enumerable.range(0, 3).select(i => (int)math.round(x.average(z => z.y[i]))).toarray() });

c# linq

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

c# - Create a Notification Object (Email or Page) At Run Time -- Dependency Injection or Factory -

Set Up Of Common Name Of SSL Certificate To Protect Plesk Panel -