Exemple #1
0
        private List <CourseData> SetupCourseData(TimetableData data)
        {
            List <CourseData> courseDataList = data.CourseList.ToList();

            for (int i = 0; i < courseDataList.Count; i++)
            {
                if (ShouldDeleseCourseFromList(courseDataList[i].CourseCode, data.CourseLecturerSettings))
                {
                    courseDataList.RemoveAt(i--);
                }
                else
                {
                    List <CourseDetails> details = courseDataList[i].GroupList.ToList();
                    for (int j = 0; j < details.Count; j++)
                    {
                        if (ShouldRemoveLecturerFromCourse(courseDataList[i].CourseCode, details[j].Lecturer, data.CourseLecturerSettings))
                        {
                            details.RemoveAt(j--);
                        }
                    }
                    courseDataList[i].GroupList = details;
                }
            }
            return(courseDataList);
        }
 public static void PrintGroup(int group, Individual i, TimetableData ttData)
 {
     System.Diagnostics.Debug.WriteLine("");
     System.Diagnostics.Debug.WriteLine("Group " + group);
     for (int block = 0; block < i.Courses.GetLength(2); block++)
     {
         System.Diagnostics.Debug.Write("Block " + block + ": ");
         for (int day = 0; day < 5; day++)
         {
             int course = i.Groups[group, day, block];
             if (course == -1)
             {
                 for (int j = 0; j < 44; j++)
                 {
                     System.Diagnostics.Debug.Write("-");
                 }
             }
             else
             {
                 string output = ttData.Courses[course].Name + ", " + ttData.Rooms[i.Courses[course, day, block]].Id;
                 System.Diagnostics.Debug.Write(output.PadRight(44, ' '));
             }
             System.Diagnostics.Debug.Write("| ");
         }
         System.Diagnostics.Debug.WriteLine("");
     }
 }
Exemple #3
0
        public static CifSchedule CreateScheduleInTimetable(TimetableData timetable,
                                                            string timetableId       = "X12345",
                                                            StpIndicator indicator   = StpIndicator.Permanent,
                                                            ICalendar calendar       = null,
                                                            ScheduleLocation[] stops = null,
                                                            string retailServiceId   = null)
        {
            var schedule = CreateSchedule(timetableId, indicator, calendar, stops, retailServiceId: retailServiceId);

            timetable.AddSchedule(schedule);

            return(schedule);
        }
Exemple #4
0
        public IActionResult GetCourseData([FromQuery] int hashCode)
        {
            TimetableData data = _timetableConfigService.GetTimetableDataByHashCode(User.Identity.Name, hashCode);

            if (data != null)
            {
                if (data.CourseLecturerSettings == null)
                {
                    data.CourseLecturerSettings = _timetableConfigService.GenerateCourseLecturerSettings(data);
                }
                return(Ok(new { response = "success", data = data.CourseLecturerSettings }));
            }
            return(Ok(new { response = "not found" }));
        }
        public IEnumerable <CourseLecturerSettings> GenerateCourseLecturerSettings(TimetableData timetableData)
        {
            List <CourseLecturerSettings> courseLecturerSettingsList = new List <CourseLecturerSettings>();

            foreach (CourseData data in timetableData.CourseList)
            {
                courseLecturerSettingsList.Add(new CourseLecturerSettings
                {
                    CourseName       = data.CourseName,
                    CourseCode       = data.CourseCode,
                    LecturerSettings = GenerateLecturerSettings(data)
                });
            }
            return(courseLecturerSettingsList);
        }
Exemple #6
0
        public IEnumerable <Timetable> GenerateTimetableList(TimetableData data, string conditions)
        {
            List <Timetable>  returnList = new List <Timetable>();
            List <CourseTime> courseTime = null;

            if (conditions != "")
            {
                courseTime = ParseConditionsToCourseTime(conditions);
            }
            else
            {
                courseTime = new List <CourseTime>();
            }
            Rec(SetupCourseData(data), new List <CourseDetails>(), courseTime, ref returnList);
            return(returnList);
        }
 public static void PrintLecturer(int lecturer, Individual i, TimetableData ttData)
 {
     System.Diagnostics.Debug.WriteLine("");
     System.Diagnostics.Debug.WriteLine("Lecturer " + lecturer);
     for (int block = 0; block < i.Courses.GetLength(2); block++)
     {
         System.Diagnostics.Debug.Write("Block " + block + ": ");
         for (int day = 0; day < 5; day++)
         {
             int course = i.Lecturers[lecturer, day, block];
             if (course == -1)
                 System.Diagnostics.Debug.Write("--- ");
             else
                 System.Diagnostics.Debug.Write(course.ToString().PadLeft(3, ttData.Courses[course].IsDummy ? 'x' : '0') + " ");
         }
         System.Diagnostics.Debug.WriteLine("");
     }
 }
