1 /* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * dialog-analysis-tool-one-mean.c:
6 * Andreas J. Guelzow <aguelzow@pyrshep.ca>
8 * (C) Copyright 2012 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-one-mean-test.h"
29 #include "analysis-tools.h"
32 #include <workbook-control.h>
34 #include <workbook-view.h>
36 #include <parse-util.h>
37 #include <gnm-format.h>
38 #include <dialogs/tool-dialogs.h>
39 #include <dialogs/dao-gui-utils.h>
42 #include <number-match.h>
44 #include <selection.h>
49 #include <widgets/gnm-dao.h>
50 #include <widgets/gnumeric-expr-entry.h>
55 #define ONE_MEAN_TEST_KEY "analysistools-one-mean-test-dialog"
57 static char const * const grouped_by_group
[] = {
65 GnmGenericToolState base
;
66 GtkWidget
*alpha_entry
;
67 GtkWidget
*mean_entry
;
68 } OneeMeanTestToolState
;
71 * one_mean_test_tool_update_common_sensitivity_cb:
75 * Update the dialog widgets sensitivity
78 one_mean_test_tool_update_common_sensitivity_cb (OneeMeanTestToolState
*state
)
86 (GTK_ENTRY (state
->mean_entry
), &mean
, FALSE
);
88 gtk_label_set_text (GTK_LABEL (state
->base
.warning
),
89 _("The predicted mean should be a number."));
90 gtk_widget_set_sensitive (state
->base
.ok_button
, FALSE
);
95 alpha
= gtk_spin_button_get_value
96 (GTK_SPIN_BUTTON (state
->alpha_entry
));
97 if (!(alpha
> 0 && alpha
< 1)) {
98 gtk_label_set_text (GTK_LABEL (state
->base
.warning
),
99 _("The alpha value should "
100 "be a number between 0 and 1."));
101 gtk_widget_set_sensitive (state
->base
.ok_button
, FALSE
);
105 /* Checking Output Page */
106 if (!gnm_dao_is_ready (GNM_DAO (state
->base
.gdao
))) {
107 gtk_label_set_text (GTK_LABEL (state
->base
.warning
),
108 _("The output specification "
110 gtk_widget_set_sensitive (state
->base
.ok_button
, FALSE
);
120 /************************************************************************************/
123 * one_mean_test_tool_ok_clicked_cb:
127 * Retrieve the information from the dialog and call the one_mean_test_tool.
128 * Note that we assume that the ok_button is only active if the entry fields
129 * contain sensible data.
132 one_mean_test_tool_ok_clicked_cb (G_GNUC_UNUSED GtkWidget
*button
,
133 OneeMeanTestToolState
*state
)
135 data_analysis_output_t
*dao
;
137 analysis_tools_data_one_mean_test_t
*data
;
139 data
= g_new0 (analysis_tools_data_one_mean_test_t
, 1);
140 dao
= parse_output ((GnmGenericToolState
*)state
, NULL
);
142 data
->base
.input
= gnm_expr_entry_parse_as_list (
143 GNM_EXPR_ENTRY (state
->base
.input_entry
), state
->base
.sheet
);
144 data
->base
.group_by
= gnm_gui_group_value (state
->base
.gui
, grouped_by_group
);
146 w
= go_gtk_builder_get_widget (state
->base
.gui
, "labels_button");
147 data
->base
.labels
= gtk_toggle_button_get_active
148 (GTK_TOGGLE_BUTTON (w
));
151 (GTK_ENTRY (state
->mean_entry
), &data
->mean
, FALSE
);
152 data
->alpha
= gtk_spin_button_get_value
153 (GTK_SPIN_BUTTON (state
->alpha_entry
));
155 if (!cmd_analysis_tool (GNM_WBC (state
->base
.wbcg
),
157 dao
, data
, analysis_tool_one_mean_test_engine
,
159 gtk_widget_destroy (state
->base
.dialog
);
165 * one_mean_test_tool_update_sensitivity_cb:
169 * Update the dialog widgets sensitivity
172 one_mean_test_tool_update_sensitivity_cb (G_GNUC_UNUSED GtkWidget
*dummy
,
173 OneeMeanTestToolState
*state
)
177 /* Checking first input range*/
178 input_range
= gnm_expr_entry_parse_as_list
179 (GNM_EXPR_ENTRY (state
->base
.input_entry
),
181 if (input_range
== NULL
) {
182 gtk_label_set_text (GTK_LABEL (state
->base
.warning
),
183 (state
->base
.input_entry_2
== NULL
)
184 ? _("The input range is invalid.")
185 : _("The first input range is invalid."));
186 gtk_widget_set_sensitive (state
->base
.ok_button
, FALSE
);
189 range_list_destroy (input_range
);
191 if (one_mean_test_tool_update_common_sensitivity_cb (state
)) {
192 gtk_label_set_text (GTK_LABEL (state
->base
.warning
), "");
193 gtk_widget_set_sensitive (state
->base
.ok_button
, TRUE
);
199 * dialog_one_mean_test_tool:
203 dialog_one_mean_test_tool (WBCGtk
*wbcg
, Sheet
*sheet
)
205 char const * plugins
[] = { "Gnumeric_fnstat",
206 "Gnumeric_fnlogical",
209 OneeMeanTestToolState
*state
;
211 if ((wbcg
== NULL
) ||
212 gnm_check_for_plugins_missing (plugins
, wbcg_toplevel (wbcg
)))
215 /* Only pop up one copy per workbook */
216 if (gnm_dialog_raise_if_exists (wbcg
, ONE_MEAN_TEST_KEY
))
219 state
= g_new0 (OneeMeanTestToolState
, 1);
221 if (dialog_tool_init (&state
->base
, wbcg
, sheet
,
222 GNUMERIC_HELP_LINK_ONE_MEAN
,
223 "res:ui/one-mean-test.ui", "One-Mean-Test",
224 _("Could not create the Student-t Test Tool dialog."),
226 G_CALLBACK (one_mean_test_tool_ok_clicked_cb
),
228 G_CALLBACK (one_mean_test_tool_update_sensitivity_cb
),
236 state
->alpha_entry
= tool_setup_update
237 (&state
->base
, "alpha-entry",
238 G_CALLBACK (one_mean_test_tool_update_sensitivity_cb
),
240 state
->mean_entry
= tool_setup_update
241 (&state
->base
, "mean-entry",
242 G_CALLBACK (one_mean_test_tool_update_sensitivity_cb
),
245 int_to_entry (GTK_ENTRY (state
->mean_entry
), 0);
246 float_to_entry (GTK_ENTRY (state
->alpha_entry
), 0.05);
248 gnm_dao_set_put (GNM_DAO (state
->base
.gdao
), TRUE
, TRUE
);
249 one_mean_test_tool_update_sensitivity_cb (NULL
, state
);
250 tool_load_selection ((GnmGenericToolState
*)state
, TRUE
);