293d0f589c7c7c36c3f63f1a828ab564c855dad6
[pspp] / src / language / stats / aggregate.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2010, 2011 Free Software Foundation, Inc.
3
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.
8
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.
13
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/>. */
16
17
18 #ifndef AGGREGATE_H
19 #define AGGREGATE_H
20
21 #include <stddef.h>
22
23 #include "data/format.h"
24 #include "data/val-type.h"
25
26 enum agr_src_vars
27   {
28     AGR_SV_NO,
29     AGR_SV_YES,
30     AGR_SV_OPT
31   };
32
33 #define AGGREGATE_FUNCTIONS                                             \
34   AGRF(AGRF_SUM,     "SUM",     N_("Sum of values"),                         AGR_SV_YES, 0, -1,           8,  2) \
35   AGRF(AGRF_MEAN,    "MEAN",    N_("Mean average"),                          AGR_SV_YES, 0, -1,           8,  2) \
36   AGRF(AGRF_MEDIAN,  "MEDIAN",  N_("Median"),                                AGR_SV_YES, 0, -1,           8,  2) \
37   AGRF(AGRF_SD,      "SD",      N_("Standard deviation"),                    AGR_SV_YES, 0, -1,           8,  2) \
38   AGRF(AGRF_MAX,     "MAX",     N_("Maximum value"),                         AGR_SV_YES, 0, VAL_STRING,  -1, -1) \
39   AGRF(AGRF_MIN,     "MIN",     N_("Minimum value"),                         AGR_SV_YES, 0, VAL_STRING,  -1, -1) \
40   AGRF(AGRF_PGT,     "PGT",     N_("Percentage greater than"),               AGR_SV_YES, 1, VAL_NUMERIC,  5,  1) \
41   AGRF(AGRF_PLT,     "PLT",     N_("Percentage less than"),                  AGR_SV_YES, 1, VAL_NUMERIC,  5,  1) \
42   AGRF(AGRF_PIN,     "PIN",     N_("Percentage included in range"),          AGR_SV_YES, 2, VAL_NUMERIC,  5,  1) \
43   AGRF(AGRF_POUT,    "POUT",    N_("Percentage excluded from range"),        AGR_SV_YES, 2, VAL_NUMERIC,  5,  1) \
44   AGRF(AGRF_FGT,     "FGT",     N_("Fraction greater than"),                 AGR_SV_YES, 1, VAL_NUMERIC,  5,  3) \
45   AGRF(AGRF_FLT,     "FLT",     N_("Fraction less than"),                    AGR_SV_YES, 1, VAL_NUMERIC,  5,  3) \
46   AGRF(AGRF_FIN,     "FIN",     N_("Fraction included in range"),            AGR_SV_YES, 2, VAL_NUMERIC,  5,  3) \
47   AGRF(AGRF_FOUT,    "FOUT",    N_("Fraction excluded from range"),          AGR_SV_YES, 2, VAL_NUMERIC,  5,  3) \
48   AGRF(AGRF_CGT,     "CGT",     N_("Count greater than"),                    AGR_SV_YES, 1, VAL_NUMERIC,  5,  1) \
49   AGRF(AGRF_CLT,     "CLT",     N_("Count less than"),                       AGR_SV_YES, 1, VAL_NUMERIC,  5,  1) \
50   AGRF(AGRF_CIN,     "CIN",     N_("Count included in range"),               AGR_SV_YES, 2, VAL_NUMERIC,  5,  1) \
51   AGRF(AGRF_COUT,    "COUT",    N_("Count excluded from range"),             AGR_SV_YES, 2, VAL_NUMERIC,  5,  1) \
52   AGRF(AGRF_N,       "N",       N_("Number of cases"),                       AGR_SV_NO,  0, VAL_NUMERIC,  7,  0) \
53   AGRF(AGRF_NU,      "NU",      N_("Number of cases (unweighted)"),          AGR_SV_OPT, 0, VAL_NUMERIC,  7,  0) \
54   AGRF(AGRF_NMISS,   "NMISS",   N_("Number of missing values"),              AGR_SV_YES, 0, VAL_NUMERIC,  7,  0) \
55   AGRF(AGRF_NUMISS,  "NUMISS",  N_("Number of missing values (unweighted)"), AGR_SV_YES, 0, VAL_NUMERIC,  7,  0) \
56   AGRF(AGRF_FIRST,   "FIRST",   N_("First non-missing value"),               AGR_SV_YES, 0, VAL_STRING,  -1, -1) \
57   AGRF(AGRF_LAST,    "LAST",    N_("Last non-missing value"),                AGR_SV_YES, 0, VAL_STRING,  -1, -1)
58
59 /* Aggregation functions. */
60 enum agr_function
61   {
62 #define AGRF(ENUM, NAME, DESCRIPTION, SRC_VARS, N_ARGS, ALPHA_TYPE, W, D) \
63     ENUM,
64 AGGREGATE_FUNCTIONS
65 #undef AGRF
66   };
67
68 /* Attributes of an aggregation function. */
69 struct agr_func
70   {
71     const char *name;           /* Aggregation function name. */
72     const char *description;    /* Translatable string describing the function. */
73     enum agr_src_vars src_vars; /* Whether source variables are a parameter of the function */
74     size_t n_args;              /* Number of arguments (not including src vars). */
75     enum val_type alpha_type;   /* When given ALPHA arguments, output type. */
76     struct fmt_spec format;     /* Format spec if alpha_type != ALPHA. */
77   };
78
79 extern const struct agr_func agr_func_tab[];
80
81
82 #endif