mirror of
https://github.com/ckaczor/HomeMonitor.git
synced 2026-02-03 09:35:41 -05:00
Add wind history support
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user