public static Dictionary <string, List <ReadingBase> > GetDailySummary(WeatherValueType valueType, int deviceId, DateTime startDate, DateTime endDate) { var summaryList = new Dictionary <string, List <ReadingBase> >(); summaryList["Average"] = new List <ReadingBase>(); summaryList["Minimum"] = new List <ReadingBase>(); summaryList["Maximum"] = new List <ReadingBase>(); for (var year = startDate.Year; year <= endDate.Year; year++) { using (var archiveData = new WeatherArchiveData(year)) { var groupList = archiveData.Readings .Where(r => r.ReadTime >= startDate && r.ReadTime <= endDate && r.DeviceId == deviceId && r.Type == (int)valueType) .GroupBy(r => DbFunctions.TruncateTime(r.ReadTime)) .Select(g => new { ReadTime = g.Key, Readings = g.Select(r => r.Value) }).ToList(); summaryList["Average"].AddRange(groupList.Select(d => ReadingBase.CreateReading(valueType, d.ReadTime.Value.DateTime, d.Readings.Average()))); summaryList["Minimum"].AddRange(groupList.Select(d => ReadingBase.CreateReading(valueType, d.ReadTime.Value.DateTime, d.Readings.Min()))); summaryList["Maximum"].AddRange(groupList.Select(d => ReadingBase.CreateReading(valueType, d.ReadTime.Value.DateTime, d.Readings.Max()))); } } return(summaryList); }
public static ReadingBase CreateReading(WeatherValueType valueType) { switch (valueType) { case WeatherValueType.Temperature: return(new TemperatureReading()); case WeatherValueType.Pressure: return(new PressureReading()); case WeatherValueType.Humidity: return(new HumidityReading()); case WeatherValueType.WindSpeed: return(new WindSpeedReading()); case WeatherValueType.WindDirection: return(new WindDirectionReading()); case WeatherValueType.Rain: return(new RainReading()); default: throw new ArgumentOutOfRangeException("valueType"); } }
private readonly DeviceBase _ownerDevice; // Owner device #endregion #region Constructor public Value(WeatherValueType valueType, DeviceBase ownerDevice) { // Remember information we were given ValueType = valueType; _ownerDevice = ownerDevice; // Create the readings Current = ReadingBase.CreateReading(ValueType); }
public static ReadingBase CreateReading(WeatherValueType valueType, DateTime readTime, double value) { var reading = CreateReading(valueType); reading.ReadTime = readTime; reading.Value = value; return(reading); }
public async Task <decimal> GetReadingValueSum(WeatherValueType weatherValueType, DateTimeOffset start, DateTimeOffset end) { await using var connection = CreateConnection(); var query = ResourceReader.GetString("ChrisKaczor.HomeMonitor.Weather.Service.Data.Resources.GetReadingValueSum.sql"); query = query.Replace("@Value", weatherValueType.ToString()); return(await connection.ExecuteScalarAsync <decimal>(query, new { Start = start, End = end })); }
public async Task <IEnumerable <WeatherValue> > GetReadingValueHistory(WeatherValueType weatherValueType, DateTimeOffset start, DateTimeOffset end) { await using var connection = CreateConnection(); var query = ResourceReader.GetString("ChrisKaczor.HomeMonitor.Weather.Service.Data.Resources.GetReadingValueHistory.sql"); query = query.Replace("@Value", weatherValueType.ToString()); return(await connection.QueryAsync <WeatherValue>(query, new { Start = start, End = end })); }
public static Dictionary <DeviceBase, List <ReadingBase> > GetGenericHistory(WeatherValueType valueType, DateTimeOffset start, DateTimeOffset end) { var devices = Program.Session.Devices.Where(d => d.SupportedValues.Contains(valueType)); var deviceHistoryList = new Dictionary <DeviceBase, List <ReadingBase> >(); foreach (var device in devices) { deviceHistoryList[device] = LoadHistory(valueType, device.Id, start, end); } return(deviceHistoryList); }
private static List <ReadingBase> LoadHistory(WeatherValueType valueType, int deviceId, DateTimeOffset start, DateTimeOffset end) { var history = new List <ReadingBase>(); for (var year = start.Year; year <= end.Year; year++) { using (var archiveData = new WeatherArchiveData(year)) { var readings = archiveData.Readings; var yearlyHistory = readings.Where(r => r.DeviceId == deviceId && r.Type == (int)valueType && r.ReadTime >= start && r.ReadTime <= end).ToList(); history.AddRange(yearlyHistory.Select(r => ReadingBase.CreateReading(valueType, r.ReadTime.DateTime, r.Value))); } } return(history); }
public List <KeyValuePair <string, List <ReadingBase> > > GetDailySummary(WeatherValueType valueType, int deviceId, DateTime startDate, DateTime endDate) { return(WeatherServiceCommon.GetDailySummary(valueType, deviceId, startDate, endDate).ToList()); }
public List <KeyValuePair <DeviceBase, List <ReadingBase> > > GetGenericHistory(WeatherValueType valueType, DateTimeOffset start, DateTimeOffset end) { return(WeatherServiceCommon.GetGenericHistory(valueType, start, end).ToList()); }
public Dictionary <DeviceBase, List <ReadingBase> > GetGenericHistory(WeatherValueType valueType, DateTimeOffset start, DateTimeOffset end) { return(WeatherServiceCommon.GetGenericHistory(valueType, start, end)); }
public ReadingBase(WeatherValueType valueType) { ValueType = valueType; }
public async Task <ActionResult <List <WeatherValueGrouped> > > GetValueHistoryGrouped(WeatherValueType weatherValueType, DateTimeOffset start, DateTimeOffset end, int bucketMinutes = 2) { return((await _database.GetReadingValueHistoryGrouped(weatherValueType, start, end, bucketMinutes)).ToList()); }
public async Task <ActionResult <List <WeatherValue> > > GetValueHistory(WeatherValueType weatherValueType, DateTimeOffset start, DateTimeOffset end) { return((await _database.GetReadingValueHistory(weatherValueType, start, end)).ToList()); }
public Value GetValue(WeatherValueType valueType) { return(Values[valueType]); }