Time Control
A decorator to run a method based on a time condition.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
condition |
dict
|
A dictionary containing conditions to check against the |
required |
when_run |
bool
|
If True, the decorated method will run when the condition is met. If False, the decorated method will not run when the condition is met. |
True
|
Example
class TestActor(Actor):
@time_condition(condition={"month": 1, "day": 1}, when_run=True)
def happy_new_year(self):
print("Today is 1th, January, Happy new year!")
parameters = {"time": {"start": "1996-12-24", "days": 1}}
model = MainModel(parameters=parameters)
agent = model.agents.new(TestActor, 1, singleton=True)
for _ in range(10):
print(f"Time now is {model.time}")
model.time.go()
agent.happy_new_year()
1998-01-01
) if we run this model longer... It means, the function will be called when the condition is fully satisfied.
Source code in abses/time.py
Bases: _Component
TimeDriver provides the functionality to manage time.
This class is responsible for managing the time of a simulation model. It keeps track of the current time period, updates it according to a given frequency, and provides properties to access different components of the current time period (e.g., day, hour, etc.). The TimeDriver
class is a singleton, meaning that there can be only one instance of it per simulation model.
When init a TimeDriver
, it accepts below parameters:
Parameter Name | Expected Data Type | Default Value | Description |
---|---|---|---|
start | str, None | None | If None: use the current time, else: should be a string which can be parsed by pendulum.parse() . |
end | str, int, None | None | If it's a string that can be parsed into datetime the model should end until achieving this time; if int: the model should end in that tick; if None no auto-end. |
irregular | bool | False | If False: not dive into an irregular mode (tick-mode); if True, the model will solve as an irregular mode. |
years | int | 0 | Time duration in years for the duration mode. |
months | int | 0 | Time duration in months for the duration mode. |
weeks | int | 0 | Time duration in weeks for the duration mode. |
days | int | 0 | Time duration in days for the duration mode. |
hours | int | 0 | Time duration in hours for the duration mode. |
minutes | int | 0 | Time duration in minutes for the duration mode. |
seconds | int | 0 | Time duration in seconds for the duration mode. |
See tutorial to see more.
Source code in abses/time.py
days_in_month
property
¶
Get the total number of days of the month that this period falls on for the model.
go ¶
Increments the tick.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ticks |
int
|
How many ticks to increase. |
1
|
Source code in abses/time.py
parse_duration ¶
Set the duration of the time driver.
Source code in abses/time.py
strftime ¶
Returns a string representing the current time.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fmt |
Optional[str]
|
An explicit format string of datetime. |
None
|