예제 #1
0
def stopRouteRequest(stopID, routeID, devStoreKey):
    logging.debug("Stop/Route Request started")

    # got fetch all of the data for this stop
    sid = stopID + str(devStoreKey) + str(time.time())
    routes = asynch.aggregateBusesAsynch(sid,stopID,routeID)
    if routes is None:
        response_dict = {'status':'0',
                         'timestamp':api_utils.getLocalTimestamp(),
                         'info':'No routes found'
                        }
        return response_dict

    response_dict = {'status':'0',
                     'timestamp':api_utils.getLocalTimestamp()
                     }

    # there should only be results. we assume the results are sorted by time
    stop_dict = {'stopID':stopID,}
    route_results = []
    for r in routes:
        if not api_utils.inthepast(r.arrivalTime):
            route_results.append(dict({'routeID':r.routeID,
                          'vehicleID':'unknown',
                          'minutes':str(api_utils.computeCountdownMinutes(r.arrivalTime)),
                          'arrivalTime':r.arrivalTime,
                          'destination':r.destination,
                          }))

    # add the populated stop details to the response
    stop_dict.update({'route':route_results})
    response_dict.update({'stop':stop_dict})

    return response_dict
예제 #2
0
def stopRequest(stopID, devKey):

    response_dict = None

    # look for memcahced results
    results_cache_key = 'stopRequest::%s' % stopID
    response_dict = memcache.get(results_cache_key)

    if( response_dict is None ):
        logging.debug("getarrivals : cache miss")
        response_dict = {'status':'0',
                         'timestamp':api_utils.getLocalTimestamp()
                         }

        # unique key to track this request
        t = str(time.time()).split('.')[0]
        sid = '%s::%s::%s' % (stopID,devKey,t)

        # fetch all of the data for this stop
        routes = asynch.aggregateBusesAsynch(sid,stopID)
        if routes is None or len(routes) == 0:
            response_dict['status'] = '-1'
            response_dict['description'] = 'No routes found for this stop'
            response_dict['stopID'] = stopID
            return response_dict

        # get the stop details
        stop_dict = {'stopID':stopID,}

        # take the first 10 results. we assume the results are sorted by time
        #route_results = sorted(route_results, key=attrgetter('time'))
        route_results = []
        for r in routes:
            minutes = api_utils.computeCountdownMinutes(r.arrivalTime)
            if minutes > 0:
                route_results.append(dict({'routeID':r.routeID,
                              'vehicleID':'unknown',
                              'minutes':str(minutes),
                              'arrivalTime':r.arrivalTime,
                              'destination':r.destination,
                              }))

        # add the populated stop details to the response
        stop_dict.update({'route':route_results});
        response_dict.update({'stop':stop_dict})

        # cleanup the results
        #asynch.clean(sid)

        # stash results in the cache
        memcache.set(results_cache_key,response_dict,60)

    else:
        logging.debug('getarrivals : cash hit')
        response_dict['cached'] = True

    return response_dict
예제 #3
0
def stopRequest(stopID, devStoreKey):

    logging.debug("Stop Request started")
    response_dict = {'status':'0',
                     'timestamp':utils.getLocalTimestamp()
                     }    
                     
    # unique key to track this request
    t = str(time.time()).split('.')[0]
    sid = stopID + str(devStoreKey) + t

    # got fetch all of the data for this stop
    routes = asynch.aggregateBusesAsynch(sid,stopID)
    if routes is None or len(routes) == 0:
        response_dict['status'] = '-1'
        response_dict['description'] = 'No routes found for this stop'
        response_dict['stopID'] = stopID
        return response_dict

    # get the stop details
    stop_dict = {'stopID':stopID,}
    
    # take the first 10 results. we assume the results are sorted by time
    #route_results = sorted(route_results, key=attrgetter('time'))
    route_results = []
    for r in routes:
        minutes = utils.computeCountdownMinutes(r.arrivalTime)
        if minutes > 0:
            route_results.append(dict({'routeID':r.routeID,
                          'vehicleID':'unknown',
                          'minutes':str(minutes),
                          'arrivalTime':r.arrivalTime,
                          'destination':r.destination,
                          }))            
    
    # add the populated stop details to the response
    stop_dict.update({'route':route_results});
    response_dict.update({'stop':stop_dict})
        
    # cleanup the results
    asynch.clean(sid)
    
    return response_dict
예제 #4
0
def stopRouteRequest(stopID, routeID, devStoreKey):
    logging.debug("Stop/Route Request started")

    # got fetch all of the data for this stop
    sid = stopID + str(devStoreKey) + str(time.time())
    routes = asynch.aggregateBusesAsynch(sid, stopID, routeID)
    if routes is None:
        response_dict = {
            'status': '0',
            'timestamp': api_utils.getLocalTimestamp(),
            'info': 'No routes found'
        }
        return response_dict

    response_dict = {'status': '0', 'timestamp': api_utils.getLocalTimestamp()}

    # there should only be results. we assume the results are sorted by time
    stop_dict = {
        'stopID': stopID,
    }
    route_results = []
    for r in routes:
        if not api_utils.inthepast(r.arrivalTime):
            route_results.append(
                dict({
                    'routeID':
                    r.routeID,
                    'vehicleID':
                    'unknown',
                    'minutes':
                    str(api_utils.computeCountdownMinutes(r.arrivalTime)),
                    'arrivalTime':
                    r.arrivalTime,
                    'destination':
                    r.destination,
                }))

    # add the populated stop details to the response
    stop_dict.update({'route': route_results})
    response_dict.update({'stop': stop_dict})

    return response_dict
예제 #5
0
def stopRequest(stopID, devKey):

    response_dict = None

    # look for memcahced results
    results_cache_key = 'stopRequest::%s' % stopID
    response_dict = memcache.get(results_cache_key)

    if (response_dict is None):
        logging.debug("getarrivals : cache miss")
        response_dict = {
            'status': '0',
            'timestamp': api_utils.getLocalTimestamp()
        }

        # unique key to track this request
        t = str(time.time()).split('.')[0]
        sid = '%s::%s::%s' % (stopID, devKey, t)

        # fetch all of the data for this stop
        routes = asynch.aggregateBusesAsynch(sid, stopID)
        if routes is None or len(routes) == 0:
            response_dict['status'] = '-1'
            response_dict['description'] = 'No routes found for this stop'
            response_dict['stopID'] = stopID
            return response_dict

        # get the stop details
        stop_dict = {
            'stopID': stopID,
        }

        # take the first 10 results. we assume the results are sorted by time
        #route_results = sorted(route_results, key=attrgetter('time'))
        route_results = []
        for r in routes:
            minutes = api_utils.computeCountdownMinutes(r.arrivalTime)
            if minutes > 0:
                route_results.append(
                    dict({
                        'routeID': r.routeID,
                        'vehicleID': 'unknown',
                        'minutes': str(minutes),
                        'arrivalTime': r.arrivalTime,
                        'destination': r.destination,
                    }))

        # add the populated stop details to the response
        stop_dict.update({'route': route_results})
        response_dict.update({'stop': stop_dict})

        # cleanup the results
        #asynch.clean(sid)

        # stash results in the cache
        memcache.set(results_cache_key, response_dict, 60)

    else:
        logging.debug('getarrivals : cash hit')
        response_dict['cached'] = True

    return response_dict