Exemplo n.º 1
0
        public static LocatedLine LocateBusesFromLine(Line line)
        {
            CheckIfNoBuses(line);

            var locatedLine = new LocatedLine(line.Number, line.LineDirection);

            for (int i = 0; i < line.Stops.Count; i++)
            {
                if (line.Stops[i].IncomingBuses.Count != 0)
                {
                    foreach (var bus in line.Stops[i].IncomingBuses)
                    {
                        var probableBus = new LocatedBus(bus.Destination, line.Stops[i].BusStopId, line.Stops[i].BusStopName, line.Stops[i].Zone, bus.EstimatedTime, bus.WaitingTime);
                        if (locatedLine.LocatedBuses.Count == 0)
                        {
                            locatedLine.LocatedBuses.Add(probableBus);
                        }
                        else
                        {
                            LocatedBus busToAdd = null;
                            foreach (var previouslyLocatedBus in locatedLine.LocatedBuses)
                            {
                                if (!AreSameBus(previouslyLocatedBus, probableBus, line))
                                {
                                    busToAdd = probableBus;
                                }
                            }
                            if (busToAdd != null)
                            {
                                locatedLine.LocatedBuses.Add(busToAdd);
                            }
                        }
                    }
                }
            }

            return(locatedLine);
        }
Exemplo n.º 2
0
 private static bool AreSameBus(LocatedBus bus1, LocatedBus bus2, Line line)
 {
     return(bus1.WaitingTime <= bus2.WaitingTime ? true : false);
 }