Skip to content

Commit d31e8bd

Browse files
exam filter
1 parent 6659e9f commit d31e8bd

File tree

8 files changed

+46
-14
lines changed

8 files changed

+46
-14
lines changed

src/client/V2/filterContext.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ interface FilterContextType {
6868
setMultiPeriod: (s: string) => void
6969
strictFilters: string[]
7070
setStrictFilters: (s: string[]) => void
71+
exam: string
72+
setExam: (s: string) => void
7173
}
7274

7375
export const filterConfigMap = (filters: any) => new Map([
@@ -172,6 +174,11 @@ export const filterConfigMap = (filters: any) => new Map([
172174
setState: filters.setMultiPeriod,
173175
superToggle: false
174176
}],
177+
['exam', {
178+
state: filters.exam,
179+
setState: filters.setExam,
180+
superToggle: false
181+
}],
175182
])
176183

177184
// Map coordinate keys to filter IDs for recommendation reasons
@@ -269,7 +276,8 @@ export const FilterContextProvider = ({ children }: { children: ReactNode }) =>
269276
const [mooc, setMooc] = useState('')
270277
const [collaboration, setCollaboration] = useState('')
271278
const [multiPeriod, setMultiPeriod] = useState('')
272-
const [strictFilters, setStrictFilters] = useState<string[]>(['collaboration'])
279+
const [exam, setExam] = useState('0')
280+
const [strictFilters, setStrictFilters] = useState<string[]>(['collaboration', 'exam'])
273281

274282

275283
const [uiVariant, setUiVariant] = useState([
@@ -355,6 +363,7 @@ export const FilterContextProvider = ({ children }: { children: ReactNode }) =>
355363
'mooc': getTrueFilterValue(mooc, 'mooc'),
356364
'collaboration': getTrueFilterValue(collaboration, 'collaboration'),
357365
'multi-period': getTrueFilterValue(multiPeriod, 'multi-period'),
366+
'exam': getTrueFilterValue(exam, 'exam'),
358367
}
359368

360369
const answerData = Object.fromEntries(
@@ -398,6 +407,7 @@ export const FilterContextProvider = ({ children }: { children: ReactNode }) =>
398407
mooc,
399408
collaboration,
400409
multiPeriod,
410+
exam,
401411
strictFilters,
402412
])
403413

@@ -459,6 +469,8 @@ export const FilterContextProvider = ({ children }: { children: ReactNode }) =>
459469
setCollaboration,
460470
multiPeriod,
461471
setMultiPeriod,
472+
exam,
473+
setExam,
462474
strictFilters,
463475
setStrictFilters,
464476
}}

src/client/hooks/useQuestions.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,22 @@ const useQuestions = () => {
563563
},
564564
],
565565
},
566+
{
567+
number: '',
568+
mandatory: false,
569+
id: 'exam',
570+
shortName: t('filterShortName:Exam'),
571+
effects: 'none',
572+
type: 'multi',
573+
variants: [
574+
{
575+
name: 'default',
576+
question: t('form:examQuestion'),
577+
skipped: false,
578+
options: generateGeneralYesNoOptions(true),
579+
},
580+
],
581+
},
566582
]
567583
return(questions)
568584

src/client/locales/en.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export default {
2727
'moocQuestion': 'Do you want to search for MOOCs (Massive Open Online Courses)?',
2828
'collaborationQuestion': 'Show collaboration partner courses',
2929
'multiPeriodQuestion': 'Search for courses that span multiple periods',
30+
'examQuestion': 'Do you want to see courses with an exam as the completion method?',
3031
'finnish': 'finnish',
3132
'swedish': 'swedish',
3233
'english': 'english',
@@ -147,5 +148,6 @@ export default {
147148
'MOOC': 'MOOC',
148149
'Yhteistyo': 'Collaboration',
149150
'Kurssinpituus': 'Course Duration',
151+
'Exam': 'Exam',
150152
}
151153
}

src/client/locales/fi.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export default {
2727
'moocQuestion': 'Haluatko etsiä MOOC-kursseja (Massive Open Online Courses)?',
2828
'collaborationQuestion': 'Näytä yhteistyökumppanien kursseja',
2929
'multiPeriodQuestion': 'Hae kursseja jotka kestävät usean periodin ajan',
30+
'examQuestion': 'Haluatko nähdä kursseilla tentti suoritustapana?',
3031
'finnish': 'suomi',
3132
'swedish': 'ruotsi',
3233
'english': 'englanti',
@@ -147,5 +148,6 @@ export default {
147148
'MOOC': 'MOOC',
148149
'Yhteistyo': 'Yhteistyö',
149150
'Kurssinpituus': 'Kurssin pituus',
151+
'Exam': 'Tentti',
150152
}
151153
}

