示例#1
0
def update_positions(ride_positions):
    """
    Handler for fleet backends to call when taxi positions changes. Sends the signals and stores the data in memcache.
    @param ride_positions: A list of C{TaxiRidePosition}
    """
    logging.info("fleet manager: positions update %s" % [rp.ride_uuid for rp in ride_positions])
    fleet_signals.positions_update_signal.send(sender="fleet_manager", positions=ride_positions)

    for rp in ride_positions:
        key = _get_key(rp.ride_uuid)
        logging.info("getting from memcache: %s, %s" % (key, FM_MEMCACHE_NAMESPACE))
        cached_rp = memcache.get(key, namespace=FM_MEMCACHE_NAMESPACE)
        if cached_rp:
            logging.info("memcache[%s] -> %s" % (key, pickle.loads(cached_rp).__dict__))

        pickled_rp = pickle.dumps(rp)
        if cached_rp != pickled_rp: # this is a new position
            logging.info("new position received: %s[%s:%s]" % (rp.ride_uuid, rp.lat, rp.lon))
            memcache.set(key, pickled_rp, namespace=FM_MEMCACHE_NAMESPACE)

            pickmeapp_ride, shared_ride = rides_from_uuid(rp.ride_uuid)
            if pickmeapp_ride or shared_ride:
                e = RideEvent(pickmeapp_ride=pickmeapp_ride, shared_ride=shared_ride,
                              status=FleetManagerRideStatus.POSITION_CHANGED, raw_status=POSITION_CHANGED, lat=rp.lat,
                              lon=rp.lon, taxi_id=rp.taxi_id, timestamp=rp.timestamp)
                e.save()
                logging.info("new ride event created: %s" % e)
            if shared_ride:
                for point in shared_ride.points.all():
                    distance = distance_between_points(point.lat, point.lon, rp.lat, rp.lon) * 1000
                    if distance <= DISTANCE_CONSIDERED_AS_VISITED_IN_METERS:
                        point.update(visited=True)
                        logging.info("%s %s visited" % (point.get_type_display(), point.id))
        else:
            logging.info("old position received: %s[%s:%s]" % (rp.ride_uuid, rp.lat, rp.lon))
示例#2
0
 def test_geo_distance(self):
     """
     Test geo distance calculation. Taken from Jan Matuschek's article.
     """
     logging.info("\nTesting geo distance liberty to eiffel")
     # distance is about 5837 km, check 3 decimal places
     d = distance_between_points(40.6892, -74.0444, 48.8583, 2.2945)
     expected_d = 5837.413
     self.assertAlmostEqual(d, expected_d, places=3, msg="geo distance error %f (expected %f)" % (d, expected_d))
示例#3
0
 def test_geo_distance(self):
     """
     Test geo distance calculation. Taken from Jan Matuschek's article.
     """
     logging.info("\nTesting geo distance liberty to eiffel")
     # distance is about 5837 km, check 3 decimal places
     d = distance_between_points(40.6892, -74.0444, 48.8583, 2.2945)
     expected_d = 5837.413
     self.assertAlmostEqual(d,
                            expected_d,
                            places=3,
                            msg="geo distance error %f (expected %f)" %
                            (d, expected_d))
示例#4
0
def send_ride_texts(sender, signal_type, positions, **kwargs):
    from ordering.models import SharedRide, RideStatus
    from fleet.fleet_manager import  send_ride_point_text

    for position in positions:
        ride = SharedRide.by_uuid(position.ride_uuid)
        if ride and ride.status == RideStatus.ACCEPTED:
            active_points = ride.points.filter(dispatched=False).order_by("stop_time")
            if active_points:
                current_point = active_points[0]
                next_point = active_points[1] if len(active_points) > 1 else None

                if distance_between_points(position.lat, position.lon, current_point.lat, current_point.lon) < RIDE_TEXT_THRESHOLD:
                    send_ride_point_text(ride, current_point, next_point=next_point)
示例#5
0
def update_positions(ride_positions):
    """
    Handler for fleet backends to call when taxi positions changes. Sends the signals and stores the data in memcache.
    @param ride_positions: A list of C{TaxiRidePosition}
    """
    logging.info("fleet manager: positions update %s" %
                 [rp.ride_uuid for rp in ride_positions])
    fleet_signals.positions_update_signal.send(sender="fleet_manager",
                                               positions=ride_positions)

    for rp in ride_positions:
        key = _get_key(rp.ride_uuid)
        logging.info("getting from memcache: %s, %s" %
                     (key, FM_MEMCACHE_NAMESPACE))
        cached_rp = memcache.get(key, namespace=FM_MEMCACHE_NAMESPACE)
        if cached_rp:
            logging.info("memcache[%s] -> %s" %
                         (key, pickle.loads(cached_rp).__dict__))

        pickled_rp = pickle.dumps(rp)
        if cached_rp != pickled_rp:  # this is a new position
            logging.info("new position received: %s[%s:%s]" %
                         (rp.ride_uuid, rp.lat, rp.lon))
            memcache.set(key, pickled_rp, namespace=FM_MEMCACHE_NAMESPACE)

            pickmeapp_ride, shared_ride = rides_from_uuid(rp.ride_uuid)
            if pickmeapp_ride or shared_ride:
                e = RideEvent(pickmeapp_ride=pickmeapp_ride,
                              shared_ride=shared_ride,
                              status=FleetManagerRideStatus.POSITION_CHANGED,
                              raw_status=POSITION_CHANGED,
                              lat=rp.lat,
                              lon=rp.lon,
                              taxi_id=rp.taxi_id,
                              timestamp=rp.timestamp)
                e.save()
                logging.info("new ride event created: %s" % e)
            if shared_ride:
                for point in shared_ride.points.all():
                    distance = distance_between_points(point.lat, point.lon,
                                                       rp.lat, rp.lon) * 1000
                    if distance <= DISTANCE_CONSIDERED_AS_VISITED_IN_METERS:
                        point.update(visited=True)
                        logging.info("%s %s visited" %
                                     (point.get_type_display(), point.id))
        else:
            logging.info("old position received: %s[%s:%s]" %
                         (rp.ride_uuid, rp.lat, rp.lon))