我有一个间隔 30 分钟的 TimeInterval 数据列表,如下所示:
List<TimeInterval> testData = new List<TimeInterval>();
testData.Add(new TimeInterval() { Start = DateTime.Parse("2012-05-09 6:00:00 AM"), End = DateTime.Parse("2012-05-09 6:30:00 AM"), Value = 1 });
testData.Add(new TimeInterval() { Start = DateTime.Parse("2012-05-09 6:30:00 AM"), End = DateTime.Parse("2012-05-09 7:00:00 AM"), Value = 1 });
testData.Add(new TimeInterval() { Start = DateTime.Parse("2012-05-09 7:00:00 AM"), End = DateTime.Parse("2012-05-09 7:30:00 AM"), Value = 1 });
testData.Add(new TimeInterval() { Start = DateTime.Parse("2012-05-09 7:30:00 AM"), End = DateTime.Parse("2012-05-09 8:00:00 AM"), Value = 1 });
.....
testData.Add(new TimeInterval() { Start = DateTime.Parse("2012-05-10 7:00:00 AM"), End = DateTime.Parse("2012-05-10 7:30:00 AM"), Value = 20 });
testData.Add(new TimeInterval() { Start = DateTime.Parse("2012-05-10 7:30:00 AM"), End = DateTime.Parse("2012-05-10 8:00:00 AM"), Value = 10 });
................... up to N number of N number of years.
public class TimeInterval
{
public DateTime Start { get; set; }
public DateTime End { get; set; }
public decimal Value { get; set; }
}
有人可以建议将上述数据汇总到的最佳方法:
- 小时
- 天
- 星期
- 月
- 年
我在这里尝试了建议的解决方案,但似乎都没有满足上述要求。谢谢你的帮助。
对于上面给出的示例,Hour 的预期结果是:
Lists Of:
TimeInterval() { Start = DateTime.Parse("2012-05-09 6:00:00 AM"), End = DateTime.Parse("2012-05-09 7:00:00 AM"), Value = 2 }
TimeInterval() { Start = DateTime.Parse("2012-05-09 7:00:00 AM"), End = DateTime.Parse("2012-05-09 8:00:00 AM"), Value = 2 }
...
TimeInterval() { Start = DateTime.Parse("2012-05-10 7:00:00 AM"), End = DateTime.Parse("2012-05-10 8:00:00 AM"), Value = 2 }
对于 Days,它将是当天的总数。对于一周,它将是一整周的总计等。基本上对给定聚合类型的值求和。