Skip to content

Commit

Permalink
cleanup: Separate Context.../ResultExtension, run prettier.
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuel committed Aug 23, 2024
1 parent 855d918 commit 8eb2d97
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 103 deletions.
5 changes: 4 additions & 1 deletion src/AbstractCmi5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ import {

export * from "./interfaces";

function _applyTransform(mergedStatement: Statement, options: SendStatementOptions) {
function _applyTransform(
mergedStatement: Statement,
options: SendStatementOptions
) {
return options && typeof options.transform === "function"
? options.transform(mergedStatement)
: mergedStatement;
Expand Down
31 changes: 15 additions & 16 deletions src/Cmi5Statements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ import {
} from "./interfaces";
import {
Cmi5ContextActivity,
Cmi5DefinedVerbs, Cmi5Extension, Cmi5InteractionIRI,
Cmi5DefinedVerbs,
Cmi5ContextExtension,
Cmi5InteractionIRI,
Cmi5InteractionType,
Cmi5ResultExtension,
} from "./constants";


export function Cmi5DefinedStatement(
ctx: LaunchContext,
statement: Partial<Statement>
Expand Down Expand Up @@ -116,7 +118,7 @@ export function Cmi5PassStatement(
score?: ResultScore | number,
objectiveOrOptions?: ObjectiveActivity | PassOptions
): Statement {
const masteryScore = ctx.launchData.masteryScore
const masteryScore = ctx.launchData.masteryScore;
// 10.0 xAPI State Data Model - https://github.com/AICC/CMI-5_Spec_Current/blob/quartz/cmi5_spec.md#100-xapi-state-data-model
if (ctx.launchData.launchMode !== "Normal")
throw new Error("Can only send PASSED when launchMode is 'Normal'");
Expand Down Expand Up @@ -148,15 +150,15 @@ export function Cmi5PassStatement(
...(objective ? { parent: [objective] } : {}),
},
...(masteryScore
? { extensions: { [Cmi5Extension.MASTERY_SCORE]: masteryScore } }
? { extensions: { [Cmi5ContextExtension.MASTERY_SCORE]: masteryScore } }
: {}),
},
});
}

export function Cmi5FailStatement(
ctx: LaunchContext,
score?: ResultScore | number,
score?: ResultScore | number
): Statement {
// 10.0 xAPI State Data Model - https://github.com/AICC/CMI-5_Spec_Current/blob/quartz/cmi5_spec.md#100-xapi-state-data-model
if (ctx.launchData.launchMode !== "Normal")
Expand All @@ -182,8 +184,7 @@ export function Cmi5FailStatement(
...(ctx.launchData.masteryScore
? {
extensions: {
[Cmi5Extension.MASTERY_SCORE]:
ctx.launchData.masteryScore,
[Cmi5ContextExtension.MASTERY_SCORE]: ctx.launchData.masteryScore,
},
}
: {}),
Expand Down Expand Up @@ -215,7 +216,7 @@ export function Cmi5ProgressStatement(
},
result: {
extensions: {
[Cmi5Extension.PROGRESS]: percent,
[Cmi5ResultExtension.PROGRESS]: percent,
},
},
});
Expand Down Expand Up @@ -615,9 +616,7 @@ export function Cmi5InteractionOtherStatement(
{
type: Cmi5InteractionIRI,
interactionType: "other",
...(correctAnswer
? { correctResponsesPattern: [correctAnswer] }
: {}),
...(correctAnswer ? { correctResponsesPattern: [correctAnswer] } : {}),
...(name ? { name } : {}),
...(description ? { description } : {}),
},
Expand Down Expand Up @@ -663,7 +662,6 @@ export function Cmi5InteractionStatement(
});
}


// Helper/utility functions

// Formatting
Expand Down Expand Up @@ -724,8 +722,9 @@ function _isNumericRange(candidate: unknown): candidate is NumericRange {
);
}

function _didMeetMasteryScore(masteryScore: number, rScore?: ResultScore): boolean {
return rScore &&
_isNumber(rScore.scaled) &&
rScore.scaled >= masteryScore;
function _didMeetMasteryScore(
masteryScore: number,
rScore?: ResultScore
): boolean {
return rScore && _isNumber(rScore.scaled) && rScore.scaled >= masteryScore;
}
4 changes: 4 additions & 0 deletions src/constants/Cmi5ContextExtension.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export class Cmi5ContextExtension {
public static readonly MASTERY_SCORE =
"https://w3id.org/xapi/cmi5/context/extensions/masteryscore";
}
5 changes: 0 additions & 5 deletions src/constants/Cmi5Extension.ts

This file was deleted.

3 changes: 2 additions & 1 deletion src/constants/Cmi5InteractionType.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const Cmi5InteractionIRI = "http://adlnet.gov/expapi/activities/cmi.interaction" as const;
export const Cmi5InteractionIRI =
"http://adlnet.gov/expapi/activities/cmi.interaction" as const;

export class Cmi5InteractionType {
public static readonly TRUE_FALSE = "true-false";
Expand Down
4 changes: 4 additions & 0 deletions src/constants/Cmi5ResultExtension.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export class Cmi5ResultExtension {
public static readonly PROGRESS =
"https://w3id.org/xapi/cmi5/result/extensions/progress";
}
3 changes: 2 additions & 1 deletion src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from "./Cmi5ContextActivity";
export * from "./Cmi5ContextExtension";
export * from "./Cmi5DefinedVerbs";
export * from "./Cmi5Extension";
export * from "./Cmi5InteractionType";
export * from "./Cmi5ResultExtension";
Loading

0 comments on commit 8eb2d97

Please sign in to comment.