Return the sorted StopTimes for this trip.
487965
def stop_sequence(self):
    """"""
    return sorted(
      self.stop_times(),
      key=lambda x:int(x.get('stop_sequence'))
    )
1012983
public static Collection<TimeSlot> calculateAvailableSots(Collection<TimeInterval> takenTimeSlots, Date date, int intervalSeconds,Time startTime, Time endTime)
   {
      Day day = new Day(date);
      
      Collection<TimeSlot> allTimeSlots = calculateTimeSots(day,intervalSeconds,startTime, endTime);
      
      if(takenTimeSlots == null || takenTimeSlots.isEmpty())
         return allTimeSlots;
      
      TimeSlot timeSlot = null;
      TreeSet<TimeSlot> availableSlots = new TreeSet<TimeSlot>();
      for (Iterator<TimeSlot> i = allTimeSlots.iterator(); i.hasNext();)
      {
         timeSlot =  i.next();
         
         if(!takenTimeSlots.contains(timeSlot))
         {
            availableSlots.add(timeSlot);
         }         
      }
      return availableSlots;
   }
1258278
def get_next_departures(stop, filter_line=None, num_line_groups=1, verbose=False):
    

    # Get departures table from online service
    # (great: we don't have to iterate over multiple pages).

    url = BVG_URL_PAT % stop
    if verbose:
        print('- Fetching table for URL "%s".' % url)
    try:
        tables = pd.read_html(url.encode('utf-8'))
    except urllib.error.URLError:
        msg = 'Not connected to the internet?'
        termcolor.cprint(msg, 'red', attrs=['bold'])
        sys.exit(1)
    except ValueError:
        return []
    table = tables[0]
    table.columns = ['Departure', 'Line', 'Destination']

    if verbose:
        print('- Got table with %d entries for "%s".' % (len(table), stop))

    # Cleanup

    # Drop entries with '*' in column Departure...
    # (causes trouble when resulting in an empty table!)
    # table = table[table.Departure.apply(lambda row: " *" not in row)]
    # So, instead remove '*' in column Departure...
    table.is_copy = False # prevents SettingWithCopyWarning
    table.Departure = table.apply(
        lambda row: re.sub('\s*\*\s*', '', row.Departure), axis=1)

    # Replace regex ' +' with ' ' in column Line...
    table.Line = table.apply(lambda row: re.sub(' +', ' ', row.Line), axis=1)

    # Filter desired number of unique combinations of Line and Destination column.
    indices = []
    for i in range(num_line_groups):
        try:
            indices += sorted([tab.index.values[i] 
                for line_dest, tab in table.groupby(['Line', 'Destination'])])
        except IndexError:
            break
    table = table[table.index.map(lambda x: x in indices)]

    # Insert a left-most column with minutes and seconds from now 
    # until the departure time.
    table.insert(0, "Wait", table.Departure.apply(lambda dep: wait_time(dep)))

    # Filter on desired lines only
    if filter_line:
        table = table[table.Line.apply(
            lambda cell: filter_line.lower().encode('utf-8') in cell.lower())]

    return table
1006586
def round_trip_time(self):
        """"""
        # This override is for unittesting only!
        if self._address in self._host_to_round_trip_time:
            return self._host_to_round_trip_time[self._address]

        return self._round_trip_time
915795
def _entries_sorted(self):
        """"""
        return sorted(self.entries.values(), key=lambda e: (e.path, e.stage))
