import winston = require ( 'winston' ) ; import ExcelSheetWrapper from '@app/batch/coursebook/excel/model/ExcelSheetWrapper' ; import SugangSnuLecture from './model/SugangSnuLecture' ; import SugangSnuLectureCategoryService = require ( '@app/batch/coursebook/sugangsnu/SugangSnuLectureCategoryService' ) ; import TimePlaceUtil = require ( '@app/core/timetable/util/TimePlaceUtil' ) ; import RefLecture from '@app/core/lecture/model/RefLecture' ; let logger = winston . loggers . get ( 'default' ) ; export function getRefLectureListFromExcelSheet ( sheet , year , semester , lectureCategory ) { let ret = [ ] ; let rowsize = sheet . getRowSize ( ) ; for ( let i = 3 ; i < rowsize ; i ++ ) { let line = getSugangSnuLectureFromSheetRow ( sheet , i ) ; let lecture = getRefLectureFromSugangSnuLecture ( year , semester , lectureCategory , line ) ; if ( lecture !== null ) { ret . push ( lecture ) ; } } return ret ; } function getRefLectureFromSugangSnuLecture ( year , semester , lectureCategory , sugangSnuLecture ) { if ( sugangSnuLecture . classification == "교양" && lectureCategory == null ) { return null ; } let department = sugangSnuLecture . department ; if ( department . length == 0 ) { department = sugangSnuLecture . college ; } department = department . replace ( "null" , "" ) ; let academic_year = sugangSnuLecture . academic_year ; if ( sugangSnuLecture . academic_course != "학사" ) { academic_year = sugangSnuLecture . academic_course ; } if ( academic_year == "0" ) { academic_year = "" ; } let course_title = sugangSnuLecture . course_title ; if ( sugangSnuLecture . course_subtitle . length > 0 ) course_title += " (" + sugangSnuLecture . course_subtitle + ")" ; let credit = parseInt ( sugangSnuLecture . credit ) ; let quota = parseInt ( sugangSnuLecture . quota . split ( " " ) [ 0 ] ) ; let parsedClassTime = parseClassTime ( sugangSnuLecture . class_time ) ; let timeJson = TimePlaceUtil . timeAndPlaceToJson ( parsedClassTime , sugangSnuLecture . location ) ; if ( timeJson === null ) { logger . warn ( "timeJson not found from (" + sugangSnuLecture . class_time + ", " + sugangSnuLecture . location + ")" ) ; } for ( let j = 0 ; j < timeJson . length ; j ++ ) { var t_end = timeJson [ j ] . start + timeJson [ j ] . len ; if ( t_end > 15 ) { logger . warn ( "(" + sugangSnuLecture . course_number + ", " + sugangSnuLecture . lecture_number + ", " + sugangSnuLecture . course_number + ") ends at " + t_end ) ; } } let class_time_mask = TimePlaceUtil . timeJsonToMask ( timeJson ) ; let category = "" ; if ( lectureCategory ) category = SugangSnuLectureCategoryService . getLectureCategoryString ( lectureCategory ) ; let classification = sugangSnuLecture . classification ; let course_number = sugangSnuLecture . course_number ; let lecture_number = sugangSnuLecture . lecture_number ; let instructor = sugangSnuLecture . instructor ; let remark = sugangSnuLecture . remark ; return { year : year , semester : semester , classification : classification , department : department , academic_year : academic_year , course_number : course_number , lecture_number : lecture_number , course_title : course_title , credit : credit , class_time : parsedClassTime , class_time_json : timeJson , class_time_mask : class_time_mask , instructor : instructor , quota : quota , remark : remark , category : category } ; } param times return function parseClassTime ( times ) { const classTimeRegEx = /(월|화|수|목|금|토|일)\((\d{2}):(\d{2})~(\d{2}):(\d{2})\)/ ; let classTimes = times . split ( '/' ) ; let ret = [ ] ; for ( let classTime of classTimes ) { if ( classTime . length == 0 ) continue ; let error = false ; let matchResult = classTimeRegEx . exec ( classTime ) ; if ( matchResult === null ) { logger . error ( "Parse error: " + classTime ) ; continue ; } let weekOfDay = matchResult [ 1 ] ; let startHour = parseInt ( matchResult [ 2 ] ) - 8 ; let startMinute = parseInt ( matchResult [ 3 ] ) ; let endHour = parseInt ( matchResult [ 4 ] ) - 8 ; let endMinute = parseInt ( matchResult [ 5 ] ) ; if ( startMinute == 30 ) startHour += 0.5 ; else if ( startMinute != 0 ) error = true ; if ( endMinute == 15 || endMinute == 20 ) endHour += 0.5 ; else if ( endMinute == 45 || endMinute == 50 ) endHour += 1 ; else error = true ; if ( error ) { logger . error ( "Parse error: " + classTime ) ; continue ; } ret . push ( weekOfDay + "(" + String ( startHour ) + "-" + String ( endHour - startHour ) + ")" ) ; } return ret . join ( '/' ) ; } function getSugangSnuLectureFromSheetRow ( sheetWrap , rowIndex ) { return { classification : sheetWrap . getCell ( rowIndex , 0 ) , college : sheetWrap . getCell ( rowIndex , 1 ) , department : sheetWrap . getCell ( rowIndex , 2 ) , academic_course : sheetWrap . getCell ( rowIndex , 3 ) , academic_year : sheetWrap . getCell ( rowIndex , 4 ) , course_number : sheetWrap . getCell ( rowIndex , 5 ) , lecture_number : sheetWrap . getCell ( rowIndex , 6 ) , course_title : sheetWrap . getCell ( rowIndex , 7 ) , course_subtitle : sheetWrap . getCell ( rowIndex , 8 ) , credit : sheetWrap . getCell ( rowIndex , 9 ) , num_lecture : sheetWrap . getCell ( rowIndex , 10 ) , num_practice : sheetWrap . getCell ( rowIndex , 11 ) , class_time : sheetWrap . getCell ( rowIndex , 12 ) , class_type : sheetWrap . getCell ( rowIndex , 13 ) , location : sheetWrap . getCell ( rowIndex , 14 ) , instructor : sheetWrap . getCell ( rowIndex , 15 ) , quota : sheetWrap . getCell ( rowIndex , 16 ) , enrollment : sheetWrap . getCell ( rowIndex , 17 ) , remark : sheetWrap . getCell ( rowIndex , 18 ) , lecture_language : sheetWrap . getCell ( rowIndex , 19 ) , lecture_status : sheetWrap . getCell ( rowIndex , 20 ) , } ; }