Add power database support

This commit is contained in:
2019-10-15 19:41:52 -04:00
parent 5bc8018068
commit d970f80278
12 changed files with 209 additions and 14 deletions

View File

@@ -0,0 +1,2 @@
INSERT INTO Status (Timestamp, Generation, Consumption)
VALUES (@Timestamp, @Generation, @Consumption)

View 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

View 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
);