Reliability Test: Do not allow splits greater than the number of variables. 20120215030501/pspp
authorJohn Darrington <john@darrington.wattle.id.au>
Tue, 14 Feb 2012 10:13:15 +0000 (11:13 +0100)
committerJohn Darrington <john@darrington.wattle.id.au>
Tue, 14 Feb 2012 17:54:27 +0000 (18:54 +0100)
It's not meaningful to have a split point which is greater than the number
of variables (and not useful when they are equal).  And the system was
exhaughsting its memory when such a test was run.  This change therefore
disallows such a combination and updates the behaviour of the GUI accordingly.

src/language/stats/reliability.c
src/ui/gui/psppire-dialog-action-reliability.c

index 5378ed897417494680e1603ae0379b396f27776d..744763382a374b815e9a235b9c86a18f82b0cc39 100644 (file)
@@ -263,6 +263,12 @@ cmd_reliability (struct lexer *lexer, struct dataset *ds)
       int i;
       const struct cronbach *s;
 
+      if ( reliability.split_point >= reliability.n_variables)
+        {
+          msg (ME, _("The split point must be less than the number of variables"));
+          goto error;
+        }
+
       reliability.n_sc += 2 ;
       reliability.sc = xrealloc (reliability.sc, sizeof (struct cronbach) * reliability.n_sc);
 
index 67d8c186a5a377cf1e5cbb966e3a7a9fe25169eb..465aea8de0726fb6d97b4fd329ffba83da55bd06 100644 (file)
@@ -29,6 +29,12 @@ static void psppire_dialog_action_reliability_class_init      (PsppireDialogActi
 
 G_DEFINE_TYPE (PsppireDialogActionReliability, psppire_dialog_action_reliability, PSPPIRE_TYPE_DIALOG_ACTION);
 
+enum 
+  {
+    ALPHA = 0,
+    SPLIT = 1
+  };
+
 static char *
 generate_syntax (PsppireDialogAction *act)
 {
@@ -42,7 +48,7 @@ generate_syntax (PsppireDialogAction *act)
 
   g_string_append (string, "\n\t/MODEL=");
 
-  if ( 0 == gtk_combo_box_get_active (GTK_COMBO_BOX (rd->model_combo)))
+  if ( ALPHA == gtk_combo_box_get_active (GTK_COMBO_BOX (rd->model_combo)))
     g_string_append (string, "ALPHA");
   else
     g_string_append_printf (string, "SPLIT (%d)",
@@ -73,10 +79,23 @@ dialog_state_valid (gpointer user_data)
 }
 
 static void
-on_method_change (PsppireDialogActionReliability *pda)
+update_split_control (PsppireDialogActionReliability *pda)
 {
+  GtkTreeModel *liststore =
+    gtk_tree_view_get_model (GTK_TREE_VIEW (pda->variables));
+
+  gint n_vars = gtk_tree_model_iter_n_children (liststore, NULL);
+
+  gint sp = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (pda->split_spinbutton));
+
+  if (sp >= n_vars)
+    gtk_spin_button_set_value (GTK_SPIN_BUTTON (pda->split_spinbutton), n_vars - 1);
+
+  gtk_spin_button_set_range (GTK_SPIN_BUTTON (pda->split_spinbutton),
+                            0, n_vars - 1);
+
   gtk_widget_set_sensitive (pda->split_point_hbox,
-                           ( 1 == gtk_combo_box_get_active (GTK_COMBO_BOX (pda->model_combo))));
+                           ( SPLIT == gtk_combo_box_get_active (GTK_COMBO_BOX (pda->model_combo))));
 }
 
 
@@ -89,7 +108,7 @@ refresh (PsppireDialogAction *pda_)
     gtk_tree_view_get_model (GTK_TREE_VIEW (pda->variables));
   gtk_list_store_clear (GTK_LIST_STORE (liststore));
 
-  gtk_combo_box_set_active (GTK_COMBO_BOX (pda->model_combo), 0);
+  gtk_combo_box_set_active (GTK_COMBO_BOX (pda->model_combo), ALPHA);
 
   gtk_spin_button_set_value (GTK_SPIN_BUTTON (pda->split_spinbutton), 0);
 
@@ -105,7 +124,7 @@ psppire_dialog_action_reliability_activate (GtkAction *a)
 {
   PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a);
   PsppireDialogActionReliability *act = PSPPIRE_DIALOG_ACTION_RELIABILITY (a);
-
+  GtkTreeModel *liststore ;
   GtkBuilder *xml = builder_new ("reliability.ui");
   pda->dialog = get_widget_assert   (xml, "reliability-dialog");
   pda->source = get_widget_assert   (xml, "dict-view");
@@ -119,10 +138,21 @@ psppire_dialog_action_reliability_activate (GtkAction *a)
   act->model_combo = get_widget_assert   (xml, "combobox1");
   act->split_spinbutton = get_widget_assert (xml, "spinbutton1");
 
+  liststore =
+    gtk_tree_view_get_model (GTK_TREE_VIEW (act->variables));
+
+
   act->scale_if_item_deleted_checkbutton = get_widget_assert (xml, "totals-checkbutton");
 
   g_signal_connect_swapped (act->model_combo, "changed",
-                           G_CALLBACK (on_method_change), pda);
+                           G_CALLBACK (update_split_control), pda);
+
+
+  g_signal_connect_swapped (liststore, "row-inserted",
+                           G_CALLBACK (update_split_control), pda);
+  g_signal_connect_swapped (liststore, "row-deleted",
+                           G_CALLBACK (update_split_control), pda);
+
 
   psppire_dialog_action_set_refresh (pda, refresh);
   psppire_dialog_action_set_valid_predicate (pda, dialog_state_valid);