dictionary: New function dict_get_weight_format().
authorBen Pfaff <blp@cs.stanford.edu>
Tue, 25 Dec 2018 05:45:52 +0000 (21:45 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Tue, 25 Dec 2018 06:05:04 +0000 (22:05 -0800)
Just a convenience.

14 files changed:
src/data/dictionary.c
src/data/dictionary.h
src/language/stats/binomial.c
src/language/stats/chisquare.c
src/language/stats/cochran.c
src/language/stats/crosstabs.q
src/language/stats/friedman.c
src/language/stats/ks-one-sample.c
src/language/stats/mcnemar.c
src/language/stats/median.c
src/language/stats/reliability.c
src/language/stats/runs.c
src/language/stats/sign.c
src/language/stats/wilcoxon.c

index d34bd9a358214e19353ad7793d9f66cc1311a3c3..2a5f4d83e78846f8b9e5371515a68bdda875750d 100644 (file)
@@ -1072,6 +1072,13 @@ dict_get_case_weight (const struct dictionary *d, const struct ccase *c,
     }
 }
 
+/* Returns the format to use for weights. */
+const struct fmt_spec *
+dict_get_weight_format (const struct dictionary *d)
+{
+  return d->weight ? var_get_print_format (d->weight) : &F_8_0;
+}
+
 /* Sets the weighting variable of D to V, or turning off
    weighting if V is a null pointer. */
 void
index 8a760081d3b935241f506ac1ffed5956417a87eb..0eb175063dc09a8958072138e493c73098a30e36 100644 (file)
@@ -100,6 +100,7 @@ double dict_get_case_weight (const struct dictionary *,
                             const struct ccase *, bool *);
 struct variable *dict_get_weight (const struct dictionary *);
 void dict_set_weight (struct dictionary *, struct variable *);
+const struct fmt_spec *dict_get_weight_format (const struct dictionary *);
 
 /* Filter variable. */
 struct variable *dict_get_filter (const struct dictionary *);
