leaderboard/leaderboard/utils/route_manipulation.py
def downsample_route(route, sample_factor):
    """
    Downsample the route by some factor.
    :param route: the trajectory , has to contain the waypoints and the road options
    :param sample_factor: Maximum distance between samples
    :return: returns the ids of the final route that can
    """

    ids_to_sample = []
    prev_option = None
    dist = 0

    for i, point in enumerate(route):
        curr_option = point[1]

        # Lane changing
        if curr_option in (RoadOption.CHANGELANELEFT, RoadOption.CHANGELANERIGHT):
            ids_to_sample.append(i)
            dist = 0

        # When road option changes
        elif prev_option != curr_option and prev_option not in (RoadOption.CHANGELANELEFT, RoadOption.CHANGELANERIGHT):
            ids_to_sample.append(i)
            dist = 0

        # After a certain max distance
        elif dist > sample_factor:
            ids_to_sample.append(i)
            dist = 0

        # At the end
        elif i == len(route) - 1:
            ids_to_sample.append(i)
            dist = 0

        # Compute the distance traveled
        else:
            curr_location = point[0].location
            prev_location = route[i-1][0].location
            dist += curr_location.distance(prev_location)

        prev_option = curr_option

    return ids_to_sample

    Downsample the route by some factor.
    :param route: the trajectory , has to contain the waypoints and the road options
    :param sample_factor: Maximum distance between samples
    :return: returns the ids of the final route that can
    
Downsample the route by some factor.
Downsample the route by some factor .
def downsample_route(route, sample_factor):
    ids_to_sample = []
    prev_option = None
    dist = 0
    for i, point in enumerate(route):
        curr_option = point[1]
        if curr_option in (RoadOption.CHANGELANELEFT, RoadOption.CHANGELANERIGHT):
            ids_to_sample.append(i)
            dist = 0
        elif prev_option != curr_option and prev_option not in (RoadOption.CHANGELANELEFT, RoadOption.CHANGELANERIGHT):
            ids_to_sample.append(i)
            dist = 0
        elif dist > sample_factor:
            ids_to_sample.append(i)
            dist = 0
        elif i == len(route) - 1:
            ids_to_sample.append(i)
            dist = 0
        else:
            curr_location = point[0].location
            prev_location = route[i-1][0].location
            dist += curr_location.distance(prev_location)
        prev_option = curr_option
    return ids_to_sample
def downsample_route ( route , sample_factor ) : ids_to_sample = [ ] prev_option = None dist = 0 for i , point in enumerate ( route ) : curr_option = point [ 1 ] if curr_option in ( RoadOption . CHANGELANELEFT , RoadOption . CHANGELANERIGHT ) : ids_to_sample . append ( i ) dist = 0 elif prev_option != curr_option and prev_option not in ( RoadOption . CHANGELANELEFT , RoadOption . CHANGELANERIGHT ) : ids_to_sample . append ( i ) dist = 0 elif dist > sample_factor : ids_to_sample . append ( i ) dist = 0 elif i == len ( route ) - 1 : ids_to_sample . append ( i ) dist = 0 else : curr_location = point [ 0 ] . location prev_location = route [ i - 1 ] [ 0 ] . location dist += curr_location . distance ( prev_location ) prev_option = curr_option return ids_to_sample
Downsample the route by some factor.
Downsample the route by some factor .
"""
    Downsample the route by some factor.
    :param route: the trajectory , has to contain the waypoints and the road options
    :param sample_factor: Maximum distance between samples
    :return: returns the ids of the final route that can
    """ # Lane changing # When road option changes # After a certain max distance # At the end # Compute the distance traveled
returns the ids of the final route that can
returns the ids of the final route that can
route
the trajectory , has to contain the waypoints and the road options
the trajectory has to contain the waypoints and the road options
sample_factor
Maximum distance between samples
Maximum distance between samples