931595
public Iterable<StopTime> getInterpolatedStopTimesForTrip (String trip_id) throws FirstAndLastStopsDoNotHaveTimes {
        // clone stop times so as not to modify base GTFS structures
        StopTime[] stopTimes = StreamSupport.stream(getOrderedStopTimesForTrip(trip_id).spliterator(), false)
                .map(st -> st.clone())
                .toArray(i -> new StopTime[i]);

        // avoid having to make sure that the array has length below.
        if (stopTimes.length == 0) return Collections.emptyList();

        // first pass: set all partially filled stop times
        for (StopTime st : stopTimes) {
            if (st.arrival_time != Entity.INT_MISSING && st.departure_time == Entity.INT_MISSING) {
                st.departure_time = st.arrival_time;
            }

            if (st.arrival_time == Entity.INT_MISSING && st.departure_time != Entity.INT_MISSING) {
                st.arrival_time = st.departure_time;
            }
        }

        // quick check: ensure that first and last stops have times.
        // technically GTFS requires that both arrival_time and departure_time be filled at both the first and last stop,
        // but we are slightly more lenient and only insist that one of them be filled at both the first and last stop.
        // The meaning of the first stop's arrival time is unclear, and same for the last stop's departure time (except
        // in the case of interlining).

        // it's fine to just check departure time, as the above pass ensures that all stop times have either both
        // arrival and departure times, or neither
        if (stopTimes[0].departure_time == Entity.INT_MISSING || stopTimes[stopTimes.length - 1].departure_time == Entity.INT_MISSING) {
            throw new FirstAndLastStopsDoNotHaveTimes();
        }

        // second pass: fill complete stop times
        int startOfInterpolatedBlock = -1;
        for (int stopTime = 0; stopTime < stopTimes.length; stopTime++) {

            if (stopTimes[stopTime].departure_time == Entity.INT_MISSING && startOfInterpolatedBlock == -1) {
                startOfInterpolatedBlock = stopTime;
            }
            else if (stopTimes[stopTime].departure_time != Entity.INT_MISSING && startOfInterpolatedBlock != -1) {
                throw new RuntimeException("Missing stop times not supported.");
            }
        }

        return Arrays.asList(stopTimes);
    }
26766
def GetTimeSecs(self):
    """"""
    if self.arrival_secs != None:
      return self.arrival_secs
    elif self.departure_secs != None:
      return self.departure_secs
    else:
      return None
1297622
def _GetTripIndex(self, schedule=None):
    
    trip_index = []
    for trip, sequence in self._GetTripSequence(schedule):
      for index, st in enumerate(trip.GetStopTimes()):
        if st.stop_sequence == sequence:
          trip_index.append((trip, index))
          break
      else:
        raise RuntimeError("stop_sequence %d not found in trip_id %s" %
                           sequence, trip.trip_id)
    return trip_index
185745
def GetFrequencyStartTimes(self):
    """"""
    start_times = []
    # for each headway period of the trip
    for freq_tuple in self.GetFrequencyTuples():
      (start_secs, end_secs, headway_secs) = freq_tuple[0:3]
      # reset run secs to the start of the timeframe
      run_secs = start_secs
      while run_secs < end_secs:
        start_times.append(run_secs)
        # increment current run secs by headway secs
        run_secs += headway_secs
    return start_times
327444
def ImportStopTimes(self, stoptimes_file):
    ""
    for line, strli, direction, seq, stoptime_id, drive_secs, wait_secs in \
    ReadCSV(stoptimes_file,
            ['LI_NR', 'STR_LI_VAR', 'LI_RI_NR', 'LI_LFD_NR',
             'FGR_NR', 'FZT_REL', 'HZEIT']):
      pattern = self.patterns[u'Pat.%s.%s.%s' % (line, strli, direction)]
      stoptimes = pattern.stoptimes.setdefault(stoptime_id, [])
      seq = int(seq) - 1
      drive_secs = int(drive_secs)
      wait_secs = int(wait_secs)
      assert len(stoptimes) == seq  # fails if seq not in order
      stoptimes.append((drive_secs, wait_secs))
965013
def queue_get_stoppable(self, q):
        
        while not self.stopped():
            try:
                return q.get(timeout=5)
            except queue.Empty:
                pass
1343084
def get_times():
    
    if f.root.stopped:
        return copy.deepcopy(f.root.times)
    else:
        t = timer()
        times = collapse.collapse_times()
        f.root.self_cut += timer() - t
        return times
623943
def get_times_covered_by_files(self):
        
        times = segments.segmentlist([])
        for entry in self:
            times.extend(entry.segment_list)
        times.coalesce()
        return times
16098
def GetFrequencyStopTimes(self, problems=None):
    
    stoptimes_list = [] # list of stoptime lists to be returned
    stoptime_pattern = self.GetStopTimes()
    first_secs = stoptime_pattern[0].arrival_secs # first time of the trip
    stoptime_class = self.GetGtfsFactory().StopTime
    # for each start time of a headway run
    for run_secs in self.GetFrequencyStartTimes():
      # stop time list for a headway run
      stoptimes = []
      # go through the pattern and generate stoptimes
      for st in stoptime_pattern:
        arrival_secs, departure_secs = None, None # default value if the stoptime is not timepoint
        if st.arrival_secs != None:
          arrival_secs = st.arrival_secs - first_secs + run_secs
        if st.departure_secs != None:
          departure_secs = st.departure_secs - first_secs + run_secs
        # append stoptime
        stoptimes.append(stoptime_class(problems=problems, stop=st.stop,
                                        arrival_secs=arrival_secs,
                                        departure_secs=departure_secs,
                                        stop_headsign=st.stop_headsign,
                                        pickup_type=st.pickup_type,
                                        drop_off_type=st.drop_off_type,
                                        shape_dist_traveled= \
                                            st.shape_dist_traveled,
                                        stop_sequence=st.stop_sequence,
                                        timepoint=st.timepoint))
      # add stoptimes to the stoptimes_list
      stoptimes_list.append ( stoptimes )
    return stoptimes_list
850244
def data(self) -> Dict[str, Any]:
        """"""
        data: Dict[str, Any] = {}
        data["station"] = self.station
        data["stationId"] = self.station_id
        data["filter"] = self.products_filter

        journeys = []
        for j in sorted(self.journeys, key=lambda k: k.real_departure)[
            : self.max_journeys
        ]:
            journeys.append(
                {
                    "product": j.product,
                    "number": j.number,
                    "trainId": j.train_id,
                    "direction": j.direction,
                    "departure_time": j.real_departure_time,
                    "minutes": j.real_departure,
                    "delay": j.delay,
                    "stops": [s["station"] for s in j.stops],
                    "info": j.info,
                    "info_long": j.info_long,
                    "icon": j.icon,
                }
            )
        data["journeys"] = journeys
        return data
731869
def GetStopTimes(self, problems=None):
    """"""
    # In theory problems=None should be safe because data from database has been
    # validated. See comment in _LoadStopTimes for why this isn't always true.
    cursor = self._schedule._connection.cursor()
    cursor.execute(
        'SELECT arrival_secs,departure_secs,stop_headsign,pickup_type,'
        'drop_off_type,shape_dist_traveled,stop_id,stop_sequence,timepoint '
        'FROM stop_times '
        'WHERE trip_id=? '
        'ORDER BY stop_sequence', (self.trip_id,))
    stop_times = []
    stoptime_class = self.GetGtfsFactory().StopTime
    if problems is None:
      # TODO: delete this branch when StopTime.__init__ doesn't need a
      # ProblemReporter
      problems = problems_module.default_problem_reporter
    for row in cursor.fetchall():
      stop = self._schedule.GetStop(row[6])
      stop_times.append(stoptime_class(problems=problems,
                                       stop=stop,
                                       arrival_secs=row[0],
                                       departure_secs=row[1],
                                       stop_headsign=row[2],
                                       pickup_type=row[3],
                                       drop_off_type=row[4],
                                       shape_dist_traveled=row[5],
                                       stop_sequence=row[7],
                                       timepoint=row[8]))
    return stop_times
34821
def ValidateChildren(self, problems):
    """"""
    assert self._schedule, "Trip must be in a schedule to ValidateChildren"
    # TODO: validate distance values in stop times (if applicable)

    self.ValidateNoDuplicateStopSequences(problems)
    stoptimes = self.GetStopTimes(problems)
    stoptimes.sort(key=lambda x: x.stop_sequence)
    self.ValidateTripStartAndEndTimes(problems, stoptimes)
    self.ValidateStopTimesSequenceHasIncreasingTimeAndDistance(problems,
                                                               stoptimes)
    self.ValidateShapeDistTraveledSmallerThanMaxShapeDistance(problems,
                                                              stoptimes)
    self.ValidateDistanceFromStopToShape(problems, stoptimes)
    self.ValidateFrequencies(problems)