handling negative rubrics

This commit is contained in:
2024-09-30 20:58:11 -06:00
parent e65b4d8627
commit 7f7827bea8
5 changed files with 109 additions and 19 deletions

View File

@@ -5,6 +5,6 @@ export const assignmentPoints = (assignment: LocalAssignment) => {
.map((r) => .map((r) =>
r.label.toLowerCase().includes("(extra credit)") ? 0 : r.points r.label.toLowerCase().includes("(extra credit)") ? 0 : r.points
) )
.reduce((acc, current) => acc + current, 0); .reduce((acc, current) => (current > 0 ? acc + current : acc), 0);
return basePoints; return basePoints;
}; };

View File

@@ -8,7 +8,7 @@ import { assignmentPoints } from "@/models/local/assignment/utils/assignmentPoin
import { getDateFromString } from "@/models/local/timeUtils"; import { getDateFromString } from "@/models/local/timeUtils";
import { canvasModuleService } from "./canvasModuleService"; import { canvasModuleService } from "./canvasModuleService";
import { CanvasModule } from "@/models/canvas/modules/canvasModule"; import { CanvasModule } from "@/models/canvas/modules/canvasModule";
import { getRubricCriterion } from "./canvasRubricUtils";
export const canvasAssignmentService = { export const canvasAssignmentService = {
async getAll(courseId: number): Promise<CanvasAssignment[]> { async getAll(courseId: number): Promise<CanvasAssignment[]> {
@@ -25,7 +25,7 @@ export const canvasAssignmentService = {
async create( async create(
canvasCourseId: number, canvasCourseId: number,
localAssignment: LocalAssignment, localAssignment: LocalAssignment,
canvasAssignmentGroupId?: number, canvasAssignmentGroupId?: number
) { ) {
console.log(`Creating assignment: ${localAssignment.name}`); console.log(`Creating assignment: ${localAssignment.name}`);
const url = `${canvasApi}/courses/${canvasCourseId}/assignments`; const url = `${canvasApi}/courses/${canvasCourseId}/assignments`;
@@ -108,22 +108,8 @@ const createRubric = async (
assignmentCanvasId: number, assignmentCanvasId: number,
localAssignment: LocalAssignment localAssignment: LocalAssignment
) => { ) => {
const criterion = localAssignment.rubric const criterion = getRubricCriterion(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 rubricBody = { const rubricBody = {
rubric_association_id: assignmentCanvasId, rubric_association_id: assignmentCanvasId,
rubric: { rubric: {

View 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
}

View 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 },
}
}
})
})
})

View File

@@ -157,5 +157,15 @@ Content-Type: application/json
"name": "test module" "name": "test module"
} }
} }
###
POST https://snow.instructure.com/api/v1/courses/courses/960410/rubrics/1961869
Authorization: Bearer {{$dotenv CANVAS_TOKEN}}
Content-Type: application/json
{
"module": {
"name": "test module"
}
}