Fix missing buttonbox in frequencies dialog
[pspp] / src / math / categoricals.c
index b621d982931c72c0eadbb04e420d943e10a5cded..8bd6683e2c94ab5d92dbe840fef7737adf367fdf 100644 (file)
@@ -196,6 +196,31 @@ struct categoricals
   const struct payload *payload;
 };
 
+
+bool
+categoricals_isbalanced (const struct categoricals *cat)
+{
+  int i;
+
+  for (i = 0 ; i < cat->n_iap; ++i)
+    {
+      int v;
+      const struct interact_params *iap = &cat->iap[i];
+
+      double oval = -1.0;
+      for (v = 0; v < hmap_count (&iap->ivmap); ++v)
+       {
+         const struct interaction_value *iv = iap->reverse_interaction_value_map[v];
+         if (oval == -1.0)
+           oval = iv->cc;
+         if (oval != iv->cc)
+           return false;
+       }
+    }
+  return true;
+}
+
+
 static void
 categoricals_dump (const struct categoricals *cat)
 {
@@ -388,6 +413,7 @@ categoricals_update (struct categoricals *cat, const struct ccase *c)
     return;
 
   weight = cat->wv ? case_data (c, cat->wv)->f : 1.0;
+  weight = var_force_valid_weight (cat->wv, weight, NULL);
 
   assert (NULL == cat->reverse_variable_map_short);
   assert (NULL == cat->reverse_variable_map_long);
@@ -446,10 +472,8 @@ categoricals_update (struct categoricals *cat, const struct ccase *c)
 
       if (cat->payload)
        {
-         double weight = cat->wv ? case_data (c, cat->wv)->f : 1.0;
          cat->payload->update (cat->aux1, cat->aux2, node->user_data, c, weight);
        }
-
     }
 }