cateogrical missing values make sense now
[pspp] / src / language / stats / ctables.c
index 621b9bab50598b9c53b047b6da94d30d66b99dbc..b5152ef6365bedfdc1791010ce9ada75793c6382 100644 (file)
@@ -3322,7 +3322,7 @@ is_listwise_missing (const struct ctables_summary_spec_set *specs,
 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_included, 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];
@@ -3330,19 +3330,7 @@ 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 is_included;
-  bool scale_missing;
-  if (specs->is_scale)
-    {
-      is_included = !is_missing;
-      scale_missing = is_missing || is_listwise_missing (specs, c);
-    }
-  else
-    {
-      is_included = (cats[s->table->summary_axis][ss->summary_idx]->type
-                     != CCT_EXCLUDED_MISSING);
-      scale_missing = false;
-    }
+  bool scale_missing = specs->is_scale && (is_missing || is_listwise_missing (specs, c));
 
   for (size_t i = 0; i < specs->n; i++)
      ctables_summary_add (&cell->summaries[i], &specs->specs[i],
@@ -3387,7 +3375,7 @@ ctables_cell_add__ (struct ctables_section *s, const struct ccase *c,
 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_included, 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++)
@@ -3405,17 +3393,10 @@ recurse_totals (struct ctables_section *s, const struct ccase *c,
           if (total)
             {
               const struct ctables_category *save = cats[a][i];
-              if (save->type != CCT_EXCLUDED_MISSING)
-                /* XXX ^^ this shows why we need to keep track of
-                   'excluded_missing' (or 'is_included') at a high level,
-                   because it gets replaced by a total category.  So we need to
-                   restore that and plumb it through again.  */
-                {
-                  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);
-                  cats[a][i] = save;
-                }
+              cats[a][i] = total;
+              ctables_cell_add__ (s, c, cats, is_included, d_weight, e_weight);
+              recurse_totals (s, c, cats, is_included, d_weight, e_weight, a, i + 1);
+              cats[a][i] = save;
             }
         }
       start_nest = 0;
@@ -3425,7 +3406,7 @@ recurse_totals (struct ctables_section *s, const struct ccase *c,
 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_included, 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++)
@@ -3440,8 +3421,8 @@ recurse_subtotals (struct ctables_section *s, const struct ccase *c,
           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_included, d_weight, e_weight);
+              recurse_subtotals (s, c, cats, is_included, d_weight, e_weight, a, i + 1);
               cats[a][i] = save;
             }
         }
@@ -3475,7 +3456,7 @@ ctables_cell_insert (struct ctables_section *s,
 {
   const struct ctables_category *cats[PIVOT_N_AXES][10]; /* XXX */
 
-  bool excluded_missing = false;
+  bool is_included = true;
 
   for (enum pivot_axis_type a = 0; a < PIVOT_N_AXES; a++)
     {
@@ -3501,12 +3482,12 @@ ctables_cell_insert (struct ctables_section *s,
                   .hide = true,
                 };
                 cats[a][i] = &cct_excluded_missing;
-                excluded_missing = true;
+                is_included = false;
               }
         }
     }
 
-  if (!excluded_missing)
+  if (is_included)
     for (enum pivot_axis_type a = 0; a < PIVOT_N_AXES; a++)
       {
         const struct ctables_nest *nest = s->nests[a];
@@ -3519,9 +3500,9 @@ ctables_cell_insert (struct ctables_section *s,
             }
       }
 
-  ctables_cell_add__ (s, c, cats, 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);
+  ctables_cell_add__ (s, c, cats, is_included, d_weight, e_weight);
+  recurse_totals (s, c, cats, is_included, d_weight, e_weight, 0, 0);
+  recurse_subtotals (s, c, cats, is_included, d_weight, e_weight, 0, 0);
 }
 
 struct merge_item