Skip to content
Snippets Groups Projects
Commit 443c56f5 authored by shinedday's avatar shinedday
Browse files

Update how iotamak work with graph

parent cbb28a87
Branches
No related tags found
No related merge requests found
File added
......@@ -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
......@@ -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()))
......@@ -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
......@@ -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", "")
......
......@@ -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
......@@ -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
......@@ -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",
],
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment