Ejemplo n.º 1
0
        public DaySchedule Clone()
        {
            DaySchedule result = new DaySchedule();

            result.MergeByRoute(this);
            return(result);
        }
Ejemplo n.º 2
0
        public void AddServiceDay(ServiceDay day, DaySchedule schedule)
        {
            if (schedule == null || schedule.IsEmpty)
            {
                return;
            }
            ServiceDay totalDay            = day;
            List <int> psuedoIdenticalDays = new List <int>();

            for (int i = 0; i < DaySchedules.Count; i++)
            {
                if (DaySchedules[i].IsIdenticalToByTripId(schedule))
                {
                    TechnicalDays[i] |= day;
                    Days[i]          |= day;
                    return;
                }
                else if (DaySchedules[i].IsIdenticalToByTime(schedule))
                {
                    totalDay |= TechnicalDays[i];
                    psuedoIdenticalDays.Add(i);
                }
            }
            foreach (var ind in psuedoIdenticalDays)
            {
                Days[ind] = totalDay;
            }
            TechnicalDays.Add(day);
            Days.Add(totalDay);
            DaySchedules.Add(schedule);
        }
Ejemplo n.º 3
0
 public void MergeByRoute(WeekSchedule other)
 {
     ServiceDay[]  days = { ServiceDay.Monday, ServiceDay.Tuesday, ServiceDay.Wednesday, ServiceDay.Thursday, ServiceDay.Friday, ServiceDay.Saturday, ServiceDay.Sunday, ServiceDay.ReducedWeekday };
     DaySchedule[] sch1 = new DaySchedule[8];
     DaySchedule[] sch2 = new DaySchedule[8];
     for (int i = 0; i < 8; i++)
     {
         sch1[i] = this[days[i]]?.Clone();
         sch2[i] = other[days[i]];
         if (sch1[i] == null)
         {
             if (sch2[i] != null)
             {
                 sch1[i] = sch2[i].Clone();
             }
         }
         else
         {
             if (sch2[i] != null)
             {
                 sch1[i].MergeByRoute(sch2[i]);
             }
         }
     }
     this.Days.Clear();
     this.DaySchedules.Clear();
     this.TechnicalDays.Clear();
     for (int i = 0; i < 8; i++)
     {
         this.AddServiceDay(days[i], sch1[i]);
     }
 }
Ejemplo n.º 4
0
        public bool IsIdenticalToByTripId(DaySchedule other)
        {
            List <string> ids      = GetTripIds(true);
            List <string> otherIds = other.GetTripIds(true);
            int           lastInd  = ids.Count - 1;

            while (lastInd >= 0)
            {
                if (!otherIds.Remove(ids[lastInd]))
                {
                    return(false);
                }
                ids.RemoveAt(lastInd);
                lastInd--;
            }
            return(otherIds.Count == 0);
        }
Ejemplo n.º 5
0
        public void MergeByRoute(DaySchedule other)
        {
            var newData = Data?.ToList();

            if (newData == null)
            {
                newData = new List <Tuple <string, string, Tuple <short, string, short?>[]> >();
            }
            foreach (var item in other.Data)
            {
                if (!newData.Any(itm => itm.Item1 == item.Item1 && itm.Item2 == item.Item2))
                {
                    newData.Add(item);
                }
            }
            Data          = newData.ToArray();
            TripIds       = null;
            NamesAndTimes = null;
        }
Ejemplo n.º 6
0
        public static async Task <WeekSchedule> GetScheduleForStop(string id, CancellationToken cancellationToken)
        {
            WeekSchedule result = new WeekSchedule();

            for (int i = 0; i < 8; i++)
            {
                DaySchedule daySched = new DaySchedule();
                ServiceDay  day      = (ServiceDay)(int)Math.Pow(2, i);
                DateTime?   date     = HelperFunctions.DateForServiceDay(day);
                if (date.HasValue)
                {
                    daySched.LoadFromVerboseString(await ApiLayer.SendRequest("schedule-for-stop/" + id, new Dictionary <string, string>()
                    {
                        ["date"] = date.Value.ToString("yyyy-MM-dd")
                    }, false, cancellationToken), id);
                    result.AddServiceDay(day, daySched);
                }
            }
            return(result);
        }
Ejemplo n.º 7
0
 public void Deformat(CompactFormatReader reader, string stopId)
 {
     Stop = stopId;
     Days.Clear();
     TechnicalDays.Clear();
     DaySchedules.Clear();
     CompactFormatReader[] items;
     while ((items = reader.Next()) != null)
     {
         ServiceDay  nextDay          = (ServiceDay)items[0].ReadInt();
         ServiceDay  nextTechnicalDay = (ServiceDay)items[1].ReadInt();
         DaySchedule schedule         = new DaySchedule()
         {
             Stop = stopId
         };
         schedule.Deformat(items[2]);
         Days.Add(nextDay);
         TechnicalDays.Add(nextTechnicalDay);
         DaySchedules.Add(schedule);
     }
 }