fix(backend): Vooruitgang wordt nu enkel op basis van effectief bereikbare leerobjecten berekend.
This commit is contained in:
parent
fe9ff5ec16
commit
f3ba47eb30
1 changed files with 30 additions and 2 deletions
|
@ -62,6 +62,8 @@ async function convertLearningPath(learningPath: LearningPathEntity, order: numb
|
||||||
// Convert the learning object notes as retrieved from the database into the expected response format-
|
// Convert the learning object notes as retrieved from the database into the expected response format-
|
||||||
const convertedNodes = await convertNodes(nodesToLearningObjects, personalizedFor);
|
const convertedNodes = await convertNodes(nodesToLearningObjects, personalizedFor);
|
||||||
|
|
||||||
|
const nodesActuallyOnPath = traverseLearningPath(convertedNodes);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
_id: `${learningPath.hruid}/${learningPath.language}`, // For backwards compatibility with the original Dwengo API.
|
_id: `${learningPath.hruid}/${learningPath.language}`, // For backwards compatibility with the original Dwengo API.
|
||||||
__order: order,
|
__order: order,
|
||||||
|
@ -71,8 +73,8 @@ async function convertLearningPath(learningPath: LearningPathEntity, order: numb
|
||||||
image: image,
|
image: image,
|
||||||
title: learningPath.title,
|
title: learningPath.title,
|
||||||
nodes: convertedNodes,
|
nodes: convertedNodes,
|
||||||
num_nodes: learningPath.nodes.length,
|
num_nodes: nodesActuallyOnPath.length,
|
||||||
num_nodes_left: convertedNodes.filter((it) => !it.done).length,
|
num_nodes_left: nodesActuallyOnPath.filter((it) => !it.done).length,
|
||||||
keywords: keywords.join(' '),
|
keywords: keywords.join(' '),
|
||||||
target_ages: targetAges,
|
target_ages: targetAges,
|
||||||
max_age: Math.max(...targetAges),
|
max_age: Math.max(...targetAges),
|
||||||
|
@ -103,6 +105,7 @@ async function convertNode(
|
||||||
isTransitionPossible(trans, optionalJsonStringToObject(lastSubmission?.content)) // Otherwise remove all transitions that aren't possible.
|
isTransitionPossible(trans, optionalJsonStringToObject(lastSubmission?.content)) // Otherwise remove all transitions that aren't possible.
|
||||||
)
|
)
|
||||||
.map((trans, i) => convertTransition(trans, i, nodesToLearningObjects));
|
.map((trans, i) => convertTransition(trans, i, nodesToLearningObjects));
|
||||||
|
|
||||||
return {
|
return {
|
||||||
_id: learningObject.uuid,
|
_id: learningObject.uuid,
|
||||||
language: learningObject.language,
|
language: learningObject.language,
|
||||||
|
@ -174,6 +177,31 @@ function convertTransition(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start from the start node and then always take the first transition until there are no transitions anymore.
|
||||||
|
* Returns the traversed nodes as an array. (This effectively filters outs nodes that cannot be reached.)
|
||||||
|
*/
|
||||||
|
function traverseLearningPath(nodes: LearningObjectNode[]): LearningObjectNode[] {
|
||||||
|
const traversedNodes: LearningObjectNode[] = [];
|
||||||
|
let currentNode = nodes.find(it => it.start_node);
|
||||||
|
|
||||||
|
while (currentNode) {
|
||||||
|
traversedNodes.push(currentNode);
|
||||||
|
|
||||||
|
const next = currentNode.transitions[0]?.next;
|
||||||
|
|
||||||
|
if (next) {
|
||||||
|
currentNode = nodes.find(it =>
|
||||||
|
it.learningobject_hruid === next.hruid && it.language === next.language && it.version === next.version
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
currentNode = undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return traversedNodes;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Service providing access to data about learning paths from the database.
|
* Service providing access to data about learning paths from the database.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue