def init_parameters(self): """Initialize the input data Initialize the input data stream as an instance of the :py:mod:`SineGenerator` class """ self._sine_stream = SineGenerator()
def init_parameters(self, amplitude=1.0, frequency=0.5): """Initialize the input data Initialize the input data stream as an instance of the :py:mod:`SineGenerator` class """ self.frequency = frequency self.amplitude = amplitude self._sine_stream = SineGenerator()
def init_parameters(self, nested_output=False, scaler=1.0): """Initialize the input data Initialize the input data stream as an instance of the :py:mod:`SineGenerator` class """ self._sine_stream = SineGenerator() self.nested_output = nested_output self.scaler = scaler
class NoisySineGeneratorAgent(AgentMET4FOF): """An agent streaming a sine signal Takes samples from the :py:mod:`SineGenerator` and pushes them sample by sample to connected agents via its output channel. """ # The datatype of the stream will be SineGenerator. _sine_stream: SineGenerator def init_parameters(self): """Initialize the input data Initialize the input data stream as an instance of the :py:mod:`SineGenerator` class """ self._sine_stream = SineGenerator() def agent_loop(self): """Model the agent's behaviour On state *Running* the agent will extract sample by sample the input data streams content and push it via invoking :py:method:`AgentMET4FOF.send_output`. """ if self.current_state == "Running": sine_data = self._sine_stream.next_sample() # dictionary sine_data["quantities"] = sine_data["quantities"] + np.random.rand( *sine_data["quantities"].shape) self.send_output(sine_data)
class ParameterisedSineGeneratorAgent(AgentMET4FOF): """An agent streaming a sine signal Takes samples from the :py:mod:`SineGenerator` and pushes them sample by sample to connected agents via its output channel. """ # The datatype of the stream will be SineGenerator. _sine_stream: SineGenerator # dictionary of possible parameter options for init # every {key:iterable} will be displayed on the dashboard as a dropdown # NOTE: Currently supports keyword arguments only. parameter_choices = { "amplitude": {0, 1, 2, 3, 4, 5, 6}, "frequency": {1, 2, 3} } stylesheet = "ellipse" def init_parameters(self, amplitude=1.0, frequency=0.5): """Initialize the input data Initialize the input data stream as an instance of the :py:mod:`SineGenerator` class """ self.frequency = frequency self.amplitude = amplitude self._sine_stream = SineGenerator() def agent_loop(self): """Model the agent's behaviour On state *Running* the agent will extract sample by sample the input data streams content and push it via invoking :py:method:`AgentMET4FOF.send_output`. """ if self.current_state == "Running": sine_data = self._sine_stream.next_sample() # dictionary self.send_output(sine_data["quantities"])
class BufferSineGeneratorAgent(AgentMET4FOF): """An agent streaming a sine signal Takes samples from the :py:mod:`SineGenerator` and pushes them sample by sample to connected agents via its output channel. """ # The datatype of the stream will be SineGenerator. _sine_stream: SineGenerator def init_parameters(self): """Initialize the input data Initialize the input data stream as an instance of the :py:mod:`SineGenerator` class """ self._sine_stream = SineGenerator() def agent_loop(self): """Model the agent's behaviour On state *Running* the agent will extract sample by sample the input data streams content and push it via invoking :py:method:`AgentMET4FOF.send_output`. """ if self.current_state == "Running": sine_data = self._sine_stream.next_sample() # dictionary # store buffer with received data from input agent # By default, the AgentBuffer is a FIFO buffer and when new n entries are added to a filled buffer, # n entries from the left of buffer will be automatically removed. # Note: self.buffer.store and self.buffer_store works the same way, but self.buffer_store has an additional `log_info` to it, # so it will print out its content if logging is enabled. self.buffer.store( agent_from=self.name, data=sine_data ) # equivalent to self.buffer_store but without logging. # check if buffer is filled up, then send out computed mean on the buffer if self.buffer.buffer_filled(self.name): # access buffer content by accessing its key, it works like a dictionary # the actual dictionary is stored in self.buffer.buffer buffer_content = self.buffer[self.name] buffer_quantities = buffer_content["quantities"] buffer_time = buffer_content["time"] # print out the buffer content self.log_info("buffer_content:" + str(buffer_content)) # send out processed data # note that 'time' is a special keyword for MonitorAgent's default plotting behaviour # which renders it as the x-axis in a time-series graph # for more customisation, see the tutorials on custom plotting. self.send_output({"Sine": buffer_quantities, "time": buffer_time}) # clear buffer self.buffer.clear(self.name)
class TimeSineGeneratorAgent(AgentMET4FOF): def init_parameters(self): self.stream = SineGenerator() def agent_loop(self): if self.current_state == "Running": sine_data = self.stream.next_sample() # dictionary # read current time stamp current_time = datetime.today().strftime("%H:%M:%S") # send out data in form of dictionary {"Time","Y"} self.send_output({"Time": current_time, "Y": sine_data["quantities"]})
class SineGeneratorAgent(AgentMET4FOF): """An agent streaming a sine signal Takes samples from the :py:mod:`SineGenerator` and pushes them sample by sample to connected agents via its output channel. """ # The datatype of the stream will be SineGenerator. _sine_stream: SineGenerator def init_parameters(self, nested_output=False, scaler=1.0): """Initialize the input data Initialize the input data stream as an instance of the :py:mod:`SineGenerator` class """ self._sine_stream = SineGenerator() self.nested_output = nested_output self.scaler = scaler def agent_loop(self): """Model the agent's behaviour On state *Running* the agent will extract sample by sample the input data streams content and push it via invoking :py:method:`AgentMET4FOF.send_output`. """ if self.current_state == "Running": sine_data = self._sine_stream.next_sample() # dictionary if self.nested_output: self.send_output({ "Sensor1": sine_data["quantities"] * self.scaler, "Sensor2": sine_data["quantities"] * self.scaler + 1.1, }) else: self.send_output(sine_data["quantities"] * self.scaler)