From 071da3672a9b4b439e13be4f2c6763a1ad35b218 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustavo=20Gir=C3=A1ldez?= Date: Tue, 14 Jun 2022 16:25:29 -0300 Subject: [PATCH] Add a threshold of 1% to consider a provider covering the demand (#711) --- client/src/planwise/client/scenarios/views.cljs | 17 ++++++++++++----- src/planwise/component/engine.clj | 4 ++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/client/src/planwise/client/scenarios/views.cljs b/client/src/planwise/client/scenarios/views.cljs index 681f4181..39c7ff6d 100644 --- a/client/src/planwise/client/scenarios/views.cljs +++ b/client/src/planwise/client/scenarios/views.cljs @@ -51,6 +51,12 @@ ;;; Providers layers +;; Minimum percentage of free capacity (over total capacity) for a provider to be considered with excess capacity +(def ^:private excess-threshold 10) + +;; Max percentage of unsatisfied demand (over reachable demand) for a provider to be considered with satisfaction covered +(def ^:private cover-threshold 1) + (defn- get-percentage [total relative] (* (/ relative total) 100)) @@ -64,11 +70,12 @@ (and (not (some? change)) (not matches-filters))) (defn- provider-satisfaction - [{:keys [unsatisfied-demand capacity free-capacity]}] + [{:keys [unsatisfied-demand reachable-demand capacity free-capacity] :as provider}] (cond - (> (get-percentage capacity free-capacity) 10) :excess - (and (>= free-capacity 0) (zero? unsatisfied-demand)) :covered - :else :unsatisfied)) + (> (get-percentage capacity free-capacity) excess-threshold) :excess + (and (>= free-capacity 0) + (< (get-percentage reachable-demand unsatisfied-demand) cover-threshold)) :covered + :else :unsatisfied)) (defn- provider-tooltip [{:keys [demand-unit capacity-unit]} @@ -90,7 +97,7 @@ (and has-change? covered?) [:p.covered - "All demand covered."] + (str "Demand covered (within " cover-threshold "% margin)")] has-change? [:p.unsatisfied diff --git a/src/planwise/component/engine.clj b/src/planwise/component/engine.clj index 8c2013d4..93061537 100644 --- a/src/planwise/component/engine.clj +++ b/src/planwise/component/engine.clj @@ -278,7 +278,7 @@ capacity (:capacity provider) scaled-capacity (* capacity capacity-multiplier) reachable-demand (demand/count-population-under-coverage demand-raster coverage-raster) - new-reachable (demand/count-population-under-coverage base-demand-raster coverage-raster) + base-reachable (demand/count-population-under-coverage base-demand-raster coverage-raster) satisfied-demand (min scaled-capacity reachable-demand) used-capacity (float (/ satisfied-demand capacity-multiplier))] (debug "Applying provider" (:id provider) "with capacity" capacity @@ -290,7 +290,7 @@ :satisfied-demand satisfied-demand :capacity capacity :used-capacity used-capacity - :reachable-demand new-reachable + :reachable-demand base-reachable :free-capacity (- capacity used-capacity)})) (defn raster-add-coverage!