Skip to content

Commit

Permalink
Add a threshold of 1% to consider a provider covering the demand (#711)
Browse files Browse the repository at this point in the history
  • Loading branch information
ggiraldez authored Jun 14, 2022
1 parent 969cb79 commit 071da36
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
17 changes: 12 additions & 5 deletions client/src/planwise/client/scenarios/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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]}
Expand All @@ -90,7 +97,7 @@

(and has-change? covered?)
[:p.covered
"All demand covered."]
(str "Demand covered (within " cover-threshold "% margin)")]

has-change?
[:p.unsatisfied
Expand Down
4 changes: 2 additions & 2 deletions src/planwise/component/engine.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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!
Expand Down

0 comments on commit 071da36

Please sign in to comment.