Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a threshold of 1% to consider a provider covering the demand #711

Merged
merged 1 commit into from
Jun 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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