mirror of
https://github.com/ckaczor/HomeMonitor.git
synced 2026-02-17 02:51:39 -05:00
Rework wind history API
This commit is contained in:
@@ -44,16 +44,10 @@ namespace ChrisKaczor.HomeMonitor.Weather.Service.Controllers
|
|||||||
return (await _database.GetReadingHistoryGrouped(start, end, bucketMinutes)).ToList();
|
return (await _database.GetReadingHistoryGrouped(start, end, bucketMinutes)).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("wind-speed-history-grouped")]
|
[HttpGet("wind-history-grouped")]
|
||||||
public async Task<ActionResult<List<WindSpeedReadingGrouped>>> GetWindSpeedHistoryGrouped(DateTimeOffset start, DateTimeOffset end, int bucketMinutes = 2)
|
public async Task<ActionResult<List<WindHistoryGrouped>>> GetWindHistoryGrouped(DateTimeOffset start, DateTimeOffset end, int bucketMinutes = 60)
|
||||||
{
|
{
|
||||||
return (await _database.GetWindSpeedHistoryGrouped(start, end, bucketMinutes)).ToList();
|
return (await _database.GetWindHistoryGrouped(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,22 +118,13 @@ namespace ChrisKaczor.HomeMonitor.Weather.Service.Data
|
|||||||
return await connection.QueryAsync<WeatherReadingGrouped>(query, new { Start = start, End = end, BucketMinutes = bucketMinutes });
|
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)
|
public async Task<IEnumerable<WindHistoryGrouped>> GetWindHistoryGrouped(DateTimeOffset start, DateTimeOffset end, int bucketMinutes)
|
||||||
{
|
{
|
||||||
await using var connection = CreateConnection();
|
await using var connection = CreateConnection();
|
||||||
|
|
||||||
var query = ResourceReader.GetString("ChrisKaczor.HomeMonitor.Weather.Service.Data.Resources.GetWindSpeedHistory.sql");
|
var query = ResourceReader.GetString("ChrisKaczor.HomeMonitor.Weather.Service.Data.Resources.GetWindHistoryGrouped.sql");
|
||||||
|
|
||||||
return await connection.QueryAsync<WindSpeedReadingGrouped>(query, new { Start = start, End = end, BucketMinutes = bucketMinutes });
|
return await connection.QueryAsync<WindHistoryGrouped>(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,5 +0,0 @@
|
|||||||
SELECT WindDirection, COUNT(WindDirection) AS Count
|
|
||||||
FROM Reading
|
|
||||||
WHERE Timestamp BETWEEN @Start AND @End
|
|
||||||
AND WindDirection != -1
|
|
||||||
GROUP BY WindDirection
|
|
||||||
@@ -1,12 +1,14 @@
|
|||||||
SELECT Bucket,
|
SELECT Bucket,
|
||||||
MIN(WindSpeed) AS Minimum,
|
MIN(WindSpeed) AS MinimumSpeed,
|
||||||
AVG(WindSpeed) AS Average,
|
AVG(WindSpeed) AS AverageSpeed,
|
||||||
MAX(WindSpeed) AS Maximum
|
MAX(WindSpeed) AS MaximumSpeed,
|
||||||
|
AVG(WindDirection) AS AverageDirection
|
||||||
FROM (
|
FROM (
|
||||||
SELECT CAST(FORMAT(Timestamp, 'yyyy-MM-ddTHH:') +
|
SELECT CAST(FORMAT(Timestamp, 'yyyy-MM-ddTHH:') +
|
||||||
RIGHT('00' + CAST(DATEPART(MINUTE, Timestamp) / @BucketMinutes * @BucketMinutes AS VARCHAR), 2)
|
RIGHT('00' + CAST(DATEPART(MINUTE, Timestamp) / @BucketMinutes * @BucketMinutes AS VARCHAR), 2)
|
||||||
+ ':00+00:00' AS DATETIMEOFFSET) AS Bucket,
|
+ ':00+00:00' AS DATETIMEOFFSET) AS Bucket,
|
||||||
WindSpeed
|
WindSpeed,
|
||||||
|
WindDirection
|
||||||
FROM Reading
|
FROM Reading
|
||||||
WHERE Timestamp BETWEEN @Start AND @End
|
WHERE Timestamp BETWEEN @Start AND @End
|
||||||
) AS Data
|
) AS Data
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
using JetBrains.Annotations;
|
|
||||||
|
|
||||||
namespace ChrisKaczor.HomeMonitor.Weather.Service.Models
|
|
||||||
{
|
|
||||||
[PublicAPI]
|
|
||||||
public class WindDirectionReadingGrouped
|
|
||||||
{
|
|
||||||
public int WindDirection { get; set; }
|
|
||||||
|
|
||||||
public int Count { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
19
Weather/Service/Models/WindHistoryGrouped.cs
Normal file
19
Weather/Service/Models/WindHistoryGrouped.cs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
using JetBrains.Annotations;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace ChrisKaczor.HomeMonitor.Weather.Service.Models
|
||||||
|
{
|
||||||
|
[PublicAPI]
|
||||||
|
public class WindHistoryGrouped
|
||||||
|
{
|
||||||
|
public DateTimeOffset Bucket { get; set; }
|
||||||
|
|
||||||
|
public decimal MinimumSpeed { get; set; }
|
||||||
|
|
||||||
|
public decimal AverageSpeed { get; set; }
|
||||||
|
|
||||||
|
public decimal MaximumSpeed { get; set; }
|
||||||
|
|
||||||
|
public decimal AverageDirection { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
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; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -14,9 +14,8 @@
|
|||||||
<None Remove="Data\Resources\GetReadingHistoryGrouped.sql" />
|
<None Remove="Data\Resources\GetReadingHistoryGrouped.sql" />
|
||||||
<None Remove="Data\Resources\GetReadingValueHistory.sql" />
|
<None Remove="Data\Resources\GetReadingValueHistory.sql" />
|
||||||
<None Remove="Data\Resources\GetRecentReading.sql" />
|
<None Remove="Data\Resources\GetRecentReading.sql" />
|
||||||
|
<None Remove="Data\Resources\GetWindHistoryGrouped.sql" />
|
||||||
<None Remove="Data\Resources\Schema.sql" />
|
<None Remove="Data\Resources\Schema.sql" />
|
||||||
<None Remove="Data\Resources\GetWindDirectionHistory.sql" />
|
|
||||||
<None Remove="Data\Resources\GetWindSpeedHistory.sql" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -26,8 +25,7 @@
|
|||||||
<EmbeddedResource Include="Data\Resources\GetRecentReading.sql" />
|
<EmbeddedResource Include="Data\Resources\GetRecentReading.sql" />
|
||||||
<EmbeddedResource Include="Data\Resources\CreateReading.sql" />
|
<EmbeddedResource Include="Data\Resources\CreateReading.sql" />
|
||||||
<EmbeddedResource Include="Data\Resources\Schema.sql" />
|
<EmbeddedResource Include="Data\Resources\Schema.sql" />
|
||||||
<EmbeddedResource Include="Data\Resources\GetWindDirectionHistory.sql" />
|
<EmbeddedResource Include="Data\Resources\GetWindHistoryGrouped.sql" />
|
||||||
<EmbeddedResource Include="Data\Resources\GetWindSpeedHistory.sql" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
Reference in New Issue
Block a user