Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions coding-scheme.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
6 changes: 4 additions & 2 deletions coding-scheme.schema.json
Original file line number Diff line number Diff line change
@@ -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.",
Expand Down Expand Up @@ -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": [
Expand All @@ -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"
]
}
Expand Down
2 changes: 1 addition & 1 deletion coding-scheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [];
Expand Down
3 changes: 2 additions & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node'
testEnvironment: 'node',
modulePathIgnorePatterns: ['<rootDir>/dist/']
};
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -27,7 +27,10 @@
"files": [
"*.ts"
],
"extends": "@iqb/eslint-config"
"extends": "@iqb/eslint-config",
"parserOptions": {
"project": ["./tsconfig.eslint.json"]
}
},
{
"files": [
Expand Down
2 changes: 1 addition & 1 deletion package_npm.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
37 changes: 37 additions & 0 deletions partial-credit.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
4 changes: 2 additions & 2 deletions test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 2 additions & 0 deletions test/test_valid/all-source-processing.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
Expand Down
14 changes: 14 additions & 0 deletions test/test_valid/partial-credit-options.json
Original file line number Diff line number Diff line change
@@ -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"]}]}]}]
}
]
}
5 changes: 5 additions & 0 deletions tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "./tsconfig.json",
"include": ["**/*.ts"],
"exclude": ["node_modules", "dist", "public"]
}
Loading