コード例 #1
0
ファイル: test_template.py プロジェクト: javipalanca/spade
def test_match_false_thread():
    template = Template()
    template.thread = "thread-id"

    message = Message()

    assert not template.match(message)

    message.thread = "thread-id-false"

    assert not template.match(message)
コード例 #2
0
ファイル: test_template.py プロジェクト: javipalanca/spade
def test_match():
    template = Template()
    template.sender = "sender1@host"
    template.to = "recv1@host"
    template.body = "Hello World"
    template.thread = "thread-id"
    template.metadata = {"performative": "query"}

    message = Message()
    message.sender = "sender1@host"
    message.to = "recv1@host"
    message.body = "Hello World"
    message.thread = "thread-id"
    message.set_metadata("performative", "query")

    assert template.match(message)
コード例 #3
0
ファイル: utils.py プロジェクト: javipalanca/simfleet
async def request_path(agent, origin, destination, route_host):
    """
    Sends a message to the RouteAgent to request a path

    Args:
        agent: the agent who is requesting the path
        origin (list): a list with the origin coordinates [longitude, latitude]
        destination (list): a list with the target coordinates [longitude, latitude]
        route_host (str): name of the route host server

    Returns:
        list, float, float: a list of points (longitude and latitude) representing the path,
                            the distance of the path in meters, a estimation of the duration of the path

    Examples:
        >>> path, distance, duration = request_path(agent, origin=[0,0], destination=[1,1])
        >>> print(path)
        [[0,0], [0,1], [1,1]]
        >>> print(distance)
        2.0
        >>> print(duration)
        3.24
    """
    if origin[0] == destination[0] and origin[1] == destination[1]:
        return [[origin[1], origin[0]]], 0, 0

    msg = Message()
    msg.thread = str(uuid.uuid4()).replace("-", "")
    template = Template()
    template.thread = msg.thread
    behav = RequestRouteBehaviour(msg, origin, destination, route_host)
    agent.add_behaviour(behav, template)

    while not behav.is_killed():
        await asyncio.sleep(0.01)

    if (behav.exit_code is {} or "type" in behav.exit_code
            and behav.exit_code["type"] == "error"):
        return None, None, None
    else:
        return (
            behav.exit_code["path"],
            behav.exit_code["distance"],
            behav.exit_code["duration"],
        )
コード例 #4
0
def test_behaviour_match():
    class TestBehaviour(OneShotBehaviour):
        async def run(self):
            pass

    template = Template()
    template.sender = "sender1@host"
    template.to = "recv1@host"
    template.body = "Hello World"
    template.thread = "thread-id"
    template.metadata = {"performative": "query"}

    behaviour = TestBehaviour()
    behaviour.set_template(template)

    msg = Message()
    msg.sender = "sender1@host"
    msg.to = "recv1@host"
    msg.body = "Hello World"
    msg.thread = "thread-id"
    msg.set_metadata("performative", "query")

    assert behaviour.match(msg)
コード例 #5
0
ファイル: test_behaviour.py プロジェクト: javipalanca/spade
def test_behaviour_match():
    class TestBehaviour(OneShotBehaviour):
        async def run(self):
            pass

    template = Template()
    template.sender = "sender1@host"
    template.to = "recv1@host"
    template.body = "Hello World"
    template.thread = "thread-id"
    template.metadata = {"performative": "query"}

    behaviour = TestBehaviour()
    behaviour.set_template(template)

    msg = Message()
    msg.sender = "sender1@host"
    msg.to = "recv1@host"
    msg.body = "Hello World"
    msg.thread = "thread-id"
    msg.set_metadata("performative", "query")

    assert behaviour.match(msg)
コード例 #6
0
ファイル: templates.py プロジェクト: Jingjing0829/RoboticArm
import time
from spade.agent import Agent
from spade.behaviour import OneShotBehaviour
from spade.message import Message
from spade.template import Template

print("1 -- Templates")

template = Template()
# template.sender = "sender1@host"
template.sender = "madks@Temp3rr0r-pc"
# template.to = "recv1@host"
template.to = "admin@Temp3rr0r-pc"
template.body = "Hello World"
template.thread = "thread-id"
template.metadata = {"performative": "query"}

message = Message()
# message.sender = "sender1@host"
message.sender = "madks@Temp3rr0r-pc"
# message.to = "recv1@host"
message.to = "admin@Temp3rr0r-pc"
message.body = "Hello World"
message.thread = "thread-id"
message.set_metadata("performative", "query")

assert template.match(message)

t1 = Template()
# t1.sender = "sender1@host"
t1.sender = "madks@Temp3rr0r-pc"