X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fstats%2Faggregate.c;h=9f0b271533888cc195c68637b9f569451d56e490;hb=40fb94bbe38b3e444df7952631ec5fe83f7f1086;hp=f4cbaac448b3acfbd67fa81c8775176fbb6b33e0;hpb=92e42986429596633f71457a585b3266209822dd;p=pspp diff --git a/src/language/stats/aggregate.c b/src/language/stats/aggregate.c index f4cbaac448..9f0b271533 100644 --- a/src/language/stats/aggregate.c +++ b/src/language/stats/aggregate.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 1997-9, 2000, 2006, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. + Copyright (C) 1997-9, 2000, 2006, 2008, 2009, 2010, 2011, 2012, 2014 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 @@ -49,6 +49,7 @@ #include "math/sort.h" #include "math/statistic.h" +#include "gl/c-strcase.h" #include "gl/minmax.h" #include "gl/xalloc.h" @@ -92,24 +93,24 @@ struct agr_var /* Attributes of aggregation functions. */ const struct agr_func agr_func_tab[] = { - {"SUM", N_("Sum of values"), AGR_SV_YES, 0, -1, {FMT_F, 8, 2}}, - {"MEAN", N_("Mean average"), AGR_SV_YES, 0, -1, {FMT_F, 8, 2}}, - {"MEDIAN", N_("Median average"), AGR_SV_YES, 0, -1, {FMT_F, 8, 2}}, - {"SD", N_("Standard deviation"), AGR_SV_YES, 0, -1, {FMT_F, 8, 2}}, + {"SUM", N_("Sum of values"), AGR_SV_YES, 0, -1, { .type = FMT_F, .w = 8, .d = 2 }}, + {"MEAN", N_("Mean average"), AGR_SV_YES, 0, -1, { .type = FMT_F, .w = 8, .d = 2 }}, + {"MEDIAN", N_("Median average"), AGR_SV_YES, 0, -1, { .type = FMT_F, .w = 8, .d = 2 }}, + {"SD", N_("Standard deviation"), AGR_SV_YES, 0, -1, { .type = FMT_F, .w = 8, .d = 2 }}, {"MAX", N_("Maximum value"), AGR_SV_YES, 0, VAL_STRING, {-1, -1, -1}}, {"MIN", N_("Minimum value"), AGR_SV_YES, 0, VAL_STRING, {-1, -1, -1}}, - {"PGT", N_("Percentage greater than"), AGR_SV_YES, 1, VAL_NUMERIC, {FMT_F, 5, 1}}, - {"PLT", N_("Percentage less than"), AGR_SV_YES, 1, VAL_NUMERIC, {FMT_F, 5, 1}}, - {"PIN", N_("Percentage included in range"), AGR_SV_YES, 2, VAL_NUMERIC, {FMT_F, 5, 1}}, - {"POUT", N_("Percentage excluded from range"), AGR_SV_YES, 2, VAL_NUMERIC, {FMT_F, 5, 1}}, - {"FGT", N_("Fraction greater than"), AGR_SV_YES, 1, VAL_NUMERIC, {FMT_F, 5, 3}}, - {"FLT", N_("Fraction less than"), AGR_SV_YES, 1, VAL_NUMERIC, {FMT_F, 5, 3}}, - {"FIN", N_("Fraction included in range"), AGR_SV_YES, 2, VAL_NUMERIC, {FMT_F, 5, 3}}, - {"FOUT", N_("Fraction excluded from range"), AGR_SV_YES, 2, VAL_NUMERIC, {FMT_F, 5, 3}}, - {"N", N_("Number of cases"), AGR_SV_NO, 0, VAL_NUMERIC, {FMT_F, 7, 0}}, - {"NU", N_("Number of cases (unweighted)"), AGR_SV_OPT, 0, VAL_NUMERIC, {FMT_F, 7, 0}}, - {"NMISS", N_("Number of missing values"), AGR_SV_YES, 0, VAL_NUMERIC, {FMT_F, 7, 0}}, - {"NUMISS", N_("Number of missing values (unweighted)"), AGR_SV_YES, 0, VAL_NUMERIC, {FMT_F, 7, 0}}, + {"PGT", N_("Percentage greater than"), AGR_SV_YES, 1, VAL_NUMERIC, { .type = FMT_F, .w = 5, .d = 1 }}, + {"PLT", N_("Percentage less than"), AGR_SV_YES, 1, VAL_NUMERIC, { .type = FMT_F, .w = 5, .d = 1 }}, + {"PIN", N_("Percentage included in range"), AGR_SV_YES, 2, VAL_NUMERIC, { .type = FMT_F, .w = 5, .d = 1 }}, + {"POUT", N_("Percentage excluded from range"), AGR_SV_YES, 2, VAL_NUMERIC, { .type = FMT_F, .w = 5, .d = 1 }}, + {"FGT", N_("Fraction greater than"), AGR_SV_YES, 1, VAL_NUMERIC, { .type = FMT_F, .w = 5, .d = 3 }}, + {"FLT", N_("Fraction less than"), AGR_SV_YES, 1, VAL_NUMERIC, { .type = FMT_F, .w = 5, .d = 3 }}, + {"FIN", N_("Fraction included in range"), AGR_SV_YES, 2, VAL_NUMERIC, { .type = FMT_F, .w = 5, .d = 3 }}, + {"FOUT", N_("Fraction excluded from range"), AGR_SV_YES, 2, VAL_NUMERIC, { .type = FMT_F, .w = 5, .d = 3 }}, + {"N", N_("Number of cases"), AGR_SV_NO, 0, VAL_NUMERIC, { .type = FMT_F, .w = 7, .d = 0 }}, + {"NU", N_("Number of cases (unweighted)"), AGR_SV_OPT, 0, VAL_NUMERIC, { .type = FMT_F, .w = 7, .d = 0 }}, + {"NMISS", N_("Number of missing values"), AGR_SV_YES, 0, VAL_NUMERIC, { .type = FMT_F, .w = 7, .d = 0 }}, + {"NUMISS", N_("Number of missing values (unweighted)"), AGR_SV_YES, 0, VAL_NUMERIC, { .type = FMT_F, .w = 7, .d = 0 }}, {"FIRST", N_("First non-missing value"), AGR_SV_YES, 0, VAL_STRING, {-1, -1, -1}}, {"LAST", N_("Last non-missing value"), AGR_SV_YES, 0, VAL_STRING, {-1, -1, -1}}, {NULL, NULL, AGR_SV_NO, 0, -1, {-1, -1, -1}}, @@ -205,7 +206,7 @@ cmd_aggregate (struct lexer *lexer, struct dataset *ds) goto error; } - if ( agr.add_variables ) + if (agr.add_variables) agr.dict = dict_clone (dict); else agr.dict = dict_create (dict_get_encoding (dict)); @@ -223,7 +224,7 @@ cmd_aggregate (struct lexer *lexer, struct dataset *ds) lex_match (lexer, T_EQUALS); if (!lex_match_id (lexer, "COLUMNWISE")) { - lex_error_expecting (lexer, "COLUMNWISE", NULL); + lex_error_expecting (lexer, "COLUMNWISE"); goto error; } agr.missing = COLUMNWISE; @@ -311,7 +312,7 @@ cmd_aggregate (struct lexer *lexer, struct dataset *ds) initialize_aggregate_info (&agr); - if ( agr.add_variables ) + if (agr.add_variables) placeholder = casereader_clone (group); { @@ -332,8 +333,8 @@ cmd_aggregate (struct lexer *lexer, struct dataset *ds) else { dump_aggregate_info (&agr, output, c); - case_unref (c); } + case_unref (c); } if (!casegrouper_destroy (grouper)) goto error; @@ -452,7 +453,7 @@ parse_aggregate_functions (struct lexer *lexer, const struct dictionary *dict, exclude = ds_chomp_byte (&function_name, '.') ? MV_SYSTEM : MV_ANY; for (function = agr_func_tab; function->name; function++) - if (!strcasecmp (function->name, ds_cstr (&function_name))) + if (!c_strcasecmp (function->name, ds_cstr (&function_name))) break; if (NULL == function->name) { @@ -469,7 +470,6 @@ parse_aggregate_functions (struct lexer *lexer, const struct dictionary *dict, { if (function->src_vars == AGR_SV_YES) { - lex_force_match (lexer, T_LPAREN); goto error; } } @@ -638,7 +638,7 @@ parse_aggregate_functions (struct lexer *lexer, const struct dictionary *dict, free (dest[i]); if (dest_label[i]) - var_set_label (destvar, dest_label[i], true); + var_set_label (destvar, dest_label[i]); v->dest = destvar; } @@ -733,7 +733,7 @@ agr_destroy (struct agr_proc *agr) free (iter); } if (agr->dict != NULL) - dict_destroy (agr->dict); + dict_unref (agr->dict); } /* Execution. */ @@ -810,8 +810,8 @@ accumulate_aggregate_info (struct agr_proc *agr, const struct ccase *input) break; case MAX | FSTRING: /* Need to do some kind of Unicode collation thingy here */ - if (memcmp (iter->string, value_str (v, src_width), src_width) < 0) - memcpy (iter->string, value_str (v, src_width), src_width); + if (memcmp (iter->string, v->s, src_width) < 0) + memcpy (iter->string, v->s, src_width); iter->int1 = 1; break; case MIN: @@ -819,8 +819,8 @@ accumulate_aggregate_info (struct agr_proc *agr, const struct ccase *input) iter->int1 = 1; break; case MIN | FSTRING: - if (memcmp (iter->string, value_str (v, src_width), src_width) > 0) - memcpy (iter->string, value_str (v, src_width), src_width); + if (memcmp (iter->string, v->s, src_width) > 0) + memcpy (iter->string, v->s, src_width); iter->int1 = 1; break; case FGT: @@ -831,8 +831,7 @@ accumulate_aggregate_info (struct agr_proc *agr, const struct ccase *input) break; case FGT | FSTRING: case PGT | FSTRING: - if (memcmp (iter->arg[0].c, - value_str (v, src_width), src_width) < 0) + if (memcmp (iter->arg[0].c, v->s, src_width) < 0) iter->dbl[0] += weight; iter->dbl[1] += weight; break; @@ -844,8 +843,7 @@ accumulate_aggregate_info (struct agr_proc *agr, const struct ccase *input) break; case FLT | FSTRING: case PLT | FSTRING: - if (memcmp (iter->arg[0].c, - value_str (v, src_width), src_width) > 0) + if (memcmp (iter->arg[0].c, v->s, src_width) > 0) iter->dbl[0] += weight; iter->dbl[1] += weight; break; @@ -857,10 +855,8 @@ accumulate_aggregate_info (struct agr_proc *agr, const struct ccase *input) break; case FIN | FSTRING: case PIN | FSTRING: - if (memcmp (iter->arg[0].c, - value_str (v, src_width), src_width) <= 0 - && memcmp (iter->arg[1].c, - value_str (v, src_width), src_width) >= 0) + if (memcmp (iter->arg[0].c, v->s, src_width) <= 0 + && memcmp (iter->arg[1].c, v->s, src_width) >= 0) iter->dbl[0] += weight; iter->dbl[1] += weight; break; @@ -872,10 +868,8 @@ accumulate_aggregate_info (struct agr_proc *agr, const struct ccase *input) break; case FOUT | FSTRING: case POUT | FSTRING: - if (memcmp (iter->arg[0].c, - value_str (v, src_width), src_width) > 0 - || memcmp (iter->arg[1].c, - value_str (v, src_width), src_width) < 0) + if (memcmp (iter->arg[0].c, v->s, src_width) > 0 + || memcmp (iter->arg[1].c, v->s, src_width) < 0) iter->dbl[0] += weight; iter->dbl[1] += weight; break; @@ -897,7 +891,7 @@ accumulate_aggregate_info (struct agr_proc *agr, const struct ccase *input) case FIRST | FSTRING: if (iter->int1 == 0) { - memcpy (iter->string, value_str (v, src_width), src_width); + memcpy (iter->string, v->s, src_width); iter->int1 = 1; } break; @@ -906,7 +900,7 @@ accumulate_aggregate_info (struct agr_proc *agr, const struct ccase *input) iter->int1 = 1; break; case LAST | FSTRING: - memcpy (iter->string, value_str (v, src_width), src_width); + memcpy (iter->string, v->s, src_width); iter->int1 = 1; break; case NMISS: @@ -940,7 +934,7 @@ dump_aggregate_info (const struct agr_proc *agr, struct casewriter *output, cons { struct ccase *c = case_create (dict_get_proto (agr->dict)); - if ( agr->add_variables) + if (agr->add_variables) { case_copy (c, 0, break_case, 0, dict_get_var_cnt (agr->src_dict)); } @@ -986,7 +980,7 @@ dump_aggregate_info (const struct agr_proc *agr, struct casewriter *output, cons break; case MEDIAN: { - if ( i->writer) + if (i->writer) { struct percentile *median = percentile_create (0.5, i->cc); struct order_stats *os = &median->parent; @@ -1024,7 +1018,7 @@ dump_aggregate_info (const struct agr_proc *agr, struct casewriter *output, cons case MAX | FSTRING: case MIN | FSTRING: if (i->int1) - memcpy (value_str_rw (v, width), i->string, width); + memcpy (v->s, i->string, width); else value_set_missing (v, width); break; @@ -1063,7 +1057,7 @@ dump_aggregate_info (const struct agr_proc *agr, struct casewriter *output, cons case FIRST | FSTRING: case LAST | FSTRING: if (i->int1) - memcpy (value_str_rw (v, width), i->string, width); + memcpy (v->s, i->string, width); else value_set_missing (v, width); break; @@ -1118,10 +1112,10 @@ initialize_aggregate_info (struct agr_proc *agr) proto = caseproto_add_width (proto, 0); proto = caseproto_add_width (proto, 0); - if ( ! iter->subject) + if (! iter->subject) iter->subject = dict_create_internal_var (0, 0); - if ( ! iter->weight) + if (! iter->weight) iter->weight = dict_create_internal_var (1, 0); subcase_init_var (&ordering, iter->subject, SC_ASCEND);