c# - Lambda: efficiently find, modify, then group elements -
let's have list
, pagehit having these properties: <pagehit
>datetime requesttime
, int pageresponsetime
.
ultimately i'm trying round each requesttime value nearest 30 minute increment (using how can round time nearest x minutes?), group them together, , overall average of pageresponsetime increment block (real world user story: track average page response time per 30 minute block).
this far i've gotten, brain won't show me how efficiently average each increment without gross loop. there way in step 1?
// step 1: round request times pagehitlist.foreach(x => x.requesttime = x.requesttime.roundup(timespan.fromminutes(30)); // step 2: average of each increment block ?
haven't tested it, do:
var avg = pagehitlist.groupby(x => x.requesttime.roundup(timespan.fromminutes(30))); .select(hit => new { hit.key, average = hit.average(x => x.pageresponsetime) });
Comments
Post a Comment