コード例 #1
0
    def query_data(self):
        data = {}
        try:
            cwd = os.path.abspath(os.path.dirname(__file__))
            queries_path = os.path.join(cwd, self.queries_file)
            project_cypher = query_utils.read_queries(queries_path)

            driver = connector.getGraphDatabaseConnectionConfiguration()
            replace = [("PROJECTID", self.identifier)]
            for query_name in project_cypher:
                title = query_name.lower().replace('_', ' ')
                query = project_cypher[query_name]['query']
                query_type = project_cypher[query_name]['query_type']
                for r, by in replace:
                    query = query.replace(r, by)
                if query_type == "pre":
                    data[title] = connector.getCursorData(driver, query)
        except Exception as err:
            exc_type, exc_obj, exc_tb = sys.exc_info()
            fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
            logger.error(
                "Reading queries from file {}: {}, file: {},line: {}, error: {}"
                .format(queries_path, sys.exc_info(), fname, exc_tb.tb_lineno,
                        err))

        return data
コード例 #2
0
    def get_similarity_network(self):
        plot = None
        try:
            cwd = os.path.abspath(os.path.dirname(__file__))
            query_path = os.path.join(cwd, self.queries_file)
            project_cypher = query_utils.read_queries(query_path)
            query = query_utils.get_query(project_cypher,
                                          query_id="projects_subgraph")
            list_projects = []
            driver = connector.getGraphDatabaseConnectionConfiguration()
            if "other_id" in self.similar_projects:
                list_projects = self.similar_projects[
                    "other_id"].values.tolist()
            list_projects.append(self.identifier)
            list_projects = ",".join(['"{}"'.format(i) for i in list_projects])
            query = query.replace("LIST_PROJECTS", list_projects)
            path = connector.sendQuery(driver, query, parameters={}).data()
            G = acore_utils.neo4j_path_to_networkx(path, key='path')
            args = {}
            style, layout = self.get_similarity_network_style()
            args['stylesheet'] = style
            args['layout'] = layout
            args['title'] = "Projects subgraph"
            net, mouseover = acore_utils.networkx_to_cytoscape(G)
            plot = viz.get_cytoscape_network(net, "projects_subgraph", args)
        except Exception as err:
            exc_type, exc_obj, exc_tb = sys.exc_info()
            fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
            logger.error(
                "Error: {}. Reading queries from file {}: {}, file: {},line: {}"
                .format(err, query_path, sys.exc_info(), fname,
                        exc_tb.tb_lineno))

        return plot
コード例 #3
0
 def remove_project(self,
                    host="localhost",
                    port=7687,
                    user="******",
                    password="******"):
     try:
         cwd = os.path.abspath(os.path.dirname(__file__))
         query_path = os.path.join(cwd, self.queries_file)
         project_cypher = query_utils.read_queries(query_path)
         query = query_utils.get_query(project_cypher,
                                       query_id="remove_project")
         driver = connector.connectToDB(host, port, user, password)
         queries = query.replace("PROJECTID", self.identifier)
         for query in queries.split(';')[:-1]:
             result = connector.sendQuery(driver,
                                          query + ';',
                                          parameters={}).data()
     except Exception as err:
         exc_type, exc_obj, exc_tb = sys.exc_info()
         fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
         logger.error(
             "Error removing project {}. Query file: {},line: {}, error: {}"
             .format(self.identifier, fname, exc_tb.tb_lineno, err))