diff --git a/dist/iotAmak-0.0.8-py3-none-any.whl b/dist/iotAmak-0.0.8-py3-none-any.whl new file mode 100644 index 0000000000000000000000000000000000000000..032ba6eeb079757c480fd66518e4447369a8df2f Binary files /dev/null and b/dist/iotAmak-0.0.8-py3-none-any.whl differ diff --git a/iotAmak/agent/agent.py b/iotAmak/agent/agent.py index 9cbf8c53977fa257f3385508d807b0fd176ee8ea..103ce0758e48c34bf36e4dbccddd1cb2e6aeb481 100644 --- a/iotAmak/agent/agent.py +++ b/iotAmak/agent/agent.py @@ -63,7 +63,7 @@ class Agent(Schedulable, BaseAgent): self.on_cycle_end() - self.publish("metric", str(self.send_metric())) + self.publish("metric", str({"id": self.id, "metric": self.send_metric(), "amas": self.amas_data()})) self.publish("canvas", str(self.to_canvas())) self.publish("cycle_done", "") self.nbr_cycle += 1 diff --git a/iotAmak/agent/async_agent.py b/iotAmak/agent/async_agent.py index 58543c0b4ec1ce9ed9f3641dfb1edd9928e76ee8..8c522cd09cbee23c34473ab178a1861ec9a8cd3e 100644 --- a/iotAmak/agent/async_agent.py +++ b/iotAmak/agent/async_agent.py @@ -53,6 +53,6 @@ class AsyncAgent(AsyncControlable, BaseAgent): self.on_decide() self.on_act() self.on_cycle_end() - self.publish("metric", str(self.send_metric())) + self.publish("metric", str({"id": self.id, "metric": self.send_metric(), "amas": self.amas_data()})) self.publish("canvas", str(self.to_canvas())) diff --git a/iotAmak/agent/base_agent.py b/iotAmak/agent/base_agent.py index 26b25406b6260a153a229aeffefae16e20afb66f..e40fa9094e26149e6a93d168ecf079ba5bf249c5 100644 --- a/iotAmak/agent/base_agent.py +++ b/iotAmak/agent/base_agent.py @@ -90,3 +90,9 @@ class BaseAgent: Should be override if the neighbor need to be aware of any other info, should be a dict """ return {"id": self.id} + + def amas_data(self) -> Dict: + """ + Should be override if needed, should be a dict + """ + return {"id": self.id} \ No newline at end of file diff --git a/iotAmak/amas/amas.py b/iotAmak/amas/amas.py index b2d81ef392d76a45fbc178ad7395c39851d986c1..10b19a2ec5a3b65dcdc43f781262b9e801153ace 100644 --- a/iotAmak/amas/amas.py +++ b/iotAmak/amas/amas.py @@ -69,6 +69,7 @@ class Amas(Schedulable, BaseAmas): return self.publish("amas/all_metric", str(self.agents_metric)) + self.publish("amas/graph", str(self.to_graph())) self.on_cycle_begin() self.client.publish("amas/action_done", "") diff --git a/iotAmak/amas/async_amas.py b/iotAmak/amas/async_amas.py index b2ba18c8f072d5c564dd3ccd0c623dc8968e302d..922643ee87d34ccc745a2210ac8728da52f20739 100644 --- a/iotAmak/amas/async_amas.py +++ b/iotAmak/amas/async_amas.py @@ -2,6 +2,7 @@ import pathlib import sys import json from ast import literal_eval +from time import sleep from typing import List @@ -59,7 +60,6 @@ class AsyncAmas(AsyncControlable, BaseAmas): def add_agent( self, - experience_name: str, client_ip: str = None, agent_name: str = "agent.py", args: List = None @@ -87,7 +87,7 @@ class AsyncAmas(AsyncControlable, BaseAmas): } command = "nohup python " - command += "\'" + self.iot_path + experience_name + "/" + agent_name + "\' \'" + command += "\'" + self.iot_path + self.experiment_folder + "/" + agent_name + "\' \'" command += json.dumps(arg_dict) + "\' " for arg in args: command += str(arg) + " " @@ -113,4 +113,24 @@ class AsyncAmas(AsyncControlable, BaseAmas): self.subscribe("agent/" + str(self.next_id) + "/metric", self.agent_metric) self.client.publish("amas/agent/new", self.next_id) - self.next_id += 1 \ No newline at end of file + self.next_id += 1 + + def run(self) -> None: + """ + Main method of the client + """ + + while not self.exit_bool: + # wait to be unpause + self.wait() + + # check the need to exit + if self.exit_bool: + return + + self.publish("amas/graph", str(self.to_graph())) + self.publish("amas/all_metric", str(self.agents_metric)) + self.behaviour() + + sleep(self.wait_delay) + self.nbr_cycle += 1 \ No newline at end of file diff --git a/iotAmak/amas/base_amas.py b/iotAmak/amas/base_amas.py index 7ae8a000ce3b39ec0e17492484b4605709b5611f..ec7b91739b1ee0f7a0f0ba4a1e4fb86050916a81 100644 --- a/iotAmak/amas/base_amas.py +++ b/iotAmak/amas/base_amas.py @@ -40,6 +40,7 @@ class BaseAmas(SSHClient): self.on_initialization() self.on_initial_agents_creation() self.agents_metric: List[Dict] = [{} for _ in range(self.next_id)] + self.agent_info: List[Dict] = [{} for _ in range(self.next_id)] def on_initialization(self) -> None: """ @@ -133,4 +134,8 @@ class BaseAmas(SSHClient): # print("Received message ", literal_eval(message.payload.decode("utf-8")), " on topic '" + message.topic) result = literal_eval(message.payload.decode("utf-8")) agent_id = result.get("id") - self.agents_metric[agent_id] = result + self.agents_metric[agent_id] = result.get("metric") + self.agent_info[agent_id] = result.get("amas") + + def to_graph(self) -> dict: + pass diff --git a/setup.py b/setup.py index fc4ebef897683b5adf56cb036be306c88c90b48e..c76ac283d8c9cc3711446558fa915d63c60fc268 100644 --- a/setup.py +++ b/setup.py @@ -3,12 +3,12 @@ from setuptools import setup, find_packages setup( name='iotAmak', packages=find_packages(), - version='0.0.7', + version='0.0.8', description='AmakFramework in python', author='SMAC - GOYON Sebastien', install_requires=[ "paho-mqtt >= 1.6.1", "paramiko >= 2.10.4", - "pexpect >= 4.8.0" + "pexpect >= 4.8.0", ], )