Beispiel #1
0
        private IEnumerable <FrozenPeriod> SubdivideCompactionPeriod(FrozenPeriod Original, FrozenPeriod New)
        {
            var inter = FrozenPeriod.Intersect(Original.Range, New.Range);

            if (FrozenPeriod.IsEmptyRange(inter))
            {
                return(new FrozenPeriod[] { Original });
            }
            else
            {
                return(new FrozenPeriod[]
                {
                    new FrozenPeriod(Original.StartTime, inter.Item1, Original.Compaction),
                    new FrozenPeriod(inter.Item1, inter.Item2, FrozenPeriod.Max(Original.Compaction, New.Compaction)),
                    new FrozenPeriod(inter.Item2, Original.EndTime, Original.Compaction)
                }.Where(item => !item.IsEmpty));
            }
        }
Beispiel #2
0
        private async Task <IEnumerable <Measurement> > GetMeasurementsAsync(FrozenPeriod Period)
        {
            const int MinutesPerHour = 60;

            switch (Period.Compaction)
            {
            case CompactionLevel.DayAverages:
            case CompactionLevel.HourAverages:
            case CompactionLevel.Measurements:
                // We'll re-create measurement data by replicating
                // hour-average data.
                var results = await GetHourAveragesAsync(
                    MeasurementAggregation.Quantize(Period.StartTime, TimeSpan.FromHours(1)),
                    (int)Math.Ceiling(Period.Duration.TotalHours));

                return(ReplicateEach(results, Period.StartTime, Period.EndTime, TimeSpan.FromMinutes(1), MinutesPerHour).ToArray());

            case CompactionLevel.None:
            default:
                // We can just fetch real measurements from the database.
                return(await Database.GetRawMeasurementsAsync(SensorId, Period.StartTime, Period.EndTime));
            }
        }
Beispiel #3
0
        private async Task <IEnumerable <Measurement> > GetHourAveragesAsync(FrozenPeriod Period)
        {
            const int HoursPerDay = 24;

            switch (Period.Compaction)
            {
            case CompactionLevel.DayAverages:
            case CompactionLevel.HourAverages:
                // We'll re-create hour-average data by replicating
                // day-average data.
                var results = await GetDayAveragesAsync(
                    MeasurementAggregation.Quantize(Period.StartTime, TimeSpan.FromDays(1)),
                    (int)Math.Ceiling(Period.Duration.TotalDays));

                return(ReplicateEach(results, Period.StartTime, Period.EndTime, TimeSpan.FromHours(1), HoursPerDay).ToArray());

            case CompactionLevel.Measurements:
            case CompactionLevel.None:
            default:
                // We can just fetch or create "real" hour-average data.
                return(await GetRealHourAveragesAsync(Period.StartTime, (int)Period.Duration.TotalHours));
            }
        }
