Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Updater] Add chosen modules to studyplan #4734

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const { STRING } = require('sequelize')

module.exports = {
up: async queryInterface => {
await queryInterface.addColumn('studyplan', 'included_modules', {
type: STRING,
})
},
down: async queryInterface => {
await queryInterface.removeColumn('studyplan', 'included_modules')
},
}
4 changes: 4 additions & 0 deletions updater/sis-updater-worker/src/db/models/studyplan.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ Studyplan.init(
included_courses: {
type: ARRAY(STRING),
},
includedModules: {
type: ARRAY(STRING),
field: 'included_modules',
},
sisu_id: {
type: STRING,
},
Expand Down
19 changes: 18 additions & 1 deletion updater/sis-updater-worker/src/updater/mapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ const studyplanMapper =
(
personIdToStudentNumber,
programmeModuleIdToCode,
programmeModuleIdToStudyModuleCode,
moduleIdToParentModuleCode,
courseUnitIdToCode,
moduleAttainments,
Expand All @@ -359,18 +360,21 @@ const studyplanMapper =
return studyPlanIdToDegrees[studyplan.id].map(programmeId => {
const code = programmeModuleIdToCode[programmeId]
if (!code) return null

const graduated = moduleAttainments[programmeId] && moduleAttainments[programmeId][studyplan.user_id]
const id = `${studentnumber}-${code}-${studyrightId}`

const courseUnitSelections = studyplan.course_unit_selections
.filter(courseUnit => moduleIdToParentModuleCode[courseUnit.parentModuleId]?.has(code))
.filter(({ substituteFor }) => !substituteFor.length) // Filter out CUs used to substitute another CU
.map(({ substitutedBy, courseUnitId }) => {
if (substitutedBy.length) return courseUnitIdToCode[substitutedBy[0]]
return courseUnitIdToCode[courseUnitId]
})

const customCourseUnitSelections = studyplan.custom_course_unit_attainment_selections
.filter(({ parentModuleId }) => moduleIdToParentModuleCode[parentModuleId]?.has(code))
.map(({ customCourseUnitAttainmentId }) => (attainmentIdToAttainment[customCourseUnitAttainmentId] || {}).code)
.map(({ customCourseUnitAttainmentId }) => attainmentIdToAttainment[customCourseUnitAttainmentId]?.code)
.map(sanitizeCourseCode)
.filter(course => !!course)

Expand Down Expand Up @@ -446,12 +450,24 @@ const studyplanMapper =
.filter(a => !!a),
'id'
)

const completed_credits = calculateTotalCreditsFromAttainments(attainmentsToCalculate)

const includedCourses = graduated
? getCourseCodesFromAttainment(moduleAttainments[programmeId][studyplan.user_id])
: courseUnitSelections.concat(customCourseUnitSelections).concat(coursesFromAttainedModules)
if (includedCourses.length === 0) return null

const includedModules = Array.from(
studyplan.module_selections.reduce((modules, { moduleId }) => {
const studyModuleCode = programmeModuleIdToStudyModuleCode[moduleId]
if (studyModuleCode) {
modules.add(studyModuleCode)
}
return modules
}, new Set())
)

return {
id,
studentnumber,
Expand All @@ -461,6 +477,7 @@ const studyplanMapper =
sisu_id: studyplan.id,
curriculum_period_id: studyplan.curriculum_period_id,
sis_study_right_id: studyrightId,
includedModules,
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const updateStudyplans = async (studyplansAll, personIds, personIdToStudentNumbe
'group_id'
)
)

const educationHasStudyRight = Object.keys(groupedStudyRightSnapshots).reduce((acc, k) => {
const sorted = groupedStudyRightSnapshots[k]
.filter(s => new Date(s.snapshot_date_time) <= new Date())
Expand Down Expand Up @@ -102,6 +103,13 @@ const updateStudyplans = async (studyplansAll, personIds, personIdToStudentNumbe
return res
}, {})

const programmeModuleIdToStudyModuleCode = programmeModules.reduce((res, mod) => {
if (mod.type === 'StudyModule') {
res[mod.id] = mod.code
}
return res
}, {})

const courseUnitIdToCode = courseUnits.reduce((res, cur) => {
res[cur.id] = cur.code
return res
Expand Down Expand Up @@ -202,6 +210,7 @@ const updateStudyplans = async (studyplansAll, personIds, personIdToStudentNumbe
const mapStudyplan = studyplanMapper(
personIdToStudentNumber,
programmeModuleIdToCode,
programmeModuleIdToStudyModuleCode,
moduleIdToParentModuleCode,
courseUnitIdToCode,
moduleAttainments,
Expand Down