Skip to content

Commit

Permalink
[Class statistics] First version of 'Show full study path' feature
Browse files Browse the repository at this point in the history
  • Loading branch information
valtterikantanen authored Oct 30, 2024
1 parent 65c6319 commit 0bdd010
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 19 deletions.
4 changes: 2 additions & 2 deletions cypress/e2e/Filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ describe('Course Statistics', () => {
it('Programme filter works', () => {
runTestStepWithPreAndPostParts('Programme', () => {
const card = cy.cs('Programme-filter-card')
const programmeDropdown = card.cs('Programme-filter-dropdown').selectFromDropdown(2)
checkFilteringResult(30)
const programmeDropdown = card.cs('Programme-filter-dropdown').selectFromDropdown(1)
checkFilteringResult(33)
programmeDropdown.get('i.delete').click()
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,16 @@ const getStudents = async (studentNumbers: string[]) => {
{
model: SISStudyRightElement,
required: true,
attributes: ['code', 'name', 'studyTrack', 'graduated', 'startDate', 'endDate', 'phase'],
attributes: [
'code',
'name',
'studyTrack',
'graduated',
'startDate',
'endDate',
'phase',
'degreeProgrammeType',
],
},
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export const GeneralTab = ({

const { data: populationStatistics, query } = populations

const showFullStudyPath = query?.showFullStudyPath === 'true'

const queryStudyrights = query ? Object.values(query.studyRights) : []
const cleanedQueryStudyrights = queryStudyrights.filter(studyright => !!studyright)

Expand Down Expand Up @@ -120,6 +122,7 @@ export const GeneralTab = ({
year,
getTextIn,
currentSemester: currentSemester?.semestercode,
showFullStudyPath,
})

const transferFrom = student => getTextIn(programmes[student.transferSource]?.name) ?? student.transferSource
Expand Down Expand Up @@ -222,10 +225,8 @@ export const GeneralTab = ({

const containsStudyTracks = filteredStudents.some(student => getStudyTracks(student.studyRights).length > 0)

const isBachelorsProgramme = Object.values(degreeProgrammeTypes).includes(
'urn:code:degree-program-type:bachelors-degree'
)
const isMastersProgramme = Object.values(degreeProgrammeTypes).includes('urn:code:degree-program-type:masters-degree')
const isBachelorsProgramme = degreeProgrammeTypes[programmeCode] === 'urn:code:degree-program-type:bachelors-degree'
const isMastersProgramme = degreeProgrammeTypes[programmeCode] === 'urn:code:degree-program-type:masters-degree'

const shouldShowAdmissionType = parseInt(query?.year, 10) >= 2020 || parseInt(group?.tags?.year, 10) >= 2020

Expand Down Expand Up @@ -283,6 +284,7 @@ export const GeneralTab = ({
studentToSecondStudyrightEndMap,
studentToStudyrightEndMap,
year,
semestersToAddToStart: showFullStudyPath && isMastersProgramme ? 6 : 0,
})

const availableCreditsColumns = {
Expand All @@ -303,10 +305,22 @@ export const GeneralTab = ({
}),
hopsCombinedProg: () => ({
key: 'credits-hopsCombinedProg',
title: combinedProgrammeCode === 'MH90_001' ? 'Licentiate\nHOPS' : 'Master\nHOPS',
title: (() => {
if (combinedProgrammeCode === 'MH90_001') return 'Licentiate\nHOPS'
if (isBachelorsProgramme) return 'Master\nHOPS'
return 'Bachelor\nHOPS'
})(),
filterType: 'range',
getRowVal: student =>
student.studyplans?.find(plan => plan.programme_code === combinedProgrammeCode)?.completed_credits ?? 0,
student.studyplans?.find(plan => {
if (combinedProgrammeCode) {
return plan.programme_code === combinedProgrammeCode
}
const studyRightIdOfProgramme = student.studyRights.find(studyRight =>
studyRight.studyRightElements?.some(element => element.code === programmeCode)
)?.id
return plan.sis_study_right_id === studyRightIdOfProgramme && plan.programme_code !== programmeCode
})?.completed_credits ?? 0,
}),
studyright: sole => ({
key: 'credits-studyright',
Expand Down Expand Up @@ -425,7 +439,11 @@ export const GeneralTab = ({
},
endDateCombinedProg: {
key: 'endDateCombinedProg',
title: combinedProgrammeCode === 'MH90_001' ? 'Licentiate\ngraduation\ndate' : 'Master\ngraduation\ndate',
title: (() => {
if (combinedProgrammeCode === 'MH90_001') return 'Licentiate\ngraduation\ndate'
if (isBachelorsProgramme) return 'Master\ngraduation\ndate'
return 'Bachelor\ngraduation\ndate'
})(),
filterType: 'date',
getRowVal: student =>
studentToSecondStudyrightEndMap[student.studentNumber]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { orderBy } from 'lodash'

import { findStudyRightForClass, getAllProgrammesOfStudent } from '@/common'

export const createMaps = ({
Expand All @@ -8,6 +10,7 @@ export const createMaps = ({
year,
currentSemester,
getTextIn,
showFullStudyPath,
}) => {
const studentToStudyrightStartMap = {}
const studentToStudyrightEndMap = {}
Expand All @@ -19,9 +22,23 @@ export const createMaps = ({
const { studyRights } = students[studentNumber]
const studyRight = findStudyRightForClass(studyRights, programmeCode, year)
const studyRightElement = studyRight?.studyRightElements?.find(element => element.code === programmeCode)
const secondStudyRightElement = studyRight?.studyRightElements?.find(
element => element.code === combinedProgrammeCode
)
const secondStudyRightElement = orderBy(
(studyRight?.studyRightElements ?? []).filter(element => {
if (combinedProgrammeCode) {
return element.code === combinedProgrammeCode
}
if (showFullStudyPath && studyRightElement) {
const degreeProgrammeTypeToCheck =
studyRightElement.degreeProgrammeType === 'urn:code:degree-program-type:bachelors-degree'
? 'urn:code:degree-program-type:masters-degree'
: 'urn:code:degree-program-type:bachelors-degree'
return element.degreeProgrammeType === degreeProgrammeTypeToCheck
}
return false
}),
['startDate'],
['desc']
)[0]
const programmes = getAllProgrammesOfStudent(students[studentNumber]?.studyRights ?? [], currentSemester)
const programmesToUse = programmeCode ? programmes.filter(p => p.code !== programmeCode) : programmes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const getSemestersPresentFunctions = ({
studentToSecondStudyrightEndMap,
studentToStudyrightEndMap,
year,
semestersToAddToStart,
}) => {
if (allSemesters?.length === 0 || !filteredStudents)
return {
Expand All @@ -26,10 +27,14 @@ export const getSemestersPresentFunctions = ({
const getFirstAndLastSemester = () => {
const associatedYear = year !== 'All' && year
if (associatedYear) {
let first = allSemesters.find(
semester => new Date(semester.startdate).getTime() === new Date(Date.UTC(associatedYear, 7, 1)).getTime()
).semestercode
if (semestersToAddToStart) {
first -= semestersToAddToStart
}
return {
first: allSemesters.find(
semester => `${semester.yearcode + 1949}` === associatedYear && isFall(semester.semestercode)
)?.semestercode,
first,
last: isFall(currentSemesterCode) ? currentSemesterCode + 1 : currentSemesterCode,
}
}
Expand Down Expand Up @@ -66,8 +71,10 @@ export const getSemestersPresentFunctions = ({
if (
secondGraduation &&
moment(secondGraduation).isBetween(allSemestersMap[semester].startdate, allSemestersMap[semester].enddate)
)
) {
if (isMastersProgramme(programmeCode)) return 1
return 2
}
return 0
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,12 @@ export const GeneralTabContainer = ({ studyGuidanceGroup, variant, ...props }) =
studyGuidanceGroup?.tags?.studyProgramme && studyGuidanceGroup?.tags?.studyProgramme.includes('+')

if (
(populations?.query?.studyRights?.combinedProgramme && variant === 'population') ||
((populations?.query?.studyRights?.combinedProgramme || populations?.query?.showFullStudyPath === 'true') &&
variant === 'population') ||
(studyGuidanceGroupCombinedProgramme && variant === 'studyGuidanceGroupPopulation')
)
) {
columnsByVariant[variant].push('credits.hopsCombinedProg', 'endDateCombinedProg')
}
const baseColumns = ['credits', 'credits.all', 'studentnumber', 'tags', 'updatedAt', 'phoneNumber']
if (!populations?.query?.studyRights?.combinedProgramme) baseColumns.push('option')
const nameColumnsToAdd = namesVisible ? ['email', 'lastname', 'firstname'] : []
Expand Down
3 changes: 3 additions & 0 deletions services/frontend/src/redux/populations.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const getPopulationStatistics = ({
years,
onProgress,
tag,
showFullStudyPath,
}) => {
const route = '/v3/populationstatistics/'
const prefix = 'GET_POPULATION_STATISTICS_'
Expand All @@ -31,6 +32,7 @@ export const getPopulationStatistics = ({
year,
years,
tag,
showFullStudyPath,
}
const params = {
semesters,
Expand Down Expand Up @@ -69,6 +71,7 @@ const populationApi = RTKApi.injectEndpoints({
}),
getProgrammes: builder.query({
query: () => '/v3/populationstatistics/studyprogrammes',
keepUnusedDataFor: 60 * 60,
}),
}),
overrideExisting: false,
Expand Down

0 comments on commit 0bdd010

Please sign in to comment.