示例#1
0
    def RetrieveFrequencyStatsForStop(stop_id, stoptimedict, start_sec,
                                      end_sec):
        '''For a given stop, query the dictionary
        and return the NumTrips, NumTripsPerHr, MaxWaitTime, and AvgHeadway given a
        specific route_id and direction. If snap to nearest five minutes is true, then
        this function will return headways snapped to the closest 5 minute interval.'''
        # Make a list of stop_times
        StopTimesAtThisPoint = []
        try:
            for trip in stoptimedict[stop_id]:
                StopTimesAtThisPoint.append(trip[1])
        except KeyError:
            pass
        StopTimesAtThisPoint.sort()

        # Calculate the number of trips
        NumTrips = len(StopTimesAtThisPoint)
        NumTripsPerHr = round(
            float(NumTrips) / ((end_sec - start_sec) / 3600), 2)
        # Get the max wait time and the average headway
        MaxWaitTime = BBB_SharedFunctions.CalculateMaxWaitTime(
            StopTimesAtThisPoint, start_sec, end_sec)
        if snap_to_nearest_5_minutes:
            round_to = 5
        else:
            round_to = None
        AvgHeadway = BBB_SharedFunctions.CalculateAvgHeadway(
            StopTimesAtThisPoint, round_to)
        return NumTrips, NumTripsPerHr, MaxWaitTime, AvgHeadway
示例#2
0
    def RetrieveStatsForStop(stop_id, rtdirtuple):
        '''For a given stop, query the stoptimedict {stop_id: [[trip_id, stop_time]]}
        and return the NumTrips, NumTripsPerHr, MaxWaitTime, and AvgHeadway given a
        specific route_id and direction'''

        try:
            stoptimedict = stoptimedict_rtdirpair[rtdirtuple]
        except KeyError:
            # We will get a KeyError if there were no trips found for the route/direction
            # pair, which usually happens if the wrong SQL database was selected.
            stoptimedict = {}

        # Make a list of stop_times
        StopTimesAtThisPoint = []
        try:
            for trip in stoptimedict[stop_id]:
                StopTimesAtThisPoint.append(trip[1])
        except KeyError:
            pass
        StopTimesAtThisPoint.sort()

        # Calculate the number of trips
        NumTrips = len(StopTimesAtThisPoint)
        NumTripsPerHr = float(NumTrips) / TimeWindowLength

        # Get the max wait time and the average headway
        MaxWaitTime = BBB_SharedFunctions.CalculateMaxWaitTime(StopTimesAtThisPoint, start_sec, end_sec)
        AvgHeadway = BBB_SharedFunctions.CalculateAvgHeadway(StopTimesAtThisPoint)

        return NumTrips, NumTripsPerHr, MaxWaitTime, AvgHeadway