예제 #1
0
        public static TimetableModel Join(this TimetableModel source, TimetableModel target)
        {
            if (source == null)
                throw new ArgumentException("source");

            if (target == null)
                throw new ArgumentException("target");

            if (source.ShiftPerDay != target.ShiftPerDay)
                throw new InvalidOperationException("Cannot join Timetable with different Shift.");

            for(int i = 0; i < source.ShiftPerDay * source.SlotPerShift; i ++)
                for(int j = 0; j < Commons.Constants.DAY_OF_WEEK; j ++)
                {
                    CourseSectionSchedule s = source.TimeTableMatrix[i, j];
                    CourseSectionSchedule t = target.TimeTableMatrix[i, j];

                    if(s.ClassCourse == t.ClassCourse && t.ClassCourse == null)
                    {
                        if(t.Stage == Schedule.Models.COURSE_SECTION_STAGE.CLOSED)
                        {
                            s.Stage = t.Stage;
                        }
                    }
                }

            return source;
        }
예제 #2
0
        private CourseSectionSchedule[,] GenerateWorkingTimeTableMatrix(int shifts)
        {
            int dayOfWeek = 7;
            var timeTable = new CourseSectionSchedule[shifts, dayOfWeek];

            for (int i = 0; i < shifts; i++)
            {
                for (int j = 0; j < dayOfWeek; j++)
                {
                    //Schedule.Models.SCHEDULE_TYPE type = Schedule.Models.SCHEDULE_TYPE.OPEN;

                    //if ((DayOfWeek)j == DayOfWeek.Saturday || (DayOfWeek)j == DayOfWeek.Sunday)
                    //type = Schedule.Models.SCHEDULE_TYPE.CLOSED;

                    CourseSectionSchedule cs = new CourseSectionSchedule();

                    /*cs.TimeShift = new Schedule.Models.TimeShift()
                     * {
                     *  Id = Guid.NewGuid(),
                     *  Day = (DayOfWeek)j,
                     *  Shift = (Schedule.Models.SHIFT)i,
                     *  ScheduleType = type
                     * };*/

                    timeTable[i, j] = cs;
                }
            }

            return(timeTable);
        }
예제 #3
0
        public static CourseSectionSchedule[,,] GenerateTimeTableMatrix2(this TimetableModel source)
        {
            if (source == null)
                throw new ArgumentException("source");

            int dayOfWeek = Commons.Constants.DAY_OF_WEEK;
            var timeTableMatrix = new CourseSectionSchedule[dayOfWeek, source.ShiftPerDay, source.SlotPerShift];

            for (int k = 0; k < dayOfWeek; k++)
            {
                for (int i = 0; i < source.ShiftPerDay ; i++)
                {
                    for (int j = 0; j < source.SlotPerShift; j++)
                    {
                        CourseSectionSchedule cs = new CourseSectionSchedule();
                        cs.Id = Guid.Empty;
                        cs.Day = (DayOfWeek)k;
                        cs.Shift = (SHIFT)(i);
                        cs.Slot = (short)(j);
                        cs.Stage = COURSE_SECTION_STAGE.OPEN;
                        timeTableMatrix[k, i, j] = cs;

                    }
                }
            }

            foreach (CourseSectionSchedule cs in source.CourseSections)
            {
                timeTableMatrix[(int)cs.Day, (int)cs.Shift, cs.Slot] = cs;
            }

            return timeTableMatrix;
        }
예제 #4
0
        public static CourseSectionSchedule[,] GenerateTimeTableMatrix(this TimetableModel source)
        {
            if (source == null)
                throw new ArgumentException("source");

            int dayOfWeek = Commons.Constants.DAY_OF_WEEK;
            var timeTableMatrix = new CourseSectionSchedule[source.ShiftPerDay * source.SlotPerShift, dayOfWeek];

            /*for (int i = 0; i < source.ShiftPerDay * source.SlotPerShift; i++)
            {
                for (int j = 0; j < dayOfWeek; j++)
                {
                    CourseSectionSchedule cs = new CourseSectionSchedule();
                    cs.Id = Guid.Empty;
                    cs.Day = (DayOfWeek)j;
                    cs.Shift = (SHIFT)(i / source.ShiftPerDay);
                    cs.Slot = (short)(i % source.SlotPerShift);
                    cs.Stage = COURSE_SECTION_STAGE.OPEN;
                    timeTable[i, j] = cs;
                }
            }*/

            foreach (CourseSectionSchedule cs in source.CourseSections)
            {
                timeTableMatrix[(int)cs.Shift * source.SlotPerShift + cs.Slot, (int)cs.Day] = cs;
            }

            return timeTableMatrix;
        }
