Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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");
            }
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        public static ReadingBase CreateReading(WeatherValueType valueType, DateTime readTime, double value)
        {
            var reading = CreateReading(valueType);

            reading.ReadTime = readTime;
            reading.Value    = value;

            return(reading);
        }
Esempio n. 5
0
        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 }));
        }
Esempio n. 6
0
        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 }));
        }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
        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);
        }
Esempio n. 9
0
 public List <KeyValuePair <string, List <ReadingBase> > > GetDailySummary(WeatherValueType valueType, int deviceId, DateTime startDate, DateTime endDate)
 {
     return(WeatherServiceCommon.GetDailySummary(valueType, deviceId, startDate, endDate).ToList());
 }
Esempio n. 10
0
 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));
 }
Esempio n. 12
0
 public ReadingBase(WeatherValueType valueType)
 {
     ValueType = valueType;
 }
Esempio n. 13
0
 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());
 }
Esempio n. 14
0
 public async Task <ActionResult <List <WeatherValue> > > GetValueHistory(WeatherValueType weatherValueType, DateTimeOffset start, DateTimeOffset end)
 {
     return((await _database.GetReadingValueHistory(weatherValueType, start, end)).ToList());
 }
Esempio n. 15
0
 public Value GetValue(WeatherValueType valueType)
 {
     return(Values[valueType]);
 }