コード例 #1
0
def get_duration_to_point(ride, point):
    assert point.ride == ride
    result = 0
    ride_points = ride.points.all()
    for i, p in enumerate(ride_points):
        if i > 0:
            prev_p = ride_points[i-1]
            result += get_shortest_duration(prev_p.lat, prev_p.lon, p.lat, p.lon)

        if p == point:
            break

    logging.info("[get_duration_to_point] result = '%s'" % result)
    return result
コード例 #2
0
def get_duration_to_point(ride, point):
    assert point.ride == ride
    result = 0
    ride_points = ride.points.all()
    for i, p in enumerate(ride_points):
        if i > 0:
            prev_p = ride_points[i - 1]
            result += get_shortest_duration(prev_p.lat, prev_p.lon, p.lat,
                                            p.lon)

        if p == point:
            break

    logging.info("[get_duration_to_point] result = '%s'" % result)
    return result
コード例 #3
0
def get_order_msg(ride, order):
    t = get_template("passenger_notification_msg.html")
    pickup_time = None
    position = get_position_for_order(order)
    if position:
        logging.info("use actual position for pickup estimate")
        duration = get_shortest_duration(position.lat,
                                         position.lon,
                                         order.from_lat,
                                         order.from_lon,
                                         sensor=True)
        logging.info("[get_order_msg] duration = '%s'" % duration)

        if duration:
            pickup_time = duration / 60

    if not pickup_time:
        if ride.pickup_estimate:  # this is an estimate from the station
            duration = get_duration_to_point(ride, order.pickup_point)
            pickup_time = (duration / 60) + ride.pickup_estimate
        else:  # no estimate given, use algo values
            if order.pickup_point.stop_time > default_tz_now():
                td = order.pickup_point.stop_time - default_tz_now()
                pickup_time = td.seconds / 60
            else:
                pickup_time = 1  # 'now'

    current_lang = translation.get_language()

    translation.activate(order.language_code)
    template_data = {
        'pickup_time': pickup_time,
        'station_name': ride.station.name,
        'taxi_number': ride.taxi_number
    }

    msg = t.render(Context(template_data))
    translation.activate(current_lang)

    logging.info(u"order message %s" % msg)

    return msg
コード例 #4
0
def get_order_msg(ride, order):
    t = get_template("passenger_notification_msg.html")
    pickup_time = None
    position = get_position_for_order(order)
    if position:
        logging.info("use actual position for pickup estimate")
        duration = get_shortest_duration(position.lat, position.lon, order.from_lat, order.from_lon, sensor=True)
        logging.info("[get_order_msg] duration = '%s'" % duration)

        if duration:
            pickup_time = duration / 60

    if not pickup_time:
        if ride.pickup_estimate: # this is an estimate from the station
            duration = get_duration_to_point(ride, order.pickup_point)
            pickup_time = (duration / 60) + ride.pickup_estimate
        else: # no estimate given, use algo values
            if order.pickup_point.stop_time > default_tz_now():
                td = order.pickup_point.stop_time - default_tz_now()
                pickup_time = td.seconds / 60
            else:
                pickup_time = 1 # 'now'

    current_lang = translation.get_language()

    translation.activate(order.language_code)
    template_data = {'pickup_time': pickup_time,
                     'station_name': ride.station.name,
                     'taxi_number': ride.taxi_number
                     }

    msg = t.render(Context(template_data))
    translation.activate(current_lang)

    logging.info(u"order message %s" % msg)

    return msg