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
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,28 @@ Additionally, this library exports multiple dialogs and helpers (see “Public A

# Installation (Angular)

## Partial credit (Schemer 2.9.0)

In the source/derivation parameters of `SUM_SCORE`, `SUM_CODE` and `CONCAT_CODE`,
two independent options allow displayed source responses or empty invalid source
responses to contribute to a partially answered task. Both are disabled by
default. They require at least one regularly coded answer; completely
unprocessed tasks retain their original status, and pending coding is deferred.

The contribution is `0` for sums and `x` for concatenated codes (`0_x`, distinct
from `0_0`). Only `null`, empty text and an empty list count as empty invalid
answers; `false` and `0` remain values. Original source responses are preserved.
The options, descriptions and `x` combinations survive scheme import/export.
Existing SOLVER policies are unchanged.

This feature requires the coordinated releases `@iqbspecs/coding-scheme@3.5.0`
and `@iqb/responses@5.4.0`. The prepared lockfile identifies the locally built
release tarballs; these versions must be published before a fresh registry-based
`npm ci` can succeed. Publish the specification first, then responses, and then
build/release the Schemer and Angular library. Refresh lockfile integrity if the
published tarballs differ from the prepared artifacts. Local verification uses
the built packages from sibling `coding-scheme` and `responses` checkouts.

## Schemer viewport support

The Schemer supports container widths of **320 CSS pixels and above**, including
Expand Down
18 changes: 9 additions & 9 deletions package-lock.json

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

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "coding-components",
"config": {
"schemer_version": "2.9.0-alpha.2"
"schemer_version": "2.9.0"
},
"scripts": {
"ng": "ng",
Expand Down Expand Up @@ -49,8 +49,8 @@
"@angular/platform-browser-dynamic": "^21.2.23",
"@angular/router": "^21.2.23",
"@iqb/mathlive": "^0.4.1",
"@iqb/responses": "5.3.1",
"@iqbspecs/coding-scheme": "^3.4.1",
"@iqb/responses": "^5.4.0",
"@iqbspecs/coding-scheme": "^3.5.0",
"@iqbspecs/response": "^2.0.0",
"@iqbspecs/variable-info": "^1.3.0",
"@ngx-translate/core": "^15.0.0",
Expand Down
8 changes: 4 additions & 4 deletions projects/ngx-coding-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"exports": {
"./lib/ngx-coding-components.module": "./lib/ngx-coding-components.module.d.ts"
},
"version": "4.1.0-alpha.2",
"author": "IQB - Institut zur Qualit\u00e4tsentwicklung im Bildungswesen",
"version": "4.1.0",
"author": "IQB - Institut zur Qualitätsentwicklung im Bildungswesen",
"license": "MIT",
"description": "Angular components for coding responses in assessments of IQB.",
"repository": {
Expand All @@ -28,7 +28,7 @@
"@angular/platform-browser": "^21.0.0",
"@angular/platform-browser-dynamic": "^21.0.0",
"@angular/router": "^21.0.0",
"@iqbspecs/coding-scheme": "^3.4.1",
"@iqbspecs/coding-scheme": "^3.5.0",
"@iqbspecs/response": "^1.5.1 || ^2.0.0",
"@iqbspecs/variable-info": "^1.3.0",
"@ngx-translate/core": "^15.0.0",
Expand Down Expand Up @@ -59,7 +59,7 @@
"ngx-tiptap": "^12.0.0",
"prosemirror-state": "^1.3.4",
"rxjs": "~7.8.0",
"@iqb/responses": "^5.3.1"
"@iqb/responses": "^5.4.0"
},
"devDependencies": {
"@angular-devkit/build-angular": "^21.2.24",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
CodeData,
CodeType,
SourceProcessingType,
VariableCodingData
} from '@iqbspecs/coding-scheme/coding-scheme.interface';
import { CodingSchemeFactory, CodingSchemeProblem } from '@iqb/responses';
Expand Down Expand Up @@ -417,6 +418,26 @@ describe('SchemerService', () => {
expect(values.length).toBeGreaterThanOrEqual(2);
});

it('should retain four-source CONCAT_CODE combinations when partial credit is enabled', () => {
const sources: VariableCodingData[] = ['a', 'b', 'c', 'd'].map(id => ({
id,
sourceType: 'BASE',
codes: [{ id: 0, type: 'NO_CREDIT', score: 0 }, { id: 1, type: 'FULL_CREDIT', score: 1 }]
}));
service.setCodingScheme({ variableCodings: sources } as unknown as never);
const derived: VariableCodingData = {
id: 'partial', sourceType: 'CONCAT_CODE', deriveSources: sources.map(source => source.id)
};
expect(service.getVarInfoByCoding(derived)?.values.length).toBe(16);
derived.sourceParameters = { processing: ['TAKE_DISPLAYED_AS_ZERO_IF_PARTIAL'] };
const values = service.getVarInfoByCoding(derived)?.values.map(value => value.value);
expect(values?.length).toBe(80);
expect(values).toContain('1_1_1_1');
expect(values).toContain('1_1_1_x');
expect(values).toContain('0_x_x_x');
expect(values).not.toContain('x_x_x_x');
});

it('should return CONCAT_CODE info with empty values list when combinations exceed limit', () => {
const manyCodes = Array.from({ length: 10 }).map((_, idx) => ({
id: idx + 1,
Expand Down Expand Up @@ -447,6 +468,27 @@ describe('SchemerService', () => {
expect((info as unknown as { values: unknown[] }).values.length).toBe(0);
});

['TAKE_DISPLAYED_AS_ZERO_IF_PARTIAL', 'TAKE_EMPTY_AS_ZERO_IF_PARTIAL'].forEach(option => {
it(`should include partial CONCAT_CODE values for ${option} without inventing x_x`, () => {
const source: VariableCodingData = {
id: 'zero', sourceType: 'BASE', codes: [{ id: 0, type: 'NO_CREDIT', score: 0 }]
};
service.setCodingScheme({ variableCodings: [source, { ...source, id: 'other' }] } as unknown as never);
const info = service.getVarInfoByCoding({
id: 'partial',
sourceType: 'CONCAT_CODE',
deriveSources: ['zero', 'other'],
sourceParameters: { processing: [option as SourceProcessingType] }
});
const values = info?.values.map(v => v.value);
expect(values).toContain('0_x');
expect(values).toContain('x_0');
expect(values).toContain('0_0');
expect(values).not.toContain('x_x');
expect(source.codes).toEqual([{ id: 0, type: 'NO_CREDIT', score: 0 }]);
});
});

it(
'should return integer synthetic VariableInfo for derive sources (non CONCAT_CODE) and undefined otherwise',
() => {
Expand Down
21 changes: 17 additions & 4 deletions projects/ngx-coding-components/src/lib/services/schemer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,20 +170,26 @@ export class SchemerService {
}
} else if (varCoding.sourceType === 'CONCAT_CODE') {
if (varCoding.deriveSources && varCoding.deriveSources.length > 0) {
const codes: (number | 'INVALID' | 'INTENDED_INCOMPLETE')[][] = [];
const codes: (number | 'INVALID' | 'INTENDED_INCOMPLETE' | 'x')[][] = [];
const partialCredit = varCoding.sourceParameters?.processing?.some(p => (
p === 'TAKE_DISPLAYED_AS_ZERO_IF_PARTIAL' || p === 'TAKE_EMPTY_AS_ZERO_IF_PARTIAL'
));
let totalCodesCount = 0;
varCoding.deriveSources.forEach((s: string) => {
if (this.codingScheme) {
const coding = this.codingScheme.variableCodings.find(
v => v.id === s
);
codes.push(coding ? (coding.codes || []).map(c => c.id) : []);
totalCodesCount += coding ? (coding.codes || []).length : 0;
const sourceCodes: (number | 'INVALID' | 'INTENDED_INCOMPLETE' | 'x')[] =
coding ? (coding.codes || []).map(c => c.id) : [];
totalCodesCount += sourceCodes.length;
if (coding && partialCredit) sourceCodes.push('x');
codes.push(sourceCodes);
}
});
let resultArray: string[] = [];
if (totalCodesCount < 10) {
codes.forEach((c: (number | 'INVALID' | 'INTENDED_INCOMPLETE')[]) => {
codes.forEach(c => {
if (resultArray.length > 0) {
resultArray = resultArray.flatMap(oldEntry => c
.filter(cEntry => cEntry !== null)
Expand All @@ -198,6 +204,13 @@ export class SchemerService {
}
});
}
if (partialCredit) {
resultArray = resultArray.filter(value => value.split(DeriveConcatDelimiter).some(code => code !== 'x'));
if (varCoding.sourceParameters?.processing?.includes('SORT')) {
resultArray = [...new Set(resultArray.map(value => value.split(DeriveConcatDelimiter)
.sort().join(DeriveConcatDelimiter)))];
}
}
return <VariableInfo>{
id: varCoding.id,
alias: varCoding.alias,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { SourceProcessingType, SourceType } from '@iqbspecs/coding-scheme';

export function sourceProcessingLabelKey(processingId: SourceProcessingType, sourceType?: SourceType): string {
const concatPartial = sourceType === 'CONCAT_CODE' && (
processingId === 'TAKE_DISPLAYED_AS_ZERO_IF_PARTIAL' || processingId === 'TAKE_EMPTY_AS_ZERO_IF_PARTIAL'
);
return `derive-processing.${processingId}${concatPartial ? '_CONCAT_CODE' : ''}`;
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,13 @@ <h1 mat-dialog-title>{{ (newVariableMode ? 'varList.add' : 'derive-processing.pr
@for (p of possibleDeriveProcessing; track p) {
<mat-checkbox [checked]="data.sourceParameters.processing?.includes(p)"
(change)="alterProcessing(p, $event.checked)">
{{ 'derive-processing.' + p | translate }}
{{ processingLabelKey(p) | translate }}
</mat-checkbox>
}
}
@if (data.sourceType === 'SUM_SCORE' || data.sourceType === 'SUM_CODE' || data.sourceType === 'CONCAT_CODE') {
<p role="note">{{ 'derive-processing.partial-credit-help' | translate }}</p>
}
@if (data.sourceType === 'SOLVER') {
<mat-form-field class="solver-expression-field">
<mat-label>{{ 'derive-processing.SOLVER_EXPRESSION' | translate }}</mat-label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ describe('EditSourceParametersDialog', () => {

it('updatePossibleDeriveProcessing should set options based on sourceType', () => {
const dialog = createDialog({ sourceType: 'CONCAT_CODE' });
expect(dialog.possibleDeriveProcessing).toEqual(['SORT']);
expect(dialog.possibleDeriveProcessing).toEqual([
'SORT', 'TAKE_DISPLAYED_AS_ZERO_IF_PARTIAL', 'TAKE_EMPTY_AS_ZERO_IF_PARTIAL'
]);

(dialog.data as unknown as { sourceType: string }).sourceType = 'UNIQUE_VALUES';
dialog.updatePossibleDeriveProcessing();
Expand All @@ -157,6 +159,24 @@ describe('EditSourceParametersDialog', () => {
expect(dialog.possibleDeriveProcessing).toEqual([]);
});

['SUM_SCORE', 'SUM_CODE', 'CONCAT_CODE'].forEach(sourceType => {
it(`should offer opt-in partial credit for ${sourceType} and preserve the original on cancel`, () => {
const original = { processing: [] as string[] };
const dialog = createDialog({ sourceType, sourceParameters: original });
const option: SourceProcessingType = 'TAKE_EMPTY_AS_ZERO_IF_PARTIAL';
expect(dialog.data.sourceParameters.processing).toEqual([]);
expect(dialog.possibleDeriveProcessing).toContain(option);
expect(dialog.processingLabelKey(option)).toBe(
`derive-processing.${option}${sourceType === 'CONCAT_CODE' ? '_CONCAT_CODE' : ''}`
);
dialog.alterProcessing(option, true);
expect(dialog.data.sourceParameters.processing).toEqual([option]);
expect(original.processing).toEqual([]);
dialog.alterProcessing(option, false);
expect(dialog.data.sourceParameters.processing).toEqual([]);
});
});

it('updatePossibleNewSources should exclude selfAlias and BASE_NO_VALUE and set selectedSources', () => {
const dialog = createDialog({
selfAlias: 'V1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
import { Response } from '@iqbspecs/response/response.interface';
import { CodingFactory, CodingSchemeFactory } from '@iqb/responses';
import { SchemerService } from '../../services/schemer.service';
import { sourceProcessingLabelKey } from '../../services/source-processing-label';
import {
isValidVariableIdentifier
} from '../../services/variable-identifier-validation';
Expand Down Expand Up @@ -397,14 +398,20 @@ export class EditSourceParametersDialog {
'TO_NUMBER',
'TO_LOWER_CASE'
],
CONCAT_CODE: ['SORT']
CONCAT_CODE: ['SORT', 'TAKE_DISPLAYED_AS_ZERO_IF_PARTIAL', 'TAKE_EMPTY_AS_ZERO_IF_PARTIAL'],
SUM_CODE: ['TAKE_DISPLAYED_AS_ZERO_IF_PARTIAL', 'TAKE_EMPTY_AS_ZERO_IF_PARTIAL'],
SUM_SCORE: ['TAKE_DISPLAYED_AS_ZERO_IF_PARTIAL', 'TAKE_EMPTY_AS_ZERO_IF_PARTIAL']
};

this.possibleDeriveProcessing =
processingOptions[this.data.sourceType] || [];
this.clearSolverTestResult();
}

processingLabelKey(processingId: SourceProcessingType): string {
return sourceProcessingLabelKey(processingId, this.data.sourceType);
}

alterProcessing(processingId: SourceProcessingType, checked: boolean): void {
const processingList = this.data.sourceParameters.processing;
if (!processingList) return;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { TestBed } from '@angular/core/testing';
import { provideNoopAnimations } from '@angular/platform-browser/animations';
import { MAT_DIALOG_DATA } from '@angular/material/dialog';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { SourceType } from '@iqbspecs/coding-scheme';
import translations from '../../../../translations/de.json';
import { SchemerService } from '../../services/schemer.service';
import { EditSourceParametersDialog, EditSourceParametersDialogData } from './edit-source-parameters-dialog.component';

describe('rendered partial-credit source parameters', () => {
(['SUM_SCORE', 'SUM_CODE', 'CONCAT_CODE'] as SourceType[]).forEach(sourceType => {
it(`renders, toggles and isolates partial-credit settings for ${sourceType}`, async () => {
const original: EditSourceParametersDialogData = {
selfId: 'derived',
selfAlias: 'derived',
sourceType,
deriveSources: ['a'],
sourceParameters: { processing: [] }
};
const service = new SchemerService();
service.setCodingScheme({ variableCodings: [{ id: 'a', sourceType: 'BASE', codes: [] }] } as never);
await TestBed.configureTestingModule({
imports: [EditSourceParametersDialog, TranslateModule.forRoot()],
providers: [
provideNoopAnimations(),
{ provide: MAT_DIALOG_DATA, useValue: original },
{ provide: SchemerService, useValue: service }
]
}).compileComponents();
const translate = TestBed.inject(TranslateService);
translate.setTranslation('de', translations);
translate.use('de');
const fixture = TestBed.createComponent(EditSourceParametersDialog);
fixture.detectChanges();
await fixture.whenStable();

const element: HTMLElement = fixture.nativeElement;
const checkboxIndex = sourceType === 'CONCAT_CODE' ? 1 : 0;
const inputs = element.querySelectorAll<HTMLInputElement>('mat-checkbox input');
expect(inputs.length).toBe(sourceType === 'CONCAT_CODE' ? 3 : 2);
expect(inputs[checkboxIndex].checked).toBeFalse();
expect(element.textContent).toContain(sourceType === 'CONCAT_CODE' ? 'durch x ersetzen' : 'als 0 werten');
expect(element.textContent).toContain('mindestens eine regulär kodierte Teilantwort');
inputs[checkboxIndex].click();
fixture.detectChanges();
expect(fixture.componentInstance.data.sourceParameters.processing).toContain('TAKE_DISPLAYED_AS_ZERO_IF_PARTIAL');
expect(original.sourceParameters.processing).toEqual([]);
inputs[checkboxIndex].click();
fixture.detectChanges();
expect(fixture.componentInstance.data.sourceParameters.processing).toEqual([]);
fixture.componentInstance.data.sourceType = 'SOLVER';
fixture.componentInstance.updatePossibleDeriveProcessing();
fixture.changeDetectorRef.markForCheck();
await fixture.whenStable();
expect(element.querySelectorAll('mat-checkbox').length).toBe(0);
fixture.destroy();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
{
<div class="fx-row-start-start" style="font-size: small">
<mat-icon style="font-size: small">check</mat-icon>
<div>{{ "derive-processing." + p | translate }}</div>
<div>{{ processingLabelKey(p) | translate }}</div>
</div>
}
</div>
Expand Down
Loading
Loading