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

실제시간 migration #227

Open
Hank-Choi opened this issue Oct 10, 2022 · 0 comments
Open

실제시간 migration #227

Hank-Choi opened this issue Oct 10, 2022 · 0 comments

Comments

@Hank-Choi
Copy link
Contributor

Hank-Choi commented Oct 10, 2022

귀찮아서 그냥 몽고 쿼리로 넣어버림

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,
        }
    })
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant