Skip to content

Commit

Permalink
Merge pull request #27 from EmTanIT/tanBE
Browse files Browse the repository at this point in the history
Finish 75% automatic
  • Loading branch information
bentran1vn committed Oct 4, 2023
2 parents 64d05cd + 1738020 commit 04618e7
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 2,244 deletions.
99 changes: 69 additions & 30 deletions routes/examSlot.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import ExamPhase from '../models/ExamPhase.js'
import TimeSlot from '../models/TimeSlot.js'
import ExamSlot from '../models/ExamSlot.js'
import Course from '../models/Course.js'
import SubInSlot from '../models/SubInSlot.js'
import fs from 'fs'

const router = express.Router()
Expand Down Expand Up @@ -73,24 +74,26 @@ router.get('/', async (req, res) => {
]
}
)
//Ensuring the order of Examphase

//Đảm bảo thứ tự của ExamPhase

const course = await Course.findAll()
// console.log(course);

const slotList = await TimeSlot.findAll()
console.log(slotList.length);
// console.log(slotList.length);

for (const key in examPhaseList) {

let dataT = "----------------------"
fs.appendFileSync("test.txt", dataT + "\n");
console.log("----------------------");
// let dataT1 = "----------------------"
// fs.appendFileSync("test1.txt", dataT1 + "\n");
// console.log("----------------------");

const startDay = new Date(examPhaseList[key].startDay)
const endDay = new Date(examPhaseList[key].endDay)
const diffInMs = Math.abs(endDay - startDay);
const dayLength = diffInMs / (1000 * 60 * 60 * 24)
//get the Different in a Examphase
//Lấy ra khoảng thời gian giữa 2 ngày start và end của 1 examPhase

let dayList = []

Expand All @@ -100,53 +103,89 @@ router.get('/', async (req, res) => {
day.setDate(startDay.getDate() + i);
}
dayList.push(day)

}
}//Add day vào danh sách dayList của 1 examPhase

let roomSlot = 0
let dayCount = 0
let slotCount = 0

for (let i = 0; i < course.length; i++) {
let examSlot = await ExamSlot.create({
ePId: examPhaseList[key].id,
day: dayList[0],
timeSlotId: slotList[0].id
})//Khởi tạo ExamSlot mặc định

for (let i = 0; i < course.length; i++) { //Duyệt danh sách Môn Thi

// let msg = "New Course"
// fs.appendFileSync("test.txt", msg + "\n");

let daySlot = dayList[dayCount]
let slot = slotList[slotCount].id

if (roomSlot > process.env.NUMBER_OF_ROOM_IN_FLOOR * process.env.NUMBER_OF_ROOM_IN_FLOOR) {
if (roomSlot > process.env.NUMBER_OF_FLOOR * process.env.NUMBER_OF_ROOM_IN_FLOOR) {
roomSlot = 0
slotCount++;
if (slotCount <= process.env.NUMBER_OF_SLOT - 1) {
slot = slotList[slotCount].id
examSlot = await ExamSlot.create({
ePId: examPhaseList[key].id,
day: daySlot,
timeSlotId: slot
})
}// Cộng thêm 1 Slot mỗi khi không đủ phòng thi


if (slotCount > process.env.NUMBER_OF_SLOT - 1) {
slotCount = 0
dayCount++;
}
if (slotCount <= process.env.NUMBER_OF_SLOT - 1) {
slot = slotList[slotCount].id
daySlot = dayList[dayCount]
examSlot = await ExamSlot.create({
ePId: examPhaseList[key].id,
day: daySlot,
timeSlotId: slot
})

}
}// Cộng thêm 1 Day mỗi khi không đủ phòng thi
}

// let examSlot = await ExamSlot.create({
// ePId: examPhaseList[key].id,
// day: daySlot,
// timeSlotId: slot
// })

const val = course[i];



let roomCourse = Math.ceil(val.numOfStu / process.env.NUMBER_OF_STUDENT_IN_ROOM)

fs.appendFileSync("test.txt", roomCourse + "\n");
let currentSlot = "Current Slot: " + slotCount
fs.appendFileSync("test.txt", currentSlot + "\n");
let roomCourseData = "roomCourse của môn: " + roomCourse
fs.appendFileSync("test.txt", roomCourseData + "\n");

roomSlot += roomCourse

if(dayCount == 0 && slotCount == 0){
let examSlot = await ExamSlot.create({
ePId: examPhaseList[key].id,
day: dayList[0],
timeSlotId: slotList[0].id
})
console.log(val.id);
}

if(roomSlot <= process.env.NUMBER_OF_STUDENT_IN_ROOM* process.env.NUMBER_OF_ROOM_IN_FLOOR){
let roomSlotData = "RoomSlot sau khi add: " + roomSlot
fs.appendFileSync("test.txt", roomSlotData + "\n");


if (roomSlot <= process.env.NUMBER_OF_FLOOR * process.env.NUMBER_OF_ROOM_IN_FLOOR) {

//Tạo mới 1 SubjectInSlot
let subjectInSlot = await SubInSlot.create({
courId: val.id,
exSlId: examSlot.id
})
let data = subjectInSlot.courId + "--" + subjectInSlot.exSlId
fs.appendFileSync("test1.txt", data + "\n");

for (let i = 0; i < roomCourse; i++) {
let data = val.id + ".." + daySlot.getDate() + ".." + slot
fs.appendFileSync("test.txt", data + "\n");
let data = val.id + ".." + val.numOfStu + ".." + daySlot.getDate() + ".." + slot
let data1 = dayCount + "---" + slotCount
fs.appendFileSync("test.txt", data1 + "\n");
fs.appendFileSync("test.txt", data + "\n");
}

} else {
i--
}
Expand Down
Loading

0 comments on commit 04618e7

Please sign in to comment.