Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,42 @@ export function fixWildcardSelections(resources: TorusResource[]) {
return resources;
}

const getSelectionPoints = (resources: TorusResource[], sel: any) => {
const tag = sel.logic.conditions.children[0].value[0];
const acts = resources.filter(
(r) => r.type === 'Activity' && r.tags.includes(tag)
);

const partPoints = (act: any): number[] =>
act.content.authoring.parts.map((part: any) => part?.outOf || 1);

const actPoints = (act: any) =>
partPoints(act).reduce((sum: number, val: number) => sum + val, 0);

// we can only assign points to selection if all possible questions have same points
const firstActPoints = actPoints(acts[0]);
return acts.every((a) => actPoints(a) === firstActPoints)
? firstActPoints
: 1;
};

export function setSelectionPoints(resources: TorusResource[]) {
resources
.filter((r) => r.type === 'Page')
.forEach((page) => {
getDescendants(
(page as Page).content.model as any[],
'selection'
).forEach((sel: any) => {
const points = getSelectionPoints(resources, sel);
if (points !== 1) {
sel.pointsPerActivity = points;
}
});
});

return resources;
}
function fixReportActivityid(resources: TorusResource[], selection: any) {
resources
.filter((r) => r.type === 'Page' && r.id === selection.activityId)
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ export function convertAction(options: CmdOptions): Promise<ConvertedResults> {
updated = Convert.updateDerivativeReferences(updated);
updated = Convert.generatePoolTags(updated);
updated = Convert.fixWildcardSelections(updated);
updated = Convert.setSelectionPoints(updated);
updated = Convert.fixActivityReports(updated);
updated = filterOutTemporaryContent(updated);
updated = Convert.updateNonDirectImageReferences(
Expand Down
4 changes: 1 addition & 3 deletions src/resources/formative.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ function buildMCQPart(question: any) {
content: Common.ensureParagraphs(r.children),
}))
),
scoringStrategy: 'average',
targeted: [],
objectives: skillrefs.map((s: any) => s.idref),
explanation: Common.maybeBuildPartExplanation(responses),
Expand Down Expand Up @@ -161,7 +160,6 @@ function buildOrderingPart(question: any) {
content: Common.ensureParagraphs(r.children),
}))
),
scoringStrategy: 'average',
objectives: skillrefs.map((s: any) => s.idref),
explanation: Common.maybeBuildPartExplanation(responses),
};
Expand Down Expand Up @@ -215,7 +213,6 @@ function buildLikertParts(question: any, items: any[]) {
},
Common.makeCatchAllResponse(),
],
scoringStrategy: 'average',
objectives: [],
targeted: [],
explanation: null,
Expand Down Expand Up @@ -557,6 +554,7 @@ export function setCustomScoringFlags(model: any, subType: string) {
const hasCustomPoints = model.authoring.parts.some(
(p: any) => Common.getOutOfPoints(p) > 1
);

if (hasCustomPoints) {
// For multi-part questions, authoring detects custom by activity-wide flag
if (['oli_multi_input', 'oli_response_multi'].includes(subType))
Expand Down
1 change: 0 additions & 1 deletion src/resources/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ function defaultContent(example: boolean) {
],
},
],
scoringStrategy: 'average',
},
],
transformations: [],
Expand Down
1 change: 0 additions & 1 deletion src/resources/questions/cata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ export function buildCATAPart(question: any) {
content: Common.ensureParagraphs(r.children),
}))
),
scoringStrategy: 'average',
objectives: skillrefs.map((s: any) => s.idref),
explanation: Common.maybeBuildPartExplanation(responses),
targeted: [],
Expand Down
7 changes: 5 additions & 2 deletions src/resources/questions/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,6 @@ export function buildTextPart(id: string, question: any) {
}))
),
objectives: skillrefs.map((s: any) => s.idref),
scoringStrategy: 'average',
explanation: maybeBuildPartExplanation(legacyResponses),
gradingApproach: getGradingApproach(question),
};
Expand Down Expand Up @@ -432,5 +431,9 @@ export function adjustSubmitCompareResponses(origResponses: any[]) {
}

