Skip to content

Commit

Permalink
[Backend] Remove enrollment state from course statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
rikurauhala committed Sep 30, 2024
1 parent df081ae commit 6375c81
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 21 deletions.
20 changes: 5 additions & 15 deletions services/backend/src/services/courses/courseYearlyStatsCounter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EnrollmentState, Name } from '../../types'
import { Name } from '../../types'
import { FormattedProgramme, OrganizationDetails } from './helpers'

type Programme = {
Expand Down Expand Up @@ -49,8 +49,8 @@ type Group = {
coursecode: string
attempts: GroupAttempts
students: GroupStudents
enrollments: { studentNumber: string; state: string; enrollmentDateTime: Date }[]
allEnrollments: { studentNumber: string; state: string; enrollmentDateTime: Date }[]
enrollments: { studentNumber: string; enrollmentDateTime: Date }[]
allEnrollments: { studentNumber: string; enrollmentDateTime: Date }[]
yearcode: number
}

Expand Down Expand Up @@ -211,7 +211,6 @@ export class CourseYearlyStatsCounter {

public markEnrollmentToGroup(
studentNumber: string,
state: string,
enrollmentDateTime: Date,
groupCode: number,
groupName: string | Name,
Expand All @@ -221,22 +220,13 @@ export class CourseYearlyStatsCounter {
if (!this.groups[groupCode]) {
this.initGroup(groupCode, groupName, courseCode, yearCode)
}
const enrollment = { studentNumber, state, enrollmentDateTime }
const enrollment = { studentNumber, enrollmentDateTime }
this.groups[groupCode].allEnrollments.push(enrollment)
const oldEnrollment = this.groups[groupCode].enrollments.find(
enrollment => enrollment.studentNumber === studentNumber
)
if (!oldEnrollment) {
return this.groups[groupCode].enrollments.push({ studentNumber, state, enrollmentDateTime })
}
if (oldEnrollment.state === EnrollmentState.ENROLLED || oldEnrollment.state === EnrollmentState.CONFIRMED) {
return
}
if (state !== EnrollmentState.ENROLLED && state !== EnrollmentState.CONFIRMED) {
return
}
if (![EnrollmentState.ENROLLED, EnrollmentState.CONFIRMED].includes(state as EnrollmentState)) {
return
return this.groups[groupCode].enrollments.push({ studentNumber, enrollmentDateTime })
}
this.groups[groupCode].enrollments = this.groups[groupCode].enrollments
.filter(enrollment => enrollment.studentNumber !== studentNumber)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export const getEnrollmentsForCourses = async (codes: string[], unification: Uni
[Op.in]: codes,
},
enrollment_date_time: { [Op.gte]: new Date('2021-05-31') },
state: [EnrollmentState.ENROLLED, EnrollmentState.CONFIRMED],
state: EnrollmentState.ENROLLED,
is_open: getIsOpen(unification),
},
})
Expand Down
7 changes: 2 additions & 5 deletions services/backend/src/services/courses/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ type FormattedEnrollment = {
semesterCode: number
semesterName: Name
courseCode: string
state: string
enrollmentDateTime: Date
studentNumber: string
programmes: Array<Record<string, any>>
Expand All @@ -114,7 +113,6 @@ const parseEnrollment = (
const {
studentnumber: studentNumber,
semester,
state,
enrollment_date_time: enrollmentDateTime,
course_code: courseCode,
} = enrollment
Expand All @@ -128,7 +126,6 @@ const parseEnrollment = (
semesterCode,
semesterName,
courseCode,
state,
enrollmentDateTime,
studentNumber,
programmes: studyRightElements.map(formatStudyRightElement),
Expand Down Expand Up @@ -222,13 +219,13 @@ const getYearlyStatsOfNew = async (
}

enrollments.forEach(enrollment => {
const { studentNumber, semesterCode, semesterName, yearCode, yearName, courseCode, state, enrollmentDateTime } =
const { studentNumber, semesterCode, semesterName, yearCode, yearName, courseCode, enrollmentDateTime } =
parseEnrollment(enrollment, anonymizationSalt, studentNumberToSrElementsMap)

const groupCode = separate ? semesterCode : yearCode
const groupName = separate ? semesterName : yearName

counter.markEnrollmentToGroup(studentNumber, state, enrollmentDateTime, groupCode, groupName, courseCode, yearCode)
counter.markEnrollmentToGroup(studentNumber, enrollmentDateTime, groupCode, groupName, courseCode, yearCode)
})

const statistics = counter.getFinalStatistics(anonymizationSalt)
Expand Down

0 comments on commit 6375c81

Please sign in to comment.