
Untitled
By: a guest on
Jul 10th, 2012 | syntax:
None | size: 0.60 KB | hits: 11 | expires: Never
var series = EnumerableEx.Generate(fixture.Min(x => x.Time), x => x <= fixture.Max(y => y.Time), x => x.AddMinutes(5.0), x => x)
.Select(x => new { Key = x, Sum = lookup[x].Sum(y => y.ProductivityInSeconds), Len = lookup[x].Count()})
.Aggregate(new {List = new List<DateTime>(), Secs = 0.0}, (acc, x) => {
var toAdd = x.Sum;
if (x.Len == 0) {
toAdd = 60.0 * (acc.Secs > 0 ? -1.0 : 1.0);
}
var secs = (acc.Secs + toAdd).Clamp(-10 * 60.0, 5 * 60.0);
if (secs <= -10 * 60.0 && x.Sum != 0.0) {
acc.List.Add(x.Key);
secs += 5 * 60.0;
}
return new {acc.List, Secs = secs};
}).List;