Esempio n. 1
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);
        }
Esempio n. 2
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);
            }
        }
Esempio n. 3
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);
        }