Example #1
0
    def sub_end_matching(self, path):
        lgth = len(path)
        i = 0
        vmap = dict()
        for v in path:
            i += 1
            vmap[v] = i

        mlist = set()
        for i in range(0,lgth):
            begin = path.begin
            end = path.end
            beginc = path.c2
            endc = path.c1
            
            p1 = Path(self.graph, 3, beginc)
            p.add_vertex(begin)
            
            va = begin
            vertex = multigraph.get_vertex(va)
            color = 3
            alt_color = beginc

            while True:
                edge = vertex.get_neighbor_edge_by_color(color)
                if edge is None:
                    break

                vb = edge.get_another_vertex(va)
                if vb not in path:
                    break

                p.add_vertex(vb)
                va = vb
                vertex = self.graph.get_vertex(va)
                color, alt_color = alt_color, color

            p2 = Path(self.graph, 3, endc)
            p.add_vertex(end)
            
            va = end
            vertex = multigraph.get_vertex(va)
            color = 3
            alt_color = endc

            while True:
                edge = vertex.get_neighbor_edge_by_color(color)
                if edge is None:
                    break

                vb = edge.get_another_vertex(va)
                if vb not in path:
                    break

                p.add_vertex(vb)
                va = vb
                vertex = self.graph.get_vertex(va)
                color, alt_color = alt_color, color
Example #2
0
 def get_completion(self, target_path, path_display, base_path=False):
     # absolute path
     if base_path is False:
         return (path_display, "/" + target_path)
     # create relative path
     else:
         return (path_display, Path.trace(base_path, target_path))
Example #3
0
    def get_final_path(path, path_needle):
        # print("cleanup path", path, "needle:", path_needle)
        #st2 - remove path_needle fragments
        #remove anything before last word separator?
        part_to_remove = re.escape(re.sub("[^\/]*$", "", path_needle))
        # print("remove:", part_to_remove)
        path = re.sub("^" + part_to_remove, "", path)
        # print("cleanup #1", path)

        # st2 - sanitize
        if re.search("\/\.\/", path):
            path = re.sub("^(\.\.\/)*", "", path)

        path = re.sub("^(\.\/)+", "./", path)
        path = re.sub("^(\/\/)+", "/", path)

        # hack reverse
        path = re.sub(config["ESCAPE_DOLLAR"], "$", path)
        for replace in Completion.replaceOnInsert:
            path = re.sub(replace[0], replace[1], path)

        if Completion.base_directory and path.startswith("/"):
            path = re.sub("^\/" + Completion.base_directory, "", path)
            path = Path.sanitize(path)

        log("final filepath: '{0}'".format(path))
        return path
Example #4
0
 def get_completion(self, target_path, path_display, base_path=False):
     # absolute path
     if base_path is False:
         return (path_display, "/" + target_path)
     # create relative path
     else:
         return (path_display, Path.trace(base_path, target_path))
Example #5
0
def update_settings():
    """ restart projectFiles with new plugin and project settings """
    global project_files, scope_cache

    scope_cache.clear()
    settings = sublime.load_settings(config["FFP_SETTINGS_FILE"])

    # st2 - has to check window
    project_settings = False
    current_window = sublime.active_window()
    if current_window:
        project_settings = current_window.active_view().settings().get('FuzzyFilePath', False)

    # sync settings to config
    for key in config:
        config[key] = settings.get(key.lower(), config[key])
    # mapping
    config["TRIGGER"] = settings.get("scopes", config["TRIGGER"])
    # merge project settings stored in "settings: { FuzzyFilePath: ..."
    if project_settings:
        # mapping
        config["TRIGGER"] = project_settings.get("scopes", config["TRIGGER"])
        for key in config:
            config[key] = project_settings.get(key.lower(), config[key])
    # build extensions to suggest
    extensionsToSuggest = []
    for scope in config["TRIGGER"]:
        ext = scope.get("extensions", [])
        extensionsToSuggest += ext
    # remove duplicates
    extensionsToSuggest = list(set(extensionsToSuggest))

    project_files = ProjectFiles()
    project_files.update_settings(extensionsToSuggest, config["EXCLUDE_FOLDERS"])
    # validate directories
    if config["BASE_DIRECTORY"]:
        config["BASE_DIRECTORY"] = Path.sanitize_base_directory(config["BASE_DIRECTORY"])
    if config["PROJECT_DIRECTORY"]:
        config["PROJECT_DIRECTORY"] = Path.sanitize_base_directory(config["PROJECT_DIRECTORY"])

    log("logging enabled")
    log("project base directory set to '{0}'".format(config["BASE_DIRECTORY"]))
    log("{0} scope triggers loaded".format(len(config["TRIGGER"])))
