以下查询似乎工作得很好:
var query =
Session.Query<SomeEvent>()
.Where(
p =>
p.Timestamp >= from.Now
&& p.Timestamp <= to.Now
)
.GroupBy(x => x.Timestamp)
.AsEnumerable()
.Select(
x =>
new SomeEvent {Timestamp = x.Key, DisplayValue = x.Average(y => y.DisplayValue)})
.OrderBy(x => x.Timestamp);
如果在时间戳(日期时间)方面存在重复,则在平均显示值中。我只是好奇是否也可以根据“分辨率”(例如在30分钟内)平均值?
答案 0 :(得分:1)
这个怎么样?我介绍了一个称为分辨率等级的概念,它为每个时间戳差异范围提供了一个水平键:如果在30分钟内则为1,如果在60分钟内则为2,如果在90分钟内则为3 ......等等。 根据这些级别,查询可以平均每个
double resolutionInMins = 30; // In minites
double divisor = to.Now.AddMinutes(resolutionInMins).Ticks - to.Now.Ticks;
Func<DateTime, double> resolutionLevel =
delegate(DateTime timestamp)
{
return Math.Ceiling((to.Now.Ticks - timestamp.Ticks) / divisor);
};
var query =
Session.Query<SomeEvent>()
.Where(p =>
p.Timestamp >= from.Now &&
p.Timestamp <= to.Now)
.GroupBy(x => new
{
ResolutionLevel = resolutionLevel(x.Timestamp)
})
.Select(x => new
{
ResolutionLevel = x.Key.ResolutionLevel,
ResolutionAvgValue = x.Average(b => b.DisplayValue)
});