@media-quest/builder 0.0.28 → 0.0.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/public-api.d.ts +3 -0
- package/dist/public-api.js +13 -2
- package/dist/public-api.js.map +1 -1
- package/package.json +2 -2
- package/src/code-book/codebook.ts +10 -2
- package/src/sum-score/sum-score-variable.spec.ts +308 -308
- package/src/sum-score/sum-score-variable.ts +102 -102
- package/src/sum-score/sum-score.ts +6 -1
|
@@ -1,102 +1,102 @@
|
|
|
1
|
-
import { PageID, SumScoreVariableID } from "../primitives/ID";
|
|
2
|
-
import { BuilderObject } from "../BuilderObject";
|
|
3
|
-
import { DUtil } from "@media-quest/engine";
|
|
4
|
-
import { BuilderPage } from "../page/Builder-page";
|
|
5
|
-
|
|
6
|
-
export interface SumScoreVariableDto {
|
|
7
|
-
id: SumScoreVariableID;
|
|
8
|
-
name: string;
|
|
9
|
-
description: string;
|
|
10
|
-
useAvg: boolean;
|
|
11
|
-
}
|
|
12
|
-
export class SumScoreVariable extends BuilderObject<
|
|
13
|
-
"builder-sum-score-variable",
|
|
14
|
-
SumScoreVariableDto
|
|
15
|
-
> {
|
|
16
|
-
readonly objectType = "builder-sum-score-variable";
|
|
17
|
-
readonly id: SumScoreVariableID;
|
|
18
|
-
private _useAvg = true;
|
|
19
|
-
private _name = "";
|
|
20
|
-
private _description = "";
|
|
21
|
-
private _error = "";
|
|
22
|
-
private _usedIn: ReadonlyArray<BuilderPage> = [];
|
|
23
|
-
// private _basedOn = new Map<pageId: Page>()
|
|
24
|
-
get usedIn() {
|
|
25
|
-
return [...this._usedIn];
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// private _basedOn: Array<{ varId: string }> = [];
|
|
29
|
-
public static readonly create = (data: {
|
|
30
|
-
name: string;
|
|
31
|
-
description: string;
|
|
32
|
-
useAvg: boolean;
|
|
33
|
-
}): SumScoreVariable => {
|
|
34
|
-
const id = SumScoreVariableID.create();
|
|
35
|
-
return new SumScoreVariable({ id, ...data });
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
get hasErrors() {
|
|
39
|
-
return this._error.length !== 0;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
public static fromDto = (dto: SumScoreVariableDto): SumScoreVariable => {
|
|
43
|
-
return new SumScoreVariable(dto);
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
private constructor(dto: SumScoreVariableDto) {
|
|
47
|
-
super(dto);
|
|
48
|
-
this.id = dto.id;
|
|
49
|
-
this._name = dto.name;
|
|
50
|
-
this._useAvg = dto.useAvg;
|
|
51
|
-
this._description = dto.description;
|
|
52
|
-
}
|
|
53
|
-
toJson(): SumScoreVariableDto {
|
|
54
|
-
const dto: SumScoreVariableDto = {
|
|
55
|
-
description: this.description,
|
|
56
|
-
id: this.id,
|
|
57
|
-
name: this.name,
|
|
58
|
-
useAvg: this.useAvg,
|
|
59
|
-
};
|
|
60
|
-
return dto;
|
|
61
|
-
}
|
|
62
|
-
clone(): SumScoreVariableDto {
|
|
63
|
-
const id = SumScoreVariableID.create();
|
|
64
|
-
const dto = this.toJson();
|
|
65
|
-
return { ...dto, id };
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/** @internal*/
|
|
69
|
-
_update(data: { name?: string; description?: string; useAvg?: boolean }) {
|
|
70
|
-
const d = data ?? {};
|
|
71
|
-
if (DUtil.isString(d.name)) {
|
|
72
|
-
this._name = d.name;
|
|
73
|
-
}
|
|
74
|
-
if (DUtil.isString(d.description)) {
|
|
75
|
-
this._description = d.description;
|
|
76
|
-
}
|
|
77
|
-
if (DUtil.isBool(d.useAvg)) {
|
|
78
|
-
this._useAvg = d.useAvg;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* @internal - used by sum-score-variable-collection.
|
|
84
|
-
*/
|
|
85
|
-
_setError(error: "" | "Duplicate name") {
|
|
86
|
-
this._error = error;
|
|
87
|
-
}
|
|
88
|
-
/** @internal - used by sum-score-variable-collection */
|
|
89
|
-
_setUsedInPages(pages: BuilderPage[]) {
|
|
90
|
-
this._usedIn = [...pages];
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
get name() {
|
|
94
|
-
return this._name;
|
|
95
|
-
}
|
|
96
|
-
get description() {
|
|
97
|
-
return this._description;
|
|
98
|
-
}
|
|
99
|
-
get useAvg() {
|
|
100
|
-
return this._useAvg;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
1
|
+
import { PageID, SumScoreVariableID } from "../primitives/ID";
|
|
2
|
+
import { BuilderObject } from "../BuilderObject";
|
|
3
|
+
import { DUtil } from "@media-quest/engine";
|
|
4
|
+
import { BuilderPage } from "../page/Builder-page";
|
|
5
|
+
|
|
6
|
+
export interface SumScoreVariableDto {
|
|
7
|
+
id: SumScoreVariableID;
|
|
8
|
+
name: string;
|
|
9
|
+
description: string;
|
|
10
|
+
useAvg: boolean;
|
|
11
|
+
}
|
|
12
|
+
export class SumScoreVariable extends BuilderObject<
|
|
13
|
+
"builder-sum-score-variable",
|
|
14
|
+
SumScoreVariableDto
|
|
15
|
+
> {
|
|
16
|
+
readonly objectType = "builder-sum-score-variable";
|
|
17
|
+
readonly id: SumScoreVariableID;
|
|
18
|
+
private _useAvg = true;
|
|
19
|
+
private _name = "";
|
|
20
|
+
private _description = "";
|
|
21
|
+
private _error = "";
|
|
22
|
+
private _usedIn: ReadonlyArray<BuilderPage> = [];
|
|
23
|
+
// private _basedOn = new Map<pageId: Page>()
|
|
24
|
+
get usedIn() {
|
|
25
|
+
return [...this._usedIn];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// private _basedOn: Array<{ varId: string }> = [];
|
|
29
|
+
public static readonly create = (data: {
|
|
30
|
+
name: string;
|
|
31
|
+
description: string;
|
|
32
|
+
useAvg: boolean;
|
|
33
|
+
}): SumScoreVariable => {
|
|
34
|
+
const id = SumScoreVariableID.create();
|
|
35
|
+
return new SumScoreVariable({ id, ...data });
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
get hasErrors() {
|
|
39
|
+
return this._error.length !== 0;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public static fromDto = (dto: SumScoreVariableDto): SumScoreVariable => {
|
|
43
|
+
return new SumScoreVariable(dto);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
private constructor(dto: SumScoreVariableDto) {
|
|
47
|
+
super(dto);
|
|
48
|
+
this.id = dto.id;
|
|
49
|
+
this._name = dto.name;
|
|
50
|
+
this._useAvg = dto.useAvg;
|
|
51
|
+
this._description = dto.description;
|
|
52
|
+
}
|
|
53
|
+
toJson(): SumScoreVariableDto {
|
|
54
|
+
const dto: SumScoreVariableDto = {
|
|
55
|
+
description: this.description,
|
|
56
|
+
id: this.id,
|
|
57
|
+
name: this.name,
|
|
58
|
+
useAvg: this.useAvg,
|
|
59
|
+
};
|
|
60
|
+
return dto;
|
|
61
|
+
}
|
|
62
|
+
clone(): SumScoreVariableDto {
|
|
63
|
+
const id = SumScoreVariableID.create();
|
|
64
|
+
const dto = this.toJson();
|
|
65
|
+
return { ...dto, id };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** @internal*/
|
|
69
|
+
_update(data: { name?: string; description?: string; useAvg?: boolean }) {
|
|
70
|
+
const d = data ?? {};
|
|
71
|
+
if (DUtil.isString(d.name)) {
|
|
72
|
+
this._name = d.name;
|
|
73
|
+
}
|
|
74
|
+
if (DUtil.isString(d.description)) {
|
|
75
|
+
this._description = d.description;
|
|
76
|
+
}
|
|
77
|
+
if (DUtil.isBool(d.useAvg)) {
|
|
78
|
+
this._useAvg = d.useAvg;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* @internal - used by sum-score-variable-collection.
|
|
84
|
+
*/
|
|
85
|
+
_setError(error: "" | "Duplicate name") {
|
|
86
|
+
this._error = error;
|
|
87
|
+
}
|
|
88
|
+
/** @internal - used by sum-score-variable-collection */
|
|
89
|
+
_setUsedInPages(pages: BuilderPage[]) {
|
|
90
|
+
this._usedIn = [...pages];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
get name() {
|
|
94
|
+
return this._name;
|
|
95
|
+
}
|
|
96
|
+
get description() {
|
|
97
|
+
return this._description;
|
|
98
|
+
}
|
|
99
|
+
get useAvg() {
|
|
100
|
+
return this._useAvg;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -21,6 +21,9 @@ type BasedOnEntry =
|
|
|
21
21
|
| { kind: "has-value"; varId: string; value: number; weight: number; varLabel: string };
|
|
22
22
|
|
|
23
23
|
export interface SumScore {
|
|
24
|
+
readonly sumScoreVariableId: SumScoreVariableID;
|
|
25
|
+
readonly name: string;
|
|
26
|
+
readonly description: string;
|
|
24
27
|
sumScore: number;
|
|
25
28
|
avg: number; // Alle besvarte spørsmål som ikke er 9.
|
|
26
29
|
useAvg: boolean;
|
|
@@ -81,7 +84,6 @@ const calculate = (
|
|
|
81
84
|
const errorMessages: string[] = [];
|
|
82
85
|
const basedOn: SumScore["basedOn"] = [];
|
|
83
86
|
const useAvg = sumScoreVariable.useAvg;
|
|
84
|
-
|
|
85
87
|
const basedOnEntries: BasedOnEntry[] = basedOnVariables.map((scv) => {
|
|
86
88
|
const maybeAnswer = answers.find((v) => v.varId === scv.varId);
|
|
87
89
|
let result: BasedOnEntry = { kind: "missing", varId: scv.varId };
|
|
@@ -129,6 +131,9 @@ const calculate = (
|
|
|
129
131
|
|
|
130
132
|
const avg = sumScore / includedAnswerCount;
|
|
131
133
|
const result: SumScore = {
|
|
134
|
+
sumScoreVariableId: sumScoreVariable.id,
|
|
135
|
+
name: sumScoreVariable.name,
|
|
136
|
+
description: sumScoreVariable.description,
|
|
132
137
|
avg,
|
|
133
138
|
useAvg,
|
|
134
139
|
includedAnswerCount,
|