1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2010 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 #include "output/pivot-table.h"
21 #include "data/case.h"
22 #include "data/casereader.h"
23 #include "math/sort.h"
25 #include "gl/xalloc.h"
28 pivot_cell_init (struct pivot_cell *cell, struct pivot_value *value)
31 cell->cmp = PIVOT_RAW;
32 cell->cmp_args[0] = cell->cmp_args[1] = cell->cmp_args[2] = NULL;
38 pivot_value_create (const struct variable *var,
39 enum pivot_operator operator,
42 enum pivot_value_include include)
44 struct pivot_value *value = xmalloc (sizeof *value);
46 value->operator = operator;
47 value->n_agg_vars[TABLE_HORZ] = n_vars_horz;
48 value->n_agg_vars[TABLE_VERT] = n_vars_vert;
49 value->include = include;
54 keep_one (struct ccase *a, struct ccase *b, void *aux UNUSED)
61 dump_projection (struct casereader *data, const struct subcase *split,
62 const struct subcase *vars)
67 subcase_clone (&sc, split);
68 subcase_concat_always (&sc, vars);
70 data = casereader_project (data, &sc);
71 data = sort_distinct_execute (data, &sc, keep_one, NULL, NULL);
74 for (; (c = casereader_read (data)) != NULL; case_unref (c))
76 const struct caseproto *proto = case_get_proto (c);
79 for (i = 0; i < caseproto_get_n_widths (proto); i++)
81 int width = caseproto_get_width (proto, i);
87 printf ("%8.2g", case_num_idx (c, i));
89 printf ("\"%.*s\"", width, case_str_idx (c, i));
95 subcase_destroy (&sc);
99 dump_data (struct pivot_table *pt)
101 struct casereader *data;
105 subcase_clone (&sc, &pt->split);
106 subcase_concat_always (&sc, &pt->dimensions[TABLE_HORZ]);
107 subcase_concat_always (&sc, &pt->dimensions[TABLE_VERT]);
109 data = sort_distinct_execute (casereader_clone (pt->data), &sc, keep_one, NULL, NULL);
110 for (; (c = casereader_read (data)) != NULL; case_unref (c))
112 const struct caseproto *proto = case_get_proto (c);
115 for (i = 0; i < caseproto_get_n_widths (proto); i++)
117 int width = caseproto_get_width (proto, i);
123 printf ("%8.2f", case_num_idx (c, i));
125 printf ("\"%.*s\"", width, case_str_idx (c, i));
133 pivot_table_dump (struct pivot_table *pt)
137 Determine row and column labels:
139 Project onto (splits, rows) and sort, discarding duplicates.
141 Project onto (splits, columns) and sort, discarding duplicates.
143 Sort data on (splits, rows, columns).
145 For each split group:
149 For each column value:
151 For each value in the pane:
153 Evaluate and print value.
157 dump_projection (casereader_clone (pt->data),
158 &pt->split, &pt->dimensions[TABLE_HORZ]);
159 dump_projection (casereader_clone (pt->data),
160 &pt->split, &pt->dimensions[TABLE_VERT]);
165 casereader_destroy (pt->data);