@@ -3,6 +3,7 @@ import { uniqueVals } from './misc.ts'
33import type { OrganisationRecommendation } from './organisationCourseRecommmendations.ts'
44import { challegeCourseCodes , codesInOrganisations , courseHasAnyOfCodes , courseHasAnyRealisationCodeUrn , courseHasCustomCodeUrn , courseMatches , finmuMentroingCourseCodes , getUserOrganisationRecommendations , languageSpesificCodes , languageToStudy , mentoringCourseCodes , readOrganisationRecommendationData } from './organisationCourseRecommmendations.ts'
55import { dateObjToPeriod , getStudyPeriod , parseDate , getStudyYear } from './studyPeriods.ts'
6+ import studyPeriods from './studyPeriods.ts'
67import { curcusWithUnitIdOf , curWithIdOf , cuWithCourseCodeOf , organisationWithGroupIdOf } from './dbActions.ts'
78import pointRecommendedCourses from './pointRecommendCourses.ts'
89import { allowedStudyPlaces , collaborationOrganisationNames , collaborationOrganisationCourseNameIncludes , correctValue , incorrectValue , notAnsweredValue , organisationCodeToUrn } from './constants.ts'
@@ -74,6 +75,7 @@ function calculateUserCoordinates(answerData: AnswerData) {
7475 collaboration : commonCoordinateFromAnswerData ( readAnswer ( answerData , 'collaboration' ) , correctValue , incorrectValue , incorrectValue ) ,
7576 studyYear : readAnswer ( answerData , 'study-year' ) ,
7677 studyPeriod : readAsStringArr ( readAnswer ( answerData , 'study-period' ) ) ,
78+ multiPeriod : commonCoordinateFromAnswerData ( readAnswer ( answerData , 'multi-period' ) , correctValue , incorrectValue , null ) ,
7779 }
7880 return userCoordinates
7981}
@@ -207,6 +209,7 @@ async function calculateCourseCoordinates(course: CourseData, userCoordinates: U
207209
208210 const isChallengeCourse = courseMatches ( course , challegeCourseCodes , courseLanguageType )
209211 const isCollaboration = await courseIsCollaboration ( course )
212+ const isMultiPeriod = courseSpansMultiplePeriods ( course )
210213
211214 const courseCoordinates = {
212215 date : course . startDate . getTime ( ) ,
@@ -223,7 +226,8 @@ async function calculateCourseCoordinates(course: CourseData, userCoordinates: U
223226 independent : isIndependent ? correctValue : incorrectValue ,
224227 flexible : hasFlexibleCodeUrn ? correctValue : incorrectValue ,
225228 mooc : hasMoocCodeUrn ? correctValue : incorrectValue ,
226- collaboration : isCollaboration ? correctValue : incorrectValue
229+ collaboration : isCollaboration ? correctValue : incorrectValue ,
230+ multiPeriod : isMultiPeriod ? correctValue : incorrectValue
227231 }
228232
229233
@@ -295,24 +299,33 @@ export async function getRealisationsWithCourseUnitCodes(courseCodeStrings: stri
295299 return courseRealisationsWithCodes
296300}
297301
298- const getPeriodForCourse = ( cur ) => {
299-
300- const studyPeriods = dateObjToPeriod ( cur . startDate )
301-
302- const studyPeriod = studyPeriods [ 0 ]
303- if ( ! studyPeriod ) {
304- dateObjToPeriod ( cur . startDate , true )
302+ const getPeriodForCourse = ( cur ) : Period [ ] | null => {
303+ const courseStart = cur . startDate
304+ const courseEnd = cur . endDate
305+
306+ const overlappingPeriods = studyPeriods . periods . filter ( periodData => {
307+ const periodStart = parseDate ( periodData . start_date )
308+ const periodEnd = parseDate ( periodData . end_date )
309+ return periodStart <= courseEnd && periodEnd >= courseStart
310+ } )
311+
312+ if ( overlappingPeriods . length === 0 ) {
305313 return null
306314 }
315+
316+ const periods : Period [ ] = overlappingPeriods . map ( periodData => ( {
317+ name : periodData . name ,
318+ startDate : parseDate ( periodData . start_date ) ,
319+ endDate : parseDate ( periodData . end_date ) ,
320+ startYear : periodData . start_year ,
321+ endYear : periodData . end_year
322+ } ) )
323+
324+ return periods
325+ }
307326
308- const period : Period = {
309- name : studyPeriod . name ,
310- startDate : parseDate ( studyPeriod . start_date ) ,
311- endDate : parseDate ( studyPeriod . end_date ) ,
312- startYear : studyPeriod . start_year ,
313- endYear : studyPeriod . end_year
314- }
315- return period
327+ function courseSpansMultiplePeriods ( course : CourseData ) : boolean {
328+ return ( course . period ?. length ?? 0 ) > 1
316329}
317330
318331const getPeriodsWantedByUser = ( periodsArg ) => {
0 commit comments