pivot-table: Initialize subtype, command_id for pivot tables.
authorBen Pfaff <blp@cs.stanford.edu>
Sat, 7 Dec 2019 23:54:50 +0000 (23:54 +0000)
committerBen Pfaff <blp@cs.stanford.edu>
Sun, 29 Dec 2019 05:28:10 +0000 (05:28 +0000)
src/language/data-io/data-parser.c
src/language/dictionary/sys-file-info.c
src/language/stats/autorecode.c
src/language/stats/chisquare.c
src/language/stats/crosstabs.q
src/language/stats/frequencies.c
src/language/stats/mcnemar.c
src/language/stats/oneway.c
src/language/stats/regression.c
src/output/pivot-table.c
src/output/pivot-table.h

index b3c4b54cbbad0f3a3c55193fd1b2beb535bbb78d..2ae8d6a36142364fa9be3882906b69ebb294ab12 100644 (file)
@@ -671,7 +671,7 @@ dump_fixed_table (const struct data_parser *parser,
                                      parser->records_per_case),
                            parser->records_per_case, fh_get_name (fh));
   struct pivot_table *table = pivot_table_create__ (
-    pivot_value_new_user_text (title, -1));
+    pivot_value_new_user_text (title, -1), "Fixed Data Records");
   free (title);
 
   pivot_dimension_create (
@@ -717,7 +717,8 @@ dump_delimited_table (const struct data_parser *parser,
 {
   struct pivot_table *table = pivot_table_create__ (
     pivot_value_new_text_format (N_("Reading free-form data from %s."),
-                                 fh_get_name (fh)));
+                                 fh_get_name (fh)),
+    "Free-Form Data Records");
 
   pivot_dimension_create (
     table, PIVOT_AXIS_COLUMN, N_("Attributes"), N_("Format"));
index 5d47725b574a0d6245cd06db4ef1270fb7028184..66ef00bb7063c988c6a4948c1049471399977da4 100644 (file)
@@ -1002,7 +1002,7 @@ report_encodings (const struct file_handle *h, struct pool *pool,
   /* Table of valid encodings. */
   struct pivot_table *table = pivot_table_create__ (
     pivot_value_new_text_format (N_("Usable encodings for %s."),
-                                 fh_get_name (h)));
+                                 fh_get_name (h)), "Usable Encodings");
   table->caption = pivot_value_new_text_format (
     N_("Encodings that can successfully read %s (by specifying the encoding "
        "name on the GET command's ENCODING subcommand).  Encodings that "
@@ -1040,7 +1040,8 @@ report_encodings (const struct file_handle *h, struct pool *pool,
   /* Table of alternative interpretations. */
   table = pivot_table_create__ (
     pivot_value_new_text_format (N_("%s Encoded Text Strings"),
-                                 fh_get_name (h)));
+                                 fh_get_name (h)),
+    "Alternate Encoded Text Strings");
   table->caption = pivot_value_new_text (
     N_("Text strings in the file dictionary that the previously listed "
        "encodings interpret differently, along with the interpretations."));
index dcd0a14d76fc1a0330774032cf35b3d3aaab8226..c093b1e6ab7af66245f47183f5e2d6c75ce03505 100644 (file)
@@ -369,7 +369,7 @@ cmd_autorecode (struct lexer *lexer, struct dataset *ds)
                : pivot_value_new_text_format (N_("Recoding %s into %s."),
                                               spec->src_name,
                                               var_get_name (spec->dst)));
-          struct pivot_table *table = pivot_table_create__ (title);
+          struct pivot_table *table = pivot_table_create__ (title, "Recoding");
 
           pivot_dimension_create (
             table, PIVOT_AXIS_COLUMN, N_("Attributes"),
index ccfa484621cde48058f6d77e0b56f44f52102d55..ffb75dd3e0ce95ad85b3732db35b6a21cfe40447 100644 (file)
@@ -176,7 +176,7 @@ chisquare_execute (const struct dataset *ds,
             }
 
           struct pivot_table *table = pivot_table_create__ (
-            pivot_value_new_variable (var));
+            pivot_value_new_variable (var), "Chisquare");
           pivot_table_set_weight_var (table, dict_get_weight (dict));
 
           pivot_dimension_create (
index 6defd2447a9424a7ce5ec0f6f81cda95c5e564c0..a772034f64c36bdc08e2fc683c7e322dc1193bde 100644 (file)
@@ -1243,7 +1243,8 @@ create_crosstab_table (struct crosstabs_proc *proc, struct crosstabulation *xt,
       free (s);
     }
   struct pivot_table *table = pivot_table_create__ (
-    pivot_value_new_user_text_nocopy (ds_steal_cstr (&title)));
+    pivot_value_new_user_text_nocopy (ds_steal_cstr (&title)),
+    "Crosstabulation");
   pivot_table_set_weight_format (table, &proc->weight_format);
   table->omit_empty = true;
 
