Skip to content

Commit

Permalink
Merge pull request #109 from oat-sa/release-0.12.0
Browse files Browse the repository at this point in the history
Release 0.12.0
  • Loading branch information
lecosson authored Sep 18, 2020
2 parents ace9b0c + 0149c2a commit 44a706b
Show file tree
Hide file tree
Showing 12 changed files with 2,052 additions and 186 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oat-sa/tao-item-runner-qti",
"version": "0.11.3",
"version": "0.12.0",
"displayName": "TAO Item Runner QTI",
"description": "TAO QTI Item Runner modules",
"files": [
Expand Down
414 changes: 242 additions & 172 deletions src/qtiItem/core/Loader.js

Large diffs are not rendered by default.

50 changes: 38 additions & 12 deletions src/qtiItem/helper/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,44 +13,70 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2014-2017 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);
* Copyright (c) 2014-2020 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);
*
*/
import _ from 'lodash';
import { responseRules as responseRulesHelper } from 'taoQtiItem/qtiItem/helper/responseRules';

var _templateNames = {
const _templateNames = {
MATCH_CORRECT: 'http://www.imsglobal.org/question/qti_v2p1/rptemplates/match_correct',
MAP_RESPONSE: 'http://www.imsglobal.org/question/qti_v2p1/rptemplates/map_response',
MAP_RESPONSE_POINT: 'http://www.imsglobal.org/question/qti_v2p1/rptemplates/map_response_point',
NONE: 'no_response_processing'
};


export default {
isUsingTemplate: function isUsingTemplate(response, tpl) {
isUsingTemplate(response, tpl) {
if (_.isString(tpl)) {
if (tpl === response.template || _templateNames[tpl] === response.template) {
return true;
}
}

return false;
},
isValidTemplateName: function isValidTemplateName(tplName) {
isValidTemplateName(tplName) {
return !!this.getTemplateUriFromName(tplName);
},
getTemplateUriFromName: function getTemplateUriFromName(tplName) {
if (_templateNames[tplName]) {
return _templateNames[tplName];
}
return '';
getTemplateUriFromName(tplName) {
return _templateNames[tplName] || '';
},
getTemplateNameFromUri: function getTemplateNameFromUri(tplUri) {
var tplName = '';
_.forIn(_templateNames, function(uri, name) {
getTemplateNameFromUri(tplUri) {
let tplName = '';

_.forIn(_templateNames, (uri, name) => {
if (uri === tplUri) {
tplName = name;
return false;
}
});

return tplName;
},
getTemplateNameFromResponseRules(responseIdentifier, responseRules) {
if (!responseRules) {
return 'NONE';
}

const {
responseIf: {
responseRules: [outcomeRules = {}] = [],
} = {}
} = responseRules;
const {
attributes: {
identifier: outcomeIdentifier,
} = {},
} = outcomeRules;

if (!outcomeIdentifier) {
return '';
}

return Object.keys(responseRulesHelper).find(
(key) => _.isEqual(responseRules, responseRulesHelper[key](responseIdentifier, outcomeIdentifier))
);
}
};
159 changes: 159 additions & 0 deletions src/qtiItem/helper/responseRules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; under version 2
* of the License (non-upgradable).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2020 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);
*
*/
export const responseRules = {
MATCH_CORRECT: (responseIdentifier, outcomeIdentifier) => ({
qtiClass: 'responseCondition',
responseIf: {
qtiClass: 'responseIf',
expression: {
qtiClass: 'match',
expressions: [
{
qtiClass: 'variable',
attributes: {
identifier: responseIdentifier,
},
},
{
qtiClass: 'correct',
attributes: {
identifier: responseIdentifier,
},
},
],
},
responseRules: [
{
qtiClass: 'setOutcomeValue',
attributes: {
identifier: outcomeIdentifier,
},
expression: {
qtiClass: 'sum',
expressions: [
{
qtiClass: 'variable',
attributes: {
identifier: outcomeIdentifier,
},
},
{
qtiClass: 'baseValue',
attributes: {
baseType: 'integer'
},
value: '1',
},
],
},
},
],
},
}),
MAP_RESPONSE: (responseIdentifier, outcomeIdentifier) => ({
qtiClass: 'responseCondition',
responseIf: {
qtiClass: 'responseIf',
expression: {
qtiClass: 'not',
expressions: [
{
qtiClass: 'isNull',
expressions: [{
qtiClass: 'variable',
attributes: {
identifier: responseIdentifier,
},
}],
},
],
},
responseRules: [
{
qtiClass: 'setOutcomeValue',
attributes: {
identifier: outcomeIdentifier,
},
expression: {
qtiClass: 'sum',
expressions: [
{
qtiClass: 'variable',
attributes: {
identifier: outcomeIdentifier,
}
},
{
qtiClass: 'mapResponse',
attributes: {
identifier: responseIdentifier,
},
},
],
},
},
],
},
}),
MAP_RESPONSE_POINT: (responseIdentifier, outcomeIdentifier) => ({
qtiClass: 'responseCondition',
responseIf: {
qtiClass: 'responseIf',
expression: {
qtiClass: 'not',
expressions: [
{
qtiClass: 'isNull',
expressions: [{
qtiClass: 'variable',
attributes: {
identifier: responseIdentifier,
},
}],
},
],
},
responseRules: [
{
qtiClass: 'setOutcomeValue',
attributes: {
identifier: outcomeIdentifier,
},
expression: {
qtiClass: 'sum',
expressions: [
{
qtiClass: 'variable',
attributes: {
identifier: outcomeIdentifier,
}
},
{
qtiClass: 'mapResponsePoint',
attributes: {
identifier: responseIdentifier,
},
},
],
},
},
],
},
}),
};
22 changes: 22 additions & 0 deletions test/qtiItem/core/loader/test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>QTI Item loader</title>
<script type="text/javascript" src="/environment/require.js"></script>
<script type="text/javascript">
require(['/environment/config.js'], function() {
require(['qunitEnv'], function() {
require(['taoQtiItem/test/qtiItem/core/loader/test'], function() {
QUnit.config.reorder = false;
QUnit.start();
});
});
});
</script>
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
</body>
</html>
Loading

0 comments on commit 44a706b

Please sign in to comment.