#include "data/casereader.h"
#include "data/casewriter.h"
+#include "data/data-out.h"
#include "data/dataset.h"
#include "data/dictionary.h"
#include "data/mrset.h"
S(CTSF_LAYERPCT_SUM, "LAYERPCT.SUM", N_("Layer Sum %"), CTF_PERCENT, CTFA_SCALE) \
S(CTSF_LAYERROWPCT_SUM, "LAYERROWPCT.SUM", N_("Layer Row Sum %"), CTF_PERCENT, CTFA_SCALE) \
S(CTSF_LAYERCOLPCT_SUM, "LAYERCOLPCT.SUM", N_("Layer Column Sum %"), CTF_PERCENT, CTFA_SCALE) \
- \
- /* Multiple response sets. */ \
+
+#if 0 /* Multiple response sets not yet implemented. */
S(CTSF_RESPONSES, "RESPONSES", N_("Responses"), CTF_COUNT, CTFA_MRSETS) \
S(CTSF_ROWPCT_RESPONSES, "ROWPCT.RESPONSES", N_("Row Responses %"), CTF_PERCENT, CTFA_MRSETS) \
S(CTSF_COLPCT_RESPONSES, "COLPCT.RESPONSES", N_("Column Responses %"), CTF_PERCENT, CTFA_MRSETS) \
S(CTSF_LAYERPCT_COUNT_RESPONSES, "LAYERPCT.COUNT.RESPONSES", N_("Layer Count % (Base: Responses)"), CTF_PERCENT, CTFA_MRSETS) \
S(CTSF_LAYERROWPCT_COUNT_RESPONSES, "LAYERROWPCT.COUNT.RESPONSES", N_("Layer Row Count % (Base: Responses)"), CTF_PERCENT, CTFA_MRSETS) \
S(CTSF_LAYERCOLPCT_COUNT_RESPONSES, "LAYERCOLPCT.RESPONSES.COUNT", N_("Layer Column Count % (Base: Responses)"), CTF_PERCENT, CTFA_MRSETS)
+#endif
enum ctables_summary_function
{
#undef S
};
+static bool ctables_summary_function_is_count (enum ctables_summary_function);
+
enum ctables_domain_type
{
/* Within a section, where stacked variables divide one section from
const struct ctables_cell *example;
double d_valid; /* Dictionary weight. */
- double d_missing;
+ double d_count;
+ double d_total;
double e_valid; /* Effective weight */
- double e_missing;
+ double e_count;
+ double e_total;
};
enum ctables_summary_variant
struct ctables_domain *domains[N_CTDTS];
bool hide;
+
+ /* Is at least one value missing, whether included or excluded? */
+ bool is_missing;
+
+ /* Is at least one value missing and excluded? */
+ bool excluded_missing;
+
bool postcompute;
enum ctables_summary_variant sv;
const struct dictionary *dict;
struct pivot_table_look *look;
+ /* CTABLES has a number of extra formats that we implement via custom
+ currency specifications on an alternate fmt_settings. */
+#define CTEF_NEGPAREN FMT_CCA
+#define CTEF_NEQUAL FMT_CCB
+#define CTEF_PAREN FMT_CCC
+#define CTEF_PCTPAREN FMT_CCD
+ struct fmt_settings ctables_formats;
+
/* If this is NULL, zeros are displayed using the normal print format.
Otherwise, this string is displayed. */
char *zero;
size_t n;
size_t allocated;
+ /* The variable to which the summary specs are applied. */
struct variable *var;
+
+ /* Whether the variable to which the summary specs are applied is a scale
+ variable for the purpose of summarization.
+
+ (VALIDN and TOTALN act differently for summarizing scale and categorical
+ variables.) */
+ bool is_scale;
};
static void ctables_summary_spec_set_clone (struct ctables_summary_spec_set *,
CCT_VALUE,
CCT_LABEL,
CCT_FUNCTION,
+
+ /* For contributing to TOTALN. */
+ CCT_EXCLUDED_MISSING,
}
type;
};
/* Source location. This is null for CCT_TOTAL, CCT_VALUE, CCT_LABEL,
- CCT_FUNCTION. */
+ CCT_FUNCTION, CCT_EXCLUDED_MISSING. */
struct msg_location *location;
};
case CCT_LABEL:
case CCT_FUNCTION:
break;
+
+ case CCT_EXCLUDED_MISSING:
+ break;
}
}
&& a->sort_function == b->sort_function
&& a->sort_var == b->sort_var
&& a->percentile == b->percentile);
+
+ case CCT_EXCLUDED_MISSING:
+ return true;
}
NOT_REACHED ();
enum ctables_summary_function function;
double percentile; /* CTSF_PTILE only. */
char *label;
- struct fmt_spec format; /* XXX extra CTABLES formats */
+
+ struct fmt_spec format;
+ bool is_ctables_format; /* Is 'format' one of CTEF_*? */
+
size_t axis_idx;
};
.specs = specs,
.n = src->n,
.allocated = src->n,
- .var = src->var
+ .var = src->var,
+ .is_scale = src->is_scale,
};
}
return availability[f];
}
+static bool
+ctables_summary_function_is_count (enum ctables_summary_function f)
+{
+ switch (f)
+ {
+ case CTSF_COUNT:
+ case CTSF_ECOUNT:
+ case CTSF_ROWPCT_COUNT:
+ case CTSF_COLPCT_COUNT:
+ case CTSF_TABLEPCT_COUNT:
+ case CTSF_SUBTABLEPCT_COUNT:
+ case CTSF_LAYERPCT_COUNT:
+ case CTSF_LAYERROWPCT_COUNT:
+ case CTSF_LAYERCOLPCT_COUNT:
+ return true;
+
+ case CTSF_ROWPCT_VALIDN:
+ case CTSF_COLPCT_VALIDN:
+ case CTSF_TABLEPCT_VALIDN:
+ case CTSF_SUBTABLEPCT_VALIDN:
+ case CTSF_LAYERPCT_VALIDN:
+ case CTSF_LAYERROWPCT_VALIDN:
+ case CTSF_LAYERCOLPCT_VALIDN:
+ case CTSF_ROWPCT_TOTALN:
+ case CTSF_COLPCT_TOTALN:
+ case CTSF_TABLEPCT_TOTALN:
+ case CTSF_SUBTABLEPCT_TOTALN:
+ case CTSF_LAYERPCT_TOTALN:
+ case CTSF_LAYERROWPCT_TOTALN:
+ case CTSF_LAYERCOLPCT_TOTALN:
+ case CTSF_MAXIMUM:
+ case CTSF_MEAN:
+ case CTSF_MEDIAN:
+ case CTSF_MINIMUM:
+ case CTSF_MISSING:
+ case CTSF_MODE:
+ case CTSF_PTILE:
+ case CTSF_RANGE:
+ case CTSF_SEMEAN:
+ case CTSF_STDDEV:
+ case CTSF_SUM:
+ case CSTF_TOTALN:
+ case CTSF_ETOTALN:
+ case CTSF_VALIDN:
+ case CTSF_EVALIDN:
+ case CTSF_VARIANCE:
+ case CTSF_ROWPCT_SUM:
+ case CTSF_COLPCT_SUM:
+ case CTSF_TABLEPCT_SUM:
+ case CTSF_SUBTABLEPCT_SUM:
+ case CTSF_LAYERPCT_SUM:
+ case CTSF_LAYERROWPCT_SUM:
+ case CTSF_LAYERCOLPCT_SUM:
+ return false;
+ }
+ NOT_REACHED ();
+}
+
+
static bool
parse_ctables_summary_function (struct lexer *lexer,
enum ctables_summary_function *f)
add_summary_spec (struct ctables_axis *axis,
enum ctables_summary_function function, double percentile,
const char *label, const struct fmt_spec *format,
- const struct msg_location *loc, enum ctables_summary_variant sv)
+ bool is_ctables_format, const struct msg_location *loc,
+ enum ctables_summary_variant sv)
{
if (axis->op == CTAO_VAR)
{
break;
case CTFA_SCALE:
+#if 0
if (!axis->scale)
{
msg_at (SE, loc,
var_name);
return false;
}
+#endif
break;
case CTFA_ALL:
.label = xstrdup (label),
.format = (format ? *format
: ctables_summary_default_format (function, &axis->var)),
+ .is_ctables_format = is_ctables_format,
};
return true;
}
{
for (size_t i = 0; i < 2; i++)
if (!add_summary_spec (axis->subs[i], function, percentile, label,
- format, loc, sv))
+ format, is_ctables_format, loc, sv))
return false;
return true;
}
return s[strcspn (s, "0123456789")] != '\0';
}
+static bool
+parse_ctables_format_specifier (struct lexer *lexer, struct fmt_spec *format,
+ bool *is_ctables_format)
+{
+ char type[FMT_TYPE_LEN_MAX + 1];
+ if (!parse_abstract_format_specifier__ (lexer, type, &format->w, &format->d))
+ return false;
+
+ if (!strcasecmp (type, "NEGPAREN"))
+ format->type = CTEF_NEGPAREN;
+ else if (!strcasecmp (type, "NEQUAL"))
+ format->type = CTEF_NEQUAL;
+ else if (!strcasecmp (type, "PAREN"))
+ format->type = CTEF_PAREN;
+ else if (!strcasecmp (type, "PCTPAREN"))
+ format->type = CTEF_PCTPAREN;
+ else
+ {
+ *is_ctables_format = false;
+ return (parse_format_specifier (lexer, format)
+ && fmt_check_output (format)
+ && fmt_check_type_compat (format, VAL_NUMERIC));
+ }
+
+ if (format->w < 2)
+ {
+ msg (SE, _("Output format %s requires width 2 or greater."), type);
+ return false;
+ }
+ else if (format->d > format->w - 1)
+ {
+ msg (SE, _("Output format %s requires width greater than decimals."),
+ type);
+ return false;
+ }
+ else
+ {
+ *is_ctables_format = true;
+ return true;
+ }
+}
+
static struct ctables_axis *
ctables_axis_parse_postfix (struct ctables_axis_parse_ctx *ctx)
{
/* Parse format. */
struct fmt_spec format;
const struct fmt_spec *formatp;
+ bool is_ctables_format = false;
if (lex_token (ctx->lexer) == T_ID
&& has_digit (lex_tokcstr (ctx->lexer)))
{
- if (!parse_format_specifier (ctx->lexer, &format)
- || !fmt_check_output (&format)
- || !fmt_check_type_compat (&format, VAL_NUMERIC))
+ if (!parse_ctables_format_specifier (ctx->lexer, &format,
+ &is_ctables_format))
{
free (label);
goto error;
struct msg_location *loc = lex_ofs_location (ctx->lexer, start_ofs,
lex_ofs (ctx->lexer) - 1);
- add_summary_spec (sub, function, percentile, label, formatp, loc, sv);
+ add_summary_spec (sub, function, percentile, label, formatp,
+ is_ctables_format, loc, sv);
free (label);
msg_location_destroy (loc);
case CCT_VALUE:
case CCT_LABEL:
case CCT_FUNCTION:
+ case CCT_EXCLUDED_MISSING:
break;
}
}
{
ctables_summary_spec_set_clone (&nest->specs[sv], &a->specs[sv]);
nest->specs[sv].var = a->var.var;
+ nest->specs[sv].is_scale = a->scale;
}
return (struct ctables_stack) { .nests = nest, .n = 1 };
union ctables_summary
{
/* COUNT, VALIDN, TOTALN. */
- struct
- {
- double valid;
- double missing;
- };
+ double count;
/* MINIMUM, MAXIMUM, RANGE. */
struct
case CTSF_ETOTALN:
case CTSF_VALIDN:
case CTSF_EVALIDN:
- s->missing = s->valid = 0;
+ s->count = 0;
break;
case CTSF_MAXIMUM:
s->ovalue = SYSMIS;
}
break;
-
- case CTSF_RESPONSES:
- case CTSF_ROWPCT_RESPONSES:
- case CTSF_COLPCT_RESPONSES:
- case CTSF_TABLEPCT_RESPONSES:
- case CTSF_SUBTABLEPCT_RESPONSES:
- case CTSF_LAYERPCT_RESPONSES:
- case CTSF_LAYERROWPCT_RESPONSES:
- case CTSF_LAYERCOLPCT_RESPONSES:
- case CTSF_ROWPCT_RESPONSES_COUNT:
- case CTSF_COLPCT_RESPONSES_COUNT:
- case CTSF_TABLEPCT_RESPONSES_COUNT:
- case CTSF_SUBTABLEPCT_RESPONSES_COUNT:
- case CTSF_LAYERPCT_RESPONSES_COUNT:
- case CTSF_LAYERROWPCT_RESPONSES_COUNT:
- case CTSF_LAYERCOLPCT_RESPONSES_COUNT:
- case CTSF_ROWPCT_COUNT_RESPONSES:
- case CTSF_COLPCT_COUNT_RESPONSES:
- case CTSF_TABLEPCT_COUNT_RESPONSES:
- case CTSF_SUBTABLEPCT_COUNT_RESPONSES:
- case CTSF_LAYERPCT_COUNT_RESPONSES:
- case CTSF_LAYERROWPCT_COUNT_RESPONSES:
- case CTSF_LAYERCOLPCT_COUNT_RESPONSES:
- NOT_REACHED ();
}
}
case CTSF_PTILE:
casewriter_destroy (s->writer);
break;
-
- case CTSF_RESPONSES:
- case CTSF_ROWPCT_RESPONSES:
- case CTSF_COLPCT_RESPONSES:
- case CTSF_TABLEPCT_RESPONSES:
- case CTSF_SUBTABLEPCT_RESPONSES:
- case CTSF_LAYERPCT_RESPONSES:
- case CTSF_LAYERROWPCT_RESPONSES:
- case CTSF_LAYERCOLPCT_RESPONSES:
- case CTSF_ROWPCT_RESPONSES_COUNT:
- case CTSF_COLPCT_RESPONSES_COUNT:
- case CTSF_TABLEPCT_RESPONSES_COUNT:
- case CTSF_SUBTABLEPCT_RESPONSES_COUNT:
- case CTSF_LAYERPCT_RESPONSES_COUNT:
- case CTSF_LAYERROWPCT_RESPONSES_COUNT:
- case CTSF_LAYERCOLPCT_RESPONSES_COUNT:
- case CTSF_ROWPCT_COUNT_RESPONSES:
- case CTSF_COLPCT_COUNT_RESPONSES:
- case CTSF_TABLEPCT_COUNT_RESPONSES:
- case CTSF_SUBTABLEPCT_COUNT_RESPONSES:
- case CTSF_LAYERPCT_COUNT_RESPONSES:
- case CTSF_LAYERROWPCT_COUNT_RESPONSES:
- case CTSF_LAYERCOLPCT_COUNT_RESPONSES:
- NOT_REACHED ();
}
}
static void
-ctables_summary_add (union ctables_summary *s,
+ctables_summary_add (const struct ctables_cell *cell, union ctables_summary *s,
const struct ctables_summary_spec *ss,
const struct variable *var, const union value *value,
+ bool is_scale, bool is_missing,
double d_weight, double e_weight)
{
+ /* To determine whether a case is included in a given table for a particular
+ kind of summary, consider the following charts for each variable in the
+ table. Only if "yes" appears for every variable for the summary is the
+ case counted.
+
+ Categorical variables: VALIDN COUNT TOTALN
+ Valid values in included categories yes yes yes
+ Missing values in included categories --- yes yes
+ Missing values in excluded categories --- --- yes
+ Valid values in excluded categories --- --- ---
+
+ Scale variables: VALIDN COUNT TOTALN
+ Valid value yes yes yes
+ Missing value --- yes yes
+
+ Missing values include both user- and system-missing. (The system-missing
+ value is always in an excluded category.)
+ */
switch (ss->function)
{
- case CTSF_COUNT:
case CSTF_TOTALN:
+ s->count += d_weight;
+ break;
+
+ case CTSF_COUNT:
+ if (is_scale || !cell->excluded_missing)
+ s->count += d_weight;
+ break;
+
case CTSF_VALIDN:
- if (var_is_value_missing (var, value))
- s->missing += d_weight;
- else
- s->valid += d_weight;
+ if (is_scale
+ ? !var_is_value_missing (var, value)
+ : !is_missing)
+ s->count += d_weight;
+ break;
+
+ case CTSF_MISSING:
+ if (is_missing)
+ s->count += d_weight;
break;
case CTSF_ECOUNT:
case CTSF_LAYERPCT_TOTALN:
case CTSF_LAYERROWPCT_TOTALN:
case CTSF_LAYERCOLPCT_TOTALN:
- case CTSF_MISSING:
- case CTSF_ETOTALN:
+ s->count += d_weight;
+ break;
+
case CTSF_EVALIDN:
- if (var_is_value_missing (var, value))
- s->missing += e_weight;
- else
- s->valid += e_weight;
+ if (is_scale
+ ? !var_is_value_missing (var, value)
+ : !is_missing)
+ s->count += e_weight;
+ break;
+
+ case CTSF_ETOTALN:
+ s->count += e_weight;
break;
case CTSF_MAXIMUM:
casewriter_write (s->writer, c);
}
break;
-
- case CTSF_RESPONSES:
- case CTSF_ROWPCT_RESPONSES:
- case CTSF_COLPCT_RESPONSES:
- case CTSF_TABLEPCT_RESPONSES:
- case CTSF_SUBTABLEPCT_RESPONSES:
- case CTSF_LAYERPCT_RESPONSES:
- case CTSF_LAYERROWPCT_RESPONSES:
- case CTSF_LAYERCOLPCT_RESPONSES:
- case CTSF_ROWPCT_RESPONSES_COUNT:
- case CTSF_COLPCT_RESPONSES_COUNT:
- case CTSF_TABLEPCT_RESPONSES_COUNT:
- case CTSF_SUBTABLEPCT_RESPONSES_COUNT:
- case CTSF_LAYERPCT_RESPONSES_COUNT:
- case CTSF_LAYERROWPCT_RESPONSES_COUNT:
- case CTSF_LAYERCOLPCT_RESPONSES_COUNT:
- case CTSF_ROWPCT_COUNT_RESPONSES:
- case CTSF_COLPCT_COUNT_RESPONSES:
- case CTSF_TABLEPCT_COUNT_RESPONSES:
- case CTSF_SUBTABLEPCT_COUNT_RESPONSES:
- case CTSF_LAYERPCT_COUNT_RESPONSES:
- case CTSF_LAYERROWPCT_COUNT_RESPONSES:
- case CTSF_LAYERCOLPCT_COUNT_RESPONSES:
- NOT_REACHED ();
}
}
case CTSF_MEDIAN:
case CTSF_PTILE:
case CTSF_MODE:
- case CTSF_RESPONSES:
NOT_REACHED ();
case CTSF_COLPCT_COUNT:
- case CTSF_COLPCT_COUNT_RESPONSES:
- case CTSF_COLPCT_RESPONSES:
- case CTSF_COLPCT_RESPONSES_COUNT:
case CTSF_COLPCT_SUM:
case CTSF_COLPCT_TOTALN:
case CTSF_COLPCT_VALIDN:
return CTDT_COL;
case CTSF_LAYERCOLPCT_COUNT:
- case CTSF_LAYERCOLPCT_COUNT_RESPONSES:
- case CTSF_LAYERCOLPCT_RESPONSES:
- case CTSF_LAYERCOLPCT_RESPONSES_COUNT:
case CTSF_LAYERCOLPCT_SUM:
case CTSF_LAYERCOLPCT_TOTALN:
case CTSF_LAYERCOLPCT_VALIDN:
return CTDT_LAYERCOL;
case CTSF_LAYERPCT_COUNT:
- case CTSF_LAYERPCT_COUNT_RESPONSES:
- case CTSF_LAYERPCT_RESPONSES:
- case CTSF_LAYERPCT_RESPONSES_COUNT:
case CTSF_LAYERPCT_SUM:
case CTSF_LAYERPCT_TOTALN:
case CTSF_LAYERPCT_VALIDN:
return CTDT_LAYER;
case CTSF_LAYERROWPCT_COUNT:
- case CTSF_LAYERROWPCT_COUNT_RESPONSES:
- case CTSF_LAYERROWPCT_RESPONSES:
- case CTSF_LAYERROWPCT_RESPONSES_COUNT:
case CTSF_LAYERROWPCT_SUM:
case CTSF_LAYERROWPCT_TOTALN:
case CTSF_LAYERROWPCT_VALIDN:
return CTDT_LAYERROW;
case CTSF_ROWPCT_COUNT:
- case CTSF_ROWPCT_COUNT_RESPONSES:
- case CTSF_ROWPCT_RESPONSES:
- case CTSF_ROWPCT_RESPONSES_COUNT:
case CTSF_ROWPCT_SUM:
case CTSF_ROWPCT_TOTALN:
case CTSF_ROWPCT_VALIDN:
return CTDT_ROW;
case CTSF_SUBTABLEPCT_COUNT:
- case CTSF_SUBTABLEPCT_COUNT_RESPONSES:
- case CTSF_SUBTABLEPCT_RESPONSES:
- case CTSF_SUBTABLEPCT_RESPONSES_COUNT:
case CTSF_SUBTABLEPCT_SUM:
case CTSF_SUBTABLEPCT_TOTALN:
case CTSF_SUBTABLEPCT_VALIDN:
return CTDT_SUBTABLE;
case CTSF_TABLEPCT_COUNT:
- case CTSF_TABLEPCT_COUNT_RESPONSES:
- case CTSF_TABLEPCT_RESPONSES:
- case CTSF_TABLEPCT_RESPONSES_COUNT:
case CTSF_TABLEPCT_SUM:
case CTSF_TABLEPCT_TOTALN:
case CTSF_TABLEPCT_VALIDN:
{
case CTSF_COUNT:
case CTSF_ECOUNT:
- return s->valid;
+ return s->count;
case CTSF_ROWPCT_COUNT:
case CTSF_COLPCT_COUNT:
{
enum ctables_domain_type d = ctables_function_domain (ss->function);
return (cell->domains[d]->e_valid
- ? s->valid / cell->domains[d]->e_valid * 100
+ ? s->count / cell->domains[d]->e_valid * 100
: SYSMIS);
}
NOT_REACHED ();
case CTSF_MISSING:
- return s->missing;
+ return s->count;
case CSTF_TOTALN:
case CTSF_ETOTALN:
- return s->valid + s->missing;
+ return s->count;
case CTSF_VALIDN:
+ return s->count;
+
case CTSF_EVALIDN:
- return s->valid;
+ return s->count;
case CTSF_MAXIMUM:
return s->max;
statistic_destroy (&mode->parent.parent);
}
return s->ovalue;
-
- case CTSF_RESPONSES:
- case CTSF_ROWPCT_RESPONSES:
- case CTSF_COLPCT_RESPONSES:
- case CTSF_TABLEPCT_RESPONSES:
- case CTSF_SUBTABLEPCT_RESPONSES:
- case CTSF_LAYERPCT_RESPONSES:
- case CTSF_LAYERROWPCT_RESPONSES:
- case CTSF_LAYERCOLPCT_RESPONSES:
- case CTSF_ROWPCT_RESPONSES_COUNT:
- case CTSF_COLPCT_RESPONSES_COUNT:
- case CTSF_TABLEPCT_RESPONSES_COUNT:
- case CTSF_SUBTABLEPCT_RESPONSES_COUNT:
- case CTSF_LAYERPCT_RESPONSES_COUNT:
- case CTSF_LAYERROWPCT_RESPONSES_COUNT:
- case CTSF_LAYERCOLPCT_RESPONSES_COUNT:
- case CTSF_ROWPCT_COUNT_RESPONSES:
- case CTSF_COLPCT_COUNT_RESPONSES:
- case CTSF_TABLEPCT_COUNT_RESPONSES:
- case CTSF_SUBTABLEPCT_COUNT_RESPONSES:
- case CTSF_LAYERPCT_COUNT_RESPONSES:
- case CTSF_LAYERROWPCT_COUNT_RESPONSES:
- case CTSF_LAYERCOLPCT_COUNT_RESPONSES:
- NOT_REACHED ();
}
NOT_REACHED ();
case CCT_SUBTOTAL:
case CCT_TOTAL:
case CCT_POSTCOMPUTE:
+ case CCT_EXCLUDED_MISSING:
/* Must be equal. */
continue;
ctables_categories_match (const struct ctables_categories *c,
const union value *v, const struct variable *var)
{
+ if (var_is_numeric (var) && v->f == SYSMIS)
+ return NULL;
+
const struct ctables_category *othernm = NULL;
for (size_t i = c->n_cats; i-- > 0; )
{
case CCT_FUNCTION:
return (cat->include_missing || !var_is_value_missing (var, v) ? cat
: NULL);
+
+ case CCT_EXCLUDED_MISSING:
+ break;
}
}
cell = xmalloc (sizeof *cell);
cell->hide = false;
+ cell->is_missing = false;
+ cell->excluded_missing = false;
cell->sv = sv;
cell->contributes_to_domains = true;
cell->postcompute = false;
for (size_t i = 0; i < nest->n; i++)
{
const struct ctables_category *cat = cats[a][i];
+ const struct variable *var = nest->vars[i];
+ const union value *value = case_data (c, var);
if (i != nest->scale_idx)
{
const struct ctables_category *subtotal = cat->subtotal;
|| cat->type == CCT_SUBTOTAL
|| cat->type == CCT_POSTCOMPUTE)
cell->contributes_to_domains = false;
+ else if (var_is_value_missing (var, value))
+ cell->is_missing = true;
+ if (cat->type == CCT_EXCLUDED_MISSING)
+ cell->excluded_missing = true;
if (cat->type == CCT_POSTCOMPUTE)
cell->postcompute = true;
}
cell->axes[a].cvs[i].category = cat;
- value_clone (&cell->axes[a].cvs[i].value, case_data (c, nest->vars[i]),
- var_get_width (nest->vars[i]));
+ value_clone (&cell->axes[a].cvs[i].value, value, var_get_width (var));
}
}
static void
ctables_cell_add__ (struct ctables_section *s, const struct ccase *c,
const struct ctables_category *cats[PIVOT_N_AXES][10],
- double d_weight, double e_weight)
+ bool is_missing, double d_weight, double e_weight)
{
struct ctables_cell *cell = ctables_cell_insert__ (s, c, cats);
const struct ctables_nest *ss = s->nests[s->table->summary_axis];
const struct ctables_summary_spec_set *specs = &ss->specs[cell->sv];
for (size_t i = 0; i < specs->n; i++)
- ctables_summary_add (&cell->summaries[i], &specs->specs[i], specs->var,
- case_data (c, specs->var), d_weight, e_weight);
+ ctables_summary_add (cell, &cell->summaries[i], &specs->specs[i],
+ specs->var, case_data (c, specs->var), specs->is_scale,
+ is_missing, d_weight, e_weight);
if (cell->contributes_to_domains)
{
for (enum ctables_domain_type dt = 0; dt < N_CTDTS; dt++)
{
- cell->domains[dt]->d_valid += d_weight;
- cell->domains[dt]->e_valid += e_weight;
+ struct ctables_domain *d = cell->domains[dt];
+ d->d_total += d_weight;
+ d->e_total += e_weight;
+ if (!cell->excluded_missing)
+ {
+ d->d_count += d_weight;
+ d->e_count += e_weight;
+ }
+ if (!cell->is_missing)
+ {
+ d->d_valid += d_weight;
+ d->e_valid += e_weight;
+ }
}
}
}
static void
recurse_totals (struct ctables_section *s, const struct ccase *c,
const struct ctables_category *cats[PIVOT_N_AXES][10],
- double d_weight, double e_weight,
+ bool is_missing, double d_weight, double e_weight,
enum pivot_axis_type start_axis, size_t start_nest)
{
for (enum pivot_axis_type a = start_axis; a < PIVOT_N_AXES; a++)
{
const struct ctables_category *save = cats[a][i];
cats[a][i] = total;
- ctables_cell_add__ (s, c, cats, d_weight, e_weight);
- recurse_totals (s, c, cats, d_weight, e_weight, a, i + 1);
+ ctables_cell_add__ (s, c, cats, is_missing, d_weight, e_weight);
+ recurse_totals (s, c, cats, is_missing,
+ d_weight, e_weight, a, i + 1);
cats[a][i] = save;
}
}
static void
recurse_subtotals (struct ctables_section *s, const struct ccase *c,
const struct ctables_category *cats[PIVOT_N_AXES][10],
- double d_weight, double e_weight,
+ bool is_missing, double d_weight, double e_weight,
enum pivot_axis_type start_axis, size_t start_nest)
{
for (enum pivot_axis_type a = start_axis; a < PIVOT_N_AXES; a++)
if (save->subtotal)
{
cats[a][i] = save->subtotal;
- ctables_cell_add__ (s, c, cats, d_weight, e_weight);
- recurse_subtotals (s, c, cats, d_weight, e_weight, a, i + 1);
+ ctables_cell_add__ (s, c, cats, is_missing, d_weight, e_weight);
+ recurse_subtotals (s, c, cats, is_missing,
+ d_weight, e_weight, a, i + 1);
cats[a][i] = save;
}
}
double d_weight, double e_weight)
{
const struct ctables_category *cats[PIVOT_N_AXES][10]; /* XXX */
+ bool is_missing = false;
+ bool excluded_missing = false;
for (enum pivot_axis_type a = 0; a < PIVOT_N_AXES; a++)
{
const struct ctables_nest *nest = s->nests[a];
const struct variable *var = nest->vars[i];
const union value *value = case_data (c, var);
- if (var_is_numeric (var) && value->f == SYSMIS)
- return;
+ bool var_missing = var_is_value_missing (var, value) != 0;
+ if (var_missing)
+ is_missing = true;
cats[a][i] = ctables_categories_match (
s->table->categories[var_get_dict_index (var)], value, var);
if (!cats[a][i])
- return;
+ {
+ if (!is_missing)
+ return;
+
+ static const struct ctables_category cct_excluded_missing = {
+ .type = CCT_EXCLUDED_MISSING,
+ .hide = true,
+ };
+ cats[a][i] = &cct_excluded_missing;
+ excluded_missing = true;
+ }
}
}
- for (enum pivot_axis_type a = 0; a < PIVOT_N_AXES; a++)
- {
- const struct ctables_nest *nest = s->nests[a];
- for (size_t i = 0; i < nest->n; i++)
- if (i != nest->scale_idx)
- {
- const struct variable *var = nest->vars[i];
- const union value *value = case_data (c, var);
- ctables_add_occurrence (var, value, &s->occurrences[a][i]);
- }
- }
+ if (!excluded_missing)
+ for (enum pivot_axis_type a = 0; a < PIVOT_N_AXES; a++)
+ {
+ const struct ctables_nest *nest = s->nests[a];
+ for (size_t i = 0; i < nest->n; i++)
+ if (i != nest->scale_idx)
+ {
+ const struct variable *var = nest->vars[i];
+ const union value *value = case_data (c, var);
+ ctables_add_occurrence (var, value, &s->occurrences[a][i]);
+ }
+ }
- ctables_cell_add__ (s, c, cats, d_weight, e_weight);
+ ctables_cell_add__ (s, c, cats, is_missing, d_weight, e_weight);
- recurse_totals (s, c, cats, d_weight, e_weight, 0, 0);
- recurse_subtotals (s, c, cats, d_weight, e_weight, 0, 0);
+ if (!excluded_missing)
+ {
+ recurse_totals (s, c, cats, is_missing, d_weight, e_weight, 0, 0);
+ recurse_subtotals (s, c, cats, is_missing, d_weight, e_weight, 0, 0);
+ }
}
struct merge_item
}
type;
+ enum settings_value_show vlabel; /* CTL_VAR only. */
size_t var_idx;
};
struct ctables_level *levels = xnmalloc (1 + 2 * max_depth, sizeof *levels);
{
levels[n_levels++] = (struct ctables_level) {
.type = CTL_VAR,
+ .vlabel = (enum settings_value_show) vlabel,
.var_idx = k,
};
}
const struct variable *var = nest->vars[level->var_idx];
struct pivot_value *label;
if (level->type == CTL_VAR)
- label = pivot_value_new_variable (var);
+ {
+ label = pivot_value_new_variable (var);
+ label->variable.show = level->vlabel;
+ }
else if (level->type == CTL_CATEGORY)
{
const struct ctables_cell_value *cv = &cell->axes[a].cvs[level->var_idx];
dindexes[n_dindexes++] = leaf;
}
+ const struct ctables_summary_spec *ss = &specs->specs[j];
+
double d = (cell->postcompute
? ctables_cell_calculate_postcompute (s, cell)
- : 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;
+ : ctables_summary_value (cell, &cell->summaries[j], ss));
+ struct pivot_value *value;
+ if (ct->hide_threshold != 0
+ && d < ct->hide_threshold
+ && (cell->postcompute
+ ? false /* XXX */
+ : ctables_summary_function_is_count (ss->function)))
+ {
+ value = pivot_value_new_user_text_nocopy (
+ xasprintf ("<%d", ct->hide_threshold));
+ }
+ else if (d == 0 && ct->zero)
+ value = pivot_value_new_user_text (ct->zero, SIZE_MAX);
+ else if (d == SYSMIS && ct->missing)
+ value = pivot_value_new_user_text (ct->missing, SIZE_MAX);
+ else if (specs->specs[j].is_ctables_format)
+ {
+ char *s = data_out_stretchy (&(union value) { .f = d },
+ "UTF-8",
+ &specs->specs[j].format,
+ &ct->ctables_formats, NULL);
+ value = pivot_value_new_user_text_nocopy (s);
+ }
+ else
+ {
+ value = pivot_value_new_number (d);
+ value->numeric.format = specs->specs[j].format;
+ }
pivot_table_put (pt, dindexes, n_dindexes, value);
}
}
specs->n = 1;
enum ctables_summary_function function
- = specs->var ? CTSF_MEAN : CTSF_COUNT;
+ = specs->is_scale ? CTSF_MEAN : CTSF_COUNT;
struct ctables_var var = { .is_mrset = false, .var = specs->var };
*specs->specs = (struct ctables_summary_spec) {
if (c->include_missing || !var_is_value_missing (var, &vl->value))
ctables_add_occurrence (var, &vl->value, occurrences);
break;
+
+ case CCT_EXCLUDED_MISSING:
+ break;
}
}
}
for (size_t i = 0; i < n_vars; i++)
vlabels[i] = (enum ctables_vlabel) tvars;
+ struct pivot_table_look *look = pivot_table_look_unshare (
+ pivot_table_look_ref (pivot_table_look_get_default ()));
+ look->omit_empty = false;
+
struct ctables *ct = xmalloc (sizeof *ct);
*ct = (struct ctables) {
.dict = dataset_dict (ds),
- .look = pivot_table_look_unshare (pivot_table_look_ref (
- pivot_table_look_get_default ())),
+ .look = look,
+ .ctables_formats = FMT_SETTINGS_INIT,
.vlabels = vlabels,
.postcomputes = HMAP_INITIALIZER (ct->postcomputes),
- .hide_threshold = 5,
};
- ct->look->omit_empty = false;
+
+ struct ctf
+ {
+ enum fmt_type type;
+ const char *dot_string;
+ const char *comma_string;
+ };
+ static const struct ctf ctfs[4] = {
+ { CTEF_NEGPAREN, "(,,,)", "(...)" },
+ { CTEF_NEQUAL, "-,N=,,", "-.N=.." },
+ { CTEF_PAREN, "-,(,),", "-.(.)." },
+ { CTEF_PCTPAREN, "-,(,%),", "-.(.%)." },
+ };
+ bool is_dot = settings_get_fmt_settings ()->decimal == '.';
+ for (size_t i = 0; i < 4; i++)
+ {
+ const char *s = is_dot ? ctfs[i].dot_string : ctfs[i].comma_string;
+ fmt_settings_set_cc (&ct->ctables_formats, ctfs[i].type,
+ fmt_number_style_from_string (s));
+ }
if (!lex_force_match (lexer, T_SLASH))
goto error;
if (!ct->e_weight)
goto error;
}
- else if (lex_match_id (lexer, "HIDESMALLCOUNTS"))
+ else if (lex_match_id (lexer, " HIDESMALLCOUNTS"))
{
- if (!lex_force_match_id (lexer, "COUNT"))
- goto error;
- lex_match (lexer, T_EQUALS);
- if (!lex_force_int_range (lexer, "HIDESMALLCOUNTS COUNT", 2, INT_MAX))
- goto error;
- ct->hide_threshold = lex_integer (lexer);
- lex_get (lexer);
+ if (lex_match_id (lexer, "COUNT"))
+ {
+ lex_match (lexer, T_EQUALS);
+ if (!lex_force_int_range (lexer, "HIDESMALLCOUNTS COUNT",
+ 2, INT_MAX))
+ goto error;
+ ct->hide_threshold = lex_integer (lexer);
+ lex_get (lexer);
+ }
+ else if (ct->hide_threshold == 0)
+ ct->hide_threshold = 5;
}
else
{