From 3c978b3ca3eb5f12f4c47b4c53a1924437171115 Mon Sep 17 00:00:00 2001 From: "DSTO\\pivatom" Date: Mon, 14 Jan 2019 11:19:27 +1030 Subject: [PATCH] Add method to get swarm participants for new leader, fix some comments --- DecisionSystem/CentralisedDecision/commander.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/DecisionSystem/CentralisedDecision/commander.py b/DecisionSystem/CentralisedDecision/commander.py index b394d4d..c78d15a 100644 --- a/DecisionSystem/CentralisedDecision/commander.py +++ b/DecisionSystem/CentralisedDecision/commander.py @@ -27,13 +27,13 @@ class Commander: # If using apache zookeeper this won't be needed. def make_decision(self): - # Should change this to be a strategy, for different implementations of making - # a decision on the votes. + # Should change this to follow strategy pattern, for different implementations of + # making a decision on the votes. votes = self._votes dif_votes = {} for vote in votes: - # Get the average/max, etc. + # Get the count of different votes. if str(vote) in dif_votes: dif_votes[str(vote)] = dif_votes[str(vote)] + 1 else: @@ -49,6 +49,7 @@ class Commander: return max_vote def get_votes(self): + # Should consider abstracting these messages to another class for portability. message = {"type": "reqVote"} message_packed = umsgpack.packb(message) self._taking_votes = True @@ -72,7 +73,7 @@ class Commander: # Commander must have requested their taking votes, and the timeout # has not occurred. # Only add vote to list if the client has not already voted. - if messageDict["client"] not in self._votes.keys: + if messageDict["client"] not in self._votes: self._votes[messageDict["client"]] = messageDict["vote"] elif messageDict["type"] == "disconnected": @@ -82,4 +83,8 @@ class Commander: pass def on_connect(self, client, userdata, flags, rc): - self.client.subscribe("swarm1/commander") \ No newline at end of file + self.client.subscribe("swarm1/commander") + + def get_participants(self): + + self.client.publish("swarm1/voters") \ No newline at end of file