Display prices as total(spot) including N1 network tariff

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-14 14:26:07 +01:00
co-authored by Claude Opus 4.6
parent d4fd3a7512
commit 2000154c8a
+14 -5
View File
@@ -5,6 +5,7 @@
[pmagnus.elprice.web.routes.utils :as utils] [pmagnus.elprice.web.routes.utils :as utils]
[pmagnus.elprice.web.htmx :refer [page fragment]] [pmagnus.elprice.web.htmx :refer [page fragment]]
[pmagnus.elprice.web.controllers.prices :as prices] [pmagnus.elprice.web.controllers.prices :as prices]
[pmagnus.elprice.web.controllers.tariffs :as tariffs]
[integrant.core :as ig] [integrant.core :as ig]
[reitit.ring.middleware.muuntaja :as muuntaja] [reitit.ring.middleware.muuntaja :as muuntaja]
[reitit.ring.middleware.parameters :as parameters]) [reitit.ring.middleware.parameters :as parameters])
@@ -32,10 +33,16 @@
(when price-dkk (when price-dkk
(/ (double price-dkk) 10.0))) (/ (double price-dkk) 10.0)))
(defn- format-ore [price-dkk] (defn- format-ore
"Format price as total(net) where total = net + tariff, or just net if no tariff."
([price-dkk]
(if-let [ore (dkk-mwh->ore-kwh price-dkk)] (if-let [ore (dkk-mwh->ore-kwh price-dkk)]
(format "%.1f" ore) (format "%.1f" ore)
"-")) "-"))
([price-dkk tariff]
(if-let [ore (dkk-mwh->ore-kwh price-dkk)]
(format "%.1f(%.1f)" (+ ore tariff) ore)
"-")))
(defn- group-by-hour [prices] (defn- group-by-hour [prices]
(->> prices (->> prices
@@ -49,18 +56,20 @@
(defn- hour-block [hour quarters] (defn- hour-block [hour quarters]
(let [sorted (sort-by #(.getMinute (->ldt (:time_dk %))) quarters) (let [sorted (sort-by #(.getMinute (->ldt (:time_dk %))) quarters)
avg (avg-ore quarters)] avg (avg-ore quarters)
month (.getMonthValue (->ldt (:time_dk (first quarters))))
tariff (tariffs/tariff-for-hour month hour)]
[:details {:class "border-2 border-blue-400 rounded-lg mb-2"} [:details {:class "border-2 border-blue-400 rounded-lg mb-2"}
[:summary {:class "flex justify-between py-2 px-3 cursor-pointer hover:bg-gray-50 [:summary {:class "flex justify-between py-2 px-3 cursor-pointer hover:bg-gray-50
font-medium text-gray-900"} font-medium text-gray-900"}
[:span (format "%02d:00" hour)] [:span (format "%02d:00" hour)]
[:span {:class "font-mono"} [:span {:class "font-mono"}
(if avg (format "%.1f" avg) "-")]] (if avg (format "%.1f(%.1f)" (+ avg tariff) avg) "-")]]
[:div {:class "border-t-2 border-blue-400 px-3 pb-2"} [:div {:class "border-t-2 border-blue-400 px-3 pb-2"}
(for [q sorted] (for [q sorted]
[:div {:class "flex justify-between py-1 ml-4 text-gray-500"} [:div {:class "flex justify-between py-1 ml-4 text-gray-500"}
[:span (format "%02d:%02d" hour (.getMinute (->ldt (:time_dk q))))] [:span (format "%02d:%02d" hour (.getMinute (->ldt (:time_dk q))))]
[:span {:class "font-mono"} (format-ore (:price_dkk q))]])]])) [:span {:class "font-mono"} (format-ore (:price_dkk q) tariff)]])]]))
(defn- price-table [prices] (defn- price-table [prices]
[:div [:div
@@ -114,7 +123,7 @@
:hx-swap "innerHTML"} :hx-swap "innerHTML"}
"Electricity Prices"] "Electricity Prices"]
[:p {:class "mt-1 text-sm text-gray-500"} [:p {:class "mt-1 text-sm text-gray-500"}
"Day-ahead spot prices for DK1 (øre/kWh)"] "Day-ahead prices for DK1 — total(spot) in øre/kWh incl. N1 tariff"]
[:div {:id "price-panel"} [:div {:id "price-panel"}
(price-content :today (prices/get-today-prices query-fn) (has-tomorrow? query-fn))])) (price-content :today (prices/get-today-prices query-fn) (has-tomorrow? query-fn))]))