def start():
    world.add_agent(vehicle)

    vehicle.path = Path.create_random_path(10,(20,20),(760,500))
    vehicle.path_follow_on(); 
    
    world.display_flags_off()
    world.view_keys = True
    world.show_steering_force = True
    world.show_path = True
Example #7
0
    def on_activated(self, view):
        project_directory = ""
        self.is_project_file = False
        self.project_folder = None

        current_window = sublime.active_window()
        if not current_window:
            return False

        file_name = view.file_name()
        folders = current_window.folders()

        if folders is None or file_name is None:
            return False

        if config["PROJECT_DIRECTORY"]:
            # sanitize project directory
            project_directory = config["PROJECT_DIRECTORY"]
            verbose("project", "project folder found {0}".format(project_directory))

        # find and build current project directory (modified by settings:project_directory)
        base_project_directory = False
        final_project_directory = False
        for folder in folders:
            final_project_directory = os.path.join(folder, project_directory)
            # does not require validation of folder since filename is always correct
            if final_project_directory in file_name:
                self.is_project_file = True
                base_project_directory = folder
                break

        # abort if file is not within a project
        if not self.is_project_file:
            sublime.status_message("FFP abort. File is not within a project {0}".format(project_directory))
            return False
        elif config["LOG"]:
            sublime.status_message("FFP enabled for file being in project {0}".format(final_project_directory))

        # save final project folder
        self.project_folder = final_project_directory

        # validate base directory
        path_to_base_directory = False
        if config["BASE_DIRECTORY"]:
            #
            # base_project_directory    | /path/to/sublime/project
            # project_folder            | /path/to/sublime/project/project_directory
            #
            # - path_to_base_directory  | /path/to/sublime/project/base_directory
            # + path_to_base_directory  | /path/to/sublime/project/project_directory/base_directory
            #
            path_to_base_directory = os.path.join(final_project_directory, config["BASE_DIRECTORY"])
            if not os.path.isdir(path_to_base_directory):

                # BASE_DIRECTORY is NOT a valid folder releative to (possibly modified) project_directory
                path_to_base_directory = os.path.join(base_project_directory, config["BASE_DIRECTORY"])

                if not os.path.isdir(path_to_base_directory):
                    print("FFP", "Error: setting's base_directory is not a valid directory in project")
                    print("FFP", "=> changing base_directory {0} to ''".format(config["BASE_DIRECTORY"]))
                    config["BASE_DIRECTORY"] = ""

                elif path_to_base_directory in final_project_directory:
                    # change BASE_DIRECTORY to be '' since its outside of project directory
                    print("FFP", "Error: setting's base_directory is within project directory")
                    print("FFP", "=> changing base_directory {0} to ''".format(config["BASE_DIRECTORY"]))
                    config["BASE_DIRECTORY"] = ""

                else:
                    # change BASE_DIRECTORY to be relative to modified project directory
                    path_to_base_directory = path_to_base_directory.replace(final_project_directory, "")
                    print("FFP", "Error: setting's base_directory is not relative to project directory")
                    print("FFP", "=> changing base_directory '{0}' to '{1}'".format(config["BASE_DIRECTORY"], path_to_base_directory))
                    config["BASE_DIRECTORY"] = Path.sanitize_base_directory(path_to_base_directory)

        # get file's current folder
        self.current_folder = Path.get_relative_folder(file_name, self.project_folder)

        if project_files:
            project_files.add(self.project_folder)
