Skip to content

Commit

Permalink
[Faculties] Replace getProgrammes with getDegreeProgrammesOfFaculty
Browse files Browse the repository at this point in the history
  • Loading branch information
valtterikantanen committed Sep 13, 2024
1 parent 2ae0d23 commit 66341a1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 55 deletions.
27 changes: 14 additions & 13 deletions services/backend/src/services/faculty/facultyCredits.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
import { Name } from '../../types'
import { getCreditsProduced } from '../providerCredits'
import { isRelevantProgramme } from '../studyProgramme/studyProgrammeHelpers'
import { getProgrammes } from './facultyService'
import { getDegreeProgrammesOfFaculty } from './faculty'

/**
* Returns credits produced by the programmes of the faculty but
* also the credits where the provider is the faculty itself
*/
export const getFacultyCredits = async (facultyCode: string, isAcademicYear: boolean) => {
const allProgrammes = (await getProgrammes(facultyCode)).data
const programmes = allProgrammes.filter(({ code }) => isRelevantProgramme(code))
const programmes = (await getDegreeProgrammesOfFaculty(facultyCode, true)).filter(({ code }) =>
isRelevantProgramme(code)
)
const facultyCredits = await getCreditsProduced(facultyCode, isAcademicYear)

const stats = {
[facultyCode]: facultyCredits,
codes: [facultyCode],
programmeNames: {},
programmeNames: {} as Record<string, { code: string } & Name>,
ids: [facultyCode],
}

for (const programme of programmes) {
const programmeCode = programme.code
const programmeCredits = await getCreditsProduced(programmeCode, isAcademicYear)
stats[programme.progId] = programmeCredits
stats.codes.push(programmeCode)
stats.ids.push(programme.progId)
stats.programmeNames[programme.progId] = {
code: programmeCode,
...programmes.find(programme => programme.code === programmeCode).name,
for (const { code, progId, name } of programmes) {
const programmeCredits = await getCreditsProduced(code, isAcademicYear)
stats[progId] = programmeCredits
stats.codes.push(code)
stats.ids.push(progId)
stats.programmeNames[progId] = {
code,
...name,
}
}

Expand Down
39 changes: 0 additions & 39 deletions services/backend/src/services/faculty/facultyService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@ import moment from 'moment'

import { DegreeProgrammeType, Graduated, Name, ProgrammeFilter, SpecialGroups, YearType } from '../../types'
import { redisClient } from '../redis'
import { getDegreeProgrammesOfFaculty } from './faculty'
import { FacultyProgressData } from './facultyStudentProgress'

const createRedisKeyForFacultyProgrammes = (id: string, programmeFilter: ProgrammeFilter) => {
return `FACULTY_PROGRAMMES_${id}_${programmeFilter}`
}
const createRedisKeyForBasicStats = (
id: string,
yearType: YearType,
Expand Down Expand Up @@ -48,41 +44,6 @@ const removeGraduationTimes = (data: GraduationData) => {
)
}

export const setFacultyProgrammes = async (id: string, data, programmeFilter: ProgrammeFilter) => {
const redisKey = createRedisKeyForFacultyProgrammes(id, programmeFilter)
const dataToRedis = {
data,
status: 'DONE',
lastUpdated: moment().format(),
}
const setOperationStatus = await redisClient.setAsync(redisKey, JSON.stringify(dataToRedis))
if (setOperationStatus !== 'OK') {
return null
}
return dataToRedis
}

const getFacultyProgrammesFromRedis = async (id: string, programmeFilter: ProgrammeFilter) => {
const redisKey = createRedisKeyForFacultyProgrammes(id, programmeFilter)
const dataFromRedis = await redisClient.getAsync(redisKey)
if (!dataFromRedis) {
return null
}
return JSON.parse(dataFromRedis)
}

export const getProgrammes = async (code: string, programmeFilter: ProgrammeFilter = 'NEW_STUDY_PROGRAMMES') => {
const programmes = await getFacultyProgrammesFromRedis(code, programmeFilter)
if (programmes) {
return programmes
}
let updatedProgrammes: any = await getDegreeProgrammesOfFaculty(code, programmeFilter === 'NEW_STUDY_PROGRAMMES')
if (updatedProgrammes) {
updatedProgrammes = await setFacultyProgrammes(code, updatedProgrammes, programmeFilter)
}
return updatedProgrammes
}

type GraduationInfo = {
graphStats: {
name: 'Bachelors' | 'Masters' | 'Doctors' | 'Others'
Expand Down
4 changes: 1 addition & 3 deletions services/backend/src/services/faculty/facultyUpdates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { combineFacultyBasics } from './facultyBasics'
import { countGraduationTimes } from './facultyGraduationTimes'
import {
setBasicStats,
setFacultyProgrammes,
setFacultyProgressStats,
setFacultyStudentStats,
setGraduationStats,
Expand Down Expand Up @@ -63,15 +62,14 @@ export const updateFacultyOverview = async (facultyCode: string, statsType: Stat

export const updateFacultyProgressOverview = async (facultyCode: string) => {
const onlyNew = await getDegreeProgrammesOfFaculty(facultyCode, true)
const newProgrammes = await setFacultyProgrammes(facultyCode, onlyNew, 'NEW_STUDY_PROGRAMMES')

for (const graduated of graduatedOptions) {
for (const specialGroups of specialGroupOptions) {
const updateFacultyStudentStats = await combineFacultyStudents(facultyCode, onlyNew, specialGroups, graduated)
await setFacultyStudentStats(updateFacultyStudentStats, specialGroups, graduated)
const updateFacultyProgressStats = await combineFacultyStudentProgress(
facultyCode,
newProgrammes?.data,
onlyNew,
specialGroups,
graduated
)
Expand Down

0 comments on commit 66341a1

Please sign in to comment.