mirror of
https://github.com/ckaczor/HomeMonitor.git
synced 2026-02-16 10:58:32 -05:00
Add power database support
This commit is contained in:
2
Power/Service/Data/Resources/CreateStatus.sql
Normal file
2
Power/Service/Data/Resources/CreateStatus.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
INSERT INTO Status (Timestamp, Generation, Consumption)
|
||||
VALUES (@Timestamp, @Generation, @Consumption)
|
||||
14
Power/Service/Data/Resources/GetStatusHistoryGrouped.sql
Normal file
14
Power/Service/Data/Resources/GetStatusHistoryGrouped.sql
Normal file
@@ -0,0 +1,14 @@
|
||||
SELECT Bucket,
|
||||
AVG(Generation) AS AverageGeneration,
|
||||
AVG(Consumption) AS AverageConsumption
|
||||
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,
|
||||
Generation,
|
||||
Consumption
|
||||
FROM Status
|
||||
WHERE Timestamp BETWEEN @Start AND @End
|
||||
) AS Data
|
||||
GROUP BY Bucket
|
||||
ORDER BY Bucket
|
||||
9
Power/Service/Data/Resources/Schema.sql
Normal file
9
Power/Service/Data/Resources/Schema.sql
Normal file
@@ -0,0 +1,9 @@
|
||||
IF NOT EXISTS(SELECT 1 FROM sys.tables WHERE name = 'Status')
|
||||
CREATE TABLE Status
|
||||
(
|
||||
Timestamp datetimeoffset NOT NULL
|
||||
CONSTRAINT status_pk
|
||||
PRIMARY KEY,
|
||||
Generation int NOT NULL,
|
||||
Consumption int NOT NULL
|
||||
);
|
||||
Reference in New Issue
Block a user