Skip to content

Commit

Permalink
refactor(SineGeneratorAgent): improve data sending by including actua…
Browse files Browse the repository at this point in the history
…lly computed time
  • Loading branch information
BjoernLudwigPTB committed Jul 28, 2021
1 parent 2d94f96 commit 87c3e34
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion agentMET4FOF/agents/signal_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def agent_loop(self):
"""
if self.current_state == "Running":
sine_data = self._sine_stream.next_sample() # dictionary
self.send_output(sine_data["quantities"])
self.send_output(sine_data)


class StaticSineWithJitterGeneratorAgent(AgentMET4FOF):
Expand Down
17 changes: 13 additions & 4 deletions agentMET4FOF_tutorials/tutorial_2_math_agent.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
from agentMET4FOF.agents import AgentMET4FOF, AgentNetwork, MonitorAgent, SineGeneratorAgent
from agentMET4FOF.agents import (
AgentMET4FOF,
AgentNetwork,
MonitorAgent,
SineGeneratorAgent,
)


class MathAgent(AgentMET4FOF):
def on_received_message(self, message):
Expand All @@ -21,10 +27,12 @@ def init_parameters(self, minus_param=0.5, plus_param=0.5):
self._plus_param = plus_param

def on_received_message(self, message):
minus_data = self.minus(message["data"], self._minus_param)
plus_data = self.plus(message["data"], self._plus_param)
minus_data = self.minus(message["data"]["quantities"], self._minus_param)
plus_data = self.plus(message["data"]["quantities"], self._plus_param)

self.send_output({"minus": minus_data, "plus": plus_data})
self.send_output(
{"minus": minus_data, "plus": plus_data, "time": message["data"]["time"]}
)

@staticmethod
def minus(minuend: float, subtrahend: float) -> float:
Expand All @@ -34,6 +42,7 @@ def minus(minuend: float, subtrahend: float) -> float:
def plus(summand_1: float, summand_2: float) -> float:
return summand_1 + summand_2


def main():
# start agent network server
agentNetwork = AgentNetwork()
Expand Down

0 comments on commit 87c3e34

Please sign in to comment.