@@ -46,7 +46,7 @@ Actions:
4646- `widget_checkbox`: Dictionary with the current values of the widgets (term => values).
4747- `widget_signal`: widget_checkbox but as Observable, a signal that emits a dictionary with the current values of the widgets.
4848- `formular_widget`: The HTML element that can be displayed to interact with the the widgets.
49- - `value_ranges`: A dictionaryy containing the value ranges of each formula term.
49+ - `value_ranges`: A dictionary containing the value ranges of each formula term.
5050"""
5151function formular_widgets (variables)
5252 value_ranges = [k => value_range (v) for (k, v) in variables]
@@ -58,13 +58,18 @@ function formular_widgets(variables)
5858 c = checkboxes[k]
5959 w_cat_term = widgets[k]. first
6060 w_value = widgets[k]. second
61- push! (widget_names, formular_text (" +" ), formular_text (c), dropdown (w_cat_term, w_value))
61+ push! (
62+ widget_names,
63+ formular_text (" +" ),
64+ formular_text (c),
65+ dropdown (w_cat_term, w_value),
66+ )
6267 end
63-
68+
6469 formular_widget = Row (widget_names... )
6570 widget_values = map (nw -> nw[2 ]. value, widgets)
6671 checkbox_values = map (c -> c. value, checkboxes)
67-
72+
6873 widget_signal =
6974 lift (widget_values... , checkbox_values... ; ignore_equal_values = true ) do args...
7075 result = []
@@ -77,34 +82,49 @@ function formular_widgets(variables)
7782 end
7883 widget_checkbox = Dict (k => c for (c, (k, v)) in zip (checkbox_values, variables))
7984
80- return widget_checkbox,
81- widget_signal,
82- formular_widget,
83- value_ranges
85+ return widget_checkbox, widget_signal, formular_widget, value_ranges
8486end
8587
86- function effects_signal (model, widget_signal, channel)
87- effects_signal = Observable {Any} (nothing ; ignore_equal_values = true )
88+ """
89+ yhats_signal(model, widget_signal, channel)
90+ Creates a dictionary with yhat values and more.\\
8891
89- onany (widget_signal, channel; update = true ) do widget_values, chan
92+ Arguments:\\
93+ - `model::UnfoldLinearModel{Float64}` - vector of key-value pairs with information about the model formula terms.
94+ - `widget_signal::Observable{Vector{Any}}` - a signal that emits a dictionary with the current values of the widgets.
95+ - `channel::Observable{Int64}` - number of selected channel-
96+
97+ Actions:
98+ - Compute predicted value (yhat) of the given model using `effects`.
99+ - Create `DataFrame` with columns: yhat, channel, dummy, time, eventname and unique columns for each formula term.
100+ - Make it Observable.
101+
102+ **Return Value:** `yhats_signal::Observable{Any}` containing DataFrame with yhats.
103+ """
104+ function yhats_signal (model, widget_signal, channel)
105+
106+ yhats_signal = Observable {Any} (nothing ; ignore_equal_values = true )
90107
91- effect_dict = Dict (
108+ onany (widget_signal, channel; update = true ) do widget_values, chan
109+ yhat_dict = Dict (
92110 k => widget_value (wv[2 ]) for (k, wv) in widget_values if ! isempty (wv) && wv[1 ]
93111 )
94- if isempty (effect_dict )
95- effect_dict = Dict (:dummy => [" dummy" ])
112+ if isempty (yhat_dict )
113+ yhat_dict = Dict (:dummy => [" dummy" ])
96114 end
97- eff = effects (effect_dict, model)
115+ yhats = effects (yhat_dict, model)
116+
98117 for (k, wv) in widget_values
99118 if isempty (wv[2 ]) || ! wv[1 ]
100- eff [! , k] .= " typical_value"
119+ yhats [! , k] .= " typical_value"
101120 end
102121 end
103122
104- filter! (x -> x. channel == chan, eff )
105- effects_signal [] = eff
123+ filter! (x -> x. channel == chan, yhats )
124+ yhats_signal [] = yhats
106125 end
107- return effects_signal
126+
127+ return yhats_signal
108128end
109129
110130
0 commit comments