Add elprice table + JSON API (GET /api/elprice?date=...)

New `elprice` table with a simpler shape (time_dk, price_area,
price_dkk) backing a JSON endpoint that returns hourly DK1 + DK2
prices for any date. Cache-miss path fetches from the same
DayAheadPrices dataset as day_ahead_prices, upserts, and returns.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-19 12:36:01 +02:00
co-authored by Claude Opus 4.7
parent ce1c3822a2
commit 06b575d709
5 changed files with 142 additions and 3 deletions
@@ -0,0 +1 @@
DROP TABLE elprice;
@@ -0,0 +1,6 @@
CREATE TABLE elprice (
time_dk TIMESTAMP NOT NULL,
price_area VARCHAR(3) NOT NULL,
price_dkk NUMERIC(10,2) NOT NULL,
PRIMARY KEY (time_dk, price_area)
);
+13
View File
@@ -65,3 +65,16 @@ ON CONFLICT (time_start, hour) DO NOTHING;
INSERT INTO consumption (time_start, hour, kwh)
VALUES (:time-start, :hour, :kwh)
ON CONFLICT (time_start, hour) DO NOTHING;
-- :name insert-elprice! :! :n
-- :doc Insert an hourly el-price row; keep first value on conflict
INSERT INTO elprice (time_dk, price_area, price_dkk)
VALUES (:time-dk, :price-area, :price-dkk)
ON CONFLICT (time_dk, price_area) DO NOTHING;
-- :name get-elprice-for-date :? :*
-- :doc Hourly prices for a DK local date, both areas
SELECT time_dk, price_area, price_dkk
FROM elprice
WHERE time_dk::date = :date
ORDER BY time_dk, price_area;