Skip to content

Commit 8b8339f

Browse files
authored
1 parent 050e846 commit 8b8339f

File tree

5 files changed

+139
-6
lines changed

5 files changed

+139
-6
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { get, has } from 'lodash';
2+
3+
import ActivityInteractionType from '../../../../models/ActivityInteractionType';
4+
import Statement from '../../../../models/Statement';
5+
6+
export const getNumericQuestionMetadata = (statement: Statement)
7+
: {readonly [key: string]: any} => {
8+
if (
9+
!(
10+
get(
11+
statement.object,
12+
['definition', 'interactionType'],
13+
) === ActivityInteractionType.NUMERIC
14+
&& has(statement, ['result', 'response'])
15+
)
16+
) {
17+
return {};
18+
}
19+
20+
const numericQuestionString = get(statement, ['result', 'response']);
21+
22+
if (!numericQuestionString.includes('[:]')) {
23+
return {'https://learninglocker&46;net/numeric-response': parseFloat(numericQuestionString)};
24+
}
25+
26+
const [min, max] = numericQuestionString.split('[:]');
27+
return {
28+
'https://learninglocker&46;net/numeric-response': {
29+
min,
30+
max,
31+
},
32+
};
33+
};

src/apps/statements/service/storeStatements/queriables/getMetadataFromStatement/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { getChoiceQuestionMetadata } from './getChoiceQuestionMetadata';
44
import { getDurationMetadata } from './getDurationMetadata';
55
import { getLikertMetadata } from './getLikertMetadata';
66
import { getMatchingQuestionsMetadata } from './getMatchingQuestionsMetadata';
7+
import { getNumericQuestionMetadata } from './getNumericQuestionMetadata';
78
import { getSequencingMetadata } from './getSequencingMetadata';
89

