mirror of
https://github.com/ckaczor/HomeMonitor.git
synced 2026-01-13 17:22:54 -05:00
Add wind history support
This commit is contained in:
@@ -43,5 +43,17 @@ namespace ChrisKaczor.HomeMonitor.Weather.Service.Controllers
|
||||
{
|
||||
return (await _database.GetReadingHistoryGrouped(start, end, bucketMinutes)).ToList();
|
||||
}
|
||||
|
||||
[HttpGet("wind-speed-history-grouped")]
|
||||
public async Task<ActionResult<List<WindSpeedReadingGrouped>>> GetWindSpeedHistoryGrouped(DateTimeOffset start, DateTimeOffset end, int bucketMinutes = 2)
|
||||
{
|
||||
return (await _database.GetWindSpeedHistoryGrouped(start, end, bucketMinutes)).ToList();
|
||||
}
|
||||
|
||||
[HttpGet("wind-direction-history-grouped")]
|
||||
public async Task<ActionResult<List<WindDirectionReadingGrouped>>> GetWindDirectionHistoryGrouped(DateTimeOffset start, DateTimeOffset end)
|
||||
{
|
||||
return (await _database.GetWindDirectionHistoryGrouped(start, end)).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -118,5 +118,22 @@ namespace ChrisKaczor.HomeMonitor.Weather.Service.Data
|
||||
return await connection.QueryAsync<WeatherReadingGrouped>(query, new { Start = start, End = end, BucketMinutes = bucketMinutes });
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<WindSpeedReadingGrouped>> GetWindSpeedHistoryGrouped(DateTimeOffset start, DateTimeOffset end, int bucketMinutes)
|
||||
{
|
||||
await using var connection = CreateConnection();
|
||||
|
||||
var query = ResourceReader.GetString("ChrisKaczor.HomeMonitor.Weather.Service.Data.Resources.GetWindSpeedHistory.sql");
|
||||
|
||||
return await connection.QueryAsync<WindSpeedReadingGrouped>(query, new { Start = start, End = end, BucketMinutes = bucketMinutes });
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<WindDirectionReadingGrouped>> GetWindDirectionHistoryGrouped(DateTimeOffset start, DateTimeOffset end)
|
||||
{
|
||||
await using var connection = CreateConnection();
|
||||
|
||||
var query = ResourceReader.GetString("ChrisKaczor.HomeMonitor.Weather.Service.Data.Resources.GetWindDirectionHistory.sql");
|
||||
|
||||
return await connection.QueryAsync<WindDirectionReadingGrouped>(query, new { Start = start, End = end });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
SELECT bucket,
|
||||
SELECT Bucket,
|
||||
AVG(HumidityTemperature) AS AverageHumidityTemperature,
|
||||
AVG(Humidity) AS AverageHumidity,
|
||||
AVG(PressureTemperature) AS AveragePressureTemperature,
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
SELECT WindDirection, COUNT(WindDirection) AS Count
|
||||
FROM Reading
|
||||
WHERE Timestamp BETWEEN @Start AND @End
|
||||
AND WindDirection != -1
|
||||
GROUP BY WindDirection
|
||||
14
Weather/Service/Data/Resources/GetWindSpeedHistory.sql
Normal file
14
Weather/Service/Data/Resources/GetWindSpeedHistory.sql
Normal file
@@ -0,0 +1,14 @@
|
||||
SELECT Bucket,
|
||||
MIN(WindSpeed) AS Minimum,
|
||||
AVG(WindSpeed) AS Average,
|
||||
MAX(WindSpeed) AS Maximum
|
||||
FROM (
|
||||
SELECT CAST(FORMAT(Timestamp, 'yyyy-MM-ddTHH:') +
|
||||
RIGHT('00' + CAST(DATEPART(MINUTE, Timestamp) / @BucketMinutes * @BucketMinutes AS VARCHAR), 2)
|
||||
+ ':00+00:00' AS DATETIMEOFFSET) AS Bucket,
|
||||
WindSpeed
|
||||
FROM Reading
|
||||
WHERE Timestamp BETWEEN @Start AND @End
|
||||
) AS Data
|
||||
GROUP BY Bucket
|
||||
ORDER BY Bucket
|
||||
12
Weather/Service/Models/WindDirectionReadingGrouped.cs
Normal file
12
Weather/Service/Models/WindDirectionReadingGrouped.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace ChrisKaczor.HomeMonitor.Weather.Service.Models
|
||||
{
|
||||
[PublicAPI]
|
||||
public class WindDirectionReadingGrouped
|
||||
{
|
||||
public int WindDirection { get; set; }
|
||||
|
||||
public int Count { get; set; }
|
||||
}
|
||||
}
|
||||
17
Weather/Service/Models/WindSpeedReadingGrouped.cs
Normal file
17
Weather/Service/Models/WindSpeedReadingGrouped.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using JetBrains.Annotations;
|
||||
using System;
|
||||
|
||||
namespace ChrisKaczor.HomeMonitor.Weather.Service.Models
|
||||
{
|
||||
[PublicAPI]
|
||||
public class WindSpeedReadingGrouped
|
||||
{
|
||||
public DateTimeOffset Bucket { get; set; }
|
||||
|
||||
public decimal Minimum { get; set; }
|
||||
|
||||
public decimal Average { get; set; }
|
||||
|
||||
public decimal Maximum { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,8 @@
|
||||
<None Remove="Data\Resources\GetReadingValueHistory.sql" />
|
||||
<None Remove="Data\Resources\GetRecentReading.sql" />
|
||||
<None Remove="Data\Resources\Schema.sql" />
|
||||
<None Remove="Data\Resources\GetWindDirectionHistory.sql" />
|
||||
<None Remove="Data\Resources\GetWindSpeedHistory.sql" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -24,6 +26,8 @@
|
||||
<EmbeddedResource Include="Data\Resources\GetRecentReading.sql" />
|
||||
<EmbeddedResource Include="Data\Resources\CreateReading.sql" />
|
||||
<EmbeddedResource Include="Data\Resources\Schema.sql" />
|
||||
<EmbeddedResource Include="Data\Resources\GetWindDirectionHistory.sql" />
|
||||
<EmbeddedResource Include="Data\Resources\GetWindSpeedHistory.sql" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user