Create conversions to use CourseGradeCalculator
refs VICE-3692 flag=restrict_quantitative_data Test Plan: - Add import and log statements (below) in AssignmentTable.jsx - go to student grade summary page with dev tools open - should see logged grades import {calculateCourseGrade} from './gradeCalculatorConversions' console.log( calculateCourseGrade( [], queryData?.assignmentGroupsConnection?.nodes, queryData?.assignmentsConnection?.nodes ) ) Note: Grades do not currently match that will be the next patch set. Change-Id: Ieb117a2d63b7e92a79c8ab70a48a1551504b82ae Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/325714 Reviewed-by: Jason Gillett <jason.gillett@instructure.com> Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> Product-Review: Drake Harper <drake.harper@instructure.com> QA-Review: Chawn Neal <chawn.neal@instructure.com>
This commit is contained in:
parent
add68629d6
commit
2284c3f740
|
@ -23,21 +23,50 @@ export const GradingPeriod = {
|
|||
fragment: gql`
|
||||
fragment GradingPeriod on GradingPeriod {
|
||||
_id
|
||||
createdAt
|
||||
displayTotals
|
||||
closeDate
|
||||
title
|
||||
weight
|
||||
displayTotals
|
||||
id
|
||||
startDate
|
||||
updatedAt
|
||||
endDate
|
||||
}
|
||||
`,
|
||||
shape: {
|
||||
_id: string,
|
||||
createdAt: string,
|
||||
displayTotals: bool,
|
||||
closeDate: string,
|
||||
title: string,
|
||||
weight: float,
|
||||
displayTotals: bool,
|
||||
id: string,
|
||||
startDate: string,
|
||||
updatedAt: string,
|
||||
endDate: string,
|
||||
},
|
||||
mock: ({_id = '1', title = 'Grading Period 1', weight = 50, displayTotals = true} = {}) => ({
|
||||
mock: ({
|
||||
_id = '1',
|
||||
createdAt = '2020-01-01',
|
||||
closeDate = '2020-01-03',
|
||||
title = 'Grading Period 1',
|
||||
weight = 50,
|
||||
displayTotals = true,
|
||||
id = '1',
|
||||
startDate = '2020-01-01',
|
||||
updatedAt = '2020-01-01',
|
||||
endDate = '2020-01-02',
|
||||
} = {}) => ({
|
||||
_id,
|
||||
createdAt,
|
||||
closeDate,
|
||||
title,
|
||||
weight,
|
||||
displayTotals,
|
||||
id,
|
||||
startDate,
|
||||
updatedAt,
|
||||
endDate,
|
||||
}),
|
||||
}
|
||||
|
|
|
@ -35,7 +35,6 @@ export const assignmentGroupRow = (
|
|||
queryData,
|
||||
calculateOnlyGradedAssignments = false
|
||||
) => {
|
||||
|
||||
const groupAssignments = queryData?.assignmentsConnection?.nodes?.filter(assignment => {
|
||||
return assignment?.assignmentGroup?._id === assignmentGroup?._id
|
||||
})
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
*/
|
||||
|
||||
import AssignmentGroupGradeCalculator from '@canvas/grading/AssignmentGroupGradeCalculator'
|
||||
import CourseGradeCalculator from '@canvas/grading/CourseGradeCalculator'
|
||||
|
||||
export const convertSubmissionToDroppableSubmission = (assignment, submission) => {
|
||||
return {
|
||||
|
@ -100,6 +101,40 @@ export const convertAssignmentGroup = assignmentGroup => {
|
|||
}
|
||||
}
|
||||
|
||||
const isInPast = dateTimeStr => {
|
||||
if (!dateTimeStr) return false
|
||||
const dateObj = new Date(dateTimeStr)
|
||||
const now = new Date()
|
||||
return dateObj < now
|
||||
}
|
||||
|
||||
export const convertGradingPeriod = gradingPeriod => {
|
||||
return {
|
||||
closeDate: gradingPeriod.closeDate, // Date
|
||||
endDate: gradingPeriod.endDate, // Date
|
||||
id: gradingPeriod._id, // string
|
||||
isClosed: isInPast(gradingPeriod.closeDate), // boolean
|
||||
isLast: false, // boolean
|
||||
startDate: gradingPeriod.startDate, // Date
|
||||
title: gradingPeriod.title, // string
|
||||
weight: gradingPeriod.weight, // number
|
||||
}
|
||||
}
|
||||
|
||||
export const convertGradingPeriodSet = (gradingPeriods, courseData) => {
|
||||
return {
|
||||
createdAt: courseData.createdAt, // Date
|
||||
displayTotalsForAllGradingPeriods: courseData.displayTotals, // boolean
|
||||
enrollmentTermIDs: courseData.enrollmentTermIDs, // string[]
|
||||
gradingPeriods: gradingPeriods.map(period => convertGradingPeriod(period)), // CamelizedGradingPeriod[]
|
||||
id: courseData._id, // string
|
||||
isClosed: isInPast(courseData.closeDate), // boolean
|
||||
permissions: null, // unknown
|
||||
title: courseData.title, // string
|
||||
weighted: courseData.applyGroupWeights, // boolean
|
||||
}
|
||||
}
|
||||
|
||||
export const calculateAssignmentGroupGrade = (
|
||||
assignments,
|
||||
assignmentGroup,
|
||||
|
@ -125,3 +160,54 @@ export const calculateAssignmentGroupGrade = (
|
|||
ignoreUnpostedAnonymous
|
||||
)
|
||||
}
|
||||
|
||||
export const convertAssignmentGroupCriteriaMap = (assignmentGroups, assignments) => {
|
||||
const assignmentGroupCriteriaMap = {}
|
||||
assignmentGroups.forEach(assignmentGroup => {
|
||||
assignmentGroupCriteriaMap[assignmentGroup._id] = {
|
||||
...convertAssignmentGroup(assignmentGroup),
|
||||
assignments: assignments
|
||||
.filter(assignment => assignment.assignmentGroupId === assignmentGroup._id)
|
||||
.map(assignment => convertAssignment(assignment)),
|
||||
invalid: false,
|
||||
gradingPeriodsIds: [],
|
||||
}
|
||||
})
|
||||
return assignmentGroupCriteriaMap
|
||||
}
|
||||
|
||||
/*
|
||||
To use the course grade calculator, you need to pass in the following:
|
||||
- submissions: an array of submissions
|
||||
- assignmentGroups: an array of assignment groups
|
||||
- assignmentGroupCriteriaMap: an object with assignment group ids as keys and assignment group criteria as values
|
||||
- gradingPeriodSet: an object with grading period set criteria
|
||||
- ignoreUnpostedAnonymous: a boolean
|
||||
- enrollmentTermIDs: an array of enrollment term ids
|
||||
|
||||
These conversions are necessary because the course grade calculator expects the data to be in a different
|
||||
format than the data we get from the GraphQL API. For example, the course grade calculator expects the
|
||||
assignments and submissions to be in separate arrays, but the GraphQL API returns them nested inside each
|
||||
other. The course grade calculator also expects the assignment groups to be in an object with the assignment
|
||||
group ids as keys, but the GraphQL API returns them in an array.
|
||||
*/
|
||||
export const calculateCourseGrade = (gradingPeriods, assignmentGroups, assignments) => {
|
||||
const convertedSubmissions = assignments.map(assignment => {
|
||||
return convertToSubmissionCriteria(
|
||||
assignment.submissionsConnection.nodes[0],
|
||||
assignment._id,
|
||||
assignment.state
|
||||
)
|
||||
})
|
||||
|
||||
// const convertedGradingPeriods = convertGradingPeriodSet(gradingPeriods, {})
|
||||
|
||||
return CourseGradeCalculator.calculate(
|
||||
convertedSubmissions,
|
||||
convertAssignmentGroupCriteriaMap(assignmentGroups, assignments),
|
||||
'points',
|
||||
true,
|
||||
null,
|
||||
[]
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue