Beispiel #1
0
        //Create period table for the day



        /// <summary>
        /// Converts the list of events for the day into their respective periods
        /// </summary>
        /// <param name="events">List of Events</param>
        /// <returns>Array of the periods between 0-6</returns>
        static public TimetablePeriod[] ParseEventsToPeriods(Firefly.FFEvent[] events)
        {
            Regex reg = new Regex(@"(\w*?)-(.)-(\d)-([1-3]?\d)-([1-3]?\d)-(\d{4})");

            TimetablePeriod[] table = new TimetablePeriod[7];
            foreach (Firefly.FFEvent item in events)
            {
                try
                {
                    Match match = reg.Match(item.guid);
                    if (match.Success)
                    {
                        table[Convert.ToInt16(match.Groups[3].Value)] = new TimetablePeriod(item.start.ToLocalTime(), item.end.ToLocalTime(), item.subject, match.Groups[1].ToString(), item.location, Convert.ToInt16(match.Groups[3].Value) != 0, Convert.ToInt16(match.Groups[3].Value), item.Teacher);
                    }
                }
                catch
                {
                    //Regex error
                }
            }

            if (table[0].Start != DateTime.MinValue)
            {
                //Override first period to start at 8:15 since for some reason it always starts at 8:30???
                table[0].Start = DateTimespan(table[0].Start, DefaultPeriods[0, 0].Start);
            }

            return(table);
        }
Beispiel #2
0
        static public List <TimetablePeriod> ProcessForUse(Firefly.FFEvent[] events, DateTime day, bool EarlyFinish, bool EventsUptoDate, bool FindForDay = true)
        {
            //If events not up to date then assume school day
            //If event is up to date and no events for the day Assume holiday

            List <TimetablePeriod> Modified = new List <TimetablePeriod>();

            TimetablePeriod[] periods = ParseEventsToPeriods(FindForDay ? EventsForDay(events, day) : events);

            for (int i = 0; i < 7; i++)
            {
                if (!string.IsNullOrWhiteSpace(periods[i].Roomcode))
                {
                    //Add if it is a valid period
                    Modified.Add(periods[i]);
                }
            }

            day = day.ToLocalTime();

            int position = 0;

            if (EarlyFinish)
            {
                position = 2;
            }
            else if (day.DayOfWeek == DayOfWeek.Wednesday)
            {
                position = 1;
            }

            //Check if weekend for whether to fill
            if (day.DayOfWeek == DayOfWeek.Sunday || day.DayOfWeek == DayOfWeek.Saturday)
            {
                //Don't fill in table only check for overlaps
                periods = OverlapCheck(Modified.ToArray());
                return(periods.ToList());
            }
            else
            {
                //Confirm data is up to date and check whether there is any periods
                //if data is updated and there is no periods don't fill in periods.
                if (EventsUptoDate && Modified.Count == 0)
                {
                    //Don't add breaks assume day off/holiday
                    return(Modified);
                }

                //Fill in table with appropriate data for day
                periods = FillInTable(periods, day, EarlyFinish);
                Array.Resize(ref periods, 9);
                periods[7] = new TimetablePeriod(DateTimespan(day, RecessPeriods[position].Start), DateTimespan(day, RecessPeriods[position].End), RecessPeriods[position].description, "Recess", "", false, 7);
                periods[8] = new TimetablePeriod(DateTimespan(day, LunchPeriods[position].Start), DateTimespan(day, LunchPeriods[position].End), LunchPeriods[position].description, LunchPeriods[position].description, "", false, 8);
                periods    = OverlapCheck(periods);
                return(periods.ToList());
            }
        }
Beispiel #3
0
        //Fix missing periods
        static public TimetablePeriod[] FillInTable(TimetablePeriod[] periods, DateTime day, bool Earlyfinish)
        {
            if (periods.Length < 7)
            {
                throw new NotImplementedException();
            }

            int position = 0;

            if (Earlyfinish)
            {
                position = 2;
            }
            else if (day.DayOfWeek == DayOfWeek.Wednesday)
            {
                position = 1;
            }

            for (int i = 0; i < 7; i++)
            {
                if (string.IsNullOrWhiteSpace(periods[i].Classcode))
                {
                    TimetablePeriod tmp = new TimetablePeriod
                    {
                        Start       = DateTimespan(day, DefaultPeriods[i, position].Start),
                        End         = DateTimespan(day, DefaultPeriods[i, position].End),
                        Classcode   = DefaultPeriods[i, position].description.Contains("period") ? "P" + DefaultPeriods[i, position].description.Last() : DefaultPeriods[i, position].description,
                        Description = DefaultPeriods[i, position].description,
                        period      = i,
                        Roomcode    = "",
                        GotoPeriod  = DefaultPeriods[i, position].description == "No Form" ? false : true
                    };
                    periods[i] = tmp;
                }
                else if (Earlyfinish)
                {
                    periods[i].Start = DateTimespan(day, DefaultPeriods[i, position].Start);
                    periods[i].End   = DateTimespan(day, DefaultPeriods[i, position].End);
                }
            }

            return(periods);
        }
Beispiel #4
0
        public static EPRcollection ProcessEPR(string EPRstr)
        {
            //Make engine ignore case sensitivity
            //day\s*([0 - 9]0 ?)[\s:]*(\d{1,2})\s*\/\s*(\d{1,2})\s*\/\s*(\d{4,})  //Bullentin day parsing - Bulletin Day 9: 27/9/2019
            //room\s{0,4}(? i) changes(?:.|\n)*?<tbody>((?:.|\n)*?)<\/tbody> //Locates the table for room changes
            //replacement\s{0,4}(?i)teachers(?:.|\n)*?<tbody.*?>((?:.|\n)*?)<\/tbody.*?> // Locates the teacher replacement table
            //(<tr>[\s\S]*?<\/tr>) //Get the row
            //<[^\/]*>\s*([\s\S]*?)\s*?<\/ //Gets the content of each coloumn excluding the html only getting innner most html


            EPRcollection EPR = new EPRcollection(new DateTime(), new Dictionary <string, TimetablePeriod>(), 0);


            ////Debug function to only run during debug mode
            //if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed == false)
            //{
            //    Console.WriteLine("EPR Debug mode on!");
            //    EPR.Date = DateTime.Now;
            //    EPR.Day = DateTime.Now.DayOfWeek == DayOfWeek.Monday ? 2 : 0;
            //    TimetablePeriod tt = new TimetablePeriod();
            //    tt.TeacherChange = true;
            //    tt.RoomChange = true;
            //    tt.Teacher = "New Teacher";
            //    tt.Roomcode = "3TEST3";
            //    for (int i = 0; i < 7; i++)
            //    {
            //        EPR.Changes.Add("122MM4-"+i, tt);
            //    }
            //    tt.Teacher = "New Teacher2";
            //    tt.Roomcode = "5TEST5";
            //    for (int i = 0; i < 7; i++)
            //    {
            //        EPR.Changes.Add("122MS1-"+i, tt);
            //    }
            //    return EPR;
            //}

            bool ErrorsParsing = false;

            try
            {
                EPRstr = Regex.Replace(EPRstr, @"\t|\n|\r", "");
                Match header = Regex.Match(EPRstr, @"day\s*?([0-9]0?)[\s:]*(\d{1,2})\s*\/\s*(\d{1,2})\s*\/\s*(\d{4,})", RegexOptions.IgnoreCase);
                if (!header.Success)
                {
                    throw new Exception("No Header located");
                }
                EPR.Day = Convert.ToInt16(header.Groups[1].Value); //Day of EPR
                if (EPR.Day > 10)
                {
                    throw new Exception("Header day exceeded range");
                }

                EPR.Date = new DateTime(Convert.ToInt16(header.Groups[4].Value), Convert.ToInt16(header.Groups[3].Value), Convert.ToInt16(header.Groups[2].Value)); //Date of EPR

                Match RoomChangeTable = Regex.Match(EPRstr, @"room\s{0,4}changes(?:.|\n)*?<tbody>((?:.|\n)*?)<\/tbody>", RegexOptions.IgnoreCase);
                if (RoomChangeTable.Success)
                {
                    MatchCollection Rows = Regex.Matches(RoomChangeTable.Groups[1].Value, @"<tr>([\s\S]*?)<\/tr>");

                    MatchCollection columnfirst     = Regex.Matches(Rows[0].Value, @"<[^\/]*>\s*([^<>]+?)\s*<\/", RegexOptions.IgnoreCase);
                    int             PeriodColoumn   = 0;
                    int             ClassColoumn    = 2;
                    int             TeacherColoumn  = 3;
                    int             RoomcodeColoumn = 5;
                    for (int i = 0; i < columnfirst.Count; i++)
                    {
                        if (columnfirst[i].Groups[1].Value.ToLower().Contains("period"))
                        {
                            PeriodColoumn = i;
                        }
                        else if (columnfirst[i].Groups[1].Value.Trim().ToLower().StartsWith("class"))
                        {
                            ClassColoumn = i;
                        }
                        else if (columnfirst[i].Groups[1].Value.Trim().ToLower().StartsWith("teacher"))
                        {
                            TeacherColoumn = i;
                        }
                        else if (columnfirst[i].Groups[1].Value.ToLower().Contains("new room"))
                        {
                            RoomcodeColoumn = i;
                        }
                    }

                    //Ignore first row since its just the headers
                    for (int i = 1; i < Rows.Count; i++)
                    {
                        try
                        {
                            //There shouldn't ever be clashes on first run
                            MatchCollection columns = Regex.Matches(Rows[i].Value, @"<[^\/]*>\s*([^<>]+?)\s*<\/", RegexOptions.IgnoreCase);
                            if (string.IsNullOrWhiteSpace(columns[ClassColoumn].Groups[1].Value) || EPR.Changes.ContainsKey(columns[ClassColoumn].Groups[1].Value + "-" + Convert.ToInt32(columns[PeriodColoumn].Groups[1].Value)))
                            {
                                continue;
                            }
                            TimetablePeriod period = new TimetablePeriod()
                            {
                                period     = Convert.ToInt32(columns[PeriodColoumn].Groups[1].Value),
                                Classcode  = columns[ClassColoumn].Groups[1].Value,
                                Teacher    = columns[TeacherColoumn].Groups[1].Value,
                                Roomcode   = columns[RoomcodeColoumn].Groups[1].Value,
                                RoomChange = true
                            };
                            EPR.Changes.Add(period.Classcode + "-" + period.period, period);
                        }
                        catch
                        {
                            ErrorsParsing = true;
                        }
                    }
                }

                Match TeacherChangeTable = Regex.Match(EPRstr, @"replacement\s{0,4}(?i)teachers(?:.|\n)*?<tbody.*?>((?:.|\n)*?)<\/tbody.*?>", RegexOptions.IgnoreCase);
                if (TeacherChangeTable.Success)
                {
                    MatchCollection Rows = Regex.Matches(TeacherChangeTable.Groups[1].Value, @"<tr>([\s\S]*?)<\/tr>");

                    //Will make coloum title to its respective coloumns
                    MatchCollection columnfirst     = Regex.Matches(Rows[0].Value, @"<[^\/]*>\s*([^<>]+?)\s*<\/", RegexOptions.IgnoreCase);
                    int             PeriodColoumn   = 0;
                    int             ClassColoumn    = 2;
                    int             TeacherColoumn  = 5;
                    int             RoomcodeColoumn = 1;
                    for (int i = 0; i < columnfirst.Count; i++)
                    {
                        if (columnfirst[i].Groups[1].Value.ToLower().Contains("period"))
                        {
                            PeriodColoumn = i;
                        }
                        else if (columnfirst[i].Groups[1].Value.Trim().ToLower().StartsWith("class"))
                        {
                            ClassColoumn = i;
                        }
                        else if (columnfirst[i].Groups[1].Value.Trim().ToLower().StartsWith("replacement teacher"))
                        {
                            TeacherColoumn = i;
                        }
                        else if (columnfirst[i].Groups[1].Value.ToLower().Contains("room"))
                        {
                            RoomcodeColoumn = i;
                        }
                    }

                    //Ignore first row since its just the headers
                    for (int i = 1; i < Rows.Count; i++)
                    {
                        try
                        {
                            MatchCollection columns = Regex.Matches(Rows[i].Value, @"<[^\/]*>\s*([^<>]+?)\s*<\/", RegexOptions.IgnoreCase);
                            if (string.IsNullOrWhiteSpace(columns[ClassColoumn].Groups[1].Value))
                            {
                                continue;
                            }
                            int PeriodTmp = Convert.ToInt16(columns[PeriodColoumn].Groups[1].Value);
                            if (EPR.Changes.ContainsKey(columns[ClassColoumn].Groups[1].Value + "-" + PeriodTmp))
                            {
                                TimetablePeriod roomchangeditem = EPR.Changes[columns[ClassColoumn].Groups[1].Value + "-" + PeriodTmp];
                                roomchangeditem.Teacher       = columns[TeacherColoumn].Groups[1].Value;
                                roomchangeditem.TeacherChange = true;
                                EPR.Changes[columns[ClassColoumn].Groups[1].Value + "-" + PeriodTmp] = roomchangeditem;
                            }
                            else
                            {
                                TimetablePeriod period = new TimetablePeriod()
                                {
                                    period        = PeriodTmp,
                                    Classcode     = columns[ClassColoumn].Groups[1].Value,
                                    Teacher       = columns[TeacherColoumn].Groups[1].Value,
                                    Roomcode      = columns[RoomcodeColoumn].Groups[1].Value,
                                    TeacherChange = true
                                };
                                EPR.Changes.Add(period.Classcode + "-" + period.period, period);
                            }
                        }
                        catch
                        {
                            ErrorsParsing = true;
                        }
                    }
                }
                EPR.Errors = ErrorsParsing;
                return(EPR);
            }
            catch
            {
                //Throw generic exception
                throw new Exception();
            }
        }