From 83cd448823b2c132f705f939f4b2b1ce5af3de29 Mon Sep 17 00:00:00 2001 From: jurei733 <67505990+jurei733@users.noreply.github.com> Date: Mon, 19 Oct 2026 12:25:53 +0200 Subject: [PATCH 1/2] Add opt-in partial credit derivation parameters --- README.md | 27 ++++++++++++++- coding-scheme.interface.ts | 2 ++ coding-scheme.schema.json | 6 ++-- coding-scheme.ts | 2 +- jest.config.ts | 3 +- package-lock.json | 4 +-- package.json | 7 ++-- package_npm.json | 2 +- partial-credit.test.ts | 37 +++++++++++++++++++++ test/test_valid/all-source-processing.json | 2 ++ test/test_valid/partial-credit-options.json | 14 ++++++++ tsconfig.eslint.json | 5 +++ 12 files changed, 101 insertions(+), 10 deletions(-) create mode 100644 partial-credit.test.ts create mode 100644 test/test_valid/partial-credit-options.json create mode 100644 tsconfig.eslint.json diff --git a/README.md b/README.md index d008933..5e20dda 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,32 @@ const status = CodingScheme.checkVersion({ The current library version constants are: - **`CodingSchemeVersionMajor`**: `3` -- **`CodingSchemeVersionMinor`**: `4` +- **`CodingSchemeVersionMinor`**: `5` + +### Partial credit with empty source responses (3.5) + +For `SUM_SCORE`, `SUM_CODE` and `CONCAT_CODE`, the derived variable can opt in +through `sourceParameters.processing`: + +- `TAKE_DISPLAYED_AS_ZERO_IF_PARTIAL`: replace contributions from `DISPLAYED` + sources, including displayed checkbox defaults such as `false`. +- `TAKE_EMPTY_AS_ZERO_IF_PARTIAL`: replace contributions from `INVALID` sources + whose value is exactly `null`, `""` or `[]`. Neither `false` nor `0` is empty. + +Both options are disabled by default. Replacement requires at least one source +with status `CODING_COMPLETE`. Pending codings are never replaced and yield +`DERIVE_PENDING` when all other sources are coded or explicitly allowed partials. +Otherwise the existing status and error precedence applies. With no coded or +pending source, the existing aggregation is preserved, including mixtures of +`DISPLAYED` and empty `INVALID`: there is no automatic zero score or `x_x`. + +Replacement happens only inside this derivation; original source status, value, +code and score remain unchanged. The replacement contribution is score `0` for +`SUM_SCORE`, code `0` for `SUM_CODE`, and the text placeholder `x` for +`CONCAT_CODE`. Thus `0_x` differs from two genuinely coded zeros (`0_0`). The +placeholder is part of the derived text value, not a new code ID. Sorting also +applies to placeholders when `SORT` is enabled. Other derivation methods, +including the existing SOLVER policies, are unaffected. ### Types diff --git a/coding-scheme.interface.ts b/coding-scheme.interface.ts index 145150c..57e0b71 100644 --- a/coding-scheme.interface.ts +++ b/coding-scheme.interface.ts @@ -54,6 +54,8 @@ export type SourceProcessingType = | 'REMOVE_DISPENSABLE_SPACES' | 'TAKE_DISPLAYED_AS_VALUE_CHANGED' | 'TAKE_EMPTY_AS_VALID' + | 'TAKE_DISPLAYED_AS_ZERO_IF_PARTIAL' + | 'TAKE_EMPTY_AS_ZERO_IF_PARTIAL' | 'SORT' | 'TAKE_NOT_REACHED_AS_VALUE_CHANGED'; diff --git a/coding-scheme.schema.json b/coding-scheme.schema.json index accf3fa..6009d42 100644 --- a/coding-scheme.schema.json +++ b/coding-scheme.schema.json @@ -1,5 +1,5 @@ { - "$id": "coding-scheme@iqb-standard@3.4", + "$id": "coding-scheme@iqb-standard@3.5", "$schema": "http://json-schema.org/draft-07/schema#", "title": "Coding Scheme", "description": "Data structure to specify all processing steps of response data in order to get coded and scored data for analyses.", @@ -58,7 +58,7 @@ }, "processing": { "type": "array", - "description": "Some options to change value or status", + "description": "Options to change value or status. TAKE_DISPLAYED_AS_ZERO_IF_PARTIAL and TAKE_EMPTY_AS_ZERO_IF_PARTIAL are opt-in options for SUM_SCORE, SUM_CODE and CONCAT_CODE. They replace DISPLAYED sources or empty INVALID sources (null, empty string, empty array), respectively, only within a derivation with at least one regularly coded source. Contributions are 0 for sums and x for concatenation. Pending sources remain pending; fully unprocessed or invalid sources alone do not trigger a calculation. Original source responses remain unchanged.", "items": { "type": "string", "enum": [ @@ -69,6 +69,8 @@ "TAKE_DISPLAYED_AS_VALUE_CHANGED", "TAKE_NOT_REACHED_AS_VALUE_CHANGED", "TAKE_EMPTY_AS_VALID", + "TAKE_DISPLAYED_AS_ZERO_IF_PARTIAL", + "TAKE_EMPTY_AS_ZERO_IF_PARTIAL", "SORT" ] } diff --git a/coding-scheme.ts b/coding-scheme.ts index db78eb6..16be7f1 100644 --- a/coding-scheme.ts +++ b/coding-scheme.ts @@ -53,7 +53,7 @@ export const booleanRules = ['IS_TRUE', 'IS_FALSE']; export const DeriveConcatDelimiter = '_'; export const CodingSchemeVersionMajor = 3; -export const CodingSchemeVersionMinor = 4; +export const CodingSchemeVersionMinor = 5; export class CodingScheme { variableCodings: VariableCodingData[] = []; diff --git a/jest.config.ts b/jest.config.ts index a58c252..aa1daeb 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -1,5 +1,6 @@ /** @type {import('ts-jest').JestConfigWithTsJest} */ module.exports = { preset: 'ts-jest', - testEnvironment: 'node' + testEnvironment: 'node', + modulePathIgnorePatterns: ['/dist/'] }; diff --git a/package-lock.json b/package-lock.json index 52309a4..20e2ee3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@iqbspecs/coding-scheme", - "version": "3.4.1", + "version": "3.5.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@iqbspecs/coding-scheme", - "version": "3.4.1", + "version": "3.5.0", "license": "MIT", "devDependencies": { "@asyncapi/cli": "^4.1.1", diff --git a/package.json b/package.json index 78a2768..69712f0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@iqbspecs/coding-scheme", - "version": "3.4.1", + "version": "3.5.0", "author": "IQB - Institut zur Qualitätsentwicklung im Bildungswesen", "license": "MIT", "description": "Data interface for coding assessment output", @@ -27,7 +27,10 @@ "files": [ "*.ts" ], - "extends": "@iqb/eslint-config" + "extends": "@iqb/eslint-config", + "parserOptions": { + "project": ["./tsconfig.eslint.json"] + } }, { "files": [ diff --git a/package_npm.json b/package_npm.json index 5df8eca..983806c 100644 --- a/package_npm.json +++ b/package_npm.json @@ -1,6 +1,6 @@ { "name": "@iqbspecs/coding-scheme", - "version": "3.4.1", + "version": "3.5.0", "author": "IQB - Institut zur Qualitätsentwicklung im Bildungswesen", "license": "CC0 1.0", "description": "Data interface: coding-scheme", diff --git a/partial-credit.test.ts b/partial-credit.test.ts new file mode 100644 index 0000000..8dbe85a --- /dev/null +++ b/partial-credit.test.ts @@ -0,0 +1,37 @@ +import Ajv from 'ajv'; +import fs from 'fs'; +import { CodingScheme, CodingSchemeVersionMinor } from './coding-scheme'; +import type { CodingSchemeData } from './coding-scheme.interface'; + +const schema = JSON.parse(fs.readFileSync(`${__dirname}/coding-scheme.schema.json`, 'utf8')); +const validate = new Ajv().compile(schema); +const data: CodingSchemeData = JSON.parse( + fs.readFileSync(`${__dirname}/test/test_valid/partial-credit-options.json`, 'utf8') +); + +describe('partial-credit derivation options', () => { + test('schema accepts both options and a regular text rule for 0_x', () => { + expect(validate(data)).toBe(true); + expect(CodingSchemeVersionMinor).toBe(5); + expect(schema.$id).toBe('coding-scheme@iqb-standard@3.5'); + }); + + test('reading, copying and exporting preserve opt-in parameters', () => { + const copy = new CodingScheme(new CodingScheme(data).toString()); + const exported = JSON.parse(copy.toString()); + expect(exported.version).toBe('3.5'); + expect(exported.variableCodings[0].sourceParameters.processing) + .toEqual(data.variableCodings[0].sourceParameters?.processing); + }); + + test('existing schemes keep the options disabled', () => { + const scheme = new CodingScheme({ version: '3.4', variableCodings: [{ id: 'a', sourceType: 'BASE' }] }); + expect(scheme.variableCodings[0].sourceParameters?.processing || []).toEqual([]); + }); + + test('x remains a derived text value and is not accepted as a code ID', () => { + const invalid = JSON.parse(JSON.stringify(data)); + invalid.variableCodings[0].codes[0].id = 'x'; + expect(validate(invalid)).toBe(false); + }); +}); diff --git a/test/test_valid/all-source-processing.json b/test/test_valid/all-source-processing.json index cd20a66..6f7b87c 100644 --- a/test/test_valid/all-source-processing.json +++ b/test/test_valid/all-source-processing.json @@ -13,6 +13,8 @@ "REMOVE_DISPENSABLE_SPACES", "TAKE_DISPLAYED_AS_VALUE_CHANGED", "TAKE_EMPTY_AS_VALID", + "TAKE_DISPLAYED_AS_ZERO_IF_PARTIAL", + "TAKE_EMPTY_AS_ZERO_IF_PARTIAL", "SORT", "TAKE_NOT_REACHED_AS_VALUE_CHANGED" ] diff --git a/test/test_valid/partial-credit-options.json b/test/test_valid/partial-credit-options.json new file mode 100644 index 0000000..86cacae --- /dev/null +++ b/test/test_valid/partial-credit-options.json @@ -0,0 +1,14 @@ +{ + "version": "3.5", + "variableCodings": [ + { + "id": "partial", + "sourceType": "CONCAT_CODE", + "deriveSources": ["a", "b"], + "sourceParameters": { + "processing": ["TAKE_DISPLAYED_AS_ZERO_IF_PARTIAL", "TAKE_EMPTY_AS_ZERO_IF_PARTIAL", "SORT"] + }, + "codes": [{"id": 1, "ruleSets": [{"rules": [{"method": "MATCH", "parameters": ["0_x"]}]}]}] + } + ] +} diff --git a/tsconfig.eslint.json b/tsconfig.eslint.json new file mode 100644 index 0000000..f3f8413 --- /dev/null +++ b/tsconfig.eslint.json @@ -0,0 +1,5 @@ +{ + "extends": "./tsconfig.json", + "include": ["**/*.ts"], + "exclude": ["node_modules", "dist", "public"] +} From 54efa1196124ed82c8c246e81923d527dc78f450 Mon Sep 17 00:00:00 2001 From: jurei733 <67505990+jurei733@users.noreply.github.com> Date: Mon, 19 Oct 2026 12:29:59 +0200 Subject: [PATCH 2/2] Fix schema fixture paths in Jest workers --- test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test.ts b/test.ts index 707059e..a074f52 100644 --- a/test.ts +++ b/test.ts @@ -5,8 +5,8 @@ import fs from 'fs'; import { log, error } from "console"; const ajv = new Ajv(); -const schemaFilename = process.argv[3]; -const testDataFolder = process.argv[4]; +const schemaFilename = process.argv[3] || `${__dirname}/coding-scheme.schema.json`; +const testDataFolder = process.argv[4] || './test'; describe(testDataFolder, () => { const schemaFileContent = fs.readFileSync(schemaFilename, 'utf8');