From a314660d711d514a3c24a9db7b4436f6b9731418 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Sat, 1 Jan 2022 17:41:50 -0800 Subject: [PATCH] summaries work --- src/language/stats/ctables.c | 47 ++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/src/language/stats/ctables.c b/src/language/stats/ctables.c index 4f23b3607d..26837f1b93 100644 --- a/src/language/stats/ctables.c +++ b/src/language/stats/ctables.c @@ -1406,7 +1406,6 @@ union ctables_summary /* XXX percentiles, median, mode, multiple response */ }; -#if 0 static void ctables_summary_init (union ctables_summary *s, const struct ctables_summary_spec *ss) @@ -1496,7 +1495,7 @@ ctables_summary_init (union ctables_summary *s, } } -static void +static void UNUSED ctables_summary_uninit (union ctables_summary *s, const struct ctables_summary_spec *ss) { @@ -1811,7 +1810,6 @@ ctables_summary_value (union ctables_summary *s, NOT_REACHED (); } -#endif struct ctables_freq { @@ -1825,8 +1823,7 @@ struct ctables_freq } axes[PIVOT_N_AXES]; - //union ctables_summary *summaries; - double count; + union ctables_summary *summaries; }; #if 0 @@ -1912,6 +1909,7 @@ ctables_freqtab_insert (struct ctables_table *t, [PIVOT_AXIS_COLUMN] = ic, [PIVOT_AXIS_LAYER] = il, }; + const struct var_array *ss = &t->vaas[t->summary_axis].vas[ix[t->summary_axis]]; size_t hash = 0; for (enum pivot_axis_type a = 0; a < PIVOT_N_AXES; a++) @@ -1938,8 +1936,7 @@ ctables_freqtab_insert (struct ctables_table *t, goto not_equal; } - f->count += weight; - return; + goto summarize; not_equal: ; } @@ -1956,8 +1953,15 @@ ctables_freqtab_insert (struct ctables_table *t, value_clone (&f->axes[a].values[i], case_data (c, va->vars[i]), var_get_width (va->vars[i])); } - f->count = weight; + f->summaries = xmalloc (ss->n_summaries * sizeof *f->summaries); + for (size_t i = 0; i < ss->n_summaries; i++) + ctables_summary_init (&f->summaries[i], &ss->summaries[i]); hmap_insert (&t->ft, &f->node, hash); + +summarize: + for (size_t i = 0; i < ss->n_summaries; i++) + ctables_summary_add (&f->summaries[i], &ss->summaries[i], ss->summary_var, + case_data (c, ss->summary_var), weight); } static bool @@ -2142,14 +2146,25 @@ ctables_execute (struct dataset *ds, struct ctables *ct) struct ctables_freq *f; HMAP_FOR_EACH (f, struct ctables_freq, node, &t->ft) { - size_t dindexes[3]; - size_t n_dindexes = 0; - - for (enum pivot_axis_type a = 0; a < PIVOT_N_AXES; a++) - if (d[a]) - dindexes[n_dindexes++] = f->axes[a].leaf; - pivot_table_put (pt, dindexes, n_dindexes, - pivot_value_new_number (f->count)); + const struct var_array *ss = &t->vaas[t->summary_axis].vas[f->axes[t->summary_axis].vaa_idx]; + for (size_t j = 0; j < ss->n_summaries; 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 = f->axes[a].leaf; + if (a == t->summary_axis) + leaf += j; + dindexes[n_dindexes++] = leaf; + } + + double value = ctables_summary_value (&f->summaries[j], &ss->summaries[j]); + pivot_table_put (pt, dindexes, n_dindexes, + pivot_value_new_number (value)); + } } pivot_table_submit (pt); -- 2.30.2