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

Update how iotamak work with graph

parent cbb28a87
No related branches found
No related tags found
No related merge requests found
File added
...@@ -63,7 +63,7 @@ class Agent(Schedulable, BaseAgent): ...@@ -63,7 +63,7 @@ class Agent(Schedulable, BaseAgent):
self.on_cycle_end() 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("canvas", str(self.to_canvas()))
self.publish("cycle_done", "") self.publish("cycle_done", "")
self.nbr_cycle += 1 self.nbr_cycle += 1
...@@ -53,6 +53,6 @@ class AsyncAgent(AsyncControlable, BaseAgent): ...@@ -53,6 +53,6 @@ class AsyncAgent(AsyncControlable, BaseAgent):
self.on_decide() self.on_decide()
self.on_act() self.on_act()
self.on_cycle_end() 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("canvas", str(self.to_canvas()))
...@@ -90,3 +90,9 @@ class BaseAgent: ...@@ -90,3 +90,9 @@ class BaseAgent:
Should be override if the neighbor need to be aware of any other info, should be a dict Should be override if the neighbor need to be aware of any other info, should be a dict
""" """
return {"id": self.id} 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): ...@@ -69,6 +69,7 @@ class Amas(Schedulable, BaseAmas):
return return
self.publish("amas/all_metric", str(self.agents_metric)) self.publish("amas/all_metric", str(self.agents_metric))
self.publish("amas/graph", str(self.to_graph()))
self.on_cycle_begin() self.on_cycle_begin()
self.client.publish("amas/action_done", "") self.client.publish("amas/action_done", "")
......
...@@ -2,6 +2,7 @@ import pathlib ...@@ -2,6 +2,7 @@ import pathlib
import sys import sys
import json import json
from ast import literal_eval from ast import literal_eval
from time import sleep
from typing import List from typing import List
...@@ -59,7 +60,6 @@ class AsyncAmas(AsyncControlable, BaseAmas): ...@@ -59,7 +60,6 @@ class AsyncAmas(AsyncControlable, BaseAmas):
def add_agent( def add_agent(
self, self,
experience_name: str,
client_ip: str = None, client_ip: str = None,
agent_name: str = "agent.py", agent_name: str = "agent.py",
args: List = None args: List = None
...@@ -87,7 +87,7 @@ class AsyncAmas(AsyncControlable, BaseAmas): ...@@ -87,7 +87,7 @@ class AsyncAmas(AsyncControlable, BaseAmas):
} }
command = "nohup python " 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) + "\' " command += json.dumps(arg_dict) + "\' "
for arg in args: for arg in args:
command += str(arg) + " " command += str(arg) + " "
...@@ -113,4 +113,24 @@ class AsyncAmas(AsyncControlable, BaseAmas): ...@@ -113,4 +113,24 @@ class AsyncAmas(AsyncControlable, BaseAmas):
self.subscribe("agent/" + str(self.next_id) + "/metric", self.agent_metric) self.subscribe("agent/" + str(self.next_id) + "/metric", self.agent_metric)
self.client.publish("amas/agent/new", self.next_id) self.client.publish("amas/agent/new", self.next_id)
self.next_id += 1 self.next_id += 1
\ No newline at end of file
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): ...@@ -40,6 +40,7 @@ class BaseAmas(SSHClient):
self.on_initialization() self.on_initialization()
self.on_initial_agents_creation() self.on_initial_agents_creation()
self.agents_metric: List[Dict] = [{} for _ in range(self.next_id)] 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: def on_initialization(self) -> None:
""" """
...@@ -133,4 +134,8 @@ class BaseAmas(SSHClient): ...@@ -133,4 +134,8 @@ class BaseAmas(SSHClient):
# print("Received message ", literal_eval(message.payload.decode("utf-8")), " on topic '" + message.topic) # print("Received message ", literal_eval(message.payload.decode("utf-8")), " on topic '" + message.topic)
result = literal_eval(message.payload.decode("utf-8")) result = literal_eval(message.payload.decode("utf-8"))
agent_id = result.get("id") 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 ...@@ -3,12 +3,12 @@ from setuptools import setup, find_packages
setup( setup(
name='iotAmak', name='iotAmak',
packages=find_packages(), packages=find_packages(),
version='0.0.7', version='0.0.8',
description='AmakFramework in python', description='AmakFramework in python',
author='SMAC - GOYON Sebastien', author='SMAC - GOYON Sebastien',
install_requires=[ install_requires=[
"paho-mqtt >= 1.6.1", "paho-mqtt >= 1.6.1",
"paramiko >= 2.10.4", "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