From 0d9d2a5fce39203c719ec6d4df5b67014cf748be Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Thu, 30 Dec 2021 15:58:42 -0800 Subject: [PATCH] vlabels works a little --- src/language/stats/ctables.c | 52 ++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 29 deletions(-) diff --git a/src/language/stats/ctables.c b/src/language/stats/ctables.c index 96d12e03fc..333b8f8c54 100644 --- a/src/language/stats/ctables.c +++ b/src/language/stats/ctables.c @@ -41,26 +41,11 @@ 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")) -- 2.30.2