From 885ac3ed70c6cf89e951792de1b0c991b309b5c4 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Sat, 15 Jan 2022 11:52:12 -0800 Subject: [PATCH] minor improvements and cleanups --- src/language/stats/ctables.c | 74 ++++++++---------------------------- 1 file changed, 16 insertions(+), 58 deletions(-) diff --git a/src/language/stats/ctables.c b/src/language/stats/ctables.c index 7247651c7e..7a1cb3b2ca 100644 --- a/src/language/stats/ctables.c +++ b/src/language/stats/ctables.c @@ -325,7 +325,7 @@ struct ctables_table struct hmap cells; struct hmap domains[N_CTDTS]; - enum pivot_axis_type slabels_position; + enum pivot_axis_type slabels_axis; bool slabels_visible; enum ctables_label_position row_labels; @@ -959,7 +959,6 @@ ctables_axis_parse_postfix (struct ctables_axis_parse_ctx *ctx) struct msg_location *loc = lex_ofs_location (ctx->lexer, start_ofs, lex_ofs (ctx->lexer) - 1); - printf ("add %s\n", ctables_summary_function_name (function)); add_summary_spec (sub, function, percentile, label, formatp, loc, sv); free (label); msg_location_destroy (loc); @@ -2437,7 +2436,6 @@ ctables_cell_insert (struct ctables_table *t, struct merge_item { - size_t tiebreaker; const struct ctables_summary_spec_set *set; size_t ofs; }; @@ -2742,11 +2740,11 @@ ctables_table_output_different_axis (struct ctables *ct, struct ctables_table *t &cell->axes[a].cvs[k].value)); if (k == nest->n - 1) { - if (a == t->summary_axis) + if (a == t->slabels_axis) { if (label) parent = pivot_category_create_group__ (parent, label); - const struct ctables_summary_spec_set *specs = &nest->specs[cell->sv]; + const struct ctables_summary_spec_set *specs = &t->summary_specs; for (size_t m = 0; m < specs->n; m++) { int leaf = pivot_category_create_leaf ( @@ -2757,11 +2755,7 @@ ctables_table_output_different_axis (struct ctables *ct, struct ctables_table *t } else { - /* This assertion is true as long as the summary axis - is the axis where the summaries are displayed. */ - assert (label); - - prev_leaf = pivot_category_create_leaf (parent, label); + prev_leaf = pivot_category_create_leaf (parent, label ? label : pivot_value_new_user_text ("text", SIZE_MAX)); } break; } @@ -2781,35 +2775,6 @@ ctables_table_output_different_axis (struct ctables *ct, struct ctables_table *t free (sorted); free (groups); } - struct ctables_cell *cell; - HMAP_FOR_EACH (cell, struct ctables_cell, node, &t->cells) - { - if (cell->hide) - continue; - - const struct ctables_nest *nest = &t->stacks[t->summary_axis].nests[cell->axes[t->summary_axis].stack_idx]; - const struct ctables_summary_spec_set *specs = &nest->specs[cell->sv]; - for (size_t j = 0; j < specs->n; j++) - { - size_t dindexes[3]; - size_t n_dindexes = 0; - - for (enum pivot_axis_type a = 0; a < PIVOT_N_AXES; a++) - if (d[a]) - { - int leaf = cell->axes[a].leaf; - if (a == t->summary_axis) - leaf += j; - dindexes[n_dindexes++] = leaf; - } - - double d = ctables_summary_value (cell, &cell->summaries[j], &specs->specs[j]); - struct pivot_value *value = pivot_value_new_number (d); - value->numeric.format = specs->specs[j].format; - pivot_table_put (pt, dindexes, n_dindexes, value); - } - } - pivot_table_submit (pt); } @@ -2921,17 +2886,9 @@ ctables_execute (struct dataset *ds, struct ctables *ct) for (size_t j = 0; j < stack->n; j++) { const struct ctables_nest *nest = &stack->nests[j]; - if (!nest->n) - continue; - - for (enum ctables_summary_variant sv = 0; sv < N_CSVS; sv++) - { - items[n_left] = (struct merge_item) { - .tiebreaker = n_left, - .set = &nest->specs[sv] - }; - n_left++; - } + if (nest->n) + for (enum ctables_summary_variant sv = 0; sv < N_CSVS; sv++) + items[n_left++] = (struct merge_item) { .set = &nest->specs[sv] }; } while (n_left > 0) @@ -2941,7 +2898,6 @@ ctables_execute (struct dataset *ds, struct ctables *ct) if (merge_item_compare_3way (&items[j], &min) < 0) min = items[j]; - /* XXX Add to 'merged' */ if (merged->n >= merged->allocated) merged->specs = x2nrealloc (merged->specs, &merged->allocated, sizeof *merged->specs); @@ -2963,6 +2919,7 @@ ctables_execute (struct dataset *ds, struct ctables *ct) } } +#if 0 for (size_t j = 0; j < merged->n; j++) printf ("%s\n", ctables_summary_function_name (merged->specs[j].function)); @@ -2978,6 +2935,7 @@ ctables_execute (struct dataset *ds, struct ctables *ct) printf ("\n"); } } +#endif } struct casereader *input = casereader_create_filter_weight (proc_open (ds), @@ -3007,7 +2965,7 @@ ctables_execute (struct dataset *ds, struct ctables *ct) for (size_t i = 0; i < ct->n_tables; i++) { struct ctables_table *t = ct->tables[i]; - if (t->summary_axis == t->slabels_position) + if (t->summary_axis == t->slabels_axis) ctables_table_output_same_axis (ct, ct->tables[i]); else ctables_table_output_different_axis (ct, ct->tables[i]); @@ -3250,7 +3208,7 @@ cmd_ctables (struct lexer *lexer, struct dataset *ds) struct ctables_table *t = xmalloc (sizeof *t); *t = (struct ctables_table) { .cells = HMAP_INITIALIZER (t->cells), - .slabels_position = PIVOT_AXIS_COLUMN, + .slabels_axis = PIVOT_AXIS_COLUMN, .slabels_visible = true, .row_labels = CTLP_NORMAL, .col_labels = CTLP_NORMAL, @@ -3349,17 +3307,17 @@ cmd_ctables (struct lexer *lexer, struct dataset *ds) { if (lex_match_id (lexer, "SLABELS")) { - while (lex_token (lexer) != T_SLASH) + while (lex_token (lexer) != T_SLASH && lex_token (lexer) != T_ENDCMD) { if (lex_match_id (lexer, "POSITION")) { lex_match (lexer, T_EQUALS); if (lex_match_id (lexer, "COLUMN")) - t->slabels_position = PIVOT_AXIS_COLUMN; + t->slabels_axis = PIVOT_AXIS_COLUMN; else if (lex_match_id (lexer, "ROW")) - t->slabels_position = PIVOT_AXIS_ROW; + t->slabels_axis = PIVOT_AXIS_ROW; else if (lex_match_id (lexer, "LAYER")) - t->slabels_position = PIVOT_AXIS_LAYER; + t->slabels_axis = PIVOT_AXIS_LAYER; else { lex_error_expecting (lexer, "COLUMN", "ROW", "LAYER"); @@ -3381,7 +3339,7 @@ cmd_ctables (struct lexer *lexer, struct dataset *ds) } else if (lex_match_id (lexer, "CLABELS")) { - while (lex_token (lexer) != T_SLASH) + while (lex_token (lexer) != T_SLASH && lex_token (lexer) != T_ENDCMD) { if (lex_match_id (lexer, "AUTO")) t->row_labels = t->col_labels = CTLP_NORMAL; -- 2.30.2