Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Lizardguard committed Feb 20, 2024
2 parents dd74b2f + 7098e29 commit bc5dfd7
Show file tree
Hide file tree
Showing 16 changed files with 203 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const MockAdaptivityData: APIAdaptivity = {
{
questionType: "multipleResponse",
questionId: 1,
questionDifficulty: 0,
questionDifficulty: 100,
questionText:
"Multiple Choice Frage: Wähle alle richtigen Antworten aus",
adaptivityRules: [
Expand Down Expand Up @@ -89,7 +89,7 @@ export const MockAdaptivityData: APIAdaptivity = {
{
questionType: "singleResponse",
questionId: 2,
questionDifficulty: 100,
questionDifficulty: 200,
questionText: "Single Choice: Wähle die richtige Antwort",
adaptivityRules: [
{
Expand Down Expand Up @@ -117,7 +117,7 @@ export const MockAdaptivityData: APIAdaptivity = {
{
questionType: "singleResponse",
questionId: 3,
questionDifficulty: 200,
questionDifficulty: 0,
questionText: "Single Choice: Wähle die richtige Antwort",
adaptivityRules: [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { inject, injectable } from "inversify";
import IDisplayLearningElementUseCase from "./IDisplayLearningElementUseCase";
import IDisplayAdaptivityHintLearningElementUseCase from "./IDisplayAdaptivityHintLearningElementUseCase";
import CORE_TYPES from "~DependencyInjection/CoreTypes";
import type ILoggerPort from "../../../Ports/Interfaces/ILoggerPort";
import { ComponentID } from "src/Components/Core/Domain/Types/EntityTypes";
Expand All @@ -16,8 +16,8 @@ import AdaptivityElementHintTO from "../../../DataTransferObjects/AdaptivityElem
import { AdaptivityElementActionTypes } from "src/Components/Core/Domain/Types/Adaptivity/AdaptivityElementActionTypes";

@injectable()
export default class DisplayLearningElementUseCase
implements IDisplayLearningElementUseCase
export default class DisplayAdaptivityHintLearningElementUseCase
implements IDisplayAdaptivityHintLearningElementUseCase
{
constructor(
@inject(CORE_TYPES.ILogger)
Expand All @@ -35,52 +35,59 @@ export default class DisplayLearningElementUseCase
) {}

async executeAsync(elementID: ComponentID): Promise<void> {
const spaces = this.entityContainer.getEntitiesOfType(LearningSpaceEntity);
const location = this.getUserLocationUseCase.execute();

if (!location.spaceID || !location.worldID) {
throw new Error(`User not in a space!`);
}

// calculate space in which external learningelement is
const space = spaces.filter((space) => {
return space.elements.filter((e) => e?.id === elementID).length > 0;
});
// get spaces of current learning world
const spaces = this.entityContainer.filterEntitiesOfType(
LearningSpaceEntity,
(entity: LearningSpaceEntity) => {
return entity.parentWorldID === location.worldID;
}
);

if (space.length === 0) {
if (spaces.length === 0) {
throw new Error(
"Could not find space in which external learning element is."
"Could not find space for currently active learning world."
);
}

const element = this.entityContainer.filterEntitiesOfType(
// get learning element with given id in current learning world
const elements = this.entityContainer.filterEntitiesOfType(
LearningElementEntity,
(e) => e.id === elementID
(e) => e.id === elementID && e.parentWorldID === location.worldID
);

if (element.length === 0) {
throw new Error("Could not find external element.");
if (elements.length === 0) {
throw new Error("Could not find referenced learning element.");
}

const location = this.getUserLocationUseCase.execute();

if (!location.spaceID || !location.worldID) {
throw new Error(`User not in a space!`);
}
// check if element is in current space
const currentSpace = spaces.find((e) => e.id === location.spaceID);
const isInCurrentSpace =
currentSpace?.elements.find((e) => e?.id === elementID) !== undefined;

// element is in space
if (location.spaceID === space[0].id) {
if (isInCurrentSpace) {
this.worldPort.onAdaptivityElementUserHintInformed({
hintID: -1,
showOnIsWrong: true,
hintAction: {
hintActionType: AdaptivityElementActionTypes.CommentAction,
textData:
"Der Hinweis für diese Frage befindet sich hier in diesem Raum. Schau dir `" +
element[0].name +
elements[0].name +
"` nochmal an.",
},
} as AdaptivityElementHintTO);
} else {
// check if space is available
const spaceAvailability =
this.calculateLearningSpaceAvailabilityUseCase.internalExecute({
spaceID: space[0].id,
spaceID: spaces[0].id,
worldID: location.worldID,
});

Expand All @@ -98,9 +105,9 @@ export default class DisplayLearningElementUseCase
hintActionType: AdaptivityElementActionTypes.CommentAction,
textData:
"Der Hinweis für diese Frage ist das Lernelement `" +
element[0].name +
elements[0].name +
"` im Lernraum `" +
space[0].name +
spaces[0].name +
"`",
},
} as AdaptivityElementHintTO);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ComponentID } from "src/Components/Core/Domain/Types/EntityTypes";
import { IAsyncUsecase } from "../../../Abstract/IAsyncUsecase";

export default interface IDisplayLearningElementUseCase
export default interface IDisplayAdaptivityHintLearningElementUseCase
extends IAsyncUsecase<ComponentID, void> {}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ const USECASE_TYPES = {
"ILoadExternalLearningElementUseCase"
),
IScoreAdaptivityElementUseCase: Symbol("IScoreAdaptivityElementUseCase"),
IDisplayLearningElementUseCase: Symbol("IDisplayLearningElementUseCase"),
IDisplayAdaptivityHintLearningElementUseCase: Symbol(
"IDisplayAdaptivityHintLearningElementUseCase"
),
ILogoutUseCase: Symbol("ILogoutUseCase"),
ILoadStoryElementUseCase: Symbol("ILoadStoryElementUseCase"),
IBeginStoryElementIntroCutSceneUseCase: Symbol(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ import ILoadExternalLearningElementUseCase from "../../Application/UseCases/Adap
import LoadExternalLearningElementUseCase from "../../Application/UseCases/Adaptivity/LoadExternalLearningElementUseCase/LoadExternalLearningElementUseCase";
import IScoreAdaptivityElementUseCase from "../../Application/UseCases/Adaptivity/ScoreAdaptivityElementUseCase/IScoreAdaptivityElementUseCase";
import ScoreAdaptivityElementUseCase from "../../Application/UseCases/Adaptivity/ScoreAdaptivityElementUseCase/ScoreAdaptivityElementUseCase";
import IDisplayLearningElementUseCase from "../../Application/UseCases/Adaptivity/DisplayLearningElementUseCase/IDisplayLearningElementUseCase";
import DisplayLearningElementUseCase from "../../Application/UseCases/Adaptivity/DisplayLearningElementUseCase/DisplayLearningElementUseCase";
import IDisplayAdaptivityHintLearningElementUseCase from "../../Application/UseCases/Adaptivity/DisplayAdaptivityHintLearningElement/IDisplayAdaptivityHintLearningElementUseCase";
import DisplayAdaptivityHintLearningElementUseCase from "../../Application/UseCases/Adaptivity/DisplayAdaptivityHintLearningElement/DisplayAdaptivityHintLearningElementUseCase";
import ILogoutUseCase from "../../Application/UseCases/Logout/ILogoutUseCase";
import LogoutUseCase from "../../Application/UseCases/Logout/LogoutUseCase";
import ILoadUserLearningWorldsInfoUseCase from "../../Application/UseCases/LoadUserLearningWorldsInfo/ILoadUserLearningWorldsInfoUseCase";
Expand Down Expand Up @@ -201,10 +201,10 @@ const UseCaseDIContainer = new ContainerModule((bind) => {
.to(ScoreAdaptivityElementUseCase)
.inSingletonScope();

bind<IDisplayLearningElementUseCase>(
USECASE_TYPES.IDisplayLearningElementUseCase
bind<IDisplayAdaptivityHintLearningElementUseCase>(
USECASE_TYPES.IDisplayAdaptivityHintLearningElementUseCase
)
.to(DisplayLearningElementUseCase)
.to(DisplayAdaptivityHintLearningElementUseCase)
.inSingletonScope();

bind<ILogoutUseCase>(USECASE_TYPES.ILogoutUseCase)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { LearningSpaceTemplateType } from "../Types/LearningSpaceTemplateType";
import ILearningSpaceTemplate from "./ILearningSpaceTemplate";

export const LearningSpaceTemplate_R15: ILearningSpaceTemplate = {
name: LearningSpaceTemplateType.R15,
export const LearningSpaceTemplate_D: ILearningSpaceTemplate = {
name: LearningSpaceTemplateType.D,
cornerPoints: [
{ x: -8.4, y: 7.6 }, // A
{ x: 1.2, y: 7.6 }, // B
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { LearningSpaceTemplate_L } from "./LearningSpaceTemplate_L";
import { LearningSpaceTemplate_T } from "./LearningSpaceTemplate_T";
import { LearningSpaceTemplate_R8 } from "./LearningSpaceTemplate_R8";
import { LearningSpaceTemplate_R6 } from "./LearningSpaceTemplate_R6";
import { LearningSpaceTemplate_R15 } from "./LearningSpaceTemplate_R15";
import { LearningSpaceTemplate_D } from "./LearningSpaceTemplate_D";

export default class LearningSpaceTemplateLookup {
static getLearningSpaceTemplate(
Expand All @@ -19,8 +19,8 @@ export default class LearningSpaceTemplateLookup {
return LearningSpaceTemplate_R8;
case LearningSpaceTemplateType.R6:
return LearningSpaceTemplate_R6;
case LearningSpaceTemplateType.R15:
return LearningSpaceTemplate_R15;
case LearningSpaceTemplateType.D:
return LearningSpaceTemplate_D;
//TODO: Add other templates here
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export enum LearningSpaceTemplateType {
T = "T_40X32_13L",
R6 = "R_20X20_6L",
R8 = "R_20X30_8L",
R15 = "R_40X37_15L",
D = "D_40X37_15L",
None = "",
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import PORT_TYPES from "~DependencyInjection/Ports/PORT_TYPES";
import ILearningWorldPort from "../../../Application/Ports/Interfaces/ILearningWorldPort";
import ILoadExternalLearningElementUseCase from "src/Components/Core/Application/UseCases/Adaptivity/LoadExternalLearningElementUseCase/ILoadExternalLearningElementUseCase";
import type { ComponentID } from "src/Components/Core/Domain/Types/EntityTypes";
import IDisplayLearningElementUseCase from "src/Components/Core/Application/UseCases/Adaptivity/DisplayLearningElementUseCase/IDisplayLearningElementUseCase";
import IDisplayAdaptivityHintLearningElementUseCase from "src/Components/Core/Application/UseCases/Adaptivity/DisplayAdaptivityHintLearningElement/IDisplayAdaptivityHintLearningElementUseCase";
import i18next from "i18next";
import IBottomTooltipPresenter from "~ReactComponents/LearningSpaceDisplay/BottomTooltip/IBottomTooltipPresenter";
import PRESENTATION_TYPES from "~DependencyInjection/Presentation/PRESENTATION_TYPES";
Expand Down Expand Up @@ -61,7 +61,7 @@ export default class AdaptivityElementController
selectedHint.hintAction.idData !== undefined
) {
// if element is in same learning space then highlight,
// if not in element nothing will happen
// if not in space nothing will happen
// call all element presenters via port
const learningWorldPort = CoreDIContainer.get<ILearningWorldPort>(
PORT_TYPES.ILearningWorldPort
Expand All @@ -71,8 +71,8 @@ export default class AdaptivityElementController
selectedHint.hintAction.idData
);

await CoreDIContainer.get<IDisplayLearningElementUseCase>(
USECASE_TYPES.IDisplayLearningElementUseCase
await CoreDIContainer.get<IDisplayAdaptivityHintLearningElementUseCase>(
USECASE_TYPES.IDisplayAdaptivityHintLearningElementUseCase
).executeAsync(selectedHint.hintAction.idData);

if (this.viewModel.selectedHint.Value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,25 @@ export default class AdaptivityElementPresenter
});
}

private sortQuestionsByDifficulty(
questions: AdaptivityElementQuestionProgressTO[]
) {
questions.sort(
(
a: AdaptivityElementQuestionProgressTO,
b: AdaptivityElementQuestionProgressTO
) => {
return a.questionDifficulty - b.questionDifficulty;
}
);
}

private mapQuestions(
questions: AdaptivityElementQuestionProgressTO[],
requiredDifficulty: AdaptivityElementQuestionDifficultyTypes,
isTaskOptional: boolean
): AdaptivityQuestion[] {
this.sortQuestionsByDifficulty(questions);
return questions.map((question) => {
// TODO: this is not completely correct yet
// What happens if the required difficulty is something like 86?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,14 @@ export default function AdaptivityElementQuestionSelection({
);
}, [setHeaderText, selectedTask, translate]);

selectedTask.questions.sort(compareQuestionsByDifficulty);
function compareQuestionsByDifficulty(
a: AdaptivityQuestion,
b: AdaptivityQuestion
) {
return a.difficulty - b.difficulty;
}

return (
<div className="grid w-full gap-4 px-2 py-2">
{selectedTask.questions.map((question) => {
let starState =
AdaptivityElementDifficultyStarState.NotRequiredUnsolved;
if (question.isRequired === true) {
starState = AdaptivityElementDifficultyStarState.RequiredUnsolved;
}
if (question.isCompleted === true && question.isRequired === true) {
starState = AdaptivityElementDifficultyStarState.RequiredSolved;
} else if (
Expand All @@ -74,7 +69,7 @@ export default function AdaptivityElementQuestionSelection({
return (
<div
key={question.questionID}
className="flex items-center w-full gap-4 "
className="flex items-center w-full gap-4 "
>
<StyledButton
shape="freefloatcenter"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,10 @@ export default function StoryElement({ className }: AdLerUIComponent<{}>) {
<div className="flex items-center justify-center p-2 bg-buttonbgblue rounded-xl">
{contentTexts[pageId].toString()}
</div>
<div className="flex w-full min-h-8 lg:max-w-5xl xl:max-w-6xl justify-end">
<div
className="flex w-full lg:max-w-5xl xl:max-w-6xl justify-end"
style={{ minHeight: "32px" }}
>
<div className="grid w-16 grid-cols-2 lg:w-32 justify-items-end">
<div>
{" "}
Expand Down
Loading

0 comments on commit bc5dfd7

Please sign in to comment.