Пример #1
0
 public TimetableViewModel Execute(TimetableRequest request)
 {
     var sessions = unifOfWork.CurrentSession.CreateCriteria<MovieSession>().List<MovieSession>();
     return new TimetableViewModel
                {
                    Sessions = sessions
                };
 }
        public IActionResult GetUoftTimetables([FromBody] TimetableRequest request)
        {
            if (request == null)
            {
                return(BadRequest());
            }

            // Each course code has a length of 10; max 10 courses to put in timetable
            if (request.CourseCodes == null || request.CourseCodes.Length > 100)
            {
                return(BadRequest());
            }

            // Check if the preferences / restrictions are set
            if (request.Preferences == null || request.Restrictions == null)
            {
                return(BadRequest());
            }

            // Get the courses from the database
            List <Activity> activities = new List <Activity>();

            foreach (string code in request.CourseCodes)
            {
                Course courseObj = UoftServices.GetService().GetCourseDetails(code);
                if (courseObj == null)
                {
                    return(NotFound());
                }
                activities.AddRange(courseObj.Activities);
            }

            // Generate the timetables
            TimetableScorer scorer = new TimetableScorer(request.Restrictions, request.Preferences);
            GeneticScheduler <YearlyTimetable> generator = new GeneticScheduler <YearlyTimetable>(activities, scorer, request.Preferences, request.Restrictions)
            {
                NumGenerations = 100,
                PopulationSize = 16,
                MutationRate   = 0.1,
                CrossoverRate  = 0.6
            };
            List <YearlyTimetable> timetables = generator.GetTimetables();

            /*
             * GreedyScheduler<YearlyTimetable> greedyGenerator = new GreedyScheduler<YearlyTimetable>(activities, request.Preferences, request.Restrictions);
             * List<YearlyTimetable> timetables = greedyGenerator.GetTimetables();
             */

            // Convert the timetables to mini timetables (which will be presented to the user)
            List <SimplifiedYearlyTimetable> miniTimetables = new List <SimplifiedYearlyTimetable>();

            for (int i = 0; i < timetables.Count; i++)
            {
                miniTimetables.Add(new SimplifiedYearlyTimetable(timetables[i], "Timetable #" + (i + 1)));
            }

            return(Created("api/timetables/getuofttimetables", miniTimetables));
        }
Пример #3
0
        public override async Task <TimetableResponse> Timetable(TimetableRequest request, ServerCallContext context)
        {
            var result = (await this.timetableService.GetTimetableAsync(new FormData()
            {
                Calendar = request.Calendar.ToModel(),
                Semester = request.Semester.ToModel(),
                BranchOfStudy = request.BranchOfStudy,
                Lecturer = request.Lecturer,
                Room = request.Room,
            })).ToGrpc();

            return(new TimetableResponse()
            {
                Result = result,
            });
        }
Пример #4
0
        public async Task <IActionResult> GetTimeTable(TimetableRequest model)
        {
            var appUser = await _userManager.FindByIdAsync(_userAccessor.GetCurrentUserId());

            var userLinks = (from userRooms in _roomDbContext.RoomUserLink
                             where userRooms.UserId == appUser.Id
                             select userRooms.RoomId).ToList();

            //Toàn bộ room người dùng này tham gia vào
            var rooms = new List <Room>();

            foreach (var roomId in userLinks)
            {
                //get room
                var room = await _roomDbContext.Room.Where(r => r.RoomId == roomId && !r.Group).FirstOrDefaultAsync();

                if (room != null)
                {
                    rooms.Add(room);
                }
            }


            var resultList = new List <TimetableResponse>();

            foreach (var room in rooms)
            {
                var roomTimetables = TimetableDAO.GetByRoomId(_roomDbContext, room.RoomId);

                foreach (var timetable in roomTimetables)
                {
                    if (timetable.Date >= model.StartDate && timetable.Date <= model.EndDate)
                    {
                        resultList.Add(new TimetableResponse
                        {
                            RoomId    = room.RoomId.ToString(),
                            EventType = 0,
                            Title     = room.Subject + "-" + room.ClassName,
                            TeacherId = room.CreatorId,
                            StartDate = timetable.Date.ToString("yyyy-MM-dd") + "T" + timetable.StartTime,
                            EndDate   = timetable.Date.ToString("yyyy-MM-dd") + "T" + timetable.EndTime,
                        });
                    }
                }
            }
            return(new OkObjectResult(resultList));
        }