Skip to content

Commit

Permalink
[Study programmes] Fix irrelevant programmes data being saved to Redis
Browse files Browse the repository at this point in the history
  • Loading branch information
valtterikantanen committed Sep 13, 2024
1 parent c4daf60 commit 86430e1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
17 changes: 8 additions & 9 deletions services/backend/src/services/analyticsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ import moment from 'moment'
import { facultyCodes, ignoredFacultyCodes } from '../config/organizationConstants'
import { Graduated, SpecialGroups, YearType } from '../types'
import { redisClient } from './redis'
import { isRelevantProgramme } from './studyProgramme/studyProgrammeHelpers'

// Only new bachelor, masters and doctoral programmes get their data updated in redis every night, use redis for them
const isUpdatedNewProgramme = (code: string) => code.includes('KH') || code.includes('MH') || /^(T)[0-9]{6}$/.test(code)
const filteredFacultyCodes = facultyCodes.filter(item => !ignoredFacultyCodes.includes(item))
const isFaculty = (code: string) => filteredFacultyCodes.includes(code)

Expand All @@ -28,7 +27,7 @@ export const getBasicStats = async (
yearType: YearType,
specialGroups: SpecialGroups
) => {
if (!isUpdatedNewProgramme(id)) {
if (!isRelevantProgramme(id)) {
return null
}
const searchkey = combinedProgramme ? `${id}-${combinedProgramme}` : id
Expand All @@ -48,7 +47,7 @@ export const setBasicStats = async (data, yearType: YearType, specialGroups: Spe
status: 'DONE',
lastUpdated: moment().format(),
}
if (!isUpdatedNewProgramme(id)) {
if (!isRelevantProgramme(id)) {
return dataToRedis
}
const setOperationStatus = await redisClient.setAsync(redisKey, JSON.stringify(dataToRedis))
Expand Down Expand Up @@ -83,7 +82,7 @@ export const setCreditStats = async (data, isAcademicYear: boolean, specialGroup
status: 'DONE',
lastUpdated: moment().format(),
}
if (!isUpdatedNewProgramme(data.id) && !isFaculty(data.id)) {
if (!isRelevantProgramme(id) && !isFaculty(id)) {
return dataToRedis
}
const setOperationStatus = await redisClient.setAsync(redisKey, JSON.stringify(dataToRedis))
Expand All @@ -99,7 +98,7 @@ export const getGraduationStats = async (
yearType: YearType,
specialGroups: SpecialGroups
) => {
if (!isUpdatedNewProgramme(id)) {
if (!isRelevantProgramme(id)) {
return null
}
const searchkey = combinedProgramme ? `${id}-${combinedProgramme}` : id
Expand All @@ -119,7 +118,7 @@ export const setGraduationStats = async (data, yearType: YearType, specialGroups
status: 'DONE',
lastUpdated: moment().format(),
}
if (!isUpdatedNewProgramme(id)) {
if (!isRelevantProgramme(id)) {
return dataToRedis
}
const setOperationStatus = await redisClient.setAsync(redisKey, JSON.stringify(dataToRedis))
Expand All @@ -135,7 +134,7 @@ export const getStudytrackStats = async (
graduated: Graduated,
specialGroups: SpecialGroups
) => {
if (!isUpdatedNewProgramme(id)) {
if (!isRelevantProgramme(id)) {
return null
}
const searchkey = combinedProgramme ? `${id}-${combinedProgramme}` : id
Expand All @@ -155,7 +154,7 @@ export const setStudytrackStats = async (data, graduated: Graduated, specialGrou
status: 'DONE',
lastUpdated: moment().format(),
}
if (!isUpdatedNewProgramme(id)) {
if (!isRelevantProgramme(id)) {
return dataToRedis
}
const setOperationStatus = await redisClient.setAsync(redisKey, JSON.stringify(dataToRedis))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,7 @@ export const getGoal = (programme?: string) => {
return 48 // unknown, likely old doctor or licentiate
}

export const isRelevantProgramme = (code: string) => {
return (
(code.includes('KH') && !code.startsWith('2_KH') && !code.endsWith('_2')) ||
(code.includes('MH') && !code.startsWith('2_MH') && !code.endsWith('_2')) ||
/^(T)[0-9]{6}$/.test(code)
)
}
export const isRelevantProgramme = (code: string) => /^(KH|MH)\d{2}_\d{3}$/.test(code) || /^T\d{6}$/.test(code)

export const getStudyRightElementsWithPhase = (studyRight: InferAttributes<SISStudyRight>, phase: Phase) => {
return orderBy(
Expand Down

0 comments on commit 86430e1

Please sign in to comment.