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

Feature/615 demand unit #623

Merged
merged 2 commits into from
Apr 9, 2021
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
16 changes: 9 additions & 7 deletions client/src/planwise/client/projects2/components/settings.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,13 @@
:on-change #(dispatch [:projects2/save-key :source-set-id %])
:disabled? read-only}]
[current-project-input "Consumers Unit" [:config :demographics :unit-name] "text" {:disabled read-only}]
[m/TextFieldHelperText {:persistent true} (str "How do you refer to the filtered population? (Eg: women)")]
[m/TextFieldHelperText {:persistent true} (str "How do you refer to the filtered consumers source?")]
[current-project-input "Demand Unit" [:config :demographics :demand-unit] "text" {:disabled read-only}]
[m/TextFieldHelperText {:persistent true} (str "How do you refer to the unit of your demand?")]
[:div.percentage-input
[current-project-input "Target" [:config :demographics :target] "number" "" "%" {:disabled read-only :sub-type :percentage}]
[:p (str "of " (or (not-empty (get-in @current-project [:config :demographics :unit-name])) "population") " should be considered")]]]))
[:p (str "of " (or (not-empty (get-in @current-project [:config :demographics :unit-name])) "total population") " should be counted as "
(or (not-empty (get-in @current-project [:config :demographics :demand-unit])) "target"))]]]))

(defn- current-project-step-providers
[read-only]
Expand All @@ -207,7 +210,7 @@
:disabled? read-only}]

[current-project-input "Capacity Workload" [:config :providers :capacity] "number" {:disabled read-only :sub-type :float}]
[m/TextFieldHelperText {:persistent true} (str "How many " (or (not-empty (get-in @current-project [:config :demographics :unit-name])) "consumers") " can each provider handle?")]
[m/TextFieldHelperText {:persistent true} (str "How many " (or (not-empty (get-in @current-project [:config :demographics :demand-unit])) "targets") " can each provider handle?")]
(when-not read-only [tag-input])
[:label "Tags: " [tag-set @tags read-only]]
[count-providers @tags @current-project]]))
Expand Down Expand Up @@ -279,8 +282,8 @@
analysis-type (get-in @current-project [:config :analysis-type])
budget (get-in @current-project [:config :actions :budget])
workload (get-in @current-project [:config :providers :capacity])
consumers-unit (get-in @current-project [:config :demographics :unit-name])
capacities (get-in @current-project [:config :actions :build])]
demand-unit (get-in @current-project [:config :demographics :demand-unit])
capacities (get-in @current-project [:config :actions :build])]
(dispatch [:sources/load])
(dispatch [:providers-set/load-providers-set])
[:section {:class "project-settings-section"}
Expand All @@ -307,8 +310,7 @@
(:capacity action)
"will provide service for"
(* (:capacity action) workload)
(or (not-empty consumers-unit) "consumers units")
" per year"])]) capacities)]))
(or (not-empty demand-unit) "targets")])]) capacities)]))


(def map-preview-size {:width 373 :height 278})
Expand Down
32 changes: 16 additions & 16 deletions client/src/planwise/client/scenarios/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
button))