src/client/locales/sv.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ export default {
2525
'independentQuestion': 'Jag vill arbeta självständigt eller autonomt.',
2626
'flexibleQuestion': 'Jag vill ta en kurs med ett flexibelt schema.',
2727
'moocQuestion': 'Vill du söka efter MOOCs (Massive Open Online Courses)?',
28-
'collaborationQuestion': 'Visa samarbetspartnerkurser', 'multiPeriodQuestion': 'Sök kurser som sträcker sig över flera perioder', 'finnish': 'finska',
28+
'collaborationQuestion': 'Visa samarbetspartnerkurser', 'multiPeriodQuestion': 'Sök kurser som sträcker sig över flera perioder',
29+
'examQuestion': 'Vill du se kurser med tentamen som slutförandemetod?', 'finnish': 'finska',
2930
'swedish': 'svenska',
3031
'english': 'engelska',
3132
'yes': 'Ja',
@@ -141,5 +142,6 @@ export default {
141142
'MOOC': 'MOOC',
142143
'Yhteistyo': 'Samarbete',
143144
'Kurssinpituus': 'Kurslängd',
145+
'Exam': 'Tentamen',
144146
}
145147
}

src/common/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export type CourseCoordinates = {
7070
studyYear?: string | null;
7171
studyPeriod?: string[] | null;
7272
multiPeriod?: number | null;
73+
exam?: number | null;
7374
}
7475

7576
export type UserCoordinates = CourseCoordinates;
@@ -156,6 +157,7 @@ export type AnswerData = {
156157
'primary-language': string;
157158
'primary-language-specification': string;
158159
'multi-period': string;
160+
'exam': string;
159161
};
160162

161163

src/server/util/pointRecommendCourses.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,6 @@ function calculatePointsForCourse (c: CourseRecommendation, userCoordinates: Use
5858
//this is different from the distance based sorting where two opposing coordinates seem to counter each other.
5959
//In this point based one a difference does not punish as much as it gets 'ignored'
6060
function pointRecommendedCourses(courses: CourseRecommendation[], userCoordinates: UserCoordinates, strictFields: any): CourseRecommendation[]{
61-
//we want to ignore all exams except those that are replacement
62-
const noExams = courses.filter(c =>
63-
{
64-
const isExam = c.course.name.fi?.toLowerCase().includes('tentti')
65-
const isReplacementCourse = c.coordinates.replacement > 0
66-
if(isReplacementCourse || !isExam){
67-
return true
68-
}
69-
return false
70-
})
7161

7262
const comparisons = [
7363
{
@@ -149,9 +139,13 @@ function pointRecommendedCourses(courses: CourseRecommendation[], userCoordinate
149139
field: 'multiPeriod',
150140
filterOnFail: strictFields.includes('multi-period'),
151141
},
142+
{
143+
field: 'exam',
144+
filterOnFail: strictFields.includes('exam'),
145+
},
152146
]
153147

154-
const recommendationWithPoints = noExams.map((c) => {
148+
const recommendationWithPoints = courses.map((c) => {
155149
const points = calculatePointsForCourse(c, userCoordinates, comparisons)
156150

157151

src/server/util/recommender.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ function calculateUserCoordinates(answerData: AnswerData) {
7878
studyYear: readAnswer(answerData, 'study-year'),
7979
studyPeriod: readAsStringArr(readAnswer(answerData, 'study-period')),
8080
multiPeriod: commonCoordinateFromAnswerData(readAnswer(answerData, 'multi-period'), correctValue, incorrectValue, null),
81+
exam: commonCoordinateFromAnswerData(readAnswer(answerData, 'exam'), correctValue, incorrectValue, null),
8182
}
8283
return userCoordinates
8384
}
@@ -227,7 +228,8 @@ async function calculateCourseCoordinates(course: CourseData, userCoordinates: U
227228
flexible: hasFlexibleCodeUrn ? correctValue : incorrectValue,
228229
mooc: hasMoocCodeUrn ? correctValue : incorrectValue,
229230
collaboration: isCollaboration ? correctValue : incorrectValue,
230-
multiPeriod: isMultiPeriod ? correctValue : incorrectValue
231+
multiPeriod: isMultiPeriod ? correctValue : incorrectValue,
232+
exam: course.name.fi?.toLowerCase().includes('tentti') ? correctValue : incorrectValue,
231233
}
232234

233235

0 commit comments

Comments
 (0)