vlabels works a little
authorBen Pfaff <blp@cs.stanford.edu>
Thu, 30 Dec 2021 23:58:42 +0000 (15:58 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Sat, 2 Apr 2022 01:48:55 +0000 (18:48 -0700)
src/language/stats/ctables.c

index 96d12e03fcd4d94c4c5dbddbdf3547b315e560cf..333b8f8c5413008adb2ee56195f212141a3d7741 100644 (file)
 
 enum ctables_vlabel
   {
-    CTVL_DEFAULT = SETTINGS_VALUE_SHOW_DEFAULT,
+    CTVL_NONE = SETTINGS_VALUE_SHOW_DEFAULT,
     CTVL_NAME = SETTINGS_VALUE_SHOW_VALUE,
     CTVL_LABEL = SETTINGS_VALUE_SHOW_LABEL,
     CTVL_BOTH = SETTINGS_VALUE_SHOW_BOTH,
-    CTVL_NONE,
   };
-static void UNUSED
-ctables_vlabel_unique (enum ctables_vlabel vlabel)
-{
-  /* This ensures that all of the values are unique. */
-  switch (vlabel)
-    {
-    case CTVL_DEFAULT:
-    case CTVL_NAME:
-    case CTVL_LABEL:
-    case CTVL_BOTH:
-    case CTVL_NONE:
-      abort ();
-    }
-}
 
 /* XXX:
    - unweighted summaries (U*)
@@ -1525,23 +1510,31 @@ ctables_execute (struct dataset *ds, struct ctables *ct)
                                     var_get_type (ft->vars.vars[n_common])))
                     break;
 
-              for (size_t m = n_common; m + 1 < ft->vars.n; m++)
+              for (size_t m = n_common; m < ft->vars.n; m++)
                 {
                   struct pivot_category *parent = m > 0 ? groups[m - 1] : d->root;
-                  if (true)
+                  const struct variable *var = ft->vars.vars[m];
+                  enum ctables_vlabel vlabel = ct->vlabels[var_get_dict_index (var)];
+
+                  if (vlabel != CTVL_NONE)
                     parent = pivot_category_create_group__ (
                       parent, pivot_value_new_variable (ft->vars.vars[m]));
-                  groups[m] = pivot_category_create_group__ (
-                    parent,
-                    pivot_value_new_var_value (ft->vars.vars[m], &f->values[m]));
-                }
 
-              int leaf = pivot_category_create_leaf (
-                ft->vars.n > 1 ? groups[ft->vars.n - 2] : d->root,
-                pivot_value_new_var_value (ft->vars.vars[ft->vars.n - 1],
-                                           &f->values[ft->vars.n - 1]));
+                  if (m + 1 < ft->vars.n)
+                    parent = pivot_category_create_group__ (
+                      parent,
+                      pivot_value_new_var_value (ft->vars.vars[m], &f->values[m]));
+                  groups[m] = parent;
 
-              pivot_table_put1 (pt, leaf, pivot_value_new_number (f->count));
+                  if (m == ft->vars.n - 1)
+                    {
+                      int leaf = pivot_category_create_leaf (
+                        parent,
+                        pivot_value_new_var_value (ft->vars.vars[ft->vars.n - 1],
+                                                   &f->values[ft->vars.n - 1]));
+                      pivot_table_put1 (pt, leaf, pivot_value_new_number (f->count));
+                    }
+                }
             }
           free (groups);
         }
@@ -1582,8 +1575,9 @@ cmd_ctables (struct lexer *lexer, struct dataset *ds)
 {
   size_t n_vars = dict_get_n_vars (dataset_dict (ds));
   enum ctables_vlabel *vlabels = xnmalloc (n_vars, sizeof *vlabels);
+  enum settings_value_show tvars = settings_get_show_variables ();
   for (size_t i = 0; i < n_vars; i++)
-    vlabels[i] = CTVL_DEFAULT;
+    vlabels[i] = (enum ctables_vlabel) tvars;
 
   struct ctables *ct = xmalloc (sizeof *ct);
   *ct = (struct ctables) {
@@ -1707,7 +1701,7 @@ cmd_ctables (struct lexer *lexer, struct dataset *ds)
 
           enum ctables_vlabel vlabel;
           if (lex_match_id (lexer, "DEFAULT"))
-            vlabel = CTVL_DEFAULT;
+            vlabel = (enum ctables_vlabel) settings_get_show_variables ();
           else if (lex_match_id (lexer, "NAME"))
             vlabel = CTVL_NAME;
           else if (lex_match_id (lexer, "LABEL"))