1 /* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * dialog-analysis-tool-sign-test.c:
6 * Andreas J. Guelzow <aguelzow@pyrshep.ca>
8 * (C) Copyright 2009-2010 by Andreas J. Guelzow <aguelzow@pyrshep.ca>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, see <https://www.gnu.org/licenses/>.
24 #include <gnumeric-config.h>
25 #include <glib/gi18n-lib.h>
28 #include "analysis-sign-test.h"
29 #include "analysis-signed-rank-test.h"
30 #include "analysis-tools.h"
33 #include <workbook-control.h>
35 #include <workbook-view.h>
37 #include <parse-util.h>
38 #include <gnm-format.h>
39 #include <tool-dialogs.h>
40 #include <dao-gui-utils.h>
43 #include <number-match.h>
45 #include <selection.h>
50 #include <widgets/gnm-dao.h>
51 #include <widgets/gnumeric-expr-entry.h>
56 #define SIGN_TEST_KEY_ONE "analysistools-sign-test-one-dialog"
57 #define SIGN_TEST_KEY_TWO "analysistools-sign-test-two-dialog"
59 static char const * const grouped_by_group
[] = {
67 GenericToolState base
;
68 GtkWidget
*alpha_entry
;
69 GtkWidget
*median_entry
;
73 * sign_test_tool_update_common_sensitivity_cb:
77 * Update the dialog widgets sensitivity
80 sign_test_tool_update_common_sensitivity_cb (SignTestToolState
*state
)
88 (GTK_ENTRY (state
->median_entry
), &median
, FALSE
);
90 gtk_label_set_text (GTK_LABEL (state
->base
.warning
),
91 _("The predicted median should be a number."));
92 gtk_widget_set_sensitive (state
->base
.ok_button
, FALSE
);
97 alpha
= gtk_spin_button_get_value
98 (GTK_SPIN_BUTTON (state
->alpha_entry
));
99 if (!(alpha
> 0 && alpha
< 1)) {
100 gtk_label_set_text (GTK_LABEL (state
->base
.warning
),
101 _("The alpha value should "
102 "be a number between 0 and 1."));
103 gtk_widget_set_sensitive (state
->base
.ok_button
, FALSE
);
107 /* Checking Output Page */
108 if (!gnm_dao_is_ready (GNM_DAO (state
->base
.gdao
))) {
109 gtk_label_set_text (GTK_LABEL (state
->base
.warning
),
110 _("The output specification "
112 gtk_widget_set_sensitive (state
->base
.ok_button
, FALSE
);
121 * sign_test_tool_update_sensitivity_cb:
125 * Update the dialog widgets sensitivity
128 sign_test_two_tool_update_sensitivity_cb (G_GNUC_UNUSED GtkWidget
*dummy
,
129 SignTestToolState
*state
)
131 GnmValue
*input_range
;
134 /* Checking first input range*/
135 input_range
= gnm_expr_entry_parse_as_value
136 (GNM_EXPR_ENTRY (state
->base
.input_entry
),
138 if (input_range
== NULL
|| !VALUE_IS_CELLRANGE (input_range
)) {
139 gtk_label_set_text (GTK_LABEL (state
->base
.warning
),
140 (state
->base
.input_entry_2
== NULL
)
141 ? _("The input range is invalid.")
142 : _("The first input range is invalid."));
143 gtk_widget_set_sensitive (state
->base
.ok_button
, FALSE
);
144 value_release (input_range
);
148 range_init_rangeref (&r
, &(input_range
->v_range
.cell
));
149 w
= range_width (&r
);
150 h
= range_height (&r
);
151 value_release (input_range
);
154 /* Checking second input range*/
155 if (state
->base
.input_entry_2
!= NULL
) {
156 input_range
= gnm_expr_entry_parse_as_value
157 (GNM_EXPR_ENTRY (state
->base
.input_entry_2
),
159 if (input_range
== NULL
|| !VALUE_IS_CELLRANGE (input_range
)) {
160 gtk_label_set_text (GTK_LABEL (state
->base
.warning
),
161 _("The second input range is invalid."));
162 gtk_widget_set_sensitive (state
->base
.ok_button
, FALSE
);
163 value_release (input_range
);
167 range_init_rangeref (&r
, &(input_range
->v_range
.cell
));
168 value_release (input_range
);
169 if (w
!= range_width (&r
) ||
170 h
!= range_height (&r
)) {
172 (GTK_LABEL (state
->base
.warning
),
173 _("The input ranges do not have the same shape."));
174 gtk_widget_set_sensitive
175 (state
->base
.ok_button
, FALSE
);
182 if (sign_test_tool_update_common_sensitivity_cb (state
)) {
183 gtk_label_set_text (GTK_LABEL (state
->base
.warning
), "");
184 gtk_widget_set_sensitive (state
->base
.ok_button
, TRUE
);
189 sign_test_two_tool_ok_clicked_cb (G_GNUC_UNUSED GtkWidget
*button
,
190 SignTestToolState
*state
)
192 data_analysis_output_t
*dao
;
194 analysis_tools_data_sign_test_two_t
*data
;
195 analysis_tool_engine engine
;
197 data
= g_new0 (analysis_tools_data_sign_test_two_t
, 1);
198 dao
= parse_output ((GenericToolState
*)state
, NULL
);
200 data
->base
.range_1
= gnm_expr_entry_parse_as_value
201 (GNM_EXPR_ENTRY (state
->base
.input_entry
), state
->base
.sheet
);
203 data
->base
.range_2
= gnm_expr_entry_parse_as_value
204 (GNM_EXPR_ENTRY (state
->base
.input_entry_2
), state
->base
.sheet
);
206 w
= go_gtk_builder_get_widget (state
->base
.gui
, "labels_button");
207 data
->base
.labels
= gtk_toggle_button_get_active
208 (GTK_TOGGLE_BUTTON (w
));
211 (GTK_ENTRY (state
->median_entry
), &data
->median
, FALSE
);
213 data
->base
.alpha
= gtk_spin_button_get_value
214 (GTK_SPIN_BUTTON (state
->alpha_entry
));
216 w
= go_gtk_builder_get_widget (state
->base
.gui
, "signtest");
217 engine
= gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (w
))
218 ? analysis_tool_sign_test_two_engine
219 : analysis_tool_signed_rank_test_two_engine
;
221 if (!cmd_analysis_tool (GNM_WBC (state
->base
.wbcg
),
223 dao
, data
, engine
, TRUE
))
224 gtk_widget_destroy (state
->base
.dialog
);
230 * dialog_sign_test_two_tool:
234 dialog_sign_test_two_tool (WBCGtk
*wbcg
, Sheet
*sheet
, signtest_type type
)
236 char const * plugins
[] = { "Gnumeric_fnstat",
237 "Gnumeric_fnlogical",
241 SignTestToolState
*state
;
244 if ((wbcg
== NULL
) ||
245 gnm_check_for_plugins_missing (plugins
, wbcg_toplevel (wbcg
)))
248 /* Only pop up one copy per workbook */
249 if (gnm_dialog_raise_if_exists (wbcg
, SIGN_TEST_KEY_TWO
))
252 state
= g_new0 (SignTestToolState
, 1);
254 if (dialog_tool_init (&state
->base
, wbcg
, sheet
,
255 GNUMERIC_HELP_LINK_SIGN_TEST_TWO
,
256 "res:ui/sign-test-two.ui", "Sign-Test",
257 _("Could not create the Sign Test Tool dialog."),
259 G_CALLBACK (sign_test_two_tool_ok_clicked_cb
),
261 G_CALLBACK (sign_test_two_tool_update_sensitivity_cb
),
262 GNM_EE_SINGLE_RANGE
))
269 state
->alpha_entry
= tool_setup_update
270 (&state
->base
, "alpha-entry",
271 G_CALLBACK (sign_test_two_tool_update_sensitivity_cb
),
273 float_to_entry (GTK_ENTRY (state
->alpha_entry
), 0.05);
275 state
->median_entry
= tool_setup_update
276 (&state
->base
, "median-entry",
277 G_CALLBACK (sign_test_two_tool_update_sensitivity_cb
),
279 int_to_entry (GTK_ENTRY (state
->median_entry
), 0);
281 w
= go_gtk_builder_get_widget (state
->base
.gui
,
282 (type
== SIGNTEST
) ? "signtest"
284 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w
), TRUE
);
286 gnm_dao_set_put (GNM_DAO (state
->base
.gdao
), TRUE
, TRUE
);
287 sign_test_two_tool_update_sensitivity_cb (NULL
, state
);
288 tool_load_selection ((GenericToolState
*)state
, TRUE
);
294 /************************************************************************************/
297 * sign_test_tool_ok_clicked_cb:
301 * Retrieve the information from the dialog and call the sign_test_tool.
302 * Note that we assume that the ok_button is only active if the entry fields
303 * contain sensible data.
306 sign_test_tool_ok_clicked_cb (G_GNUC_UNUSED GtkWidget
*button
,
307 SignTestToolState
*state
)
309 data_analysis_output_t
*dao
;
311 analysis_tools_data_sign_test_t
*data
;
312 analysis_tool_engine engine
;
314 data
= g_new0 (analysis_tools_data_sign_test_t
, 1);
315 dao
= parse_output ((GenericToolState
*)state
, NULL
);
317 data
->base
.input
= gnm_expr_entry_parse_as_list (
318 GNM_EXPR_ENTRY (state
->base
.input_entry
), state
->base
.sheet
);
319 data
->base
.group_by
= gnm_gui_group_value (state
->base
.gui
, grouped_by_group
);
321 w
= go_gtk_builder_get_widget (state
->base
.gui
, "labels_button");
322 data
->base
.labels
= gtk_toggle_button_get_active
323 (GTK_TOGGLE_BUTTON (w
));
326 (GTK_ENTRY (state
->median_entry
), &data
->median
, FALSE
);
327 data
->alpha
= gtk_spin_button_get_value
328 (GTK_SPIN_BUTTON (state
->alpha_entry
));
330 w
= go_gtk_builder_get_widget (state
->base
.gui
, "signtest");
331 engine
= gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (w
))
332 ? analysis_tool_sign_test_engine
333 : analysis_tool_signed_rank_test_engine
;
335 if (!cmd_analysis_tool (GNM_WBC (state
->base
.wbcg
),
337 dao
, data
, engine
, TRUE
))
338 gtk_widget_destroy (state
->base
.dialog
);
344 * sign_test_tool_update_sensitivity_cb:
348 * Update the dialog widgets sensitivity
351 sign_test_tool_update_sensitivity_cb (G_GNUC_UNUSED GtkWidget
*dummy
,
352 SignTestToolState
*state
)
356 /* Checking first input range*/
357 input_range
= gnm_expr_entry_parse_as_list
358 (GNM_EXPR_ENTRY (state
->base
.input_entry
),
360 if (input_range
== NULL
) {
361 gtk_label_set_text (GTK_LABEL (state
->base
.warning
),
362 (state
->base
.input_entry_2
== NULL
)
363 ? _("The input range is invalid.")
364 : _("The first input range is invalid."));
365 gtk_widget_set_sensitive (state
->base
.ok_button
, FALSE
);
368 range_list_destroy (input_range
);
370 if (sign_test_tool_update_common_sensitivity_cb (state
)) {
371 gtk_label_set_text (GTK_LABEL (state
->base
.warning
), "");
372 gtk_widget_set_sensitive (state
->base
.ok_button
, TRUE
);
378 * dialog_sign_test_tool:
382 dialog_sign_test_tool (WBCGtk
*wbcg
, Sheet
*sheet
, signtest_type type
)
384 char const * plugins
[] = { "Gnumeric_fnstat",
385 "Gnumeric_fnlogical",
389 SignTestToolState
*state
;
392 if ((wbcg
== NULL
) ||
393 gnm_check_for_plugins_missing (plugins
, wbcg_toplevel (wbcg
)))
396 /* Only pop up one copy per workbook */
397 if (gnm_dialog_raise_if_exists (wbcg
, SIGN_TEST_KEY_ONE
))
400 state
= g_new0 (SignTestToolState
, 1);
402 if (dialog_tool_init (&state
->base
, wbcg
, sheet
,
403 GNUMERIC_HELP_LINK_SIGN_TEST
,
404 "res:ui/sign-test.ui", "Sign-Test",
405 _("Could not create the Sign Test Tool dialog."),
407 G_CALLBACK (sign_test_tool_ok_clicked_cb
),
409 G_CALLBACK (sign_test_tool_update_sensitivity_cb
),
417 state
->alpha_entry
= tool_setup_update
418 (&state
->base
, "alpha-entry",
419 G_CALLBACK (sign_test_two_tool_update_sensitivity_cb
),
421 state
->median_entry
= tool_setup_update
422 (&state
->base
, "median-entry",
423 G_CALLBACK (sign_test_two_tool_update_sensitivity_cb
),
426 int_to_entry (GTK_ENTRY (state
->median_entry
), 0);
427 float_to_entry (GTK_ENTRY (state
->alpha_entry
), 0.05);
429 w
= go_gtk_builder_get_widget (state
->base
.gui
,
430 (type
== SIGNTEST
) ? "signtest"
432 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w
), TRUE
);
434 gnm_dao_set_put (GNM_DAO (state
->base
.gdao
), TRUE
, TRUE
);
435 sign_test_tool_update_sensitivity_cb (NULL
, state
);
436 tool_load_selection ((GenericToolState
*)state
, TRUE
);