Example #1
0
 private void CalculateSchedule(ClassGroupSchedule classGroup, ScheduleBoard board)
 {
     foreach (ClassRoomSchedule classRoom in classGroup.ClassRooms)
     {
         //foreach (CourseSubjectSchedule courseSubject in classGroup.TrainingProgram.CourseSubjects)
         foreach (ClassCourseSchedule course in classRoom.Courses)
         {
             StoneCastle.Scheduler.Models.TimetableModel tt = classRoom.Timetable;
             this.CalculateTimetable(tt, course, board);
         }
         Logger.Debug($"Calculated class: {classRoom.Name}");
     }
 }
Example #2
0
        private bool CanBeBookedForTeacher(TeacherScheduleModel teacher, TimeShift tf, ScheduleBoard board)
        {
            foreach (ClassGroupSchedule cg in board.ClassGroups)
            {
                foreach (ClassRoomSchedule cr in cg.ClassRooms)
                {
                    StoneCastle.Scheduler.Models.TimetableModel tt = cr.Timetable;

                    if (this.IsTeacherAlreadyBooked(teacher, tf, tt))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Example #3
0
        private void CalculateClassGroupSchedule(ClassGroupSchedule cg)
        {
            if (cg == null)
            {
                Logger.Error($"Null exception: cg");
                throw new ArgumentNullException("cg");
            }
            TrainingProgramSchedule trainingProgram = cg.TrainingProgram;

            if (trainingProgram == null)
            {
                Logger.Error($"Class-group does not containt Training Program.");
                throw new InvalidOperationException($"ClassGroup {cg.Id} does not containt training program.");
            }

            trainingProgram.Timetable = this.timetableService.GetProgramTimetable(trainingProgram.Id);

            List <Course> css = this.UnitOfWork.CourseRepository.GetCourseSubjectByTrainingProgram(trainingProgram.Id).ToList();

            var mapper = config.CreateMapper();

            List <CourseSchedule> courseSubjects = mapper.Map <List <Course>, List <CourseSchedule> >(css);

            trainingProgram.CourseSubjects = courseSubjects;

            int shiftPerDay  = trainingProgram.Timetable.ShiftPerDay;
            int slotPerShift = trainingProgram.Timetable.SlotPerShift;

            foreach (ClassRoomSchedule cr in cg.ClassRooms)
            {
                StoneCastle.Scheduler.Models.TimetableModel tt = this.timetableService.GetWorkingTimeTable(shiftPerDay, slotPerShift);
                tt = tt.Join(trainingProgram.Timetable);

                cr.Timetable = tt;

                // Get Courses
                List <ClassCourse>         courses         = this.UnitOfWork.ClassCourseRepository.GetCoursesByClassRoom(cr.Id).ToList();
                List <ClassCourseSchedule> courseSchedules = mapper.Map <List <ClassCourse>, List <ClassCourseSchedule> >(courses);
                cr.Courses = courseSchedules;
            }
        }
Example #4
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);
        }
Example #5
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);
            }
        }
Example #6
0
        private StoneCastle.Scheduler.Models.ClassGroupSchedule GetRandomScheduleGroup(string groupName, int workingShiftInDay)
        {
            TrainingProgramSchedule trainingProgram = new TrainingProgramSchedule()
            {
                Id        = Guid.NewGuid(),
                Timetable = timetableService.GetWorkingTimeTable(this.workingShiftInDay, this.workingSlotPerShift)
                            //Timetable = timetableService.GetTimeTable(this.workingShiftInDay)
            };

            string[] courseSubjectNames = new string[] { "Math", "History", "Geo", "English", "Art", "Literality", "Chemistry" };

            int courseSubjectCount = 0;

            while (courseSubjectCount == 0)
            {
                courseSubjectCount = rand.Next(6);
            }

            for (int i = 0; i < courseSubjectCount; i++)
            {
                CourseSchedule courseSubject = new CourseSchedule()
                {
                    Id = Guid.NewGuid(),
                    //TrainingProgram = trainingProgram,
                    Name           = courseSubjectNames[i],
                    SectionPerWeek = rand.Next(3),
                    HighlightColor = Commons.Ultility.GetHighlightColor(rand),
                };

                trainingProgram.CourseSubjects.Add(courseSubject);
            }

            StoneCastle.Scheduler.Models.ClassGroupSchedule cg = new StoneCastle.Scheduler.Models.ClassGroupSchedule()
            {
                Id              = Guid.NewGuid(),
                Name            = groupName,
                TrainingProgram = trainingProgram
            };

            int classCount = 0;

            while (classCount == 0)
            {
                classCount = rand.Next(6);
            }

            List <StoneCastle.Scheduler.Models.ClassRoomSchedule> classRooms = new List <StoneCastle.Scheduler.Models.ClassRoomSchedule>();

            for (int i = 0; i < classCount; i++)
            {
                StoneCastle.Scheduler.Models.TimetableModel tt = this.timetableService.GetWorkingTimeTable(workingShiftInDay, this.workingSlotPerShift);
                tt = tt.Join(trainingProgram.Timetable);

                StoneCastle.Scheduler.Models.ClassRoomSchedule cr = new StoneCastle.Scheduler.Models.ClassRoomSchedule()
                {
                    Id   = Guid.NewGuid(),
                    Name = $"{groupName}.{(i + 1)}",
                    //ClassGroup = cg,
                    Timetable = tt,
                };

                cg.ClassRooms.Add(cr);
                classRooms.Add(cr);
            }

            // Course
            for (int i = 0; i < courseSubjectCount; i++)
            {
                CourseSchedule courseSubject = ((List <CourseSchedule>)trainingProgram.CourseSubjects)[i];

                StoneCastle.Scheduler.Models.TimetableModel tt = this.timetableService.GetWorkingTimeTable(workingShiftInDay, this.workingSlotPerShift);

                TeacherScheduleModel teacher = new TeacherScheduleModel()
                {
                    Id = Guid.NewGuid(),
                    //FirstName = "Teacher",
                    //LastName = i.ToString(),
                    Timetable = tt
                };

                //for (int j = 0; j < classCount; j++)
                foreach (ClassRoomSchedule classRoom in classRooms)
                {
                    StoneCastle.Scheduler.Models.TimetableModel t = this.timetableService.GetWorkingTimeTable(workingShiftInDay, this.workingSlotPerShift);

                    ClassCourseSchedule course = new ClassCourseSchedule()
                    {
                        Id        = Guid.NewGuid(),
                        Teacher   = teacher,
                        Course    = courseSubject,
                        Timetable = t
                    };

                    classRoom.Courses.Add(course);
                }
            }

            return(cg);
        }