mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
handling negative rubrics
This commit is contained in:
@@ -5,6 +5,6 @@ export const assignmentPoints = (assignment: LocalAssignment) => {
|
||||
.map((r) =>
|
||||
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;
|
||||
};
|
||||
|
||||
@@ -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,21 +108,7 @@ 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,
|
||||
|
||||
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 },
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -157,5 +157,15 @@ Content-Type: application/json
|
||||
"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"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user