예제 #5
0
        public Guid SaveTimetable(TimetableModel timetable)
        {
            if (timetable == null)
            {
                throw new ArgumentNullException("timetable");
            }

            if (timetable.Id == null)
            {
                throw new ArgumentNullException("timetable.Id");
            }

            Timetable tt = this.UnitOfWork.TimetableRepository.GetById(timetable.Id);

            if (tt == null)
            {
                throw new InvalidOperationException($"Timetable ({timetable.Id}) does not exist.");
            }


            for (int i = 0; i < timetable.ShiftPerDay * timetable.SlotPerShift; i++)
            {
                for (int j = 0; j < Commons.Constants.DAY_OF_WEEK; j++)
                {
                    CourseSectionSchedule cs = timetable.TimeTableMatrix[i, j];
                    if (cs.Checked && (cs.Id == null || cs.Id == Guid.Empty))
                    {// Added
                        //CourseSection courseSection = Mapper.Map<CourseSectionSchedule, CourseSection>(cs);
                        CourseSection courseSection = new CourseSection();
                        courseSection.Day         = (DayOfWeek)j;
                        courseSection.Id          = Guid.NewGuid();
                        courseSection.TimetableId = timetable.Id;
                        courseSection.Stage       = COURSE_SECTION_STAGE.OPEN;
                        courseSection.Shift       = cs.Shift;
                        courseSection.Slot        = cs.Slot;

                        this.UnitOfWork.CourseSectionRepository.Insert(courseSection);
                    }
                    else if (!cs.Checked && (cs.Id != Guid.Empty))
                    {// Remove
                        //CourseSection courseSection = Mapper.Map<CourseSectionSchedule, CourseSection>(cs);
                        this.UnitOfWork.CourseSectionRepository.DeleteCourseSection(cs.Id);
                    }
                }
            }

            this.UnitOfWork.SaveChanges();

            return(tt.Id);
        }
예제 #6
0
        private bool IsTeacherAlreadyBooked(TeacherScheduleModel teacher, TimeShift tf, StoneCastle.Scheduler.Models.TimetableModel tt)
        {
            if (teacher == null || tf == null || tt == null)
            {
                return(false);
            }

            CourseSectionSchedule cs     = tt.TimeTableMatrix[tf.Shift * tf.Slot + tf.Slot, (int)tf.Day];
            ClassCourseSchedule   course = cs.ClassCourse;

            if (cs.Stage == COURSE_SECTION_STAGE.BOOKED && course != null && course.Teacher != null && course.Teacher.Id == teacher.Id)
            {
                return(true);
            }

            return(false);
        }
예제 #7
0
        private CourseSectionSchedule[,] GenerateTimeTableMatrix(int totalShift, int slotPerShift, COURSE_SECTION_STAGE stage)
        {
            int dayOfWeek = Commons.Constants.DAY_OF_WEEK;
            var timeTable = new CourseSectionSchedule[totalShift * slotPerShift, dayOfWeek];

            for (int i = 0; i < totalShift * slotPerShift; i++)
            {
                for (int j = 0; j < dayOfWeek; j++)
                {
                    CourseSectionSchedule cs = new CourseSectionSchedule();
                    //cs.Id = Guid.NewGuid();
                    cs.Day          = (DayOfWeek)j;
                    cs.Shift        = (SHIFT)(i / slotPerShift);
                    cs.Slot         = (short)(i % slotPerShift);
                    cs.Stage        = stage;
                    timeTable[i, j] = cs;
                }
            }

            return(timeTable);
        }
