Skip to content

Commit 879f665

Browse files
improved code flow
1 parent 0adf4fb commit 879f665

File tree

1 file changed

+13
-38
lines changed

1 file changed

+13
-38
lines changed

src/server/util/pointRecommendCourses.ts

Lines changed: 13 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -149,46 +149,21 @@ function pointRecommendedCourses(courses: CourseRecommendation[], userCoordinate
149149
const points = calculatePointsForCourse(c, userCoordinates, comparisons)
150150

151151

152-
//this code is bad and wont scale for more exceptions...
153-
/*
154-
155-
the goal of these bonus points is to show courses that are spesifically for the user even when the sisu custom tags are missing by rewarding certain types of courses.
156-
157-
158-
*/
152+
// Bonus point tiers (when no other filters active):
153+
// 1. faculty-specific mandatory (RUFARM, RUMATLU, ENLAAK…) → 4×
154+
// 2. generic / KAIKKI → 3×
155+
// 3. numbered (ENG-201, RUO-205…) → 2×
156+
// 4. ERI / challenge → 0× (unless user wants challenge)
157+
const isEriOrChallenge = c.coordinates.challenge === 1 || c.course.courseCodes.some(code => code.includes('ERI'))
158+
const isGeneric = c.course.courseCodes.some(code => code.includes('KAIKKI'))
159+
const isNumbered = c.course.courseCodes.some(code => /\d+$/.test(code))
160+
const isMandatory = c.coordinates.mentoring === 0
159161

160162
let bonusPoints = 0
161-
162-
const isChallengeCourseOrEri = c.coordinates.challenge === 1 || c.course.courseCodes.find((c) => c.includes('ERI'))
163-
164-
const mandatory = c.coordinates.mentoring === 0 ? true : false//it is believed that if course is not a mentoring course it is a mandatory course.
165-
const calculateBonusForMandatory = userCoordinates?.mentoring === undefined | null
166-
if (calculateBonusForMandatory && !isChallengeCourseOrEri){
167-
//lets add some extra points when the course is mandatory course
168-
if(mandatory){
169-
bonusPoints += bonusPoint
170-
}
171-
}
172-
173-
// Ordering: specific (RUFARM) > KAIKKI > numbered (ENG-123) > ERI (challenge)
174-
const isGenericCourse = !!c.course.courseCodes.find((c) => c.includes('KAIKKI'))
175-
const isNumberedCourse = c.course.courseCodes.some((code) => /\d+$/.test(code))
176-
177-
if(!isGenericCourse && mandatory && !isChallengeCourseOrEri){
178-
bonusPoints += bonusPoint // non-generic non-challenge: +1
179-
if(!isNumberedCourse){
180-
bonusPoints += bonusPoint * 2 // specific courses (RUKFARM etc): extra +2
181-
}
182-
}
183-
184-
// KAIKKI (generic) courses rank between specific and numbered courses
185-
if(isGenericCourse && mandatory && !isChallengeCourseOrEri){
186-
bonusPoints += bonusPoint * 2
187-
}
188-
189-
const pickedChallenge = userCoordinates?.challenge === undefined | null
190-
if(!pickedChallenge && isChallengeCourseOrEri){
191-
bonusPoints = 0
163+
if (!isEriOrChallenge) {
164+
if (isMandatory && !isGeneric && !isNumbered) bonusPoints = bonusPoint * 4 // tier 1: faculty-specific
165+
else if (isGeneric) bonusPoints = bonusPoint * 3 // tier 2: KAIKKI
166+
else if (isMandatory) bonusPoints = bonusPoint * 2 // tier 3: numbered
192167
}
193168

194169
return points >= 0 ? {...c, points: points + bonusPoints} : {...c, points}

0 commit comments

Comments
 (0)