mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-26 07:38:33 -06:00
handling negative rubrics
This commit is contained in:
@@ -8,7 +8,7 @@ import { assignmentPoints } from "@/models/local/assignment/utils/assignmentPoin
|
||||
import { getDateFromString } from "@/models/local/timeUtils";
|
||||
import { canvasModuleService } from "./canvasModuleService";
|
||||
import { CanvasModule } from "@/models/canvas/modules/canvasModule";
|
||||
|
||||
import { getRubricCriterion } from "./canvasRubricUtils";
|
||||
|
||||
export const canvasAssignmentService = {
|
||||
async getAll(courseId: number): Promise<CanvasAssignment[]> {
|
||||
@@ -25,7 +25,7 @@ export const canvasAssignmentService = {
|
||||
async create(
|
||||
canvasCourseId: number,
|
||||
localAssignment: LocalAssignment,
|
||||
canvasAssignmentGroupId?: number,
|
||||
canvasAssignmentGroupId?: number
|
||||
) {
|
||||
console.log(`Creating assignment: ${localAssignment.name}`);
|
||||
const url = `${canvasApi}/courses/${canvasCourseId}/assignments`;
|
||||
@@ -108,22 +108,8 @@ const createRubric = async (
|
||||
assignmentCanvasId: number,
|
||||
localAssignment: LocalAssignment
|
||||
) => {
|
||||
const criterion = localAssignment.rubric
|
||||
.map((rubricItem) => ({
|
||||
description: rubricItem.label,
|
||||
points: rubricItem.points,
|
||||
ratings: {
|
||||
0: { description: "Full Marks", points: rubricItem.points },
|
||||
1: { description: "No Marks", points: 0 },
|
||||
},
|
||||
}))
|
||||
.reduce((acc, item, index) => {
|
||||
return {
|
||||
...acc,
|
||||
[index]: item,
|
||||
};
|
||||
}, {} as { [key: number]: { description: string; points: number; ratings: { [key: number]: { description: string; points: number } } } });
|
||||
|
||||
const criterion = getRubricCriterion(localAssignment.rubric);
|
||||
|
||||
const rubricBody = {
|
||||
rubric_association_id: assignmentCanvasId,
|
||||
rubric: {
|
||||
|
||||
22
nextjs/src/services/canvas/canvasRubricUtils.ts
Normal file
22
nextjs/src/services/canvas/canvasRubricUtils.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { RubricItem } from "@/models/local/assignment/rubricItem";
|
||||
|
||||
export const getRubricCriterion = (rubric: RubricItem[]) => {
|
||||
const criterion = rubric
|
||||
.map((rubricItem) => ({
|
||||
description: rubricItem.label,
|
||||
points: rubricItem.points,
|
||||
ratings: {
|
||||
0: { description: "Full Marks", points: rubricItem.points },
|
||||
1: { description: "No Marks", points: 0 },
|
||||
},
|
||||
}))
|
||||
.reduce((acc, item, index) => {
|
||||
return {
|
||||
...acc,
|
||||
[index]: item,
|
||||
};
|
||||
}, {} as { [key: number]: { description: string; points: number; ratings: { [key: number]: { description: string; points: number } } } });
|
||||
|
||||
return criterion
|
||||
|
||||
}
|
||||
72
nextjs/src/services/canvas/rubric.test.ts
Normal file
72
nextjs/src/services/canvas/rubric.test.ts
Normal file
@@ -0,0 +1,72 @@
|
||||
import { RubricItem } from "@/models/local/assignment/rubricItem";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { getRubricCriterion } from "./canvasRubricUtils";
|
||||
|
||||
describe("can prepare rubric for canvas", () =>{
|
||||
it("can parse normal rubric into criterion", () =>{
|
||||
const rubric: RubricItem[] = [
|
||||
{
|
||||
label: "first",
|
||||
points: 1
|
||||
},
|
||||
{
|
||||
label: "second",
|
||||
points: 2
|
||||
},
|
||||
]
|
||||
const criterion = getRubricCriterion(rubric)
|
||||
|
||||
expect(criterion).toStrictEqual({
|
||||
0: {
|
||||
description: "first",
|
||||
points: 1,
|
||||
ratings: {
|
||||
0: { description: "Full Marks", points: 1 },
|
||||
1: { description: "No Marks", points: 0 },
|
||||
}
|
||||
},
|
||||
1: {
|
||||
description: "second",
|
||||
points: 2,
|
||||
ratings: {
|
||||
0: { description: "Full Marks", points: 2 },
|
||||
1: { description: "No Marks", points: 0 },
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
it("can parse negative rubric into criterion", () =>{
|
||||
const rubric: RubricItem[] = [
|
||||
{
|
||||
label: "first",
|
||||
points: 1
|
||||
},
|
||||
{
|
||||
label: "second",
|
||||
points: -2
|
||||
},
|
||||
]
|
||||
const criterion = getRubricCriterion(rubric)
|
||||
|
||||
expect(criterion).toStrictEqual({
|
||||
0: {
|
||||
description: "first",
|
||||
points: 1,
|
||||
ratings: {
|
||||
0: { description: "Full Marks", points: 1 },
|
||||
1: { description: "No Marks", points: 0 },
|
||||
}
|
||||
},
|
||||
1: {
|
||||
description: "second",
|
||||
points: -2,
|
||||
ratings: {
|
||||
0: { description: "Full Marks", points: -2 },
|
||||
1: { description: "No Marks", points: 0 },
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user