Exemple #8
0
        public IActionResult GenerateTimetable([FromQuery] int hashCode, [FromBody] IEnumerable <CourseLecturerSettings> courseLecturerSettings)
        {
            bool courseUpdate = _timetableConfigService.UpdateUserCourseLecturerSettings(User.Identity.Name, hashCode, courseLecturerSettings);

            string conditions = _accountService.GetUser(User.Identity.Name).Conditions;

            TimetableData data = _timetableConfigService.GetTimetableDataByHashCode(User.Identity.Name, hashCode);

            if (!courseUpdate)
            {
                return(Ok(new { response = "failed to update course lecturer settings!" }));
            }
            if (data != null)
            {
                IEnumerable <Timetable> timetableList = _timetableGeneratorService.GenerateTimetableList(data, conditions);
                return(Ok(new { response = "success", data = timetableList }));
            }
            return(Ok(new { response = "not found" }));
        }
Exemple #9
0
        internal static IService GetService(this TimetableData timetable, string timetableUid)
        {
            var services = (Dictionary <string, IService>)timetable.AsDynamic()._timetableUidMap.RealObject;

            return(services[timetableUid]);
        }
Exemple #10
0
        private Data AddSchedules(IEnumerable <IRecord> records, Data data)
        {
            var tocLookup    = data.Tocs as TocLookup;
            var locations    = data.Locations;
            var timetable    = new TimetableData(_filters, _logger);
            var associations = new List <Association>(6000);

            void UpdateLocations(TiplocInsertAmend cifTiploc)
            {
                var location = _mapper.Map <CifParser.Records.TiplocInsertAmend, Timetable.Location>(cifTiploc);

                locations.Update(location);
            }

            Timetable.CifSchedule MapSchedule(CifParser.Schedule schedule)
            {
                return(_mapper.Map <CifParser.Schedule, Timetable.CifSchedule>(schedule, o =>
                {
                    o.Items.Add("Tocs", tocLookup);
                    o.Items.Add("Locations", locations);
                    o.Items.Add("Timetable", timetable);
                }));
            }

            Timetable.Association MapAssociation(CifParser.Records.Association association)
            {
                return(_mapper.Map <CifParser.Records.Association, Timetable.Association>(association,
                                                                                          o => { o.Items.Add("Locations", locations); }));
            }

            var dodgySchedules = new List <ISchedule>();
            int count          = 0;

            foreach (var record in records)
            {
                switch (record)
                {
                case CifParser.Records.TiplocInsertAmend tiploc:
                    UpdateLocations(tiploc);
                    break;

                case CifParser.Schedule schedule:
                    var s = MapSchedule(schedule);
                    if (!s.IsPublicSchedule())
                    {
                        dodgySchedules.Add(s);
                    }
                    break;

                case CifParser.Records.Association association:
                    var a = MapAssociation(association);
                    associations.Add(a);
                    break;

                case CifParser.Records.Header header:
                case CifParser.Records.Trailer trailer:
                    _logger.Information("Ignored record {recordType}: {record}", record.GetType(), record);
                    break;

                default:
                    _logger.Warning("Unhandled record {recordType}: {record}", record.GetType(), record);
                    break;
                }

                count++;
                if (count % LogAfter == 0)
                {
                    _logger.Information("Loaded records: {count}", count);
                }
            }

            if (dodgySchedules.Any())
            {
                _logger.Warning("Dodgy schedules loaded: {count} {schedules}", dodgySchedules.Count, dodgySchedules);
            }


            _logger.Information("Loaded records: {count}", count);

            var applied = timetable.AddAssociations(associations.Where(a => a.IsPassenger || a.IsCancelled()));

            _logger.Information("Applied Associations: {applied} of {Count}", applied, associations.Count);

            timetable.IsLoaded = true;
            data.Timetable     = timetable;
            return(data);
        }