910
export default (statement: Statement): { readonly [key: string]: any } => {
@@ -13,10 +14,12 @@ export default (statement: Statement): { readonly [key: string]: any } => {
1314
const choicesMetadata = getChoiceQuestionMetadata(statement);
1415
const matchingMetadata = getMatchingQuestionsMetadata(statement);
1516
const booleanMetadata = getBooleanMetadata(statement);
17+
const numericQuestionMetadata = getNumericQuestionMetadata(statement);
1618

1719
return {
1820
...durationMetadata,
1921
...sequencingMetadata,
22+
...numericQuestionMetadata,
2023
...choicesMetadata,
2124
...matchingMetadata,
2225
...booleanMetadata,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import ActivityInteractionType from '../../../../../models/ActivityInteractionType';
2+
import InteractionActivityDefinition from '../../../../../models/InteractionActivityDefinition';
3+
import Statement from '../../../../../models/Statement';
4+
import SubStatementObject from '../../../../../models/SubStatementObject';
5+
import { statementDefaults } from './statements.fixture';
6+
7+
const numericQuestionInteractionActivityStatement: Statement = {
8+
...statementDefaults,
9+
...{
10+
result: {
11+
response: '4:',
12+
},
13+
object: {
14+
definition: {
15+
name: {'en-US': 'Question 7'},
16+
description: {'en-US': 'How many jokes is Chris the butt of each day?'},
17+
type: 'http://adlnet.gov/expapi/activities/cmi.interaction',
18+
interactionType: ActivityInteractionType.NUMERIC,
19+
correctResponsesPattern: ['4:'],
20+
} as Partial<InteractionActivityDefinition>,
21+
} as SubStatementObject,
22+
} as Partial<Statement>,
23+
};
24+
25+
const numericQuestionWithMinAndMaxInteractionActivityStatement: Statement = {
26+
...statementDefaults,
27+
...{
28+
result: {
29+
response: '4[:]5',
30+
},
31+
object: {
32+
definition: {
33+
name: {'en-US': 'Question 7'},
34+
description: {'en-US': 'How many jokes is Chris the butt of each day?'},
35+
type: 'http://adlnet.gov/expapi/activities/cmi.interaction',
36+
interactionType: ActivityInteractionType.NUMERIC,
37+
correctResponsesPattern: ['4[:]5'],
38+
} as Partial<InteractionActivityDefinition>,
39+
} as SubStatementObject,
40+
} as Partial<Statement>,
41+
};
42+
43+
export {
44+
numericQuestionInteractionActivityStatement,
45+
numericQuestionWithMinAndMaxInteractionActivityStatement,
46+
};
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import * as assert from 'assert';
2+
3+
import { getNumericQuestionMetadata } from '../../../../service/storeStatements/queriables/getMetadataFromStatement/getNumericQuestionMetadata';
4+
import {
5+
numericQuestionInteractionActivityStatement as statementFixture,
6+
numericQuestionWithMinAndMaxInteractionActivityStatement as statementWithMinAndMaxFixture,
7+
} from './fixtures/numeric-question-interaction.fixture';
8+
9+
describe('Retrieve numeric question metadata from statement', () => {
10+
it('should return empty metadata from empty result', () => {
11+
const expectedEmptyMetadata = {};
12+
13+
const actualEmptyMetadataFromEmptyResult = getNumericQuestionMetadata(
14+
{
15+
...statementFixture,
16+
...{
17+
result: {},
18+
},
19+
},
20+
);
21+
22+
assert.deepEqual(actualEmptyMetadataFromEmptyResult, expectedEmptyMetadata);
23+
});
24+
25+
it('should return numeric question for correct result', () => {
26+
const actualCorrectMetadata = getNumericQuestionMetadata(
27+
statementFixture,
28+
);
29+
const expectedCorrectMetadata = {
30+
'https://learninglocker&46;net/numeric-response': 4,
31+
};
32+
33+
assert.deepEqual(actualCorrectMetadata, expectedCorrectMetadata);
34+
});
35+
36+
it('should return numeric question with min and max values for correct result', () => {
37+
const actualCorrectMetadata = getNumericQuestionMetadata(
38+
statementWithMinAndMaxFixture,
39+
);
40+
const expectedCorrectMetadata = {
41+
'https://learninglocker&46;net/numeric-response': {
42+
min: 4,
43+
max: 5,
44+
},
45+
};
46+
47+
assert.deepEqual(actualCorrectMetadata, expectedCorrectMetadata);
48+
});
49+
});

yarn.lock

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@
3434
dependencies:
3535
"@babel/highlight" "^7.8.3"
3636

37-
"@babel/highlight@^7.8.0":
38-
version "7.8.0"
39-
resolved "https://registry.yarnpkg.com/@babel/highlight/-/highlight-7.8.0.tgz#4cc003dc10359919e2e3a1d9459150942913dd1a"
37+
"@babel/highlight@^7.8.3":
38+
version "7.8.3"
39+
resolved "https://registry.yarnpkg.com/@babel/highlight/-/highlight-7.8.3.tgz#28f173d04223eaaa59bc1d439a3836e6d1265797"
40+
integrity sha512-PX4y5xQUvy0fnEVHrYOarRPXVWafSjTW9T0Hab8gVIawpl2Sj0ORyrygANq+KjcNlSSTw0YCLSNA8OyZ1I4yEg==
4041
dependencies:
4142
chalk "^2.0.0"
4243
esutils "^2.0.2"
@@ -3130,9 +3131,10 @@ [email protected]:
31303131
resolved "https://registry.yarnpkg.com/eyes/-/eyes-0.1.8.tgz#62cf120234c683785d902348a800ef3e0cc20bc0"
31313132
integrity sha1-Ys8SAjTGg3hdkCNIqADvPgzCC8A=
31323133

3133-
fast-deep-equal@^2.0.1:
3134-
version "2.0.1"
3135-
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz#7b05218ddf9667bf7f370bf7fdb2cb15fdd0aa49"
3134+
fast-deep-equal@^3.1.1:
3135+
version "3.1.1"
3136+
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-3.1.1.tgz#545145077c501491e33b15ec408c294376e94ae4"
3137+
integrity sha512-8UEa58QDLauDNfpbrX55Q9jrGHThw2ZMdOky5Gl1CDtVeJDPVrG4Jxx1N8jw2gkWaff5UUuX1KJd+9zGe2B+ZA==
31363138

31373139
fast-glob@^3.0.3:
31383140
version "3.2.0"

0 commit comments

Comments
 (0)