(defn- show-provider
[read-only? unit-name {:keys [change matches-filters name capacity free-capacity required-capacity satisfied-demand unsatisfied-demand reachable-demand] :as provider}]
[read-only? demand-unit {:keys [change matches-filters name capacity free-capacity required-capacity satisfied-demand unsatisfied-demand reachable-demand] :as provider}]
(let [format-number (fnil utils/format-number 0)
change* (if (some? change)
change
Expand All @@ -63,7 +63,7 @@
[:p (str "Satisfied demand: " (utils/format-number satisfied-demand))])
(when (or matches-filters change)
[:p (str "Free capacity: " (utils/format-number (Math/floor free-capacity)))])
[:p (str unit-name " under geographic coverage: " (utils/format-number (Math/ceil reachable-demand)))]
[:p (str demand-unit " under geographic coverage: " (utils/format-number (Math/ceil reachable-demand)))]
(when-not read-only?
(popup-connected-button
(cond
Expand Down Expand Up @@ -156,7 +156,7 @@
add-point (fn [lat lon] (dispatch [:scenarios/create-provider {:lat lat :lon lon}]))
use-providers-clustering false
providers-layer-type (if use-providers-clustering :cluster-layer :marker-layer)
unit-name (get-in project [:config :demographics :unit-name])]
demand-unit (get-in project [:config :demographics :demand-unit])]
(fn [{:keys [bbox]} {:keys [changeset raster sources-data] :as scenario} state error]
(let [indexed-providers (to-indexed-map @all-providers)
indexed-sources (to-indexed-map sources-data)
Expand Down Expand Up @@ -198,7 +198,7 @@
:lat-fn #(get-in % [:location :lat])
:lon-fn #(get-in % [:location :lon])
:icon-fn #(icon-function % @selected-provider)
:popup-fn #(show-provider read-only? unit-name %)
:popup-fn #(show-provider read-only? demand-unit %)
:mouseover-fn (fn [provider]
(dispatch [:scenarios.map/select-provider provider]))
:mouseout-fn (fn [provider]
Expand Down Expand Up @@ -239,22 +239,22 @@
(defn initial-scenario-panel
[_ _]
(let [source-demand (subscribe [:scenarios.current/source-demand])]
(fn [{:keys [name demand-coverage state]} unit-name]
(fn [{:keys [name demand-coverage state]} demand-unit]
[:div
[:div {:class-name "section"}
[:h1 {:class-name "title-icon"} name]]
[:hr]
[:div {:class-name "section"}
[:h1 {:class-name "large"}
[:small (str "Initial " unit-name " coverage")]
[:small (str "Initial " demand-unit " coverage")]
(cond
(= "pending" state) "loading..."
:else (str (utils/format-number demand-coverage) " (" (format-percentage demand-coverage @source-demand) ")"))]
[:p {:class-name "grey-text"}
(str "of a total of " (utils/format-number @source-demand))]]])))

(defn scenario-info
[view-state current-scenario unit-name analysis-type]
[view-state current-scenario demand-unit analysis-type]
(let [{:keys [name label effort demand-coverage source-demand population-under-coverage increase-coverage state]} current-scenario]
[:div
[:div {:class-name "section"}
Expand All @@ -263,7 +263,7 @@
[:hr]
[:div {:class-name "section"}
[:h1 {:class-name "large"}
[:small (str "Increase in " unit-name " coverage")]
[:small (str "Increase in " demand-unit " coverage")]
(cond
(= "pending" state) "loading..."
:else (str (utils/format-number increase-coverage) " (" (format-percentage increase-coverage source-demand) ")"))]
Expand All @@ -273,7 +273,7 @@
:else (str "to a total of " (utils/format-number demand-coverage) " (" (format-percentage demand-coverage source-demand) ")"))]]
[:div {:class-name "section"}
[:h1 {:class-name "large"}
[:small (str "Total " unit-name " under geographic coverage")]
[:small (str "Total " demand-unit " under geographic coverage")]
(cond
(= "pending" state) "loading..."
:else (utils/format-number population-under-coverage))]]
Expand Down Expand Up @@ -303,7 +303,7 @@
providers-from-changeset (subscribe [:scenarios/providers-from-changeset])
current-project (subscribe [:projects2/current-project])
analysis-type (get-in @current-project [:config :analysis-type])]
(fn [{:keys [state] :as current-scenario} unit-name error]
(fn [{:keys [state] :as current-scenario} demand-unit error]
(let [computing-suggestions? (or @computing-best-locations? @computing-best-improvements?)
edit-button [edit/create-new-action-component @view-state computing-suggestions?]]
(if @suggested-locations
Expand All @@ -313,7 +313,7 @@
[suggested-locations-list @suggested-locations state]]
[:<>
[:div
[scenario-info @view-state current-scenario unit-name analysis-type]
[scenario-info @view-state current-scenario demand-unit analysis-type]
[edit/create-new-action-component @view-state computing-suggestions?]
(if computing-suggestions?
[:div {:class-name "info-computing-best-location"}
Expand All @@ -328,19 +328,19 @@
[:div {:class-name "fade inverted"}]])])))))

(defn side-panel-view
[current-scenario unit-name error read-only?]
[current-scenario demand-unit error read-only?]
[:<>
(if read-only?
[initial-scenario-panel current-scenario unit-name]
[side-panel-view-2 current-scenario unit-name error])
[initial-scenario-panel current-scenario demand-unit]
[side-panel-view-2 current-scenario demand-unit error])
[create-new-scenario current-scenario]])

(defn display-current-scenario
[current-project {:keys [id] :as current-scenario}]
(let [read-only? (subscribe [:scenarios/read-only?])
state (subscribe [:scenarios/view-state])
error (subscribe [:scenarios/error])
unit-name (get-in current-project [:config :demographics :unit-name])
demand-unit (get-in current-project [:config :demographics :demand-unit])
export-providers-button [:a {:class "mdc-fab disable-a"
:id "main-action"
:href (str "/api/scenarios/" id "/csv")}
Expand All @@ -354,7 +354,7 @@
[:li [m/Icon {:strategy "ligature" :use "keyboard_arrow_right"}]]
[:li (:name current-scenario)]]
:action export-providers-button})
[side-panel-view current-scenario unit-name @error @read-only?]
[side-panel-view current-scenario demand-unit @error @read-only?]
[edit/rename-scenario-dialog]
[edit/changeset-dialog current-project current-scenario]
[edit/delete-scenario-dialog @state current-scenario]])))
Expand Down
3 changes: 2 additions & 1 deletion common/src/planwise/model/project.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
(s/def ::source-set-id number?)
(s/def ::target number?)
(s/def ::unit-name string?)
(s/def ::demographics (s/keys :req-un [::unit-name ::target]))
(s/def ::demand-unit string?)
(s/def ::demographics (s/keys :req-un [::unit-name ::target ::demand-unit]))

;; Providers
(s/def ::provider-set-id (s/nilable number?))
Expand Down
3 changes: 2 additions & 1 deletion src/planwise/configuration/templates.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
:defaults {:name "Improve the coverage of meningitis rapid test"
:config {:coverage {:filter-options {:driving-time 90}} ;How to define Region?
:demographics {:target 12
:unit-name "suspected cases of meningitis"}
:unit-name "children under 15 years old"
:demand-unit "suspected cases of meningitis"}
:actions {:budget 500000
:build [{:id "build-0"
:capacity 100
Expand Down