mirror of
https://github.com/ckaczor/HomeMonitor.git
synced 2026-01-13 17:22:54 -05:00
Merge branch 'master' of github.com:ckaczor/HomeMonitor
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,3 +1,5 @@
|
|||||||
|
*.user
|
||||||
|
|
||||||
bin/
|
bin/
|
||||||
log/
|
log/
|
||||||
obj/
|
obj/
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Converters;
|
using Newtonsoft.Json.Converters;
|
||||||
using System;
|
using System;
|
||||||
using System.Globalization;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace ChrisKaczor.HomeMonitor.Weather.Models
|
namespace ChrisKaczor.HomeMonitor.Weather.Models
|
||||||
@@ -33,22 +32,34 @@ namespace ChrisKaczor.HomeMonitor.Weather.Models
|
|||||||
|
|
||||||
var messageValues = messageParts.Select(m => m.Split('=')).ToDictionary(a => a[0], a => a[1]);
|
var messageValues = messageParts.Select(m => m.Split('=')).ToDictionary(a => a[0], a => a[1]);
|
||||||
|
|
||||||
WindDirection = (WindDirection)Enum.Parse(typeof(WindDirection), messageValues[@"winddir"]);
|
WindDirection = GetWindDirection(double.Parse(messageValues[@"wd"]));
|
||||||
WindSpeed = decimal.Parse(messageValues[@"windspeedmph"]);
|
WindSpeed = decimal.Parse(messageValues[@"ws"]);
|
||||||
Humidity = decimal.Parse(messageValues[@"humidity"]);
|
Humidity = decimal.Parse(messageValues[@"sh"]);
|
||||||
HumidityTemperature = decimal.Parse(messageValues[@"tempH"]);
|
HumidityTemperature = decimal.Parse(messageValues[@"st"]);
|
||||||
Rain = decimal.Parse(messageValues[@"rain"]);
|
Rain = decimal.Parse(messageValues[@"r"]);
|
||||||
Pressure = decimal.Parse(messageValues[@"pressure"]);
|
Pressure = decimal.Parse(messageValues[@"bp"]);
|
||||||
PressureTemperature = decimal.Parse(messageValues[@"tempP"]);
|
PressureTemperature = decimal.Parse(messageValues[@"bt"]);
|
||||||
BatteryLevel = decimal.Parse(messageValues[@"batt_lvl"]);
|
LightLevel = decimal.Parse(messageValues[@"tl"]);
|
||||||
LightLevel = decimal.Parse(messageValues[@"light_lvl"]);
|
Latitude = decimal.Parse(messageValues[@"glt"]);
|
||||||
Latitude = decimal.Parse(messageValues[@"lat"]);
|
Longitude = decimal.Parse(messageValues[@"gln"]);
|
||||||
Longitude = decimal.Parse(messageValues[@"lng"]);
|
|
||||||
Altitude = decimal.Parse(messageValues[@"altitude"]);
|
|
||||||
SatelliteCount = int.Parse(messageValues[@"sats"]);
|
|
||||||
|
|
||||||
DateTimeOffset.TryParseExact($"{messageValues[@"date"]} {messageValues[@"time"]}", "MM/dd/yyyy HH:mm:ss", null, DateTimeStyles.None, out var gpsTimestamp);
|
var gpsFix = int.Parse(messageValues[@"gf"]);
|
||||||
GpsTimestamp = gpsTimestamp;
|
|
||||||
|
if (gpsFix == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Altitude = decimal.Parse(messageValues[@"ga"]);
|
||||||
|
SatelliteCount = int.Parse(messageValues[@"gs"]);
|
||||||
|
|
||||||
|
var year = int.Parse(messageValues[@"gdy"]) + 2000;
|
||||||
|
var month = int.Parse(messageValues[@"gdm"]);
|
||||||
|
var day = int.Parse(messageValues[@"gdd"]);
|
||||||
|
|
||||||
|
var hour = int.Parse(messageValues[@"gth"]);
|
||||||
|
var minute = int.Parse(messageValues[@"gtm"]);
|
||||||
|
var second = int.Parse(messageValues[@"gts"]);
|
||||||
|
|
||||||
|
GpsTimestamp = new DateTimeOffset(year, month, day, hour, minute, second, 0, TimeSpan.Zero);
|
||||||
}
|
}
|
||||||
|
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
@@ -59,5 +70,61 @@ namespace ChrisKaczor.HomeMonitor.Weather.Models
|
|||||||
|
|
||||||
return new WeatherMessage { Message = message };
|
return new WeatherMessage { Message = message };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static WindDirection GetWindDirection(double degrees)
|
||||||
|
{
|
||||||
|
switch (degrees)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
return WindDirection.North;
|
||||||
|
|
||||||
|
case 22.5:
|
||||||
|
return WindDirection.NorthNorthEast;
|
||||||
|
|
||||||
|
case 45:
|
||||||
|
return WindDirection.NorthEast;
|
||||||
|
|
||||||
|
case 67.5:
|
||||||
|
return WindDirection.EastNorthEast;
|
||||||
|
|
||||||
|
case 90:
|
||||||
|
return WindDirection.East;
|
||||||
|
|
||||||
|
case 112.5:
|
||||||
|
return WindDirection.EastSouthEast;
|
||||||
|
|
||||||
|
case 135:
|
||||||
|
return WindDirection.SouthEast;
|
||||||
|
|
||||||
|
case 157.5:
|
||||||
|
return WindDirection.SouthSouthEast;
|
||||||
|
|
||||||
|
case 180:
|
||||||
|
return WindDirection.South;
|
||||||
|
|
||||||
|
case 202.5:
|
||||||
|
return WindDirection.SouthSouthWest;
|
||||||
|
|
||||||
|
case 225:
|
||||||
|
return WindDirection.SouthWest;
|
||||||
|
|
||||||
|
case 247.5:
|
||||||
|
return WindDirection.WestSouthWest;
|
||||||
|
|
||||||
|
case 270:
|
||||||
|
return WindDirection.West;
|
||||||
|
|
||||||
|
case 292.5:
|
||||||
|
return WindDirection.WestNorthWest;
|
||||||
|
|
||||||
|
case 315:
|
||||||
|
return WindDirection.NorthWest;
|
||||||
|
|
||||||
|
case 337.5:
|
||||||
|
return WindDirection.NorthNorthWest;
|
||||||
|
}
|
||||||
|
|
||||||
|
return WindDirection.None;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -25,8 +25,6 @@ namespace ChrisKaczor.HomeMonitor.Weather.Models
|
|||||||
|
|
||||||
public decimal PressureTemperature { get; set; }
|
public decimal PressureTemperature { get; set; }
|
||||||
|
|
||||||
public decimal BatteryLevel { get; set; }
|
|
||||||
|
|
||||||
public decimal LightLevel { get; set; }
|
public decimal LightLevel { get; set; }
|
||||||
|
|
||||||
public decimal Latitude { get; set; }
|
public decimal Latitude { get; set; }
|
||||||
|
|||||||
@@ -5,22 +5,22 @@ namespace ChrisKaczor.HomeMonitor.Weather.Models
|
|||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public enum WindDirection
|
public enum WindDirection
|
||||||
{
|
{
|
||||||
None = -1,
|
None,
|
||||||
North = 0,
|
North,
|
||||||
East = 90,
|
East,
|
||||||
South = 180,
|
South,
|
||||||
West = 270,
|
West,
|
||||||
NorthEast = 45,
|
NorthEast,
|
||||||
SouthEast = 135,
|
SouthEast,
|
||||||
SouthWest = 225,
|
SouthWest,
|
||||||
NorthWest = 315,
|
NorthWest,
|
||||||
NorthNorthEast = 23,
|
NorthNorthEast,
|
||||||
EastNorthEast = 68,
|
EastNorthEast,
|
||||||
EastSouthEast = 113,
|
EastSouthEast,
|
||||||
SouthSouthEast = 158,
|
SouthSouthEast,
|
||||||
SouthSouthWest = 203,
|
SouthSouthWest,
|
||||||
WestSouthWest = 248,
|
WestSouthWest,
|
||||||
WestNorthWest = 293,
|
WestNorthWest,
|
||||||
NorthNorthWest = 338
|
NorthNorthWest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
20
Weather/ModelsTests/ModelsTests.csproj
Normal file
20
Weather/ModelsTests/ModelsTests.csproj
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
|
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
|
||||||
|
<PackageReference Include="MSTest.TestAdapter" Version="2.1.0" />
|
||||||
|
<PackageReference Include="MSTest.TestFramework" Version="2.1.0" />
|
||||||
|
<PackageReference Include="coverlet.collector" Version="1.2.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Models\Models.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
33
Weather/ModelsTests/WeatherMessageTests.cs
Normal file
33
Weather/ModelsTests/WeatherMessageTests.cs
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
using System;
|
||||||
|
using ChrisKaczor.HomeMonitor.Weather.Models;
|
||||||
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
|
||||||
|
namespace ModelsTests
|
||||||
|
{
|
||||||
|
[TestClass]
|
||||||
|
public class WeatherMessageTests
|
||||||
|
{
|
||||||
|
[TestMethod]
|
||||||
|
public void ParseTest()
|
||||||
|
{
|
||||||
|
var weatherMessage = WeatherMessage.Parse("$,ws=1.80,wg=1.15,wd=180.00,r=0.01,bt=14.44,bp=1016.76,tl=597.83,st=9.68,sh=78.95,gf=1,gs=13,glt=42.764725,gln=-71.042038,ga=20.70,gth=22,gtm=20,gts=11,gdy=21,gdm=5,gdd=28,#");
|
||||||
|
|
||||||
|
Assert.AreEqual(MessageType.Data, weatherMessage.Type);
|
||||||
|
|
||||||
|
Assert.AreEqual(WindDirection.South, weatherMessage.WindDirection);
|
||||||
|
Assert.AreEqual(1.80M, weatherMessage.WindSpeed);
|
||||||
|
Assert.AreEqual(42.764725M, weatherMessage.Latitude);
|
||||||
|
Assert.AreEqual(-71.042038M, weatherMessage.Longitude);
|
||||||
|
Assert.AreEqual(1016.76M, weatherMessage.Pressure);
|
||||||
|
Assert.AreEqual(14.44M, weatherMessage.PressureTemperature);
|
||||||
|
Assert.AreEqual(0.01M, weatherMessage.Rain);
|
||||||
|
Assert.AreEqual(9.68M, weatherMessage.HumidityTemperature);
|
||||||
|
Assert.AreEqual(78.95M, weatherMessage.Humidity);
|
||||||
|
Assert.AreEqual(13, weatherMessage.SatelliteCount);
|
||||||
|
Assert.AreEqual(20.70M, weatherMessage.Altitude);
|
||||||
|
Assert.AreEqual(1.80M, weatherMessage.WindSpeed);
|
||||||
|
Assert.AreEqual(597.83M, weatherMessage.LightLevel);
|
||||||
|
Assert.AreEqual(DateTimeOffset.Parse("2021-05-28 22:20:11 +00:00"), weatherMessage.GpsTimestamp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="ChrisKaczor.HomeMonitor.Weather.Models" Version="1.0.1" />
|
<PackageReference Include="ChrisKaczor.HomeMonitor.Weather.Models" Version="1.1.6" />
|
||||||
<PackageReference Include="JetBrains.Annotations" Version="2019.1.3" />
|
<PackageReference Include="JetBrains.Annotations" Version="2019.1.3" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="3.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="3.0.0" />
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
{
|
{
|
||||||
"Weather": {
|
"Weather": {
|
||||||
"Port": {
|
"Port": {
|
||||||
"Prefix": "/dev/ttyUSB",
|
"Prefix": "/dev/ttyACM",
|
||||||
"BaudRate": 9600
|
"BaudRate": 115200
|
||||||
},
|
},
|
||||||
"Queue": {
|
"Queue": {
|
||||||
"Name": "weather"
|
"Name": "weather"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
INSERT INTO Reading (Timestamp, WindDirection, WindSpeed, Humidity, HumidityTemperature, Rain, Pressure,
|
INSERT INTO Reading (Timestamp, WindDirection, WindSpeed, Humidity, HumidityTemperature, Rain, Pressure,
|
||||||
PressureTemperature, BatteryLevel, LightLevel, Latitude, Longitude, Altitude,
|
PressureTemperature, LightLevel, Latitude, Longitude, Altitude,
|
||||||
SatelliteCount, GpsTimestamp)
|
SatelliteCount, GpsTimestamp)
|
||||||
VALUES (@Timestamp, @WindDirection, @WindSpeed, @Humidity, @HumidityTemperature, @Rain, @Pressure, @PressureTemperature,
|
VALUES (@Timestamp, @WindDirection, @WindSpeed, @Humidity, @HumidityTemperature, @Rain, @Pressure, @PressureTemperature,
|
||||||
@BatteryLevel, @LightLevel, @Latitude, @Longitude, @Altitude, @SatelliteCount, @GpsTimestamp)
|
@LightLevel, @Latitude, @Longitude, @Altitude, @SatelliteCount, @GpsTimestamp)
|
||||||
@@ -5,7 +5,6 @@ SELECT Timestamp,
|
|||||||
Rain,
|
Rain,
|
||||||
Pressure,
|
Pressure,
|
||||||
PressureTemperature AS Temperature,
|
PressureTemperature AS Temperature,
|
||||||
BatteryLevel,
|
|
||||||
LightLevel,
|
LightLevel,
|
||||||
Latitude,
|
Latitude,
|
||||||
Longitude,
|
Longitude,
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ SELECT TOP 1 Timestamp,
|
|||||||
Rain,
|
Rain,
|
||||||
Pressure,
|
Pressure,
|
||||||
PressureTemperature AS Temperature,
|
PressureTemperature AS Temperature,
|
||||||
BatteryLevel,
|
|
||||||
LightLevel,
|
LightLevel,
|
||||||
Latitude,
|
Latitude,
|
||||||
Longitude,
|
Longitude,
|
||||||
|
|||||||
@@ -11,7 +11,6 @@
|
|||||||
Rain decimal(2, 2) NOT NULL,
|
Rain decimal(2, 2) NOT NULL,
|
||||||
Pressure decimal(8, 2) NOT NULL,
|
Pressure decimal(8, 2) NOT NULL,
|
||||||
PressureTemperature decimal(4, 1) NOT NULL,
|
PressureTemperature decimal(4, 1) NOT NULL,
|
||||||
BatteryLevel decimal(4, 2) NOT NULL,
|
|
||||||
LightLevel decimal(3, 2) NOT NULL,
|
LightLevel decimal(3, 2) NOT NULL,
|
||||||
Latitude decimal(9, 6) NOT NULL,
|
Latitude decimal(9, 6) NOT NULL,
|
||||||
Longitude decimal(9, 6) NOT NULL,
|
Longitude decimal(9, 6) NOT NULL,
|
||||||
@@ -22,4 +21,7 @@
|
|||||||
|
|
||||||
ALTER TABLE Reading ALTER COLUMN Rain decimal(3, 3);
|
ALTER TABLE Reading ALTER COLUMN Rain decimal(3, 3);
|
||||||
|
|
||||||
ALTER TABLE Reading ALTER COLUMN BatteryLevel decimal(4, 2);
|
IF COL_LENGTH('Reading', 'BatteryLevel') IS NOT NULL
|
||||||
|
ALTER TABLE Reading DROP COLUMN BatteryLevel;
|
||||||
|
|
||||||
|
ALTER TABLE Reading ALTER COLUMN LightLevel decimal(8, 2);
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ namespace ChrisKaczor.HomeMonitor.Weather.Service.Models
|
|||||||
Rain,
|
Rain,
|
||||||
Pressure,
|
Pressure,
|
||||||
PressureTemperature,
|
PressureTemperature,
|
||||||
BatteryLevel,
|
|
||||||
LightLevel,
|
LightLevel,
|
||||||
Altitude,
|
Altitude,
|
||||||
SatelliteCount
|
SatelliteCount
|
||||||
|
|||||||
@@ -34,7 +34,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="ChrisKaczor.HomeMonitor.Weather.Models" Version="1.1.1" />
|
<PackageReference Include="ChrisKaczor.HomeMonitor.Weather.Models" Version="1.1.6" />
|
||||||
<PackageReference Include="Dapper" Version="2.0.30" />
|
<PackageReference Include="Dapper" Version="2.0.30" />
|
||||||
<PackageReference Include="DecimalMath.DecimalEx" Version="1.0.2" />
|
<PackageReference Include="DecimalMath.DecimalEx" Version="1.0.2" />
|
||||||
<PackageReference Include="MathNet.Numerics" Version="4.11.0" />
|
<PackageReference Include="MathNet.Numerics" Version="4.11.0" />
|
||||||
|
|||||||
@@ -7,7 +7,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SerialReader", "SerialReade
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Models", "Models\Models.csproj", "{39E5DE26-CD8D-47AF-AB94-6ACB0AF24EA1}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Models", "Models\Models.csproj", "{39E5DE26-CD8D-47AF-AB94-6ACB0AF24EA1}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Service", "Service\Service.csproj", "{914B9DB9-3BCD-4B55-8289-2E59D6CA96BA}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Service", "Service\Service.csproj", "{914B9DB9-3BCD-4B55-8289-2E59D6CA96BA}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModelsTests", "ModelsTests\ModelsTests.csproj", "{F83A3E8C-3A03-4264-B136-1FBE569A9411}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@@ -27,6 +29,10 @@ Global
|
|||||||
{914B9DB9-3BCD-4B55-8289-2E59D6CA96BA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{914B9DB9-3BCD-4B55-8289-2E59D6CA96BA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{914B9DB9-3BCD-4B55-8289-2E59D6CA96BA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{914B9DB9-3BCD-4B55-8289-2E59D6CA96BA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{914B9DB9-3BCD-4B55-8289-2E59D6CA96BA}.Release|Any CPU.Build.0 = Release|Any CPU
|
{914B9DB9-3BCD-4B55-8289-2E59D6CA96BA}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{F83A3E8C-3A03-4264-B136-1FBE569A9411}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{F83A3E8C-3A03-4264-B136-1FBE569A9411}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{F83A3E8C-3A03-4264-B136-1FBE569A9411}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{F83A3E8C-3A03-4264-B136-1FBE569A9411}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
|
||||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/AutoDetectedNamingRules/=Locals/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /></s:String>
|
|
||||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/AutoDetectedNamingRules/=EnumMember/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /></s:String>
|
|
||||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/AutoDetectedNamingRules/=Property/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /></s:String>
|
|
||||||
<s:Int64 x:Key="/Default/CodeStyle/Naming/CSharpAutoNaming/AutoNamingCompletedVersion/@EntryValue">2</s:Int64></wpf:ResourceDictionary>
|
|
||||||
Reference in New Issue
Block a user