snutt
snutt copied to clipboard
실제시간 migration
귀찮아서 그냥 몽고 쿼리로 넣어버림
let cursor = db.lectures.find();
while (cursor.hasNext()) {
let document = cursor.next()
const class_time_json = document["class_time_json"].map((json, idx) => {
let start = json["start"];
let len = json["len"];
let end = start + len
let startHour = Math.floor(start + 8);
let endHour = Math.floor(end + 8)
let isCustom = false
let islen30 = Math.floor(len) !== len
const startTime = startHour === start + 8 ? `${startHour}:00` : `${startHour}:30`
const endTime = endHour === end + 8 ?
(islen30 ? `${endHour - 1}:45` : `${endHour - 1}:50`)
: (islen30 ? `${endHour}:15` : `${endHour}:20`)
return {
...json,
start_time: startTime,
end_time: endTime
}
})
const real_class_time = class_time_json.map((j, idx) => {
return `${"월화수목금토일"[j.day]}(${j.start_time}~${j.end_time})`
}).join("/")
db.lectures.updateOne({_id: document["_id"]}, {
$set: {
class_time_json: class_time_json,
real_class_time: real_class_time
}
})
}
let cursor2 = db.timetables.find().sort({updated_at: -1});
while (cursor2.hasNext()) {
let documentTT = cursor2.next()
let change = documentTT["lecture_list"].map((document, idx) => {
if (document["class_time_json"] !== null && document["class_time_json"].length !== 0) {
const class_time_json = document["class_time_json"].map((json, idx) => {
let start = json["start"];
let len = json["len"];
let end = start + len
let startHour = Math.floor(start + 8);
let endHour = Math.floor(end + 8)
let isCustom = document["course_number"] == null
let islen30 = Math.floor(len) !== len
const startTime = startHour === start + 8 ? `${startHour}:00` : `${startHour}:30`
const endTime = isCustom ? (endHour === end + 8 ? `${endHour}:00` : `${endHour}:30`) : (endHour === end + 8 ?
(islen30 ? `${endHour - 1}:45` : `${endHour - 1}:50`)
: (islen30 ? `${endHour}:15` : `${endHour}:20`))
return {
...json,
start_time: startTime,
end_time: endTime
}
})
const real_time = class_time_json.map((j, idx) => {
return `${"월화수목금토일"[j.day]}(${j.start_time}~${j.end_time})`
}).join("/")
return {
...document,
class_time_json: class_time_json,
real_class_time: real_time
}
} else return document
})
db.timetables.updateOne({_id: documentTT["_id"]}, {
$set: {
lecture_list: change,
}
})
}