mysql - nhibernate select n points in date range -
so here's situation: have 2 tables contains statistics, 1 table statistic definitions, , table statistic events. each row in stats event table has timestamp, value, , reference statistic definition applies to, , each statistic definition has collection of stat entries. (i.e. 1 many)
my app allows user select statistic definition , date range, , graphs entries stat event table selected definition. however, it's possible user select large date range, , result in larger number of returned events necessary.
i'd return subset of data (n points) that's evenly distributed on time range user selects. current (naive) implementation following:
var totalentries = session.queryover<statevent>() .where(x => x.date > start_date && x.date < end_date && statdef.id == defn.id) .list() int modfactor = (int) math.ceiling((double)totalentries.count/30); var temp = totalentries.where((x, i) => i%modfactor == 0); return temp.orderby(x => x.date).tolist();
so i'm retrieving of records db matching date range , stat defn, selecting 30 entries.
the problems approach are:
1) it's inefficient of entries db, , discard ones don't want.
2) if data clumped (i.e. there many records around time, , not many records around time) selection weighted there data. not bad thing, i'd graphs prettier, , have evenly distributed data points.
so, know of smart way achieve same result in more efficient manner?
thanks!
i suggest aggregating values on set of intervals, size of interval calculated 1/30th of selected date range. manner in aggregate depend on stats, naive implementation sum them or average them or max value.
Comments
Post a Comment