Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

time_json에 실제 시간 추가 #231

Merged
merged 4 commits into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

뒤에서 변경 없으면 const 쓰면 어떨까요? + 강박적으로 지킬 필욘 없지만 보여서 언급하자면 위 라인에서 마지막 ; 찍어줘도 좋을 듯 합니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거 그냥 기존에 있던 코드는 냅뒀어요ㅋㅋ
다 const로 바꿔버릴까 하다가 그냥 한도 끝도 없을 것 같아서..

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) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 친구도 혹시 const 안 되나여?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

마찬가쥐

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: 연속된 강의 머지기능 유지 논의
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이건 어떤 의미에요? 관련 쓰레드 던져놔주셔도 좋음

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

한 강의가 같은 강의실에서 연속된 시간에 존재하면 머지하는 로직이 있어요
예를 들어 자구? 301 101호에서 13시부터 14:50까지 강의 15시부터 15:50까지 실습이면 그냥 13시~15:50 자구 이런식으로 뜨거든요
그거 실제시간으로 바꿀 때 나눌 필요가 있을까? 하는 얘기입니다

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' } ],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 PR 에 어울리는 얘기는 아니지만, KST 기준으로 DB 에 저장하는 거 당연히 괜찮은 선택이겠죠?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넹 스트링으로 저장해서 일단은

class_time_mask: [ 0, 0, 0, 0, 258048, 0, 0 ],
instructor: '류재명',
quota: 40,
Expand Down
Loading