ClockTrigger#
- class fridom.framework.clock_trigger.ClockTrigger(start_date: datetime64 | float | None = None, start_step: int | None = None, stop_date: datetime64 | float | None = None, stop_step: int | None = None, time_interval: timedelta64 | float | None = None, step_size: int | None = None)[source]#
Bases:
objectEmits signals based on the state of a clock.
Description#
Some modules should not be active all the time. For example you may want a module that is only active every 10 time steps. This class provides some basic functionality to check if a start condition is met, if a stop condition is met, and if the module should advance.
Parameters#
- start_datenp.datetime64, float, optional
The start date of the module. If provided, the module will start when the model time is greater or equal to this date.
- start_stepint, optional
The start step of the module. If provided, the module will start when the model step is greater or equal to this step.
- stop_datenp.datetime64, float, optional
The stop date of the module. If provided, the module will stop when the model time is greater or equal to this date.
- stop_stepint, optional
The stop step of the module. If provided, the module will stop when the model step is greater or equal to this step.
- time_intervalnp.timedelta64, float, optional
The time interval between each advance of the module. If provided, the object will trigger an advance every time_interval seconds.
- step_numberint, optional
The number of steps between each advance of the module. If provided, the object will trigger an advance every step_number steps.
- __init__(start_date: datetime64 | float | None = None, start_step: int | None = None, stop_date: datetime64 | float | None = None, stop_step: int | None = None, time_interval: timedelta64 | float | None = None, step_size: int | None = None) None[source]#
Methods
__init__([start_date, start_step, ...])check(clock)Check if the module should advance with automatic start and stop.
reset()Reset the module.
should_advance(clock)Check if the module should advance.
should_start(clock)Check if the module should start.
should_stop(clock)Check if the module should stop.
Attributes
Check if the module should trigger on the first step.
Examples using
fridom.framework.ClockTrigger#- should_start(clock: Clock) bool[source]#
Check if the module should start.
Description#
This method checks if a start requirement is met. And returns True if this requirement is met and the start condition has not been met before. Hence, this method will only return True once.
Parameters#
- clockfr.Clock
The clock of the model.
Returns#
- bool
True if the module should start, False otherwise.
- should_stop(clock: Clock) bool[source]#
Check if the module should stop.
Description#
This method checks if a stop requirement is met. And returns True if this requirement is met and the stop condition has not been met before. Hence, this method will only return True once.
Parameters#
- clockfr.Clock
The clock of the model.
Returns#
- bool
True if the module should stop, False otherwise.
- should_advance(clock: Clock) bool[source]#
Check if the module should advance.
Description#
This method checks if the module should advance. It returns True if the module should advance and False otherwise.
Parameters#
- clockfr.Clock
The clock of the model.
Returns#
- bool
True if the module should advance, False otherwise.
- check(clock: Clock) bool[source]#
Check if the module should advance with automatic start and stop.
Description#
This method checks if the module should advance. It will automatically start and stop the module if the start and stop conditions are met.
Parameters#
- clockfr.Clock
The clock of the model.
Returns#
- bool
True if the module should advance, False otherwise.
- property trigger_on_first_step: bool#
Check if the module should trigger on the first step.