index c96b4eab190efb7d6872f5d20d2e82a994f6cf91..ef1b7592dc94157765184a107f11f75b680d2497 100644 (file)
@@ -296,7 +296,7 @@ dump_freq_table (const struct var_freqs *vf, const struct variable *wv)
   const struct freq_tab *ft = &vf->tab;
 
   struct pivot_table *table = pivot_table_create__ (pivot_value_new_variable (
-                                                      vf->var));
+                                                      vf->var), "Frequencies");
   pivot_table_set_weight_var (table, wv);
 
   pivot_dimension_create (table, PIVOT_AXIS_COLUMN, N_("Statistics"),
index 0456b909c59a75688d97ada4a109ec71775caab8..ef84b77a4e923f20dccee77f93251cfcae87ea7a 100644 (file)
@@ -169,7 +169,7 @@ output_freq_table (variable_pair *vp,
                   const struct dictionary *dict)
 {
   struct pivot_table *table = pivot_table_create__ (
-    pivot_value_new_user_text_nocopy (make_pair_name (vp)));
+    pivot_value_new_user_text_nocopy (make_pair_name (vp)), "Frequencies");
   pivot_table_set_weight_var (table, dict_get_weight (dict));
 
   struct pivot_dimension *vars[2];
index 7f28b75b8a45098de84fb736d452642e0ffdde59..c33d333ce4b9a459d8f3f94809b6f069720eba5e 100644 (file)
@@ -1365,7 +1365,8 @@ show_comparisons (const struct oneway_spec *cmd, const struct oneway_workspace *
   struct pivot_table *table = pivot_table_create__ (
     pivot_value_new_user_text_nocopy (xasprintf (
                                         _("Multiple Comparisons (%s)"),
-                                        var_to_string (cmd->vars[v]))));
+                                        var_to_string (cmd->vars[v]))),
+    "Multiple Comparisons");
   table->omit_empty = true;
 
   struct pivot_dimension *statistics = pivot_dimension_create (
index 9ca056943eb52d4631394cdd90937dcb136170df..28618f12b0a89a2a04a04b10d2f8bd6425d20cc2 100644 (file)
@@ -856,7 +856,8 @@ reg_stats_r (const struct linreg * c, const struct variable *var)
 {
   struct pivot_table *table = pivot_table_create__ (
     pivot_value_new_text_format (N_("Model Summary (%s)"),
-                                 var_to_string (var)));
+                                 var_to_string (var)),
+    "Model Summary");
 
   pivot_dimension_create (table, PIVOT_AXIS_COLUMN, N_("Statistics"),
                           N_("R"), N_("R Square"), N_("Adjusted R Square"),
@@ -886,8 +887,8 @@ reg_stats_coeff (const struct regression *cmd, const struct linreg *c,
                 const struct variable *var)
 {
   struct pivot_table *table = pivot_table_create__ (
-    pivot_value_new_text_format (N_("Coefficients (%s)"),
-                                 var_to_string (var)));
+    pivot_value_new_text_format (N_("Coefficients (%s)"), var_to_string (var)),
+    "Coefficients");
 
   struct pivot_dimension *statistics = pivot_dimension_create (
     table, PIVOT_AXIS_COLUMN, N_("Statistics"));
@@ -1011,7 +1012,8 @@ static void
 reg_stats_anova (const struct linreg * c, const struct variable *var)
 {
   struct pivot_table *table = pivot_table_create__ (
-    pivot_value_new_text_format (N_("ANOVA (%s)"), var_to_string (var)));
+    pivot_value_new_text_format (N_("ANOVA (%s)"), var_to_string (var)),
+    "ANOVA");
 
   pivot_dimension_create (table, PIVOT_AXIS_COLUMN, N_("Statistics"),
                           N_("Sum of Squares"), PIVOT_RC_OTHER,
@@ -1066,7 +1068,8 @@ reg_stats_bcov (const struct linreg * c, const struct variable *var)
 {
   struct pivot_table *table = pivot_table_create__ (
     pivot_value_new_text_format (N_("Coefficient Correlations (%s)"),
-                                 var_to_string (var)));
+                                 var_to_string (var)),
+    "Coefficient Correlations");
 
   for (size_t i = 0; i < 2; i++)
     {
index 057df4ef02f226cc612b28e9537e52e49bb39dc3..ff45226e6475928b97365d163e719a7162b1ea9e 100644 (file)
@@ -26,6 +26,7 @@
 #include "data/variable.h"
 #include "libpspp/hash-functions.h"
 #include "libpspp/i18n.h"
+#include "output/driver.h"
 
 #include "gl/c-ctype.h"
 #include "gl/intprops.h"
@@ -655,7 +656,8 @@ pivot_result_class_change (const char *s_, const struct fmt_spec *format)
 
 /* Creates and returns a new pivot table with the given TITLE.  TITLE should be
    a text string marked for translation but not actually translated yet,
-   e.g. N_("Descriptive Statistics").
+   e.g. N_("Descriptive Statistics").  The un-translated text string is used as
+   the pivot table's subtype.
 
    Operations commonly performed on the new pivot_table:
 
@@ -667,18 +669,22 @@ pivot_result_class_change (const char *s_, const struct fmt_spec *format)
 
    This function is a shortcut for pivot_table_create__() for the most common
    case.  Use pivot_table_create__() directly if the title should be some kind
-   of value other than an ordinary text string.
+   of value other than an ordinary text string, or if the subtype should be
+different from the title.
 
    See the large comment at the top of pivot-table.h for general advice on
    creating pivot tables. */
 struct pivot_table *
 pivot_table_create (const char *title)
 {
-  return pivot_table_create__ (pivot_value_new_text (title));
+  return pivot_table_create__ (pivot_value_new_text (title), title);
 }
 
 /* Creates and returns a new pivot table with the given TITLE, and takes
-   ownership of TITLE.
+   ownership of TITLE.  The new pivot table's subtype is SUBTYPE, which
+   should be an untranslated English string that describes the contents of
+   the table at a high level without being specific about the variables or
+   other context involved.
 
    Operations commonly performed on the new pivot_table:
 
@@ -691,12 +697,16 @@ pivot_table_create (const char *title)
    See the large comment at the top of pivot-table.h for general advice on
    creating pivot tables. */
 struct pivot_table *
-pivot_table_create__ (struct pivot_value *title)
+pivot_table_create__ (struct pivot_value *title, const char *subtype)
 {
   struct pivot_table *table = xzalloc (sizeof *table);
   table->ref_cnt = 1;
   table->weight_format = (struct fmt_spec) { FMT_F, 40, 0 };
   table->title = title;
+  table->subtype = pivot_value_new_text (subtype);
+
+  const char *command_id = output_get_command_name ();
+  table->command_c = command_id ? xstrdup (command_id) : NULL;
 
   table->sizing[TABLE_HORZ].range[0] = 50;
   table->sizing[TABLE_HORZ].range[1] = 72;
@@ -748,7 +758,7 @@ struct pivot_table *
 pivot_table_create_for_text (struct pivot_value *title,
                              struct pivot_value *content)
 {
-  struct pivot_table *table = pivot_table_create__ (title);
+  struct pivot_table *table = pivot_table_create__ (title, "Error");
 
   struct pivot_dimension *d = pivot_dimension_create (
     table, PIVOT_AXIS_ROW, N_("Error"));
index 99308c9e443daa3f2294744732f569f48223ba95..c11874da2e3802efef4d291e0d352cfcea3b6186 100644 (file)
@@ -432,7 +432,7 @@ struct pivot_table
 
     /* Titles. */
     struct pivot_value *title;
-    struct pivot_value *subtype;  /* Same as pivot_item's subtype. */
+    struct pivot_value *subtype;  /* Same as spv_item's subtype. */
     struct pivot_value *corner_text;
     struct pivot_value *caption;
     char *notes;
@@ -453,7 +453,8 @@ struct pivot_table
 
 /* Creating and destroy pivot tables. */
 struct pivot_table *pivot_table_create (const char *title);
-struct pivot_table *pivot_table_create__ (struct pivot_value *title);
+struct pivot_table *pivot_table_create__ (struct pivot_value *title,
+                                          const char *subtype);
 struct pivot_table *pivot_table_create_for_text (struct pivot_value *title,
                                                  struct pivot_value *content);