private List <ExamEntity> normalArrange(CourseEntity ce, List <SessionEntity> remainSessions, TimeValueInterval timeData) { List <ExamEntity> ret = new List <ExamEntity>(); int sessionCt = remainSessions.Count; int sessionIndex = 0; foreach (RoomEntity r in allRoom) { if (r.roomType == ce.requiredRoomType && getConflictTimeData(r.occupied, timeData) == null) { ExamEntity entity = new ExamEntity(); entity.courseId = ce.courseId; entity.roomId = r.roomId; entity.roomType = r.roomType; entity.startMinute = TimeValueInterval.value2Min(timeData.startValue); entity.startHour = TimeValueInterval.value2Hour(timeData.startValue); entity.weekDay = TimeValueInterval.value2Weekday(timeData.startValue); entity.endMinute = TimeValueInterval.value2Min(timeData.endValue); entity.endHour = TimeValueInterval.value2Hour(timeData.endValue); r.arrangeExam(timeData); // Jane: added null check 20180426 if (allLevelTimeLine[ce.level] != null) if (allLevelTimeLine[ce.level] != null) { allLevelTimeLine[ce.level].Add(timeData); } int sessionsThisRoom = r.roomCapacity / SESSION_CAPACITY; for (int i = 0; i < sessionsThisRoom; ++i, ++sessionIndex) { if (sessionIndex >= remainSessions.Count) { break; } entity.sessionIds.Add(remainSessions[sessionIndex]); //if (protorId <= 0) protorId = remainSessions[sessionIndex].facultyId; } bool hasProtor = false; ProtorEntity sessionFaculty = null; foreach (SessionEntity se in entity.sessionIds) { int protorId = se.facultyId; foreach (ProtorEntity pe in allProtor) { if (pe.protorId == protorId) { sessionFaculty = pe; break; } } if (sessionFaculty != null) { if (getConflictTimeData(sessionFaculty.occupied, timeData) == null) { entity.protorId = sessionFaculty.protorId; sessionFaculty.arrangeExam(timeData); hasProtor = true; break; } } } if (!hasProtor) { bool valid = true; foreach (ProtorEntity pe in allProtor) { valid = true; foreach (SessionEntity ss in ce.sessionIds) { if (pe.protorId == ss.sessionId && pe.protorId > 0) { valid = false; break; } } if (!valid) { continue; } if (getConflictTimeData(pe.occupied, timeData) == null) { entity.protorId = pe.protorId; pe.arrangeExam(timeData); break; } } Console.WriteLine("DOES NOT use teacher as protor!!!"); } ret.Add(entity); } if (sessionCt <= sessionIndex) { break; } } remainSessions.Clear(); return(ret); }
private ExamEntity specialArrange(CourseEntity course, SpecialEntity special, TimeValueInterval timeData, List <SessionEntity> remainSessions, List <SpecialEntity> specialsOfThisCourse) { int sessionCt = remainSessions.Count; int sessionIndex = 0; RoomEntity room = null; foreach (RoomEntity r in allRoom) { if (special.roomId > 0) { if (r.roomId == special.roomId) { room = r; break; } } else { if (r.roomType == course.requiredRoomType && getConflictTimeData(r.occupied, timeData) == null) { room = r; foreach (SpecialEntity sot in specialsOfThisCourse) { if (sot.roomId <= 0) { continue; } if (r.roomId == sot.roomId) { room = null; break; } } if (room != null) { break; } } } } if (room == null) { return(null); } bool hasSpecialProtor = special.protorId > 0; ExamEntity exam = new ExamEntity(); exam.courseId = special.courseId; exam.roomId = special.roomId; exam.roomType = room.roomType; exam.startMinute = TimeValueInterval.value2Min(timeData.startValue); exam.startHour = TimeValueInterval.value2Hour(timeData.startValue); exam.weekDay = TimeValueInterval.value2Weekday(timeData.startValue); exam.endMinute = TimeValueInterval.value2Min(timeData.endValue); exam.endHour = TimeValueInterval.value2Hour(timeData.endValue); int sessionsThisRoom = room.roomCapacity / SESSION_CAPACITY; if (special.sessionId > 0) { SessionEntity target = null; foreach (SessionEntity s in remainSessions) { if (s.sessionId == special.sessionId) { target = s; break; } } if (target != null) { exam.sessionIds.Add(target); remainSessions.Remove(target); } --sessionsThisRoom; } for (int i = 0; i < sessionsThisRoom; ++sessionIndex) { if (sessionIndex >= remainSessions.Count) { break; } bool sessionInSpecial = false; foreach (SpecialEntity e in specialsOfThisCourse) { if (e.courseId == course.courseId && e.roomId != room.roomId && e.sessionId == remainSessions[sessionIndex].sessionId) { sessionInSpecial = true; break; } } if (!sessionInSpecial) { exam.sessionIds.Add(remainSessions[sessionIndex]); ++i; } } remainSessions.RemoveRange(0, sessionIndex); if (hasSpecialProtor) { exam.protorId = special.protorId; ProtorEntity pe = null; foreach (ProtorEntity p in allProtor) { if (p.protorId == special.protorId) { pe = p; break; } } if (pe != null) { pe.arrangeExam(timeData); } } else { ProtorEntity sessionFaculty = null; foreach (SessionEntity ss in exam.sessionIds) { foreach (ProtorEntity pe in allProtor) { if (ss.facultyId == pe.protorId) { sessionFaculty = pe; break; } } if (sessionFaculty != null) { if (getConflictTimeData(sessionFaculty.occupied, timeData) == null) { break; } else { sessionFaculty = null; } } } if (sessionFaculty != null) { exam.protorId = sessionFaculty.protorId; sessionFaculty.arrangeExam(timeData); } else { foreach (ProtorEntity pe in allProtor) { sessionFaculty = pe; foreach (SpecialEntity e in specialsOfThisCourse) { if (sessionFaculty.protorId == e.protorId) { sessionFaculty = null; break; } } if (sessionFaculty == null) { continue; } if (getConflictTimeData(sessionFaculty.occupied, timeData) == null && sessionFaculty.protorId != special.protorId) { exam.protorId = sessionFaculty.protorId; sessionFaculty.arrangeExam(timeData); break; } } } } room.arrangeExam(timeData); // Jane: added null check 20180426 if (allLevelTimeLine[ce.level] != null) if (allLevelTimeLine[course.level] != null) { allLevelTimeLine[course.level].Add(timeData); } return(exam); }