Beispiel #4
0
        private async Task <IEnumerable <Measurement> > GetDayAveragesAsync(FrozenPeriod Period)
        {
            switch (Period.Compaction)
            {
            case CompactionLevel.DayAverages:
                // We'll re-create day-average data by replicating
                // month-average data.
                var results = new List <Measurement>();
                for (var day = Period.StartTime; day < Period.EndTime; day = day.AddDays(1))
                {
                    var monthMeasurement = await GetMonthAverageAsync(MeasurementAggregation.QuantizeMonth(day));

                    results.Add(new Measurement(SensorId, day, monthMeasurement.MeasuredData, monthMeasurement.Notes));
                }
                return(results);

            case CompactionLevel.HourAverages:
            case CompactionLevel.Measurements:
            case CompactionLevel.None:
            default:
                // We can just fetch or create "real" day-average data.
                return(await GetRealDayAveragesAsync(Period.StartTime, (int)Period.Duration.TotalDays));
            }
        }
 /// <summary>
 /// Tests if this time period overlaps with the given
 /// time period.
 /// </summary>
 public bool OverlapsWith(FrozenPeriod Other)
 {
     return Other.StartTime <= this.EndTime && this.StartTime <= Other.EndTime;
 }
		private async Task<IEnumerable<Measurement>> GetMeasurementsAsync(FrozenPeriod Period)
		{
			const int MinutesPerHour = 60;

			switch (Period.Compaction)
			{
				case CompactionLevel.DayAverages:
				case CompactionLevel.HourAverages:
				case CompactionLevel.Measurements:
					// We'll re-create measurement data by replicating 
					// hour-average data.
					var results = await GetHourAveragesAsync(
	                    MeasurementAggregation.Quantize(Period.StartTime, TimeSpan.FromHours(1)), 
	                    (int)Math.Ceiling(Period.Duration.TotalHours));
					return ReplicateEach(results, Period.StartTime, Period.EndTime, TimeSpan.FromMinutes(1), MinutesPerHour).ToArray();
					
				case CompactionLevel.None:
				default:
					// We can just fetch real measurements from the database.
					return await Database.GetRawMeasurementsAsync(SensorId, Period.StartTime, Period.EndTime);
			}
		}
		private async Task<IEnumerable<Measurement>> GetHourAveragesAsync(FrozenPeriod Period)
		{
			const int HoursPerDay = 24;

			switch (Period.Compaction)
			{
				case CompactionLevel.DayAverages:
				case CompactionLevel.HourAverages:
					// We'll re-create hour-average data by replicating 
					// day-average data.
					var results = await GetDayAveragesAsync(
						MeasurementAggregation.Quantize(Period.StartTime, TimeSpan.FromDays(1)),
						(int)Math.Ceiling(Period.Duration.TotalDays));
					return ReplicateEach(results, Period.StartTime, Period.EndTime, TimeSpan.FromHours(1), HoursPerDay).ToArray();

				case CompactionLevel.Measurements:
				case CompactionLevel.None:
				default:
					// We can just fetch or create "real" hour-average data.
					return await GetRealHourAveragesAsync(Period.StartTime, (int)Period.Duration.TotalHours);
			}
		}
		private async Task<IEnumerable<Measurement>> GetDayAveragesAsync(FrozenPeriod Period)
		{
			switch (Period.Compaction)
			{
				case CompactionLevel.DayAverages:
					// We'll re-create day-average data by replicating 
					// month-average data.
					var results = new List<Measurement>();
					for (var day = Period.StartTime; day < Period.EndTime; day = day.AddDays(1))
					{
						var monthMeasurement = await GetMonthAverageAsync(MeasurementAggregation.QuantizeMonth(day));
						results.Add(new Measurement(SensorId, day, monthMeasurement.MeasuredData, monthMeasurement.Notes));
					}
					return results;

				case CompactionLevel.HourAverages:
				case CompactionLevel.Measurements:
				case CompactionLevel.None:
				default:
					// We can just fetch or create "real" day-average data.
					return await GetRealDayAveragesAsync(Period.StartTime, (int)Period.Duration.TotalDays);
			}
		}
		private IEnumerable<FrozenPeriod> SubdivideCompactionPeriod(FrozenPeriod Original, FrozenPeriod New)
		{
			var inter = FrozenPeriod.Intersect(Original.Range, New.Range);
			if (FrozenPeriod.IsEmptyRange(inter))
			{
				return new FrozenPeriod[] { Original };
			}
			else
			{
				return new FrozenPeriod[] 
				{
					new FrozenPeriod(Original.StartTime, inter.Item1, Original.Compaction),
					new FrozenPeriod(inter.Item1, inter.Item2, FrozenPeriod.Max(Original.Compaction, New.Compaction)),
					new FrozenPeriod(inter.Item2, Original.EndTime, Original.Compaction)
				}.Where(item => !item.IsEmpty);
			}
		}
Beispiel #10
0
 /// <summary>
 /// Tests if this time period overlaps with the given
 /// time period.
 /// </summary>
 public bool OverlapsWith(FrozenPeriod Other)
 {
     return(Other.StartTime <= this.EndTime && this.StartTime <= Other.EndTime);
 }