当前位置: 首页>>代码示例>>C#>>正文


C# DataConnection.GetMonthAveragesAsync方法代码示例

本文整理汇总了C#中DataConnection.GetMonthAveragesAsync方法的典型用法代码示例。如果您正苦于以下问题:C# DataConnection.GetMonthAveragesAsync方法的具体用法?C# DataConnection.GetMonthAveragesAsync怎么用?C# DataConnection.GetMonthAveragesAsync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataConnection的用法示例。


在下文中一共展示了DataConnection.GetMonthAveragesAsync方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetFittedMeasurements

		private static Task<IEnumerable<Measurement>> GetFittedMeasurements(
			DataConnection Connection, int SensorId, DateTime StartTime, DateTime EndTime,
			int MaxMeasurementCount)
		{
			if (EndTime < StartTime)
				throw new ArgumentException($"{nameof(StartTime)} was greater than {nameof(EndTime)}");

			var timeSpan = EndTime - StartTime;
			if (timeSpan.TotalMinutes <= MaxMeasurementCount)
			{
				// Assume that one measurement was made per minute.
				// This assumption may not _always_ prove to be correct,
				// but we'd like to keep database chatter to a minimum.
				return Connection.GetMeasurementsAsync(SensorId, StartTime, EndTime);
			}
			else if (timeSpan.TotalHours <= MaxMeasurementCount)
			{
				return Connection.GetHourAveragesAsync(
					SensorId, MeasurementAggregation.Quantize(StartTime, TimeSpan.FromHours(1)), 
					(int)Math.Round(timeSpan.TotalHours));
			}
			else if (timeSpan.TotalDays <= MaxMeasurementCount)
			{
				return Connection.GetDayAveragesAsync(
					SensorId, MeasurementAggregation.Quantize(StartTime, TimeSpan.FromDays(1)), 
					(int)Math.Round(timeSpan.TotalDays));
			}
			else
			{
				int yearCount = EndTime.Year - StartTime.Year;
				int monthCount = 12 * yearCount + EndTime.Month - StartTime.Month;
				if (monthCount <= MaxMeasurementCount)
				{
					return Connection.GetMonthAveragesAsync(
						SensorId, MeasurementAggregation.QuantizeMonth(StartTime), monthCount);
				}
				else
				{
					return Connection.GetYearAveragesAsync(
						SensorId, MeasurementAggregation.QuantizeYear(StartTime), yearCount);
				}
			}
		}
开发者ID:jonathanvdc,项目名称:smarthomeweb,代码行数:43,代码来源:ApiAutofitModule.cs

示例2: GetAggregatedRangeAsync

 public override Task<IEnumerable<Measurement>> GetAggregatedRangeAsync(DataConnection Connection, int SensorId, DateTime StartTime, int ResultCount)
 {
     return Connection.GetMonthAveragesAsync(SensorId, StartTime, ResultCount);
 }
开发者ID:jonathanvdc,项目名称:smarthomeweb,代码行数:4,代码来源:ApiMonthAverageModule.cs


注:本文中的DataConnection.GetMonthAveragesAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。