Skip to content
Open
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
111 changes: 59 additions & 52 deletions projects/behave/src/cljs/behave/worksheet/events.cljs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
(ns behave.worksheet.events
(:require [re-frame.core :as rf]
[re-posh.core :as rp]
[datascript.core :as d]
[behave.components.toolbar :refer [step-priority]]
(:require [behave.components.toolbar :refer [step-priority]]
[behave.importer :refer [import-worksheet]]
[behave.logger :refer [log]]
[behave.solver.core :refer [solve-worksheet]]
[vimsical.re-frame.cofx.inject :as inject]
[number-utils.core :refer [to-precision]]
[behave.wizard.subs :refer [all-conditionals-pass?]]
[clojure.string :as str]))
[clojure.string :as str]
[datascript.core :as d]
[number-utils.core :refer [to-precision]]
[re-frame.core :as rf]
[re-posh.core :as rp]
[vimsical.re-frame.cofx.inject :as inject]))

;;; Helpers

Expand Down Expand Up @@ -92,7 +92,7 @@
(rp/reg-event-fx
:worksheet/new
(fn [_ [_ {:keys [uuid name modules version]}]]
(let [tx (cond-> {:worksheet/uuid (or uuid (str (d/squuid)))
(let [tx (cond-> {:worksheet/uuid (or uuid (str (d/squuid)))
:worksheet/modules modules
:worksheet/created (.now js/Date)}
version
Expand Down Expand Up @@ -591,16 +591,23 @@

(rp/reg-event-fx
:worksheet/update-graph-settings-attr
[(rp/inject-cofx :ds)]
(fn [{:keys [ds]} [_ ws-uuid attr value]]
[(rp/inject-cofx :ds)
(rf/inject-cofx ::inject/sub (fn [[_ ws-uuid attr]] [:worksheet/graph-settings-axis-group-variable-uuid ws-uuid attr]))
(rf/inject-cofx ::inject/sub (fn [[_ ws-uuid _ value]] [:worksheet/graph-settings-axis-attr ws-uuid value]))]
(fn [{ds :ds
original-gv-uuid :worksheet/graph-settings-axis-group-variable-uuid
attr-to-swap :worksheet/graph-settings-axis-attr} [_ ws-uuid attr value]]
(when-let [g (first (d/q '[:find [?g]
:in $ ?uuid
:where
[?w :worksheet/uuid ?uuid]
[?w :worksheet/graph-settings ?g]]
ds
ws-uuid))]
{:transact [(assoc {:db/id g} attr value)]})))
(if attr-to-swap
{:transact [(assoc {:db/id g} attr value)
(assoc {:db/id g} attr-to-swap original-gv-uuid)]}
{:transact [(assoc {:db/id g} attr value)]}))))

;;Notes

Expand All @@ -614,12 +621,12 @@
submodule-io
{:keys [title body] :as _payload}]]
(when-let [ws-id (d/entid ds [:worksheet/uuid ws-uuid])]
{:transact [(cond-> {:db/id -1
{:transact [(cond-> {:db/id -1
:worksheet/_notes ws-id
:note/name (if (empty? title)
(str submodule-name " " submodule-io)
title)
:note/content body}
:note/name (if (empty? title)
(str submodule-name " " submodule-io)
title)
:note/content body}
submodule-uuid (assoc :note/submodule submodule-uuid))]})))

(rp/reg-event-fx
Expand Down Expand Up @@ -698,25 +705,25 @@
fire-head-at-attack
contain-status
units-uuid]]
{:transact [(cond-> {:worksheet/_diagrams [:worksheet/uuid ws-uuid]
:worksheet.diagram/title title
{:transact [(cond-> {:worksheet/_diagrams [:worksheet/uuid ws-uuid]
:worksheet.diagram/title title
:worksheet.diagram/group-variable-uuid group-variable-uuid
:worksheet.diagram/row-id row-id
:worksheet.diagram/units-uuid units-uuid
:worksheet.diagram/ellipses [(let [l (- fire-head-at-report fire-back-at-report)
w (/ l length-to-width-ratio)]
{:ellipse/legend-id "Fire Perimeter at Report"
:ellipse/semi-major-axis (/ l 2)
:ellipse/semi-minor-axis (/ w 2)
:ellipse/rotation 90
:ellipse/color "blue"})
(let [l (- fire-head-at-attack fire-back-at-attack)
w (/ l length-to-width-ratio)]
{:ellipse/legend-id "Fire Perimeter at Attack"
:ellipse/semi-major-axis (/ l 2)
:ellipse/semi-minor-axis (/ w 2)
:ellipse/rotation 90
:ellipse/color "red"})]}
:worksheet.diagram/row-id row-id
:worksheet.diagram/units-uuid units-uuid
:worksheet.diagram/ellipses [(let [l (- fire-head-at-report fire-back-at-report)
w (/ l length-to-width-ratio)]
{:ellipse/legend-id "Fire Perimeter at Report"
:ellipse/semi-major-axis (/ l 2)
:ellipse/semi-minor-axis (/ w 2)
:ellipse/rotation 90
:ellipse/color "blue"})
(let [l (- fire-head-at-attack fire-back-at-attack)
w (/ l length-to-width-ratio)]
{:ellipse/legend-id "Fire Perimeter at Attack"
:ellipse/semi-major-axis (/ l 2)
:ellipse/semi-minor-axis (/ w 2)
:ellipse/rotation 90
:ellipse/color "red"})]}
(= contain-status 3)
(assoc :worksheet.diagram/scatter-plots [{:scatter-plot/legend-id "Fireline Constructed"
:scatter-plot/color "black"
Expand Down Expand Up @@ -816,37 +823,37 @@
:worksheet.diagram/row-id row-id
:worksheet.diagram/units-uuid units-uuid
:worksheet.diagram/arrows (cond-> [{:arrow/legend-id "MaxSpread"
:arrow/length max-spread-rate
:arrow/rotation max-spread-dir
:arrow/color "red"}
:arrow/length max-spread-rate
:arrow/rotation max-spread-dir
:arrow/color "red"}

{:arrow/legend-id "Flanking1"
:arrow/length flanking-spread-rate
:arrow/rotation flanking-dir
:arrow/color "#81c3cb"}
:arrow/length flanking-spread-rate
:arrow/rotation flanking-dir
:arrow/color "#81c3cb"}

{:arrow/legend-id "Flanking2"
:arrow/length flanking-spread-rate
:arrow/rotation (mod (+ flanking-dir 180) 360)
:arrow/color "#347da0"}
:arrow/length flanking-spread-rate
:arrow/rotation (mod (+ flanking-dir 180) 360)
:arrow/color "#347da0"}

{:arrow/legend-id "Backing"
:arrow/length backing-spread-rate
:arrow/rotation backing-dir
:arrow/color "orange"}
:arrow/length backing-spread-rate
:arrow/rotation backing-dir
:arrow/color "orange"}

(let [l (min max-spread-rate wind-speed)]
{:arrow/legend-id "Wind"
;; NOTE for visual purposes
;; make wind 10% larger than
;; max spread rate.
;; :arrow/length wind-speed
:arrow/length (if (> wind-speed max-spread-rate)
(* l 1.1)
l)
:arrow/rotation wind-dir
:arrow/color "blue"
:arrow/dashed? true})]
:arrow/length (if (> wind-speed max-spread-rate)
(* l 1.1)
l)
:arrow/rotation wind-dir
:arrow/color "blue"
:arrow/dashed? true})]

has-direction-of-interest?
(conj {:arrow/legend-id "Interest"
Expand Down
112 changes: 68 additions & 44 deletions projects/behave/src/cljs/behave/worksheet/subs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,30 @@
[?g ?attr ?value]]
:variables [ws-uuid attr]}))

(rp/reg-sub
:worksheet/graph-settings-axis-group-variable-uuid
(fn [_ [_ ws-uuid attr]]
{:type :query
:query '[:find ?gv-uuid .
:in $ ?ws-uuid ?attr
:where
[?w :worksheet/uuid ?ws-uuid]
[?w :worksheet/graph-settings ?gs]
[?gs ?attr ?gv-uuid]]
:variables [ws-uuid attr]}))

(rp/reg-sub
:worksheet/graph-settings-axis-attr
(fn [_ [_ ws-uuid gv-uuid]]
{:type :query
:query '[:find ?attr .
:in $ ?ws-uuid ?gv-uuid
:where
[?w :worksheet/uuid ?ws-uuid]
[?w :worksheet/graph-settings ?gs]
[?gs ?attr ?gv-uuid]]
:variables [ws-uuid gv-uuid]}))

(rp/reg-sub
:worksheet/graph-settings-y-axis-limits
(fn [[_ ws-uuid]]
Expand Down Expand Up @@ -775,25 +799,25 @@
(rp/reg-sub
:worksheet/result-table-cell-data
(fn [_ [_ ws-uuid]]
{:type :query
:query '[:find ?row ?col-uuid ?repeat-id ?value
:in $ ?ws-uuid
:where
[?w :worksheet/uuid ?ws-uuid]
[?w :worksheet/result-table ?rt]
[?rt :result-table/rows ?r]
{:type :query
:query '[:find ?row ?col-uuid ?repeat-id ?value
:in $ ?ws-uuid
:where
[?w :worksheet/uuid ?ws-uuid]
[?w :worksheet/result-table ?rt]
[?rt :result-table/rows ?r]

;;get row
[?r :result-row/id ?row]
[?r :result-row/id ?row]

;;get-header
[?r :result-row/cells ?c]
[?c :result-cell/header ?h]
[?h :result-header/group-variable-uuid ?col-uuid]
[?h :result-header/repeat-id ?repeat-id]
[?r :result-row/cells ?c]
[?c :result-cell/header ?h]
[?h :result-header/group-variable-uuid ?col-uuid]
[?h :result-header/repeat-id ?repeat-id]

;;get value
[?c :result-cell/value ?value]]
[?c :result-cell/value ?value]]
:variables
[ws-uuid]}))

Expand Down Expand Up @@ -1060,50 +1084,50 @@
(rp/reg-sub
:worksheet/input-gv-uuid+value+units
(fn [_ [_ ws-uuid row-id]]
{:type :query
:query '[:find ?gv-uuid ?value ?units
:in $ ?ws-uuid ?row-id
:where
[?ws :worksheet/uuid ?ws-uuid]
[?ws :worksheet/input-groups ?ig]
[?ws :worksheet/result-table ?t]
[?t :result-table/rows ?rr]
[?rr :result-row/id ?row-id]
[?rr :result-row/cells ?c]
{:type :query
:query '[:find ?gv-uuid ?value ?units
:in $ ?ws-uuid ?row-id
:where
[?ws :worksheet/uuid ?ws-uuid]
[?ws :worksheet/input-groups ?ig]
[?ws :worksheet/result-table ?t]
[?t :result-table/rows ?rr]
[?rr :result-row/id ?row-id]
[?rr :result-row/cells ?c]

;; Filter only input variables
[?ig :input-group/inputs ?i]
[?i :input/group-variable-uuid ?gv-uuid]
[?ig :input-group/inputs ?i]
[?i :input/group-variable-uuid ?gv-uuid]

;; Get gv-uuid, value and units
[?rh :result-header/group-variable-uuid ?gv-uuid]
[?rh :result-header/units ?units]
[?c :result-cell/header ?rh]
[?c :result-cell/value ?value]]
[?rh :result-header/group-variable-uuid ?gv-uuid]
[?rh :result-header/units ?units]
[?c :result-cell/header ?rh]
[?c :result-cell/value ?value]]
:variables [ws-uuid row-id]}))

(rp/reg-sub
:worksheet/output-gv-uuid+value+units
(fn [_ [_ ws-uuid row-id]]
{:type :query
:query '[:find ?gv-uuid ?value ?units
:in $ ?ws-uuid ?row-id
:where
[?ws :worksheet/uuid ?ws-uuid]
[?ws :worksheet/outputs ?o]
[?ws :worksheet/result-table ?t]
[?t :result-table/rows ?rr]
[?rr :result-row/id ?row-id]
[?rr :result-row/cells ?c]
{:type :query
:query '[:find ?gv-uuid ?value ?units
:in $ ?ws-uuid ?row-id
:where
[?ws :worksheet/uuid ?ws-uuid]
[?ws :worksheet/outputs ?o]
[?ws :worksheet/result-table ?t]
[?t :result-table/rows ?rr]
[?rr :result-row/id ?row-id]
[?rr :result-row/cells ?c]

;; Filter only output variables
[?o :output/group-variable-uuid ?gv-uuid]
[?o :output/group-variable-uuid ?gv-uuid]

;; Get gv-uuid, value and units
[?rh :result-header/group-variable-uuid ?gv-uuid]
[?rh :result-header/units ?units]
[?c :result-cell/header ?rh]
[?c :result-cell/value ?value]]
[?rh :result-header/group-variable-uuid ?gv-uuid]
[?rh :result-header/units ?units]
[?c :result-cell/header ?rh]
[?c :result-cell/value ?value]]
:variables [ws-uuid row-id]}))

(rf/reg-sub
Expand Down