Skip to content

Commit

Permalink
time_json에 실제 시간 추가 (#231)
Browse files Browse the repository at this point in the history
* time_json에 실제 시간 추가

* 테스트 코드 수정 & 정렬

* 테스트 코드 수정 & 정렬

* 테스트 코드 수정
  • Loading branch information
Hank-Choi authored Nov 9, 2022
1 parent f337ee4 commit e3d5f2a
Show file tree
Hide file tree
Showing 6 changed files with 347 additions and 276 deletions.
3 changes: 2 additions & 1 deletion src/batch/coursebook/sugangsnu/SugangSnuLectureService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ function getRefLectureFromSugangSnuLecture(year: number, semester: number, lectu
let quota = parseInt(sugangSnuLecture.quota.split(" ")[0]);

let parsedClassTime = parseClassTime(sugangSnuLecture.class_time);
let timeJson = TimePlaceUtil.timeAndPlaceToJson(parsedClassTime, sugangSnuLecture.location);
const realClassTime = sugangSnuLecture.class_time
let timeJson = TimePlaceUtil.timeAndPlaceToJson(parsedClassTime, sugangSnuLecture.location, realClassTime);
if (timeJson === null) {
logger.warn("timeJson not found from (" + sugangSnuLecture.class_time + ", " + sugangSnuLecture.location + ")");
}
Expand Down
2 changes: 2 additions & 0 deletions src/core/timetable/model/TimePlace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ export default interface TimePlace {
day: number;
start: number;
len: number;
start_time: string;
end_time: string;
place: string;
};
16 changes: 12 additions & 4 deletions src/core/timetable/util/TimePlaceUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import InvalidLectureTimeJsonError from '../../lecture/error/InvalidLectureTimeJ

var logger = winston.loggers.get('default');

export function timeAndPlaceToJson(timesString: string, locationsString: string): TimePlace[] {
export function timeAndPlaceToJson(timesString: string, locationsString: string, realTimesString: string): TimePlace[] {
try {
// 시간 정보가 없다면 빈 정보를 반환한다.
if (timesString === '') {
Expand All @@ -15,6 +15,7 @@ export function timeAndPlaceToJson(timesString: string, locationsString: string)

let locations = locationsString.split('/');
let times = timesString.split('/');
let realTimes = realTimesString.split('/')

// 만약 강의실이 하나 뿐이거나 없다면, 시간에 맞춰서 강의 장소를 추가해준다.
if (locations.length != times.length) {
Expand All @@ -31,15 +32,20 @@ export function timeAndPlaceToJson(timesString: string, locationsString: string)
}
}

let classes = times.map((time, idx) => {
let classes = times.map((time, idx) => {
let timeSplitted = time.split('-');
const parsedRealTimes = realTimes[idx].match(/\d{2}:\d{2}/g)
const startTime = parsedRealTimes[0]
const endTime = parsedRealTimes[1]
let day = ['월', '화', '수', '목', '금', '토', '일'].indexOf(timeSplitted[0].charAt(0));
let start = Number(timeSplitted[0].slice(2));
let len = Number(timeSplitted[1].slice(0, -1));
let place = locations[idx];
return {
day,
start,
start_time: startTime,
end_time: endTime,
len,
place
};
Expand All @@ -63,11 +69,13 @@ export function timeAndPlaceToJson(timesString: string, locationsString: string)

// Merge same time with different location
// Merge continuous time with same location
// TODO: 연속된 강의 머지기능 유지 논의
for (let i = 1; i < classes.length; i++) {
let prev = classes[i-1];
let curr = classes[i];
if (prev.day == curr.day && prev.place == curr.place && curr.start == (prev.start + prev.len)) {
prev.len += curr.len;
prev.end_time = curr.end_time
classes.splice(i--, 1);
} else if (prev.day == curr.day && prev.start == curr.start && prev.len == curr.len) {
prev.place += '/' + curr.place;
Expand All @@ -77,7 +85,7 @@ export function timeAndPlaceToJson(timesString: string, locationsString: string)
return classes;
} catch (err) {
logger.error(err);
logger.error("Failed to parse timePlace (times: " + timesString + ", locations: " + locationsString + ")");
logger.error("Failed to parse timePlace (times: " + timesString + ", locations: " + locationsString + ", realTime: " + realTimesString + ")");
return [];
}
}
Expand Down Expand Up @@ -130,4 +138,4 @@ export function timeJsonToMask(timeJson:Array<TimePlace>, duplicateCheck?:boolea
timeMasks.push(mask);
}
return timeMasks;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe("SugangSnuLectureServiceIntegrationTest", function() {
course_title: '그린리더십 인턴십',
credit: 3,
class_time: '금(6-3)',
class_time_json: [ { day: 4, start: 6, len: 3, place: '220-202' } ],
class_time_json: [ { day: 4, start: 6, len: 3, place: '220-202', start_time: '14:00', end_time: '16:50' } ],
class_time_mask: [ 0, 0, 0, 0, 258048, 0, 0 ],
instructor: '류재명',
quota: 40,
Expand Down
Loading

0 comments on commit e3d5f2a

Please sign in to comment.