clock
clock
¶
Classes:
| Name | Description |
|---|---|
Clock |
A class for managing time cycles and converting between timestamp and cycle indices. |
Classes¶
Clock
¶
A class for managing time cycles and converting between timestamp and cycle indices.
This class interacts with an NTP server to synchronize time and supports operations to track cycles, manage timestamps, and calculate the time differences between cycles.
Initialize a Clock instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_delta
|
float
|
Minimum time (in seconds) between consecutive cycles. If less than or equal to zero, the cycles will be real-time-based. |
-1
|
Methods:
| Name | Description |
|---|---|
time2cycle |
Convert a given timestamp to the corresponding cycle index. |
cycle2time |
Convert a cycle index to the corresponding timestamp. |
get_time |
Get the current time based on the NTP server synchronization. |
get_time_as_string |
Get the current time as a string (ISO format). |
get_cycle |
Get the current cycle index. |
get_cycle_time |
Get the timestamp corresponding to the current cycle. |
next_cycle |
Move to the next cycle if the minimum delta time has passed or if cycles are not constrained. |
Source code in unaiverse/clock.py
Methods:¶
time2cycle
¶
Convert a given timestamp to the corresponding cycle index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timestamp
|
float
|
The timestamp to convert. |
required |
delta
|
float | None
|
The optional delta value for converting time to cycles. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The cycle index corresponding to the given timestamp. |
Source code in unaiverse/clock.py
cycle2time
¶
Convert a cycle index to the corresponding timestamp.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cycle
|
int
|
The cycle index to convert. |
required |
delta
|
float | None
|
The optional delta value for converting cycles to time. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
The timestamp corresponding to the given cycle index. |
Source code in unaiverse/clock.py
get_time
¶
Get the current time based on the NTP server synchronization.
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
The current synchronized time (in seconds since the Unix epoch). |
Source code in unaiverse/clock.py
get_time_as_string
¶
Get the current time as a string (ISO format).
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
A string representation of the current time (ISO format, UTC). |
Source code in unaiverse/clock.py
get_cycle
¶
get_cycle_time
¶
Get the timestamp corresponding to the current cycle.
Returns:
| Name | Type | Description |
|---|---|---|
float |
The timestamp corresponding to the current cycle index. |
next_cycle
¶
Move to the next cycle if the minimum delta time has passed or if cycles are not constrained.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the cycle was successfully moved to the next one, False otherwise. |