index b8ed5da9acecbf4e732c3da620ef7cc8bab4b582..00f37ab8b7e825f3b39fa81f489e06dff204a327 100644 (file)
@@ -179,9 +179,7 @@ binomial_execute (const struct dataset *ds,
 
   if (do_binomial (dataset_dict (ds), input, ost, cat[0], cat[1], exclude))
     {
-      const struct variable *wvar = dict_get_weight (dict);
-      const struct fmt_spec *wfmt = wvar ?
-       var_get_print_format (wvar) : & F_8_0;
+      const struct fmt_spec *wfmt = dict_get_weight_format (dict);
 
       struct tab_table *table = tab_create (7, ost->n_vars * 3 + 1);
       tab_set_format (table, RC_WEIGHT, wfmt);
index e2ed8fef64808c003dc8bdf6073b1eaa11f2eb80..dd04749f987ac8ab0a5d2bc5531cfd92f8f25abe 100644 (file)
@@ -195,8 +195,7 @@ create_combo_frequency_table (const struct dictionary *dict, const struct chisqu
 
   struct tab_table *table ;
 
-  const struct variable *wvar = dict_get_weight (dict);
-  const struct fmt_spec *wfmt = wvar ? var_get_print_format (wvar) : & F_8_0;
+  const struct fmt_spec *wfmt = dict_get_weight_format (dict);
 
   int n_cells = test->hi - test->lo + 1;
 
index cea9a054bb2014fc25920c2ecf47e89b5796b76f..091715694e0aa064f202e0334c88c8acdbc3be00 100644 (file)
@@ -147,8 +147,7 @@ static void
 show_freqs_box (const struct one_sample_test *ost, const struct cochran *ct)
 {
   int i;
-  const struct variable *weight = dict_get_weight (ct->dict);
-  const struct fmt_spec *wfmt = weight ? var_get_print_format (weight) : &F_8_0;
+  const struct fmt_spec *wfmt = dict_get_weight_format (ct->dict);
 
   const int row_headers = 1;
   const int column_headers = 2;
@@ -199,8 +198,7 @@ show_freqs_box (const struct one_sample_test *ost, const struct cochran *ct)
 static void
 show_sig_box (const struct cochran *ch)
 {
-  const struct variable *weight = dict_get_weight (ch->dict);
-  const struct fmt_spec *wfmt = weight ? var_get_print_format (weight) : &F_8_0;
+  const struct fmt_spec *wfmt = dict_get_weight_format (ch->dict);
 
   const int row_headers = 1;
   const int column_headers = 0;
index c2f34c2df213d6a19866edbf87a8e8cf387fe7e4..aa77fb8b7c72bef9acfee293167806e7e4b95437 100644 (file)
@@ -217,7 +217,6 @@ round_weight (const struct crosstabs_proc *proc, double weight)
 int
 cmd_crosstabs (struct lexer *lexer, struct dataset *ds)
 {
-  const struct variable *wv = dict_get_weight (dataset_dict (ds));
   struct var_range *range, *next_range;
   struct crosstabs_proc proc;
   struct casegrouper *grouper;
@@ -236,7 +235,7 @@ cmd_crosstabs (struct lexer *lexer, struct dataset *ds)
   proc.pivots = NULL;
   proc.n_pivots = 0;
   proc.descending = false;
-  proc.weight_format = wv ? *var_get_print_format (wv) : F_8_0;
+  proc.weight_format = *dict_get_weight_format (dataset_dict (ds));
 
   if (!parse_crosstabs (lexer, ds, &cmd, &proc))
     {
index 8fa49f7d118b07fdc17f40ba80d7bd8c0949df34..cf03c83c12d22065467ce2a38c41fc3212793749 100644 (file)
@@ -259,8 +259,7 @@ show_sig_box (const struct one_sample_test *ost, const struct friedman *fr)
   const struct friedman_test *ft = UP_CAST (ost, const struct friedman_test, parent);
 
   int row = 0;
-  const struct variable *weight = dict_get_weight (fr->dict);
-  const struct fmt_spec *wfmt = weight ? var_get_print_format (weight) : &F_8_0;
+  const struct fmt_spec *wfmt = dict_get_weight_format (fr->dict);
 
   const int row_headers = 1;
   const int column_headers = 0;
index ea7ac71b7e036aa5d39456f67cae4ffa26f921c4..7e2e5bb6312cb1e6a9787682ad3245619c72a605 100644 (file)
@@ -139,8 +139,7 @@ ks_one_sample_execute (const struct dataset *ds,
   const struct ks_one_sample_test *kst = UP_CAST (test, const struct ks_one_sample_test, parent.parent);
   const struct one_sample_test *ost = &kst->parent;
   struct ccase *c;
-  const struct variable *wvar = dict_get_weight (dict);
-  const struct fmt_spec *wfmt = wvar ? var_get_print_format (wvar) : & F_8_0;
+  const struct fmt_spec *wfmt = dict_get_weight_format (dict);
   bool warn = true;
   int v;
   struct casereader *r = casereader_clone (input);
index 648dc9c3f7d62365d6a8f748d60fd47dec01c4ff..d3f48192fa9f9a91c20c026cdda398f277a99115 100644 (file)
@@ -166,8 +166,7 @@ output_freq_table (variable_pair *vp,
 
   struct tab_table *table = tab_create (header_cols + 2, header_rows + 2);
 
-  const struct variable *wv = dict_get_weight (dict);
-  const struct fmt_spec *wfmt = wv ? var_get_print_format (wv) : & F_8_0;
+  const struct fmt_spec *wfmt = dict_get_weight_format (dict);
 
 
   struct string pair_name;
@@ -236,8 +235,7 @@ output_statistics_table (const struct two_sample_test *t2s,
 
   struct tab_table *table = tab_create (5, t2s->n_pairs + 1);
 
-  const struct variable *wv = dict_get_weight (dict);
-  const struct fmt_spec *wfmt = wv ? var_get_print_format (wv) : & F_8_0;
+  const struct fmt_spec *wfmt = dict_get_weight_format (dict);
 
   tab_title (table, _("Test Statistics"));
   tab_set_format (table, RC_WEIGHT, wfmt);
index 49a4bc12e8bd6042efc38794761d1a88d0954386..7bb87f92f299eddc5c07741b2e1e9ea1e3db6554 100644 (file)
@@ -301,8 +301,7 @@ median_execute (const struct dataset *ds,
 static void
 show_frequencies (const struct n_sample_test *nst, const struct results *results,  int n_vals, const struct dictionary *dict)
 {
-  const struct variable *weight = dict_get_weight (dict);
-  const struct fmt_spec *wfmt = weight ? var_get_print_format (weight) : &F_8_0;
+  const struct fmt_spec *wfmt = dict_get_weight_format (dict);
 
   int i;
   int v;
@@ -391,8 +390,7 @@ show_test_statistics (const struct n_sample_test *nst,
                      int n_vals,
                      const struct dictionary *dict)
 {
-  const struct variable *weight = dict_get_weight (dict);
-  const struct fmt_spec *wfmt = weight ? var_get_print_format (weight) : &F_8_0;
+  const struct fmt_spec *wfmt = dict_get_weight_format (dict);
 
   int v;
 
index 560b89f980cc219e50419dcd2e317c660c06bf46..27a4656723ab28920710943d6f53184a388d0517 100644 (file)
@@ -536,8 +536,7 @@ static void
 case_processing_summary (casenumber n_valid, casenumber n_missing,
                         const struct dictionary *dict)
 {
-  const struct variable *wv = dict_get_weight (dict);
-  const struct fmt_spec *wfmt = wv ? var_get_print_format (wv) : & F_8_0;
+  const struct fmt_spec *wfmt = dict_get_weight_format (dict);
 
   casenumber total;
   int n_cols = 4;
index cd963d32736f2630cc12663162aa9a9b9eba983c..9a32a530e836744f827ff39e524f43a3c9b85f4e 100644 (file)
@@ -308,8 +308,7 @@ runs_execute (const struct dataset *ds,
 static void
 show_runs_result (const struct runs_test *rt, const struct run_state *rs, const struct dictionary *dict)
 {
-  const struct variable *weight = dict_get_weight (dict);
-  const struct fmt_spec *wfmt = weight ? var_get_print_format (weight) : &F_8_0;
+  const struct fmt_spec *wfmt = dict_get_weight_format (dict);
 
   const struct one_sample_test *otp = &rt->parent;
 
index 5149489d1185fd6633fe7eb2b27c1255f40ef872..e16298a6baf5501ce5cecae732b2c5d1c29c27b7 100644 (file)
@@ -56,8 +56,7 @@ output_frequency_table (const struct two_sample_test *t2s,
   int i;
   struct tab_table *table = tab_create (3, 1 + 4 * t2s->n_pairs);
 
-  const struct variable *wv = dict_get_weight (dict);
-  const struct fmt_spec *wfmt = wv ? var_get_print_format (wv) : & F_8_0;
+  const struct fmt_spec *wfmt = dict_get_weight_format (dict);
 
   tab_set_format (table, RC_WEIGHT, wfmt);
   tab_title (table, _("Frequencies"));
index 2a8061dd91e0e17328e6ce45e0b25ffe5452b8d0..2c58962047cba5a7ee662a93aa612145e6c9ace9 100644 (file)
@@ -217,8 +217,7 @@ show_ranks_box (const struct wilcoxon_state *ws,
 {
   size_t i;
 
-  const struct variable *wv = dict_get_weight (dict);
-  const struct fmt_spec *wfmt = wv ? var_get_print_format (wv) : & F_8_0;
+  const struct fmt_spec *wfmt = dict_get_weight_format (dict);
 
   struct tab_table *table = tab_create (5, 1 + 4 * t2s->n_pairs);
   tab_set_format (table, RC_WEIGHT, wfmt);