Update Weather to .NET 8 and add telemetry

This commit is contained in:
2024-01-25 16:25:59 -05:00
parent 2394f613d2
commit 5d0bc2c31c
28 changed files with 856 additions and 775 deletions

View File

@@ -1,49 +1,48 @@
using ChrisKaczor.HomeMonitor.Weather.Models;
using JetBrains.Annotations;
using System;
using System.Collections.Generic;
using System.Linq;
using ChrisKaczor.HomeMonitor.Weather.Models;
using JetBrains.Annotations;
namespace ChrisKaczor.HomeMonitor.Weather.Service.Models
namespace ChrisKaczor.HomeMonitor.Weather.Service.Models;
[PublicAPI]
public class WeatherAggregate
{
[PublicAPI]
public class WeatherAggregate
public ReadingAggregate Humidity { get; set; }
public ReadingAggregate Temperature { get; set; }
public ReadingAggregate Pressure { get; set; }
public ReadingAggregate Light { get; set; }
public ReadingAggregate WindSpeed { get; set; }
public WindDirection WindDirectionAverage { get; set; }
public decimal RainTotal { get; set; }
private static readonly List<int> WindDirectionValues = ((WindDirection[])Enum.GetValues(typeof(WindDirection))).Select(e => (int)e).ToList();
public WeatherAggregate(List<WeatherReading> readings)
{
public ReadingAggregate Humidity { get; set; }
if (!readings.Any())
return;
public ReadingAggregate Temperature { get; set; }
Humidity = new ReadingAggregate(readings, r => r.Humidity, 1);
public ReadingAggregate Pressure { get; set; }
Temperature = new ReadingAggregate(readings, r => r.HumidityTemperature, 1);
public ReadingAggregate Light { get; set; }
Pressure = new ReadingAggregate(readings, r => r.Pressure, 2);
public ReadingAggregate WindSpeed { get; set; }
Light = new ReadingAggregate(readings, r => r.LightLevel, 2);
public WindDirection WindDirectionAverage { get; set; }
WindSpeed = new ReadingAggregate(readings, r => r.WindSpeed, 1);
public decimal RainTotal { get; set; }
var windDirectionAverage = readings.Average(r => (decimal)r.WindDirection);
WindDirectionAverage = (WindDirection)WindDirectionValues.Aggregate((x, y) => Math.Abs(x - windDirectionAverage) < Math.Abs(y - windDirectionAverage) ? x : y);
private static readonly List<int> WindDirectionValues = ((WindDirection[])Enum.GetValues(typeof(WindDirection))).Select(e => (int)e).ToList();
public WeatherAggregate(List<WeatherReading> readings)
{
if (!readings.Any())
return;
Humidity = new ReadingAggregate(readings, r => r.Humidity, 1);
Temperature = new ReadingAggregate(readings, r => r.HumidityTemperature, 1);
Pressure = new ReadingAggregate(readings, r => r.Pressure, 2);
Light = new ReadingAggregate(readings, r => r.LightLevel, 2);
WindSpeed = new ReadingAggregate(readings, r => r.WindSpeed, 1);
var windDirectionAverage = readings.Average(r => (decimal)r.WindDirection);
WindDirectionAverage = (WindDirection)WindDirectionValues.Aggregate((x, y) => Math.Abs(x - windDirectionAverage) < Math.Abs(y - windDirectionAverage) ? x : y);
RainTotal = readings.Sum(r => r.Rain);
}
RainTotal = readings.Sum(r => r.Rain);
}
}