Exemple #1
0
 /// <summary>
 /// Computes the given number of
 /// </summary>
 private void ComputeInCacheHourAverages(
     DateTime Start, int Offset, int Count, Measurement[] Target)
 {
     for (int i = 0; i < Count; i++)
     {
         var hour = Start.AddHours(i + Offset);
         Target[i + Offset] = MeasurementAggregation.Aggregate(hourData[hour], SensorId, hour);
     }
 }
Exemple #2
0
        /// <summary>
        /// Gets the hour average for the given hour.
        /// </summary>
        private async Task <Measurement> GetRealHourAverageAsync(DateTime Hour)
        {
            if (hourAverages == null)
            {
                await FetchHourAveragesAsync();
            }

            Measurement result;

            if (hourAverages.TryGetValue(Hour, out result))
            {
                return(result);
            }
            else
            {
                result = MeasurementAggregation.Aggregate(
                    await GetMeasurementsAsync(Hour), SensorId, Hour);
                hourAverages[Hour] = result;
                return(result);
            }
        }
Exemple #3
0
        /// <summary>
        /// Gets the day average for the given day.
        /// </summary>
        private async Task <Measurement> GetRealDayAverageAsync(DateTime Day)
        {
            if (dayAverages == null)
            {
                await FetchDayAveragesAsync();
            }

            Measurement result;

            if (dayAverages.TryGetValue(Day, out result))
            {
                return(result);
            }
            else
            {
                result = MeasurementAggregation.Aggregate(
                    await GetRealHourAveragesAsync(Day, 24),
                    SensorId, Day, Enumerable.Average);
                dayAverages[Day] = result;
                return(result);
            }
        }
Exemple #4
0
        /// <summary>
        /// Gets the month-average for the given month.
        /// </summary>
        public async Task <Measurement> GetMonthAverageAsync(DateTime Month)
        {
            if (monthAverages == null)
            {
                await FetchMonthAveragesAsync();
            }

            Measurement result;

            if (monthAverages.TryGetValue(Month, out result))
            {
                return(result);
            }
            else
            {
                var timeSpan = Month.AddMonths(1) - Month;
                result = MeasurementAggregation.Aggregate(
                    await GetRealDayAveragesAsync(Month, (int)timeSpan.TotalDays),
                    SensorId, Month, Enumerable.Average);
                monthAverages[Month] = result;
                return(result);
            }
        }