From de5cf746feba8323d734e8a3d279ab257db68463 Mon Sep 17 00:00:00 2001 From: Kefei Mo Date: Fri, 20 Oct 2023 12:40:22 -0500 Subject: [PATCH 1/2] revivied Craig s code to resolved the issue that uuid has extra chars when using vctl status --- volttron/platform/control/control_utils.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/volttron/platform/control/control_utils.py b/volttron/platform/control/control_utils.py index a4300e6603..c33034e2a2 100644 --- a/volttron/platform/control/control_utils.py +++ b/volttron/platform/control/control_utils.py @@ -36,11 +36,11 @@ # under Contract DE-AC05-76RL01830 # }}} import collections -import itertools import sys import re from volttron.platform import jsonapi from volttron.platform.agent.utils import is_secure_mode +import os _stdout = sys.stdout _stderr = sys.stderr @@ -48,10 +48,13 @@ def _calc_min_uuid_length(agents): n = 0 - for agent1, agent2 in itertools.combinations(agents, 2): - common_len = sum(1 for a, b in zip(agent1.uuid, agent2.uuid) if a == b) - if common_len > n: - n = common_len + for agent1 in agents: + for agent2 in agents: + if agent1 is agent2: + continue + common_len = len(os.path.commonprefix([agent1.uuid, agent2.uuid])) + if common_len > n: + n = common_len return n + 1 From 8a513f0cae88c4ab6dc4044985188ec9b78cdb5f Mon Sep 17 00:00:00 2001 From: Kefei Mo Date: Fri, 20 Oct 2023 13:14:30 -0500 Subject: [PATCH 2/2] optimized _calc_min_uuid_length(agents) --- volttron/platform/control/control_utils.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/volttron/platform/control/control_utils.py b/volttron/platform/control/control_utils.py index c33034e2a2..8aad804fd7 100644 --- a/volttron/platform/control/control_utils.py +++ b/volttron/platform/control/control_utils.py @@ -47,15 +47,9 @@ def _calc_min_uuid_length(agents): - n = 0 - for agent1 in agents: - for agent2 in agents: - if agent1 is agent2: - continue - common_len = len(os.path.commonprefix([agent1.uuid, agent2.uuid])) - if common_len > n: - n = common_len - return n + 1 + agent_ids = [agent.uuid for agent in agents] + common_len = len(os.path.commonprefix(agent_ids)) + return common_len + 1 def _list_agents(aip):