diff --git a/src/sakia/core/graph/wot_graph.py b/src/sakia/core/graph/wot_graph.py index 50a63b74fe893ce6cd5b8e41725bae25be41d487..60ab1cd28b9ece3c61eab094f059ddda35be54ab 100644 --- a/src/sakia/core/graph/wot_graph.py +++ b/src/sakia/core/graph/wot_graph.py @@ -38,7 +38,7 @@ class WoTGraph(BaseGraph): await asyncio.gather(certifier_coro, certified_coro) - async def get_shortest_path_to_identity(self, account_identity, to_identity): + async def get_shortest_path_to_identity(self, from_identity, to_identity): """ Return path list of nodes from from_identity to to_identity :param identity from_identity: @@ -47,16 +47,16 @@ class WoTGraph(BaseGraph): """ path = list() - logging.debug("path between %s to %s..." % (account_identity.uid, to_identity.uid)) - self.add_identity(account_identity, NodeStatus.HIGHLIGHTED) + logging.debug("path between %s to %s..." % (from_identity.uid, to_identity.uid)) + self.add_identity(from_identity, NodeStatus.HIGHLIGHTED) # recursively feed graph searching for account node... - await self.explore_to_find_member(account_identity, to_identity) + await self.explore_to_find_member(from_identity, to_identity) # calculate path of nodes between identity and to_identity try: - path = networkx.shortest_path(self.nx_graph.reverse(copy=True), account_identity.pubkey, to_identity.pubkey) - except networkx.NetworkXNoPath as e: + path = networkx.shortest_path(self.nx_graph, from_identity.pubkey, to_identity.pubkey) + except networkx.exception.NetworkXException as e: logging.debug(str(e)) return path @@ -72,23 +72,15 @@ class WoTGraph(BaseGraph): while len(explorable) > 0: current = explorable.pop() - certifier_coro = asyncio.ensure_future(current.unique_valid_certifiers_of(self.app.identities_registry, - self.community)) - certified_coro = asyncio.ensure_future(current.unique_valid_certified_by(self.app.identities_registry, - self.community)) - - certifier_list, certified_list = await asyncio.gather(certifier_coro, certified_coro) - - await self.add_certifier_list(certifier_list, current, account_identity) - if to_identity.pubkey in [data['identity'].pubkey for data in certifier_list]: - return True + certified_list = await current.unique_valid_certified_by(self.app.identities_registry, + self.community) await self.add_certified_list(certified_list, current, account_identity) if to_identity.pubkey in [data['identity'].pubkey for data in certified_list]: return True explored.append(current) - for entry in certifier_list + certified_list: + for entry in certified_list: if entry['identity'] not in explored + explorable: explorable.append(entry['identity']) diff --git a/src/sakia/gui/graphs/wot_tab.py b/src/sakia/gui/graphs/wot_tab.py index a3119357ab7964b474c826e578bbb92443d7cc14..31eedfdce5b7470cc8343bc5ee1dce59ec012c56 100644 --- a/src/sakia/gui/graphs/wot_tab.py +++ b/src/sakia/gui/graphs/wot_tab.py @@ -102,7 +102,7 @@ class WotTabWidget(GraphTabWidget): # if selected member is not the account member... if identity.pubkey != identity_account.pubkey: # add path from selected member to account member - path = await graph.get_shortest_path_to_identity(identity_account, identity) + path = await graph.get_shortest_path_to_identity(identity, identity_account) if path: self.ui.graphicsView.scene().update_path(graph.nx_graph, path) self.busy.hide() diff --git a/src/sakia/gui/member.py b/src/sakia/gui/member.py index c1c6f63dd253c77d9d7accbdb8207ce3e93fa3e0..5d2744dea1d3e3e9953e514727da816f423814bd 100644 --- a/src/sakia/gui/member.py +++ b/src/sakia/gui/member.py @@ -118,7 +118,7 @@ class MemberDialog(QObject): path = None # if selected member is not the account member... if self.identity.pubkey != self.account.pubkey: - # add path from selected member to account member + # add path from us to him account_identity = await self.account.identity(self.community) path = await graph.get_shortest_path_to_identity(self.identity, account_identity) diff --git a/src/sakia/gui/views/scenes/wot_scene.py b/src/sakia/gui/views/scenes/wot_scene.py index 19867adfd96ec93faef180cada137850818dbae3..743a044b537cdee0acda72a0a1ffe3394aa5ead8 100644 --- a/src/sakia/gui/views/scenes/wot_scene.py +++ b/src/sakia/gui/views/scenes/wot_scene.py @@ -53,6 +53,10 @@ class WotScene(BaseScene): pos[n[0]] = (x, y) return pos + @staticmethod + def center_pos(nb_certifiers, nb_certified, scale): + return 0, max(nb_certified, nb_certifiers,) / 2 * 0.12 * scale + @staticmethod def certifiers_partial_layout(nx_graph, center, scale=1): """ @@ -67,8 +71,7 @@ class WotScene(BaseScene): certifier = [n for n in nx_graph.nodes(data=True) if n[0] in certifier_edge] - pos = {center: (0, max(len(certified_edge), - len(certifier_edge))/2*0.12*scale)} + pos = {center: WotScene.center_pos(len(certified_edge), len(certifier_edge), scale)} y = 0 x = -1 * scale @@ -95,8 +98,7 @@ class WotScene(BaseScene): certified = [n for n in nx_graph.nodes(data=True) if n[0] in certified_edge] - pos = {center: (0, max(len(certified_edge), - len(certifier_edge))/2*0.12*scale)} + pos = {center: WotScene.center_pos(len(certified_edge), len(certifier_edge), scale)} y = 0 x = 1 * scale @@ -111,23 +113,22 @@ class WotScene(BaseScene): @staticmethod def path_partial_layout(nx_graph, path, scale=1): """ - + Layout from the center to the outside, showing the network path :param networkx.MultiDiGraph nx_graph: The graph to show :param list path: :param int scale: :return: """ - destination = path[-1] - certifier_edge = [edge[0] for edge in nx_graph.in_edges() if edge[1] == destination] - certified_edge = [edge[1] for edge in nx_graph.out_edges() if edge[0] == destination] + origin = path[0] + certifier_edge = [edge[0] for edge in nx_graph.in_edges() if edge[1] == origin] + certified_edge = [edge[1] for edge in nx_graph.out_edges() if edge[0] == origin] - x = 0 - y = max(len(certified_edge), len(certifier_edge))/2*0.12*scale - pos = {destination: (x, y)} + x, y = WotScene.center_pos(len(certified_edge), len(certifier_edge), scale) + pos = {} - for node in reversed(path[:-1]): - y -= 100 + for node in path: pos[node] = (x, y) + y -= 100 return pos def update_wot(self, nx_graph, identity): @@ -161,7 +162,7 @@ class WotScene(BaseScene): def update_path(self, nx_graph, path): path_graph_pos = WotScene.path_partial_layout(nx_graph, path, scale=200) - nodes_path = [n for n in nx_graph.nodes(data=True) if n[0] in path[:-1]] + nodes_path = [n for n in nx_graph.nodes(data=True) if n[0] in path[1:]] for node in nodes_path: v = WotNode(node, path_graph_pos) self.addItem(v)