import { CourseScoreInfo } from '@/store/types' ; import { SemesterScoreRecord } from '@/plugins/score/types' ; import { Num } from './util' ; export const convertSemesterNumberToName = ( semesterNumber ) : string => { const r = semesterNumber . match ( /(\d+)-(\d+)-(\d)/ ) ; if ( ! r ) { return semesterNumber ; } return `${ r [ 1 ] }-${ r [ 2 ] }学年 ${ r [ 3 ] === '1' ? '秋' : '春' }季学期` ; } ; export const convertSemesterNameToNumber = ( semesterName ) : string => { const r = semesterName . match ( /^(\d+)-(\d+)学年\s(.)季学期$/ ) ; if ( ! r ) { return semesterName ; } return `${ r [ 1 ] }-${ r [ 2 ] }-${ r [ 3 ] === '秋' ? 1 : 2 }-1` ; } ; export const convertCourseScoreInfoListToScoreRecords = ( list ) : SemesterScoreRecord [ ] => list . sort ( ( a , b ) => { const weights = new Map ( [ [ '必修' , 1000 ] , [ '选修' , 100 ] , [ '任选' , 10 ] , [ '辅修' , 1 ] ] ) ; return ( ( weights . get ( b . coursePropertyName ) || 0 ) + b . credit - ( weights . get ( a . coursePropertyName ) || 0 ) - a . credit ) ; } ) . reduce ( ( acc , cur ) => { const failReason = cur . unpassedReasonExplain ? ( cur . unpassedReasonExplain as string ) : null ; if ( failReason && failReason . includes ( '缓考' ) ) { return acc ; } const currentSemesterRecords = acc . filter ( ( v ) => v . semester === cur . executiveEducationPlanName ) ; const record = { ... cur , selected : false } ; if ( currentSemesterRecords . length ) { currentSemesterRecords [ 0 ] . courses . push ( record ) ; } else { acc . push ( { semester : record . executiveEducationPlanName , courses : [ record ] } ) ; } return acc ; } , [ ] as SemesterScoreRecord [ ] ) . filter ( ( v ) => v . courses && v . courses . length ) . map ( ( { semester , courses } ) => ( { semester , courses : courses . filter ( ( { courseName , courseNumber , courseSequenceNumber , examTime } ) => ! courses . some ( ( v ) => v . courseName === courseName && v . courseNumber === courseNumber && v . courseSequenceNumber === courseSequenceNumber && Num ( v . examTime ) > Num ( examTime ) ) ) } ) ) . sort ( ( a , b ) => { const getWeightSum = ( { semester } ) : number => { const r = semester . match ( /^(\d+)-(\d+)学年\s(.)季学期$/ ) ; return r ? Num ( r [ 1 ] ) + Num ( r [ 2 ] ) + ( r [ 3 ] === '秋' ? 0 : 1 ) : 0 ; } ; return getWeightSum ( b ) - getWeightSum ( a ) ; } ) ;