Fetch and display day-ahead electricity spot prices from Energi Data Service
Adds a prices controller that fetches DK1/DK2 hourly spot prices via the Energi Data Service API, stores them in PostgreSQL, and displays today's and tomorrow's DK1 prices on the home page in øre/kWh. An HTMX "Refresh Prices" button triggers the fetch-and-display cycle. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS day_ahead_prices;
|
||||
@@ -0,0 +1,8 @@
|
||||
CREATE TABLE day_ahead_prices (
|
||||
time_utc TIMESTAMPTZ NOT NULL,
|
||||
time_dk TIMESTAMP NOT NULL,
|
||||
price_area VARCHAR(3) NOT NULL,
|
||||
price_dkk NUMERIC(10,2),
|
||||
price_eur NUMERIC(10,6),
|
||||
PRIMARY KEY (time_utc, price_area)
|
||||
);
|
||||
+16
-2
@@ -1,2 +1,16 @@
|
||||
-- place your sql queries here
|
||||
-- see https://www.hugsql.org/ for documentation
|
||||
-- :name upsert-price! :! :n
|
||||
-- :doc Upsert a day-ahead price record
|
||||
INSERT INTO day_ahead_prices (time_utc, time_dk, price_area, price_dkk, price_eur)
|
||||
VALUES (:time-utc, :time-dk, :price-area, :price-dkk, :price-eur)
|
||||
ON CONFLICT (time_utc, price_area) DO UPDATE
|
||||
SET time_dk = EXCLUDED.time_dk,
|
||||
price_dkk = EXCLUDED.price_dkk,
|
||||
price_eur = EXCLUDED.price_eur;
|
||||
|
||||
-- :name get-prices-for-date :? :*
|
||||
-- :doc Get all prices for a given date (time_dk local date) and price area
|
||||
SELECT time_utc, time_dk, price_area, price_dkk, price_eur
|
||||
FROM day_ahead_prices
|
||||
WHERE time_dk::date = :date
|
||||
AND price_area = :price-area
|
||||
ORDER BY time_dk;
|
||||
|
||||
@@ -66,4 +66,5 @@
|
||||
:db {:datasource #ig/ref :db.sql/connection}
|
||||
:migrate-on-init? true}
|
||||
:reitit.routes/ui {:base-path "",
|
||||
:env #ig/ref :system/env}}
|
||||
:env #ig/ref :system/env
|
||||
:query-fn #ig/ref :db.sql/query-fn}}
|
||||
|
||||
Reference in New Issue
Block a user