From: Ben Pfaff Date: Tue, 2 Aug 2022 05:19:09 +0000 (-0700) Subject: CTABLES strings work X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?p=pspp;a=commitdiff_plain;h=49c7604863a430c263b6a21440849bf61db6764a CTABLES strings work --- diff --git a/src/language/stats/ctables.c b/src/language/stats/ctables.c index 3b7dc24d10..a69e8d5659 100644 --- a/src/language/stats/ctables.c +++ b/src/language/stats/ctables.c @@ -4261,7 +4261,6 @@ ctables_pcexpr_evaluate (const struct ctables_pcexpr_evaluate_ctx *ctx, } case CTPO_CAT_NUMBER: - case CTPO_CAT_STRING: case CTPO_CAT_MISSING: case CTPO_CAT_OTHERNM: case CTPO_CAT_SUBTOTAL: @@ -4275,6 +4274,25 @@ ctables_pcexpr_evaluate (const struct ctables_pcexpr_evaluate_ctx *ctx, return ctables_pcexpr_evaluate_category (ctx, &cv); } + case CTPO_CAT_STRING: + { + int width = var_get_width (ctx->section->nests[ctx->pc_a]->vars[ctx->pc_a_idx]); + char *s = NULL; + if (width > e->string.length) + { + s = xmalloc (width); + buf_copy_rpad (s, width, e->string.string, e->string.length, ' '); + } + struct ctables_cell_value cv = { + .category = ctables_find_category_for_postcompute (ctx->section->table->ctables->dict, ctx->cats, ctx->parse_format, e), + .value = { .s = CHAR_CAST (uint8_t *, s ? s : e->string.string) }, + }; + assert (cv.category != NULL); + double retval = ctables_pcexpr_evaluate_category (ctx, &cv); + free (s); + return retval; + } + case CTPO_ADD: return ctables_pcexpr_evaluate_nonterminal (ctx, e, 2, ctpo_add); diff --git a/tests/language/stats/ctables.at b/tests/language/stats/ctables.at index 82e0f9bea8..ebda3ce826 100644 --- a/tests/language/stats/ctables.at +++ b/tests/language/stats/ctables.at @@ -2,12 +2,10 @@ AT_BANNER([CTABLES]) dnl Features not yet tested: dnl - Preprocessing to distinguish categorical from scale. -dnl - String variables and values dnl - Testing details of missing value handling in summaries. dnl - test CLABELS ROWLABELS=LAYER. dnl - Test VLABELS. dnl - Test WEIGHT and adjustment weights. -dnl - EMPTY=INCLUDE For string ranges. dnl - Summary functions: dnl * Separate summary functions for totals and subtotals. dnl * )CILEVEL in summary label specification @@ -16,10 +14,8 @@ dnl * VALUE dnl * LABEL dnl * ascending/descending dnl - CATEGORIES: -dnl * String values dnl * Date values dnl * THRU (numeric ranges) -dnl * THRU (string ranges) dnl * OTHERNM dnl - FORMAT: dnl * MINCOLWIDTH, MAXCOLWIDTH, UNITS. @@ -54,23 +50,6 @@ dnl * .LCL and .UCL suffixes. dnl * .SE suffixes. dnl - CATEGORIES: dnl * Data-dependent sorting. -dnl -dnl -dnl Bug: -dnl CTABLES /TABLE=qnd1 [MEAN, MEDIAN] BY qns3a. -dnl produces a bad median: -dnl Custom Tables -dnl +--------------------------+-----------------------+ -dnl | | S3a. GENDER: | -dnl | +-----------+-----------+ -dnl | | Male | Female | -dnl | +----+------+----+------+ -dnl | |Mean|Median|Mean|Median| -dnl +--------------------------+----+------+----+------+ -dnl |D1. AGE: What is your age?| 46| 999| 50| 999| -dnl +--------------------------+----+------+----+------+ - - AT_SETUP([CTABLES parsing]) AT_CHECK([ln $top_srcdir/examples/nhtsa.sav . || cp $top_srcdir/examples/nhtsa.sav .]) @@ -760,6 +739,88 @@ Every day ]) AT_CLEANUP +AT_SETUP([CTABLES one string variable]) +AT_CHECK([ln $top_srcdir/examples/nhtsa.sav . || cp $top_srcdir/examples/nhtsa.sav .]) +AT_DATA([ctables.sps], +[[GET 'nhtsa.sav'. +STRING licensed(A8). +MISSING VALUES licensed('DontKnow', 'Refused'). +RECODE qnd7a(1='Yes')(2='No')(3='DontKnow')(4='Refused') INTO licensed. +CTABLES /TABLE licensed. +CTABLES /TABLE licensed [COUNT, TOTALS[COUNT, VALIDN]] /CATEGORIES VARIABLES=ALL TOTAL=YES MISSING=INCLUDE. +CTABLES /TABLE licensed /CATEGORIES VARIABLES=licensed ['Yes', 'No'] TOTAL=YES. +* Notice that the string matching is case-sensitive. +CTABLES /TABLE licensed /CATEGORIES VARIABLES=licensed ['Yes', 'no'] TOTAL=YES. +CTABLES /TABLE licensed /CATEGORIES VARIABLES=licensed ['No' THRU 'yes'] TOTAL=YES. +CTABLES + /PCOMPUTE ¬yes=EXPR(['No']+['DontKnow']+['Refused']) + /PPROPERTIES ¬yes LABEL='Not Yes' HIDESOURCECATS=YES + /TABLE licensed + /CATEGORIES VARIABLES=licensed ['Yes', ¬yes, 'No', 'DontKnow', 'Refused']. +CTABLES + /PCOMPUTE ¬yes=EXPR(['No']+['DontKnow']+['Refused']) + /PPROPERTIES ¬yes LABEL='Not Yes' HIDESOURCECATS=YES + /TABLE licensed + /CATEGORIES VARIABLES=licensed ['Yes', ¬yes, 'DontKnow' THRU 'No', 'Refused']. +]]) +AT_CHECK([pspp ctables.sps -O box=unicode -O width=80], [0], [dnl + Custom Tables +╭────────────┬─────╮ +│ │Count│ +├────────────┼─────┤ +│licensed No │ 572│ +│ Yes│ 6379│ +╰────────────┴─────╯ + + Custom Tables +╭─────────────────┬─────┬───────╮ +│ │Count│Valid N│ +├─────────────────┼─────┼───────┤ +│licensed DontKnow│ 4│ │ +│ No │ 572│ │ +│ Refused │ 44│ │ +│ Yes │ 6379│ │ +│ Total │ 6999│ 6951│ +╰─────────────────┴─────┴───────╯ + + Custom Tables +╭──────────────┬─────╮ +│ │Count│ +├──────────────┼─────┤ +│licensed Yes │ 6379│ +│ No │ 572│ +│ Total│ 6951│ +╰──────────────┴─────╯ + + Custom Tables +╭──────────────┬─────╮ +│ │Count│ +├──────────────┼─────┤ +│licensed Yes │ 6379│ +│ no │ 0│ +│ Total│ 6379│ +╰──────────────┴─────╯ + + Custom Tables +╭────────────────┬─────╮ +│ │Count│ +├────────────────┼─────┤ +│licensed No │ 572│ +│ Refused│ 44│ +│ Yes │ 6379│ +│ Total │ 6995│ +╰────────────────┴─────╯ + + Custom Tables +╭────────────────┬─────╮ +│ │Count│ +├────────────────┼─────┤ +│licensed Yes │ 6379│ +│ Not Yes│ 620│ +╰────────────────┴─────╯ +]) +AT_CLEANUP + AT_SETUP([CTABLES one scale variable]) AT_CHECK([ln $top_srcdir/examples/nhtsa.sav . || cp $top_srcdir/examples/nhtsa.sav .]) AT_DATA([ctables.sps],