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

Version : IotAmak-0.0.4

Feature :
 * Amas, Env and Agent now take only 1 argument to simplify arg managment for the user. (Not compatible with 0.0.3)
 * It's now possible to seed the experiment.
 * Scheduler will print exec time

Requirements.txt / Setup.py :
 * add requirement version

Known bug :
 * Scheduler : auto mode pause seem to lock the scheduler in a state where it's not possible to interact anymore with it.
parent 2b991da3
No related branches found
No related tags found
No related merge requests found
No preview for this file type
File added
"""
Agent class file
"""
import json
import random
from ast import literal_eval
from typing import Dict, List
......@@ -17,9 +19,20 @@ class Agent(Schedulable):
base class for agent
"""
def __init__(self, identifier: int, broker_ip: str) -> None:
def __init__(self, arguments: str) -> None:
arguments = json.loads(arguments)
broker_ip: str = arguments.get("broker_ip")
identifier: int = int(arguments.get("identifier"))
seed: int = int(arguments.get("seed"))
self.id: int = identifier
random.seed(seed + 10 + self.id)
print(random.random())
Schedulable.__init__(self, broker_ip, "Agent" + str(self.id))
self.subscribe("scheduler/agent/wakeup", self.wake_up)
......
"""
Amas class
"""
import json
from ast import literal_eval
from typing import List, Dict
import sys
import pathlib
import random
sys.path.insert(0, str(pathlib.Path(__file__).parent))
......@@ -19,13 +21,24 @@ class Amas(Schedulable, SSHClient):
Amas class
"""
def __init__(self, broker_ip: str, clients: str) -> None:
def __init__(self, arguments: str) -> None:
arguments = json.loads(arguments)
broker_ip: str = arguments.get("broker_ip")
clients: str = arguments.get("clients")
seed: int = int(arguments.get("seed"))
random.seed(seed)
Schedulable.__init__(self, broker_ip, "Amas")
true_client = [RemoteClient(i.get("hostname"), i.get("user"), i.get("password")) for i in literal_eval(clients)]
SSHClient.__init__(self, true_client)
self.seed = seed
self.broker_ip: str = broker_ip
self.subscribe("scheduler/schedulable/wakeup", self.wake_up)
......@@ -54,10 +67,12 @@ class Amas(Schedulable, SSHClient):
"""
if args is None:
args = []
arg_dict = {"broker_ip": str(self.broker_ip), "seed": self.seed, "identifier": self.next_id}
command = "nohup python "
command += "\"Desktop/mqtt_goyon/example/" + experience_name + "/agent.py\" "
command += str(self.next_id) + " \""
command += str(self.broker_ip) + "\" "
command += "\'Desktop/mqtt_goyon/example/" + experience_name + "/agent.py\' \'"
command += json.dumps(arg_dict) + "\' "
for arg in args:
command += str(arg) + " "
command += "&"
......
"""
Environment class
"""
import json
import random
import sys
import pathlib
......@@ -14,7 +16,15 @@ class Environment(Schedulable):
Environment class
"""
def __init__(self, broker_ip: str) -> None:
def __init__(self, arguments: str) -> None:
arguments = json.loads(arguments)
broker_ip: str = arguments.get("broker_ip")
seed: int = int(arguments.get("seed"))
random.seed(seed + 1)
Schedulable.__init__(self, broker_ip, "Env")
self.subscribe("scheduler/schedulable/wakeup", self.wake_up)
......
......@@ -2,7 +2,7 @@
Scheduler class file
"""
from threading import Semaphore
from time import sleep
from time import sleep, time
import sys
import pathlib
......@@ -144,19 +144,28 @@ class Scheduler(Schedulable):
self.wait_ihm()
if self.exit_bool:
print("Exit")
break
print("-First part")
start_time = time()
self.first_part()
print("--- %s seconds ---" % (time() - start_time))
print("-Main part")
start_time = time()
self.main_part()
print("--- %s seconds ---" % (time() - start_time))
print("-Last part")
start_time = time()
self.last_part()
print("--- %s seconds ---" % (time() - start_time))
self.nbr_cycle += 1
self.publish("scheduler/cycledone", "")
# exit
print("Exit loop")
self.client.publish("scheduler/schedulable/wakeup", "")
self.client.publish("scheduler/agent/wakeup", "")
sleep(5)
print("Done")
paho-mqtt
paramiko
pexpect
\ No newline at end of file
paho-mqtt >= 1.6.1
paramiko >= 2.10.4
pexpect >= 4.8.0
\ No newline at end of file
......@@ -3,8 +3,12 @@ from setuptools import setup, find_packages
setup(
name='iotAmak',
packages=find_packages(),
version='0.0.3',
version='0.0.4',
description='AmakFramework in python',
author='SMAC - GOYON Sebastien',
install_requires=[],
install_requires=[
"paho-mqtt >= 1.6.1",
"paramiko >= 2.10.4",
"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