/* PSPP - a program for statistical analysis.
- Copyright (C) 2005, 2006, 2007, 2009, 2010, 2011, 2012, 2013, 2014 Free Software Foundation, Inc
+ Copyright (C) 2005, 2006, 2007, 2009, 2010, 2011, 2012, 2013, 2014, 2016 Free Software Foundation, Inc
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#include "libpspp/pool.h"
#include "libpspp/string-set.h"
#include "libpspp/taint.h"
-
-#include "output/tab.h"
+#include "output/pivot-table.h"
#include "gettext.h"
#define _(msgid) gettext (msgid)
}
/* Returns a variable name for storing ranks of a variable named SRC_NAME
- accoring to the rank function F. The name chosen will not be one already in
+ according to the rank function F. The name chosen will not be one already in
DICT or NEW_NAMES.
If successful, adds the new name to NEW_NAMES and returns the name added.
cmd->rs = pool_realloc (cmd->pool, cmd->rs, sizeof (*cmd->rs) * (cmd->n_rs + 1));
rs = &cmd->rs[cmd->n_rs];
-
+
if (lex_match_id (lexer, "RANK"))
{
rs->rfunc = RANK;
{
if ( !lex_force_match (lexer, T_LPAREN))
return false;
-
+
if (! lex_force_int (lexer) )
return false;
-
+
cmd->k_ntiles = lex_integer (lexer);
lex_get (lexer);
-
+
if ( !lex_force_match (lexer, T_RPAREN))
return false;
}
else
{
+ lex_error (lexer, NULL);
return false;
}
function_name[f], var_get_name (src_var));
pool_label = pool_strdup (cmd->pool, ds_cstr (&label));
-
+
ds_destroy (&label);
return pool_label;
struct string_set new_names;
struct rank rank;
struct rank_spec *rs;
- int i;
subcase_init_empty (&rank.sc);
string_set_init (&new_names);
if (lex_match_id (lexer, "VARIABLES"))
- lex_force_match (lexer, T_EQUALS);
+ if (! lex_force_match (lexer, T_EQUALS))
+ goto error;
if (!parse_sort_criteria (lexer, rank.dict,
&rank.sc,
while (lex_token (lexer) != T_ENDCMD )
{
- lex_force_match (lexer, T_SLASH);
+ if (! lex_force_match (lexer, T_SLASH))
+ goto error;
if (lex_match_id (lexer, "TIES"))
{
- lex_force_match (lexer, T_EQUALS);
+ if (! lex_force_match (lexer, T_EQUALS))
+ goto error;
if (lex_match_id (lexer, "MEAN"))
{
rank.ties = TIES_MEAN;
}
else if (lex_match_id (lexer, "FRACTION"))
{
- lex_force_match (lexer, T_EQUALS);
+ if (! lex_force_match (lexer, T_EQUALS))
+ goto error;
if (lex_match_id (lexer, "BLOM"))
{
rank.fraction = FRAC_BLOM;
}
else if (lex_match_id (lexer, "PRINT"))
{
- lex_force_match (lexer, T_EQUALS);
+ if (! lex_force_match (lexer, T_EQUALS))
+ goto error;
if (lex_match_id (lexer, "YES"))
{
rank.print = true;
}
else if (lex_match_id (lexer, "MISSING"))
{
- lex_force_match (lexer, T_EQUALS);
+ if (! lex_force_match (lexer, T_EQUALS))
+ goto error;
if (lex_match_id (lexer, "INCLUDE"))
{
rank.exclude = MV_SYSTEM;
created with INTO. */
for (rs = rank.rs; rs < &rank.rs[rank.n_rs]; rs++)
{
- int v;
-
rs->dest_labels = pool_calloc (rank.pool, rank.n_vars,
sizeof *rs->dest_labels);
- for ( v = 0 ; v < rank.n_vars ; v ++ )
+ for (int v = 0 ; v < rank.n_vars ; v ++ )
{
const char **dst_name = &rs->dest_names[v];
if ( *dst_name == NULL )
if ( rank.print )
{
- int v;
+ struct pivot_table *table = pivot_table_create (
+ N_("Variables Created by RANK"));
+ table->omit_empty = true;
- tab_output_text_format (0, _("Variables Created By %s"), "RANK");
- tab_output_text (0, "");
+ pivot_dimension_create (table, PIVOT_AXIS_COLUMN, N_("New Variable"),
+ N_("New Variable"), N_("Function"),
+ N_("Fraction"), N_("Grouping Variables"));
- for (i = 0 ; i < rank.n_rs ; ++i )
+ struct pivot_dimension *variables = pivot_dimension_create (
+ table, PIVOT_AXIS_ROW, N_("Existing Variable"),
+ N_("Existing Variable"));
+ variables->root->show_label = true;
+
+ for (size_t i = 0 ; i < rank.n_rs ; ++i )
{
- for ( v = 0 ; v < rank.n_vars ; v ++ )
+ for (size_t v = 0 ; v < rank.n_vars ; v ++ )
{
- if ( rank.n_group_vars > 0 )
- {
- struct string varlist;
- int g;
-
- ds_init_empty (&varlist);
- for ( g = 0 ; g < rank.n_group_vars ; ++g )
- {
- ds_put_cstr (&varlist, var_get_name (rank.group_vars[g]));
-
- if ( g < rank.n_group_vars - 1)
- ds_put_cstr (&varlist, " ");
- }
-
- if ( rank.rs[i].rfunc == NORMAL ||
- rank.rs[i].rfunc == PROPORTION )
- tab_output_text_format (0,
- _("%s into %s(%s of %s using %s BY %s)"),
- var_get_name (rank.vars[v]),
- rank.rs[i].dest_names[v],
- function_name[rank.rs[i].rfunc],
- var_get_name (rank.vars[v]),
- fraction_name (&rank),
- ds_cstr (&varlist));
-
- else
- tab_output_text_format (0,
- _("%s into %s(%s of %s BY %s)"),
- var_get_name (rank.vars[v]),
- rank.rs[i].dest_names[v],
- function_name[rank.rs[i].rfunc],
- var_get_name (rank.vars[v]),
- ds_cstr (&varlist));
- ds_destroy (&varlist);
- }
- else
- {
- if ( rank.rs[i].rfunc == NORMAL ||
- rank.rs[i].rfunc == PROPORTION )
- tab_output_text_format (0,
- _("%s into %s(%s of %s using %s)"),
- var_get_name (rank.vars[v]),
- rank.rs[i].dest_names[v],
- function_name[rank.rs[i].rfunc],
- var_get_name (rank.vars[v]),
- fraction_name (&rank));
-
- else
- tab_output_text_format (0,
- _("%s into %s(%s of %s)"),
- var_get_name (rank.vars[v]),
- rank.rs[i].dest_names[v],
- function_name[rank.rs[i].rfunc],
- var_get_name (rank.vars[v]));
- }
+ int row_idx = pivot_category_create_leaf (
+ variables->root, pivot_value_new_variable (rank.vars[v]));
+
+ struct string group_vars = DS_EMPTY_INITIALIZER;
+ for (int g = 0 ; g < rank.n_group_vars ; ++g )
+ {
+ if (g)
+ ds_put_byte (&group_vars, ' ');
+ ds_put_cstr (&group_vars, var_get_name (rank.group_vars[g]));
+ }
+
+ enum rank_func rfunc = rank.rs[i].rfunc;
+ bool has_fraction = rfunc == NORMAL || rfunc == PROPORTION;
+ const char *entries[] =
+ {
+ rank.rs[i].dest_names[v],
+ function_name[rank.rs[i].rfunc],
+ has_fraction ? fraction_name (&rank) : NULL,
+ rank.n_group_vars ? ds_cstr (&group_vars) : NULL,
+ };
+ for (size_t j = 0; j < sizeof entries / sizeof *entries; j++)
+ {
+ const char *entry = entries[j];
+ if (entry)
+ pivot_table_put2 (table, j, row_idx,
+ pivot_value_new_user_text (entry, -1));
+ }
+ ds_destroy (&group_vars);
}
}
+
+ pivot_table_submit (table);
}
/* Do the ranking */