mirror of
https://github.com/ckaczor/HomeMonitor.git
synced 2026-03-12 12:01:40 -04:00
Rework wind history API
This commit is contained in:
@@ -118,22 +118,13 @@ 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)
|
||||
public async Task<IEnumerable<WindHistoryGrouped>> GetWindHistoryGrouped(DateTimeOffset start, DateTimeOffset end, int bucketMinutes)
|
||||
{
|
||||
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 });
|
||||
}
|
||||
|
||||
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 });
|
||||
return await connection.QueryAsync<WindHistoryGrouped>(query, new { Start = start, End = end, BucketMinutes = bucketMinutes });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
MIN(WindSpeed) AS Minimum,
|
||||
AVG(WindSpeed) AS Average,
|
||||
MAX(WindSpeed) AS Maximum
|
||||
MIN(WindSpeed) AS MinimumSpeed,
|
||||
AVG(WindSpeed) AS AverageSpeed,
|
||||
MAX(WindSpeed) AS MaximumSpeed,
|
||||
AVG(WindDirection) AS AverageDirection
|
||||
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
|
||||
WindSpeed,
|
||||
WindDirection
|
||||
FROM Reading
|
||||
WHERE Timestamp BETWEEN @Start AND @End
|
||||
) AS Data
|
||||
Reference in New Issue
Block a user