Example #8
0
    def build(needle, trigger, current_folder, project_folder):
        force_type = Query.get("filepath_type", False)
        triggered = Query.by_command()
        filepath_type = "relative"
        needle = Path.sanitize(needle)
        needle_is_absolute = Path.is_absolute(needle)
        needle_is_relative = Path.is_relative(needle)
        needle_is_path = needle_is_absolute or needle_is_relative
        # abort if autocomplete is not available
        if not triggered and trigger.get("auto", False) is False and needle_is_path is False:
            return False
        # test path to trigger auto-completion by needle
        if not triggered and trigger["auto"] is False and config["AUTO_TRIGGER"] and needle_is_absolute:
            force_type = "absolute"
        # base_directory: override - trigger - False
        base_directory = trigger.get("base_directory", False)
        base_directory = Query.get("base_directory", base_directory)
        #
        # set current directory by force, else by trigger:
        #
        # trigger       |
        # --------------|--------------------
        # False         | use current file's directory
        # True          | use settings: base_directory
        # String        | use string as base_directory
        # change base folder to base directory
        #
        # st2? - fix missing or bugged base_directory
        adjusted_basepath = current_folder
        if base_directory is True:
            adjusted_basepath = config["BASE_DIRECTORY"]
        elif base_directory:
            adjusted_basepath = Path.sanitize_base_directory(base_directory)
        # notify completion to replace path
        if base_directory and needle_is_absolute:
            Completion.base_directory = current_folder
        # st2? - fix missing or bugged base_directory
        if adjusted_basepath is False:
            adjusted_basepath = current_folder
        #
        # filepath_type
        #
        # needle    | trigger rel   | force     | RESULT
        # ----------|---------------|-----------|---------
        # ?         | relative      | False     | relative
        # ?         | absolute      | False     | absolute
        # absolute  | *             | False     | absolute
        # relative  | *             | False     | relative
        # *         | *             | relative  | relative
        # *         | *             | absolute  | absolute
        #
        if force_type:
            filepath_type = force_type
        elif needle_is_absolute:
            filepath_type = "absolute"
        elif needle_is_relative:
            filepath_type = "relative"
        elif trigger.get("relative") is True:
            filepath_type = "relative"
        elif trigger.get("relative") is False:
            filepath_type = "absolute"

        Query.base_path = current_folder if filepath_type == "relative" else False
        # replacements: override - trigger - None
        Query.replace_on_insert = trigger.get("replace_on_insert", [])
        Query.replace_on_insert = Query.get("replace_on_insert", Query.replace_on_insert)
        # extensions: override - trigger - "js"
        Query.extensions = trigger.get("extensions", ["*"])
        Query.extensions = Query.get("extensions", Query.extensions)
        Query.needle = Query.build_needle_query(needle, current_folder)
        log("\nfilepath type\n--------")
        log("type:", filepath_type)
        log("base_path:", Query.base_path)
        log("needle:", Query.needle)
        log("current folder", current_folder)
        return triggered or (config["AUTO_TRIGGER"] if needle_is_path else trigger.get("auto", config["AUTO_TRIGGER"]))
