From f978ab3b3eb82ba7dcabf79e42515dc1b516fd4e Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Sun, 26 Dec 2021 16:01:47 -0800 Subject: [PATCH] work on CTABLES --- src/language/command.def | 2 +- src/language/stats/automake.mk | 1 + src/language/stats/ctables.c | 120 +++++++++++++++++++++++++++++++++ 3 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 src/language/stats/ctables.c diff --git a/src/language/command.def b/src/language/command.def index 352f7c1078..6db5e74e2e 100644 --- a/src/language/command.def +++ b/src/language/command.def @@ -114,6 +114,7 @@ DEF_CMD (S_DATA, 0, "AUTORECODE", cmd_autorecode) DEF_CMD (S_DATA, 0, "BEGIN DATA", cmd_begin_data) DEF_CMD (S_DATA, 0, "COUNT", cmd_count) DEF_CMD (S_DATA, 0, "CROSSTABS", cmd_crosstabs) +DEF_CMD (S_DATA, 0, "CTABLES", cmd_ctables) DEF_CMD (S_DATA, 0, "CORRELATIONS", cmd_correlation) DEF_CMD (S_DATA, 0, "DELETE VARIABLES", cmd_delete_variables) DEF_CMD (S_DATA, 0, "DESCRIPTIVES", cmd_descriptives) @@ -194,7 +195,6 @@ UNIMPL_CMD ("CSLOGISTIC", "Complex samples logistic regression") UNIMPL_CMD ("CSPLAN", "Complex samples design") UNIMPL_CMD ("CSSELECT", "Select complex samples") UNIMPL_CMD ("CSTABULATE", "Tabulate complex samples") -UNIMPL_CMD ("CTABLES", "Display complex samples") UNIMPL_CMD ("CURVEFIT", "Fit curve to line plot") UNIMPL_CMD ("DATE", "Create time series data") UNIMPL_CMD ("DETECTANOMALY", "Find unusual cases") diff --git a/src/language/stats/automake.mk b/src/language/stats/automake.mk index 460e95e707..99d0051081 100644 --- a/src/language/stats/automake.mk +++ b/src/language/stats/automake.mk @@ -31,6 +31,7 @@ language_stats_sources = \ src/language/stats/cochran.h \ src/language/stats/correlations.c \ src/language/stats/crosstabs.c \ + src/language/stats/ctables.c \ src/language/stats/descriptives.c \ src/language/stats/examine.c \ src/language/stats/factor.c \ diff --git a/src/language/stats/ctables.c b/src/language/stats/ctables.c new file mode 100644 index 0000000000..6ac8a7f83b --- /dev/null +++ b/src/language/stats/ctables.c @@ -0,0 +1,120 @@ +/* PSPP - a program for statistical analysis. + Copyright (C) 2021 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +#include "language/command.h" +#include "language/lexer/lexer.h" +#include "libpspp/message.h" + +#include "gl/xalloc.h" + +#include "gettext.h" +#define _(msgid) gettext (msgid) + +struct ctables + { + struct pivot_table_look *look; + + /* If this is NULL, zeros are displayed using the normal print format. + Otherwise, this string is displayed. */ + char *zero; + + /* If this is NULL, missing values are displayed using the normal print + format. Otherwise, this string is displayed. */ + char *missing; + + /* Contains "struct ctables_vlabel" structs. */ + struct hmap vlabels; + + bool mrsets_count_duplicates; /* MRSETS. */ + bool smissing_listwise; /* SMISSING. */ + struct variable *base_weight; /* WEIGHT. */ + double hide_threshold; /* HIDESMALLCOUNTS. */ + + struct ctables_table *tables; + size_t n_tables; + }; + +struct ctables_vlabel + { + struct hmap_node hmap_node; /* In struct ctables's 'vlabels' hmap. */ + const char *name; /* Variable name. */ + + /* SETTINGS_VALUE_SHOW_DEFAULT is interpreted as "none". */ + enum settings_value_show show; + }; + +struct ctables_postcompute + { + struct hmap_node hmap_node; /* In struct ctables's 'pcompute' hmap. */ + const char *name; /* Name, without leading &. */ + + struct ctables_postcompute_expr *expr; + char *label; + /* XXX FORMAT */ + bool hide_source_cats; + }; + +struct ctables_postcompute_expr + { + enum ctables_postcompute_op + { + /* Terminals. */ + CTPET_CAT_NUMBER, + CTPET_CAT_STRING, + CTPET_CAT_RANGE, + CTPET_CAT_MISSING, + /* XXX OTHERNM */ + /* XXX SUBTOTAL and HSUBTOTAL */ + + /* Nonterminals. */ + CTPET_ADD, + CTPET_SUB, + CTPET_MUL, + CTPET_DIV, + CTPET_POW, + } + op; + + union + { + /* CTPET_CAT_NUMBER, CTPET_NUMBER. */ + double number; + + /* CTPET_CAT_RANGE. + + XXX what about string ranges? */ + struct + { + double low; /* -DBL_MAX for LO. */ + double high; /* DBL_MAX for HIGH. */ + } + range; + + /* CTPET_ADD, CTPET_SUB, CTPET_MUL, CTPET_DIV, CTPET_POW. */ + struct ctables_postcompute_expr *subs[2]; + }; + }; + + +int +cmd_ctables (struct lexer *lexer, struct dataset *ds) +{ + + +} + -- 2.30.2