diff --git a/src/clj/pmagnus/elprice/web/routes/ui.clj b/src/clj/pmagnus/elprice/web/routes/ui.clj index a872d2e..94aee3b 100644 --- a/src/clj/pmagnus/elprice/web/routes/ui.clj +++ b/src/clj/pmagnus/elprice/web/routes/ui.clj @@ -5,6 +5,7 @@ [pmagnus.elprice.web.routes.utils :as utils] [pmagnus.elprice.web.htmx :refer [page fragment]] [pmagnus.elprice.web.controllers.prices :as prices] + [pmagnus.elprice.web.controllers.tariffs :as tariffs] [integrant.core :as ig] [reitit.ring.middleware.muuntaja :as muuntaja] [reitit.ring.middleware.parameters :as parameters]) @@ -32,10 +33,16 @@ (when price-dkk (/ (double price-dkk) 10.0))) -(defn- format-ore [price-dkk] - (if-let [ore (dkk-mwh->ore-kwh price-dkk)] - (format "%.1f" ore) - "-")) +(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)] + (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] (->> prices @@ -49,18 +56,20 @@ (defn- hour-block [hour 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"} [:summary {:class "flex justify-between py-2 px-3 cursor-pointer hover:bg-gray-50 font-medium text-gray-900"} [:span (format "%02d:00" hour)] [: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"} (for [q sorted] [:div {:class "flex justify-between py-1 ml-4 text-gray-500"} [: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] [:div @@ -114,7 +123,7 @@ :hx-swap "innerHTML"} "Electricity Prices"] [: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"} (price-content :today (prices/get-today-prices query-fn) (has-tomorrow? query-fn))]))