The timers and counters
Overview
API: Timers and Counters
clear_counter(id_or_obj, name)
Removes a counter. Args: id_or_obj (Agent | int): The agent id or object. name (str): The name of the counter.
clear_timer(id_or_obj, name)
Deactivate a timer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id_or_obj
|
Agent | int
|
The id or object of the agent that has the timer. |
required |
name
|
str
|
Timer name. |
required |
delay_app(seconds=0, minutes=0)
Creates a Promise that waits for the specified time to elapse. This is in application time (i.e. it could NOT get paused).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seconds
|
int
|
The number of seconds. Defaults to 0. |
0
|
minutes
|
int
|
The number of minutes. Defaults to 0. |
0
|
Returns:
| Name | Type | Description |
|---|---|---|
Promise |
Delay
|
A promise that is done when time has elapsed. |
delay_sim(seconds=0, minutes=0)
Creates a Promise that waits for the specified time to elapse. This is in simulation time (i.e. it could get paused).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seconds
|
int
|
The number of seconds. Defaults to 0. |
0
|
minutes
|
int
|
The number of minutes. Defaults to 0. |
0
|
Returns:
| Name | Type | Description |
|---|---|---|
Promise |
Delay
|
A promise that is done when time has elapsed. |
delay_test(seconds=0, minutes=0)
Creates a Promise that waits for the specified time to elapse. This is for unit testing and not realtime.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seconds
|
int
|
The number of seconds. Defaults to 0. |
0
|
minutes
|
int
|
The number of minutes. Defaults to 0. |
0
|
Returns:
| Name | Type | Description |
|---|---|---|
Promise |
A promise that is done when time has elapsed. |
format_time_remaining(id_or_obj, name)
Get the remaining time on a timer and return a formatted string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id_or_obj
|
Agent | int
|
The agent id or object. |
required |
name
|
str
|
The timer name. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
A formatted string with the minutes and seconds left on the timer. |
get_counter_elapsed_seconds(id_or_obj, name, default_value=None)
Returns the number of seconds since the counter started.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id_or_obj
|
Agent | int
|
The agent id or object. |
required |
name
|
str
|
The counter name. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
The number of seconds since the counter started. |
get_time_remaining(id_or_obj, name)
The number of seconds remaining for a timer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id_or_obj
|
agent
|
The agent id or object. |
required |
name
|
str
|
The timer name. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
The number of seconds remaining. |
is_timer_finished(id_or_obj, name)
Check to see if a timer is finished.
Note
- If the timer is not set, this function returns true.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id_or_obj
|
Agent | int
|
The id or object of the agent that has the timer. |
required |
name
|
str
|
Timer name |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
True if a timer finished, or if it is not set. |
is_timer_set(id_or_obj, name)
Check to see if a timer is running.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id_or_obj
|
Agent | int
|
The id or object of the agent that has the timer |
required |
name
|
str
|
Timer name |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
True if a timer exists |
is_timer_set_and_finished(id_or_obj, name)
Check to see if a timer was set and is finished.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id_or_obj
|
Agent | int
|
The id or object of the agent that has the timer. |
required |
name
|
str
|
Timer name. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
True if a timer finished and was set. |
set_timer(id_or_obj, name, seconds=0, minutes=0)
Set up a timer
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id_or_obj
|
Agent | int
|
The agent to set the timer for |
required |
name
|
str
|
The name of the timer |
required |
seconds
|
int
|
The number of seconds. Defaults to 0. |
0
|
minutes
|
int
|
The number of minutes. Defaults to 0. |
0
|
start_counter(id_or_obj, name)
Starts counting seconds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id_or_obj
|
Agent | int
|
The agent for which to set the timer. |
required |
name
|
str
|
The name of the counter. |
required |
timeout(seconds=0, minutes=0)
Creates a Promise that waits for the specified time to elapse. This is in simulation time (i.e. it could NOT get paused).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seconds
|
int
|
The number of seconds. Defaults to 0. |
0
|
minutes
|
int
|
The number of minutes. Defaults to 0. |
0
|
Returns:
| Name | Type | Description |
|---|---|---|
Promise |
Delay
|
A promise that is done when time has elapsed. |
timeout_sim(seconds=0, minutes=0)
Creates a Promise that waits for the specified time to elapse. This is in simulation time (i.e. it could get paused).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seconds
|
int
|
The number of seconds. Defaults to 0. |
0
|
minutes
|
int
|
The number of minutes. Defaults to 0. |
0
|
Returns:
| Name | Type | Description |
|---|---|---|
Promise |
Delay
|
A promise that is done when time has elapsed |