summary_add makes sense, finally
[pspp] / src / language / stats / ctables.c
index 68d3e852bada61724c5fcfd5f45696eca28c7903..cb38a37dea3a7801fe4848c9b3379c769e58975b 100644 (file)
@@ -1224,7 +1224,6 @@ add_summary_spec (struct ctables_axis *axis,
 static struct ctables_axis *ctables_axis_parse_stack (
   struct ctables_axis_parse_ctx *);
 
-
 static struct ctables_axis *
 ctables_axis_parse_primary (struct ctables_axis_parse_ctx *ctx)
 {
@@ -2658,59 +2657,45 @@ static void
 ctables_summary_add (union ctables_summary *s,
                      const struct ctables_summary_spec *ss,
                      const union value *value,
-                     bool is_scale, bool is_scale_missing,
                      bool is_missing, bool is_included,
                      double 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.
+     kind of summary, consider the following charts for the variable being
+     summarized.  Only if "yes" appears is the case counted.
 
-     Categorical variables:                    VALIDN   COUNT   TOTALN
+     Categorical variables:                    VALIDN   other   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
+     Scale variables:                          VALIDN   other   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.)
+
+     One way to interpret the above table is that scale variables are like
+     categorical variables in which all values are in included categories.
   */
   switch (ss->function)
     {
     case CTSF_TOTALN:
-      s->count += weight;
-      break;
-
     case CTSF_areaPCT_TOTALN:
       s->count += weight;
       break;
 
     case CTSF_COUNT:
-      if (is_scale || is_included)
-        s->count += weight;
-      break;
-
     case CTSF_areaPCT_COUNT:
-      if (is_scale || is_included)
+      if (is_included)
         s->count += weight;
       break;
 
     case CTSF_VALIDN:
-      if (is_scale
-          ? !is_scale_missing
-          : !is_missing)
-        s->count += weight;
-      break;
-
     case CTSF_areaPCT_VALIDN:
-      if (is_scale
-          ? !is_scale_missing
-          : !is_missing)
+      if (!is_missing)
         s->count += weight;
       break;
 
@@ -2718,16 +2703,14 @@ ctables_summary_add (union ctables_summary *s,
       break;
 
     case CTSF_MISSING:
-      if (is_scale
-          ? is_scale_missing
-          : is_missing)
+      if (is_missing)
         s->count += weight;
       break;
 
     case CTSF_MAXIMUM:
     case CTSF_MINIMUM:
     case CTSF_RANGE:
-      if (!is_scale_missing)
+      if (!is_missing)
         {
           if (s->min == SYSMIS || value->f < s->min)
             s->min = value->f;
@@ -2741,19 +2724,19 @@ ctables_summary_add (union ctables_summary *s,
     case CTSF_STDDEV:
     case CTSF_SUM:
     case CTSF_VARIANCE:
-      if (!is_scale_missing)
+      if (!is_missing)
         moments1_add (s->moments, value->f, weight);
       break;
 
     case CTSF_areaPCT_SUM:
-      if (!is_missing && !is_scale_missing)
+      if (!is_missing)
         moments1_add (s->moments, value->f, weight);
       break;
 
     case CTSF_MEDIAN:
     case CTSF_MODE:
     case CTSF_PTILE:
-      if (!is_scale_missing)
+      if (!is_missing)
         {
           s->ovalid += weight;
 
@@ -3297,12 +3280,13 @@ ctables_cell_add__ (struct ctables_section *s, const struct ccase *c,
   const struct ctables_summary_spec_set *specs = &ss->specs[cell->sv];
   const union value *value = case_data (c, specs->var);
   bool is_missing = var_is_value_missing (specs->var, value);
-  bool scale_missing = specs->is_scale && (is_missing || is_listwise_missing (specs, c));
+  bool is_scale_missing
+    = is_missing || (specs->is_scale && is_listwise_missing (specs, c));
 
   for (size_t i = 0; i < specs->n; i++)
      ctables_summary_add (&cell->summaries[i], &specs->specs[i], value,
-                          specs->is_scale, scale_missing, is_missing,
-                          is_included, weight[specs->specs[i].weighting]);
+                          is_scale_missing, is_included,
+                          weight[specs->specs[i].weighting]);
   for (enum ctables_area_type at = 0; at < N_CTATS; at++)
     if (!(cell->omit_areas && (1u << at)))
       {
@@ -3315,7 +3299,7 @@ ctables_cell_add__ (struct ctables_section *s, const struct ccase *c,
           {
             add_weight (a->valid, weight);
 
-            if (!scale_missing)
+            if (!is_scale_missing)
               for (size_t i = 0; i < s->table->n_sum_vars; i++)
                 {
                   const struct variable *var = s->table->sum_vars[i];