Example #9
0
def construct_path(rn, mm_traj, routing_weight):
    """
    construct the path of the map matched trajectory
    Note: the enter time of the first path entity & the leave time of the last path entity is not accurate
    :param rn: the road network
    :param mm_traj: the map matched trajectory
    :param routing_weight: the attribute name to find the routing weight
    :return: a list of paths (Note: in case that the route is broken)
    """
    paths = []
    path = []
    mm_pt_list = mm_traj.pt_list
    start_idx = len(mm_pt_list) - 1
    # find the first matched point
    for i in range(len(mm_pt_list)):
        if mm_pt_list[i].data['candi_pt'] is not None:
            start_idx = i
            break
    pre_edge_enter_time = mm_pt_list[start_idx].time
    for i in range(start_idx + 1, len(mm_pt_list)):
        pre_mm_pt = mm_pt_list[i - 1]
        cur_mm_pt = mm_pt_list[i]
        # unmatched -> matched
        if pre_mm_pt.data['candi_pt'] is None:
            pre_edge_enter_time = cur_mm_pt.time
            continue
        # matched -> unmatched
        pre_candi_pt = pre_mm_pt.data['candi_pt']
        if cur_mm_pt.data['candi_pt'] is None:
            path.append(
                PathEntity(pre_edge_enter_time, pre_mm_pt.time,
                           pre_candi_pt.eid))
            if len(path) > 2:
                paths.append(
                    Path(mm_traj.oid, get_pid(mm_traj.oid, path), path))
            path = []
            continue
        # matched -> matched
        cur_candi_pt = cur_mm_pt.data['candi_pt']
        # if consecutive points are on the same road, cur_mm_pt doesn't bring new information
        if pre_candi_pt.eid != cur_candi_pt.eid:
            weight_p, p = find_shortest_path(rn, pre_candi_pt, cur_candi_pt,
                                             routing_weight)
            # cannot connect
            if p is None:
                path.append(
                    PathEntity(pre_edge_enter_time, pre_mm_pt.time,
                               pre_candi_pt.eid))
                if len(path) > 2:
                    paths.append(
                        Path(mm_traj.oid, get_pid(mm_traj.oid, path), path))
                path = []
                pre_edge_enter_time = cur_mm_pt.time
                continue
            # can connect
            if nx.is_directed(rn):
                dist_to_p_entrance = rn.edges[rn.edge_idx[
                    pre_candi_pt.eid]]['length'] - pre_candi_pt.offset
                dist_to_p_exit = cur_candi_pt.offset
            else:
                entrance_vertex = p[0]
                pre_edge_coords = rn.edges[rn.edge_idx[
                    pre_candi_pt.eid]]['coords']
                if (pre_edge_coords[0].lng,
                        pre_edge_coords[0].lat) == entrance_vertex:
                    dist_to_p_entrance = pre_candi_pt.offset
                else:
                    dist_to_p_entrance = rn.edges[rn.edge_idx[
                        pre_candi_pt.eid]]['length'] - pre_candi_pt.offset
                exit_vertex = p[-1]
                cur_edge_coords = rn.edges[rn.edge_idx[
                    cur_candi_pt.eid]]['coords']
                if (cur_edge_coords[0].lng,
                        cur_edge_coords[0].lat) == exit_vertex:
                    dist_to_p_exit = cur_candi_pt.offset
                else:
                    dist_to_p_exit = rn.edges[rn.edge_idx[
                        cur_candi_pt.eid]]['length'] - pre_candi_pt.offset
            if routing_weight == 'length':
                total_dist = weight_p
            else:
                dist_inner = 0.0
                for i in range(len(p) - 1):
                    start, end = p[i], p[i + 1]
                    dist_inner += rn[start][end]['length']
                total_dist = dist_inner + dist_to_p_entrance + dist_to_p_exit
            delta_time = (cur_mm_pt.time - pre_mm_pt.time).total_seconds()
            # two consecutive points matched to the same vertex
            if total_dist == 0:
                pre_edge_leave_time = cur_mm_pt.time
                path.append(
                    PathEntity(pre_edge_enter_time, pre_edge_leave_time,
                               pre_candi_pt.eid))
                cur_edge_enter_time = cur_mm_pt.time
            else:
                pre_edge_leave_time = pre_mm_pt.time + timedelta(
                    seconds=delta_time * (dist_to_p_entrance / total_dist))
                path.append(
                    PathEntity(pre_edge_enter_time, pre_edge_leave_time,
                               pre_candi_pt.eid))
                cur_edge_enter_time = cur_mm_pt.time - timedelta(
                    seconds=delta_time * (dist_to_p_exit / total_dist))
                sub_path = linear_interpolate_path(
                    p, total_dist - dist_to_p_entrance - dist_to_p_exit, rn,
                    pre_edge_leave_time, cur_edge_enter_time)
                path.extend(sub_path)
            pre_edge_enter_time = cur_edge_enter_time
    # handle last matched similar to (matched -> unmatched)
    if mm_pt_list[-1].data['candi_pt'] is not None:
        path.append(
            PathEntity(pre_edge_enter_time, mm_pt_list[-1].time,
                       mm_pt_list[-1].data['candi_pt'].eid))
        if len(path) > 2:
            paths.append(Path(mm_traj.oid, get_pid(mm_traj.oid, path), path))
    return paths