Beispiel #1
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)
Beispiel #2
0
def handle_accepted_ride(sender, signal_type, ride, status, **kwargs):
    from ordering.enums import RideStatus
    from ordering.models import SharedRide
    from sharing.passenger_controller import send_ride_notifications
    from sharing.station_controller import send_ride_voucher
    from fleet.fleet_manager import send_ride_point_text


    if isinstance(ride, SharedRide) and status == RideStatus.ACCEPTED:
        deferred.defer(send_ride_voucher, ride_id=ride.id)
        send_ride_notifications(ride)

        points = ride.points.all().order_by("stop_time")
        current_point = points[0]
        deferred.defer(ride_text_sentinel, ride=ride, current_point=current_point, _eta=(current_point.stop_time - timedelta(seconds=RIDE_TEXT_TIMEOUT)) )
        send_ride_point_text(ride, current_point, next_point=points[1])
Beispiel #3
0
def ride_text_sentinel(ride, current_point):
    from fleet.fleet_manager import send_ride_point_text
    logging.info(u"ride_text_sentinel: current point [%s]" % current_point)

    points = list(ride.points.all().order_by("stop_time"))
    logging.info(u"all points: %s" % points)
    if current_point == points[-1]: # this is the last point
        logging.info("current point is last")
        return # last point was announced in previous message, no need to repeat

    logging.info("current point is not last")
    next_point = None
    try: # setup sentinel for next point
        next_point = points[points.index(current_point) +1]
        deferred.defer(ride_text_sentinel, ride=ride, current_point=next_point, _eta=(next_point.stop_time - timedelta(seconds=RIDE_TEXT_TIMEOUT)) )
    except IndexError:
        pass

    current_point = current_point.fresh_copy()
    if not current_point.dispatched: # send ride text if not sent by now by position trigger
        send_ride_point_text(ride, current_point, next_point=next_point)