export function getOutOfPoints(part: any) {
return Math.max(...part.responses.map((r: any) => r?.score ?? 0));
return (
// instructor-graded questions have no responses but may still have custom
// outOf points set from score_out_of attribute on legacy part
part?.outOf || Math.max(...part.responses.map((r: any) => r?.score ?? 0))
);
}
11 changes: 7 additions & 4 deletions src/resources/questions/multi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,6 @@ function buildDropdownPart(part: any, i: number, ignorePartId: boolean) {
}))
),
objectives: skillrefs.map((s: any) => s.idref),
scoringStrategy: 'average',
explanation: Common.maybeBuildPartExplanation(responses),
};
}
Expand Down Expand Up @@ -461,7 +460,7 @@ export function buildInputPart(
const skillrefs = Common.getChildren(part, 'skillref');
const id = part.id !== undefined && part.id !== null ? part.id + '' : guid();

return {
const torusPart: any = {
id,
responses: responses.map((r: any) => {
const cleanedMatch = convertCatchAll(r.match);
Expand All @@ -488,10 +487,15 @@ export function buildInputPart(
}))
),
objectives: skillrefs.map((s: any) => s.idref),
scoringStrategy: 'average',
explanation: Common.maybeBuildPartExplanation(responses),
gradingApproach: Common.getGradingApproach(input),
};
// include custom outOf points for instructor-graded questions if specified by score_out_of attr
if (torusPart.gradingApproach === 'manual' && part?.score_out_of) {
torusPart.outOf = Number(part.score_out_of);
}

return torusPart;
}

// Build a response_multi question. Similar to multi-input, but each part subsumes a *set* of
Expand Down Expand Up @@ -611,7 +615,6 @@ const toResponseMultiPart = (part: any, items: any[]) => {
}))
),
objectives: skillrefs.map((s: any) => s.idref),
scoringStrategy: 'average',
explanation: Common.maybeBuildPartExplanation(responses),
};
};
Expand Down
1 change: 0 additions & 1 deletion src/resources/superactivity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ function toActivityModel(
parts: [
{
id: guid(),
scoringStrategy: 'average',
responses: [],
hints: [],
},
Expand Down
11 changes: 5 additions & 6 deletions test/resources/feedback-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,6 @@ describe('convert feedback', () => {
},
},
],
scoringStrategy: 'average',
objectives: expect.any(Array),
targeted: expect.any(Array),
explanation: null,
Expand Down Expand Up @@ -477,7 +476,7 @@ describe('convert feedback', () => {
},
},
],
scoringStrategy: 'average',

objectives: expect.any(Array),
targeted: expect.any(Array),
explanation: null,
Expand Down Expand Up @@ -524,7 +523,7 @@ describe('convert feedback', () => {
},
},
],
scoringStrategy: 'average',

objectives: expect.any(Array),
targeted: expect.any(Array),
explanation: null,
Expand Down Expand Up @@ -657,7 +656,7 @@ describe('convert feedback', () => {
},
},
],
scoringStrategy: 'average',

objectives: expect.any(Array),
targeted: expect.any(Array),
explanation: null,
Expand Down Expand Up @@ -730,7 +729,7 @@ describe('convert feedback', () => {
},
],
objectives: [],
scoringStrategy: 'average',

explanation: null,
},
],
Expand Down Expand Up @@ -1071,7 +1070,7 @@ describe('convert feedback', () => {
content: [{ type: 'p', children: [{ text: '' }] }],
},
],
scoringStrategy: 'average',

targeted: expect.any(Array),
objectives: [],
explanation: null,
Expand Down
2 changes: 0 additions & 2 deletions test/resources/summative-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ describe('convert summative', () => {
content: [{ type: 'p', children: [{ text: '' }] }],
},
],
scoringStrategy: 'average',
targeted: [],
objectives: [],
explanation: null,
Expand Down Expand Up @@ -342,7 +341,6 @@ describe('convert summative', () => {
content: [{ type: 'p', children: [{ text: '' }] }],
},
],
scoringStrategy: 'average',
targeted: [],
objectives: [],
explanation: null,
Expand Down
Loading