Merge remote-tracking branch 'origin/feature/own-learning-objects' into feature/own-learning-objects

# Conflicts:
#	backend/src/services/learning-paths/learning-path-provider.ts
#	backend/src/services/learning-paths/learning-path-service.ts
This commit is contained in:
Gerald Schmittinger 2025-03-11 06:18:20 +01:00
commit b539c28d8c
4 changed files with 41 additions and 31 deletions

View file

@ -26,7 +26,7 @@ export interface LearningObjectNode {
transitions: Transition[];
created_at: string;
updatedAt: string;
done?: boolean; // true if a submission exists for this node by the user for whom the learning path is customized.
done?: boolean; // True if a submission exists for this node by the user for whom the learning path is customized.
}
export interface LearningPath {

View file

@ -6,11 +6,7 @@ import { Language } from '../../entities/content/language';
import learningObjectService from '../learning-objects/learning-object-service';
import { LearningPathNode } from '../../entities/content/learning-path-node.entity';
import { LearningPathTransition } from '../../entities/content/learning-path-transition.entity';
import {
getLastSubmissionForCustomizationTarget,
isTransitionPossible,
PersonalizationTarget
} from "./learning-path-personalization-util";
import { getLastSubmissionForCustomizationTarget, isTransitionPossible, PersonalizationTarget } from './learning-path-personalization-util';
/**
* Fetches the corresponding learning object for each of the nodes and creates a map that maps each node to its
@ -69,7 +65,7 @@ async function convertLearningPath(learningPath: LearningPathEntity, order: numb
title: learningPath.title,
nodes: convertedNodes,
num_nodes: learningPath.nodes.length,
num_nodes_left: convertedNodes.filter(it => !it.done).length,
num_nodes_left: convertedNodes.filter((it) => !it.done).length,
keywords: keywords.join(' '),
target_ages: targetAges,
max_age: Math.max(...targetAges),
@ -83,10 +79,13 @@ async function convertLearningPath(learningPath: LearningPathEntity, order: numb
* @param nodesToLearningObjects
* @param personalizedFor
*/
async function convertNodes(nodesToLearningObjects: Map<LearningPathNode, FilteredLearningObject>, personalizedFor?: PersonalizationTarget): Promise<LearningObjectNode[]> {
async function convertNodes(
nodesToLearningObjects: Map<LearningPathNode, FilteredLearningObject>,
personalizedFor?: PersonalizationTarget
): Promise<LearningObjectNode[]> {
const nodesPromise = nodesToLearningObjects
.entries()
.map(async(entry) => {
.map(async (entry) => {
const [node, learningObject] = entry;
const lastSubmission = personalizedFor ? await getLastSubmissionForCustomizationTarget(node, personalizedFor) : null;
return {
@ -98,8 +97,8 @@ async function convertNodes(nodesToLearningObjects: Map<LearningPathNode, Filter
learningobject_hruid: node.learningObjectHruid,
version: learningObject.version,
transitions: node.transitions
.filter(trans => !personalizedFor || isTransitionPossible(trans, lastSubmission)) // If we want a personalized learning path, remove all transitions that aren't possible.
.map((trans, i) => convertTransition(trans, i, nodesToLearningObjects)), // then convert all the transition
.filter((trans) => !personalizedFor || isTransitionPossible(trans, lastSubmission)) // If we want a personalized learning path, remove all transitions that aren't possible.
.map((trans, i) => convertTransition(trans, i, nodesToLearningObjects)), // Then convert all the transition
};
})
.toArray();
@ -143,14 +142,17 @@ const databaseLearningPathProvider: LearningPathProvider = {
/**
* Fetch the learning paths with the given hruids from the database.
*/
async fetchLearningPaths(hruids: string[], language: Language, source: string, personalizedFor?: PersonalizationTarget): Promise<LearningPathResponse> {
async fetchLearningPaths(
hruids: string[],
language: Language,
source: string,
personalizedFor?: PersonalizationTarget
): Promise<LearningPathResponse> {
const learningPathRepo = getLearningPathRepository();
const learningPaths = (
await Promise.all(
hruids.map((hruid) => learningPathRepo.findByHruidAndLanguage(hruid, language))
)
).filter((learningPath) => learningPath !== null);
const learningPaths = (await Promise.all(hruids.map((hruid) => learningPathRepo.findByHruidAndLanguage(hruid, language)))).filter(
(learningPath) => learningPath !== null
);
const filteredLearningPaths = await Promise.all(
learningPaths.map((learningPath, index) => convertLearningPath(learningPath, index, personalizedFor))
);

View file

@ -1,11 +1,11 @@
import {LearningPathNode} from "../../entities/content/learning-path-node.entity";
import {Student} from "../../entities/users/student.entity";
import {Group} from "../../entities/assignments/group.entity";
import {Submission} from "../../entities/assignments/submission.entity";
import {getSubmissionRepository} from "../../data/repositories";
import {LearningObjectIdentifier} from "../../entities/content/learning-object-identifier";
import {LearningPathTransition} from "../../entities/content/learning-path-transition.entity";
import {JSONPath} from "jsonpath-plus";
import { LearningPathNode } from '../../entities/content/learning-path-node.entity';
import { Student } from '../../entities/users/student.entity';
import { Group } from '../../entities/assignments/group.entity';
import { Submission } from '../../entities/assignments/submission.entity';
import { getSubmissionRepository } from '../../data/repositories';
import { LearningObjectIdentifier } from '../../entities/content/learning-object-identifier';
import { LearningPathTransition } from '../../entities/content/learning-path-transition.entity';
import { JSONPath } from 'jsonpath-plus';
export type PersonalizationTarget = { type: 'student'; student: Student } | { type: 'group'; group: Group };
/**
@ -20,12 +20,10 @@ export async function getLastSubmissionForCustomizationTarget(node: LearningPath
};
if (pathFor.type === 'group') {
return await submissionRepo.findMostRecentSubmissionForGroup(learningObjectId, pathFor.group);
} else {
return await submissionRepo.findMostRecentSubmissionForStudent(learningObjectId, pathFor.student);
}
return await submissionRepo.findMostRecentSubmissionForStudent(learningObjectId, pathFor.student);
}
/**
* Checks whether the condition of the given transaction is fulfilled by the given submission.
* @param transition

View file

@ -19,14 +19,24 @@ const learningPathService = {
* @param source
* @param personalizedFor If this is set, a learning path personalized for the given group or student will be returned.
*/
async fetchLearningPaths(hruids: string[], language: Language, source: string, personalizedFor?: PersonalizationTarget): Promise<LearningPathResponse> {
async fetchLearningPaths(
hruids: string[],
language: Language,
source: string,
personalizedFor?: PersonalizationTarget
): Promise<LearningPathResponse> {
const userContentHruids = hruids.filter((hruid) => hruid.startsWith(userContentPrefix));
const nonUserContentHruids = hruids.filter((hruid) => !hruid.startsWith(userContentPrefix));
const userContentLearningPaths = await databaseLearningPathProvider.fetchLearningPaths(userContentHruids, language, source, personalizedFor);
const nonUserContentLearningPaths = await dwengoApiLearningPathProvider.fetchLearningPaths(nonUserContentHruids, language, source, personalizedFor);
const nonUserContentLearningPaths = await dwengoApiLearningPathProvider.fetchLearningPaths(
nonUserContentHruids,
language,
source,
personalizedFor
);
let result = (userContentLearningPaths.data || []).concat(nonUserContentLearningPaths.data || []);
const result = (userContentLearningPaths.data || []).concat(nonUserContentLearningPaths.data || []);
return {
data: result,