protected AbstractReadingStatsIndex(TimeSpan period)
        {
            Map = readings => from reading in readings
                  let periodTicks = long.MinValue
                                    let roundedTime = new DateTime(((reading.Timestamp.Ticks + periodTicks - 1) / periodTicks) * periodTicks, DateTimeKind.Utc)
                                                      select new {
                reading.SensorId,
                Timestamp    = roundedTime,
                MinValue     = reading.Value,
                MaxValue     = reading.Value,
                AverageValue = reading.Value,
                Count        = 1
            };

            Map = new PeriodUpdateVistor(period).VisitAndConvert(Map, "AbstractReadingStatsIndex");

            Reduce = results => from result in results
                     group result by new { result.SensorId, result.Timestamp }
            into g
                select new {
                g.Key.SensorId,
                g.Key.Timestamp,
                MinValue     = g.Min(x => x.MinValue),
                MaxValue     = g.Max(x => x.MaxValue),
                AverageValue = g.Average(x => x.AverageValue),
                Count        = g.Sum(x => x.Count)
            };
        }
Beispiel #2
0
        protected AbstractReadingStatsIndex(TimeSpan period)
        {
            Map = readings => from reading in readings
                  let periodTicks = long.MinValue
                                    let roundedTime = new DateTime(((reading.Timestamp.Ticks + periodTicks - 1) / periodTicks) * periodTicks, DateTimeKind.Utc)
                                                      select new {
                reading.SensorId,
                Timestamp    = roundedTime,
                MinValue     = reading.Value,
                MaxValue     = reading.Value,
                TotalValue   = reading.Value,
                Count        = 1,
                AverageValue = 0
            };

            Map = new PeriodUpdateVistor(period).VisitAndConvert(Map, "AbstractReadingStatsIndex");

            Reduce = results => from result in results
                     group result by new { result.SensorId, result.Timestamp }
            into g
            let min = g.Min(x => x.MinValue)
                      let max                                                             = g.Max(x => x.MaxValue)
                                                        let total                         = g.Sum(x => x.TotalValue)
                                                                                let count = g.Sum(x => x.Count)
                                                                                            select new {
                g.Key.SensorId,
                g.Key.Timestamp,
                MinValue     = min,
                MaxValue     = max,
                TotalValue   = total,
                Count        = count,
                AverageValue = total / count,
            };

            Sort(x => x.MinValue, SortOptions.Double);
            Sort(x => x.MaxValue, SortOptions.Double);
            Sort(x => x.TotalValue, SortOptions.Double);
            Sort(x => x.Count, SortOptions.Int);
            Sort(x => x.AverageValue, SortOptions.Double);
        }