def get_nodes_and_edges(self, state_transition_table): nodes = [] edges = [] for transition, transition_func in state_transition_table.items(): fr, to = transition nodes.append(fr) nodes.append(to) label = '' if transition_func.__name__ == 'Dummy' else transition_func.__name__ edges.append(Edge(fr, to, label)) # make it as unique string list nodes = list(set(nodes)) return nodes, edges
def get_nodes_and_edges(self, conductor_graph_instance): """ Get all the nodes and edges corresponding to our conductor's graph of concert clients. :returns: all the nodes and edges :rtype: (concert_client.ConcertClient[], rosgraph.impl.graph.Edge[]) """ nodes = conductor_graph_instance.concert_clients.values() edges = [] important_states = [ concert_msgs.ConcertClientState.MISSING, concert_msgs.ConcertClientState.AVAILABLE ] for node in nodes: if node.msg.state in important_states: # and node.msg.conn_stats.gateway_available: edges.append(Edge("conductor", node.concert_alias, node.link_type)) return (nodes, edges)
def update(self): if not self._resolve_gateway_namespace(): return self._local_gateway = self._gateway_info() req = gateway_srvs.RemoteGatewayInfoRequest() req.gateways = [] self._remote_gateways = self._remote_gateway_info(req).gateways self._last_update = rospy.get_rostime() # Gateways self.gateway_nodes.append(self._local_gateway.name) self.gateway_nodes.extend([remote_gateway.name for remote_gateway in self._remote_gateways]) # Edges self.pulled_edges = EdgeList() self.gateway_edges = EdgeList() self.pulled_edges = EdgeList() self.flipped_edges = EdgeList() # Check local gateway for remote_rule in self._local_gateway.flipped_connections: self.gateway_edges.add(Edge(self._local_gateway.name, remote_rule.gateway)) # this adds a bloody magic space, to help disambiguate node names from topic names connection_id = rosgraph.impl.graph.topic_node(remote_rule.rule.name + '-' + remote_rule.rule.type) self.flipped_nodes.append(connection_id) self.flipped_edges.add(Edge(self._local_gateway.name, connection_id)) self.flipped_edges.add(Edge(connection_id, remote_rule.gateway)) for remote_rule in self._local_gateway.pulled_connections: connection_id = rosgraph.impl.graph.topic_node(remote_rule.rule.name + '-' + remote_rule.rule.type) self.pulled_nodes.append(connection_id) self.pulled_edges.add(Edge(self._local_gateway.name, connection_id)) self.pulled_edges.add(Edge(connection_id, remote_rule.gateway)) for rule in self._local_gateway.public_interface: connection_id = rosgraph.impl.graph.topic_node(rule.name + '-' + rule.type) #print "pulled edge: %s->%s" % (self._local_gateway.name, connection_id) self.pulled_nodes.append(connection_id) self.pulled_edges.add(Edge(self._local_gateway.name, connection_id)) # Check remote gateways for remote_gateway in self._remote_gateways: for remote_rule in remote_gateway.flipped_interface: connection_id = rosgraph.impl.graph.topic_node(remote_rule.rule.name + '-' + remote_rule.rule.type) self.flipped_nodes.append(connection_id) self.flipped_edges.add(Edge(remote_gateway.name, connection_id)) self.flipped_edges.add(Edge(connection_id, remote_rule.gateway)) self.gateway_edges.add(Edge(remote_gateway.name, remote_rule.gateway)) for remote_rule in remote_gateway.pulled_interface: connection_id = rosgraph.impl.graph.topic_node(remote_rule.rule.name + '-' + remote_rule.rule.type) self.pulled_nodes.append(connection_id) self.pulled_edges.add(Edge(remote_rule.gateway, connection_id)) self.pulled_edges.add(Edge(connection_id, remote_gateway.name)) self.gateway_edges.add(Edge(remote_gateway.name, remote_rule.gateway))
def update_client_list(self, data): print "[conductor_graph_info]: update_client_list" if self.is_first_update == False: if self._event_callback != None: self._event_callback() if self._period_callback != None: self._period_callback() self.is_first_update = True #update dotgraph info self.gateway_nodes = [] self.gateway_nodes.append(self._concert_conductor_name) self.gateway_edges = EdgeList() client_list = [] for k in data.clients: client_list.append((k, True)) for k in data.uninvited_clients: client_list.append((k, False)) for client in client_list: k = client[0] client_name = client[0].name if self._client_info_list.has_key(client_name): self._client_info_list[client_name]["is_new"] = False else: self._client_info_list[client_name] = {} self._client_info_list[client_name]["is_new"] = True self._client_info_list[client_name]["is_check"] = True self._client_info_list[client_name]["is_invite"] = client[1] self._client_info_list[client_name]["name"] = client[0].name self._client_info_list[client_name]["gateway_name"] = client[ 0].gateway_name self._client_info_list[client_name]["platform_info"] = client[ 0].platform_info self._client_info_list[client_name]["client_status"] = client[ 0].client_status self._client_info_list[client_name]["app_status"] = client[ 0].app_status self._client_info_list[client_name]["is_local_client"] = client[ 0].is_local_client self._client_info_list[client_name]["status"] = client[0].status self._client_info_list[client_name]["conn_stats"] = client[ 0].conn_stats self._client_info_list[client_name]["gateway_available"] = client[ 0].conn_stats.gateway_available self._client_info_list[client_name][ "time_since_last_seen"] = client[ 0].conn_stats.time_since_last_seen self._client_info_list[client_name]["ping_latency_min"] = client[ 0].conn_stats.ping_latency_min self._client_info_list[client_name]["ping_latency_max"] = client[ 0].conn_stats.ping_latency_max self._client_info_list[client_name]["ping_latency_avg"] = client[ 0].conn_stats.ping_latency_avg self._client_info_list[client_name]["ping_latency_mdev"] = client[ 0].conn_stats.ping_latency_mdev self._client_info_list[client_name][ "network_info_available"] = client[ 0].conn_stats.network_info_available self._client_info_list[client_name]["network_type"] = client[ 0].conn_stats.network_type self._client_info_list[client_name]["wireless_bitrate"] = client[ 0].conn_stats.wireless_bitrate self._client_info_list[client_name][ "wireless_link_quality"] = client[ 0].conn_stats.wireless_link_quality self._client_info_list[client_name][ "wireless_signal_level"] = client[ 0].conn_stats.wireless_signal_level self._client_info_list[client_name][ "wireless_noise_level"] = client[ 0].conn_stats.wireless_noise_level self._client_info_list[client_name]["apps"] = {} for l in client[0].apps: app_name = l.name self._client_info_list[client_name]["apps"][app_name] = {} self._client_info_list[client_name]["apps"][app_name][ 'name'] = l.name self._client_info_list[client_name]["apps"][app_name][ 'display_name'] = l.display_name self._client_info_list[client_name]["apps"][app_name][ 'description'] = l.description self._client_info_list[client_name]["apps"][app_name][ 'compatibility'] = l.compatibility self._client_info_list[client_name]["apps"][app_name][ 'status'] = l.status #text info app_context = "<html>" app_context += "<p>-------------------------------------------</p>" app_context += "<p><b>name: </b>" + client[0].name + "</p>" app_context += "<p><b>gateway_name: </b>" + client[ 0].gateway_name + "</p>" app_context += "<p><b>rocon_uri: </b>" + client[ 0].platform_info.uri + "</p>" app_context += "<p><b>concert_version: </b>" + client[ 0].platform_info.version + "</p>" app_context += "<p>-------------------------------------------</p>" app_context += "<p><b>client_status: </b>" + client[ 0].client_status + "</p>" app_context += "<p><b>app_status: </b>" + client[ 0].app_status + "</p>" for l in self._client_info_list[client_name]["apps"].values(): app_context += "<p>-------------------------------------------</p>" app_context += "<p><b>app_name: </b>" + l['name'] + "</p>" app_context += "<p><b>app_display_name: </b>" + l[ 'display_name'] + "</p>" app_context += "<p><b>app_description: </b>" + l[ 'description'] + "</p>" app_context += "<p><b>app_compatibility: </b>" + l[ 'compatibility'] + "</p>" app_context += "<p><b>app_status: </b>" + l['status'] + "</p>" app_context += "</html>" self._client_info_list[client_name]["app_context"] = app_context #How to set the strength range??? connection_strength = self.get_connection_strength( client[0].is_local_client, client[0].conn_stats.wireless_link_quality) self._client_info_list[client_name][ "connection_strength"] = connection_strength #graph info self.gateway_nodes.append(client[0].name) if client[1] == False: # uninvited client has only node,no link. continue if client[0].conn_stats.gateway_available == True: if client[0].is_local_client == True: self.gateway_edges.add( Edge(self._concert_conductor_name, client[0].name, "local")) elif client[ 0].conn_stats.network_type == ConnectionStatistics.WIRED: self.gateway_edges.add( Edge(self._concert_conductor_name, client[0].name, "wired")) elif client[ 0].conn_stats.network_type == ConnectionStatistics.WIRELESS: self.gateway_edges.add( Edge(self._concert_conductor_name, client[0].name, "wireless")) else: print "[conductor_graph_info]: Unknown network type" else: print "[conductor_graph_info]:No network connection" #new node check for k in self._client_info_list.keys(): if self._client_info_list[k]["is_check"] == True: self._client_info_list[k]["is_check"] = False else: del self._client_info_list[k] #update check if self._compare_client_info_list(): pass else: self._event_callback() self._pre_client_info_list = copy.deepcopy(self._client_info_list) #call period callback function if self._period_callback != None: self._period_callback()