예제 #8
0
        private void CalculateTimetable(StoneCastle.Scheduler.Models.TimetableModel tt, ClassCourseSchedule course, ScheduleBoard board)
        {
            if (course.Course.SectionPerWeek == 0)
            {
                return;
            }

            bool canSchedule = false;

            // Check tt has open-shifts for courses
            int openSlotCount = 0;

            for (int i = 0; i < tt.ShiftPerDay * tt.SlotPerShift; i++)
            {
                for (int j = 0; j < Commons.Constants.DAY_OF_WEEK; j++)
                {
                    CourseSectionSchedule cs = tt.TimeTableMatrix[i, j];
                    if (cs.Stage == COURSE_SECTION_STAGE.OPEN)
                    {
                        openSlotCount++;
                    }
                }
            }

            if (openSlotCount >= course.Course.SectionPerWeek)
            {
                canSchedule = true;
            }

            if (canSchedule)
            {
                List <TimeShift> checklist = new List <TimeShift>();

                int bookedCount = 0;
                do
                {
                    int i = rand.Next(tt.ShiftPerDay);
                    int j = rand.Next(Commons.Constants.DAY_OF_WEEK);
                    int k = rand.Next(tt.SlotPerShift);

                    CourseSectionSchedule cs = tt.TimeTableMatrix[i * tt.SlotPerShift + k, j];
                    if (cs.Stage == COURSE_SECTION_STAGE.OPEN)
                    {
                        TimeShift tf = new TimeShift()
                        {
                            Day   = (DayOfWeek)j,
                            Shift = i,
                            Slot  = k
                        };

                        if (!this.IsTimeShiftExistInList(tf, checklist))
                        {
                            checklist.Add(tf);

                            // Check exiting teacher section booked
                            if (this.CanBeBookedForTeacher(course.Teacher, tf, board))
                            {
                                cs.ClassCourse = course;
                                cs.Stage       = COURSE_SECTION_STAGE.BOOKED;
                                bookedCount++;
                            }
                        }
                    }
                } while (bookedCount < course.Course.SectionPerWeek && checklist.Count < openSlotCount);
            }
        }
예제 #9
0
        public void SaveScheduleBoard(ScheduleBoard scheduleBoard)
        {
            if (scheduleBoard == null)
            {
                Logger.Error($"scheduleBoard is empty.");
                throw new ArgumentNullException("scheduleBoard");
            }

            Logger.Debug($"Start saving schedule board: {scheduleBoard.Id}");

            Schedule.Models.SchedulingTable schedule = this.UnitOfWork.SchedulingTableRepository.GetById(scheduleBoard.Id);

            if (schedule == null)
            {
                Logger.Error($"Schedule ({scheduleBoard.Id}) does not exist.");
                throw new InvalidOperationException($"Schedule ({scheduleBoard.Id}) does not exist.");
            }

            var mapper = config.CreateMapper();

            foreach (ClassGroupSchedule cg in scheduleBoard.ClassGroups)
            {
                foreach (ClassRoomSchedule crs in cg.ClassRooms)
                {
                    Timetable tt = new Timetable()
                    {
                        Id           = Guid.NewGuid(),
                        Name         = crs.Name,
                        ShiftPerDay  = crs.Timetable.ShiftPerDay,
                        SlotPerShift = crs.Timetable.SlotPerShift,
                    };

                    this.UnitOfWork.ClassTimetableRepository.Create(scheduleBoard.Id, crs.Id, tt);

                    for (int i = 0; i < crs.Timetable.ShiftPerDay * crs.Timetable.SlotPerShift; i++)
                    {
                        for (int j = 0; j < Commons.Constants.DAY_OF_WEEK; j++)
                        {
                            CourseSectionSchedule cs = crs.Timetable.TimeTableMatrix[i, j];

                            if (cs != null && (cs.Id != null && cs.Id != Guid.Empty) && (cs.ClassCourse != null && (cs.ClassCourse.Id != null && cs.ClassCourse.Id != Guid.Empty)))
                            {// Added
                                //CourseSection courseSection = mapper.Map<CourseSectionSchedule, CourseSection>(cs);
                                CourseSection courseSection = new CourseSection();
                                courseSection.Day           = (DayOfWeek)j;
                                courseSection.Id            = Guid.NewGuid();
                                courseSection.TimetableId   = tt.Id;
                                courseSection.ClassCourseId = cs.ClassCourse.Id;
                                courseSection.Stage         = cs.Stage;
                                courseSection.Shift         = cs.Shift;
                                courseSection.Slot          = cs.Slot;

                                this.UnitOfWork.CourseSectionRepository.Insert(courseSection);
                            }
                        }
                    }
                }
            }

            this.UnitOfWork.SaveChanges();

            Logger.Debug($"Complete saving schedule board: {scheduleBoard.Id}");
        }