WattsonTime#
- class wattson.time.wattson_time.WattsonTime(wall_clock_reference: float = None, sim_clock_reference: float = None, speed: float = 1)#
Bases:
object
A representation for time in both, the wall-clock perspective and the simulated time. Simulated time is defined at a different speed and with a given offset to wall-clock time, i.e., the offset is derived from a representation of a wall-clock timestamp that corresponds to a simulation clock timestamp.
Methods
Creates a new WattsonTime object.
copy
Synchronize this time instance with other participants in the simulation.
extract_timestamp_from_file
Returns the current wall time as a datetime string for usage as a file name in ISO 8601.
from_offset
iso_format
Returns the number of seconds passed since the start of the simulation in wall clock time
Returns the number of seconds passed since the start of the simulation in simulation clock time
passed_wall_clock_seconds
pull
push
set_sim_clock_reference
set_speed
set_wall_clock_reference
set_wallclock_function
Returns the current simulation clock timestamp
Returns the timestamp the simulation started at in sim-clock time
Returns a datetime object representing the simulation start time of the given time type
start_datetime_local
The timestamp the simulation started at in wall-clock time
sync_from
Returns the current timestamp for the selected time type
Returns the represented time as a datetime.datetime object.
to_local_datetime
to_utc_datetime
Returns the current (wall-clock) timestamp
Returns the timestamp the simulation started at in wall-clock time
Attributes
reference_sim
reference_wall
speed
- __init__(wall_clock_reference: float = None, sim_clock_reference: float = None, speed: float = 1)#
Creates a new WattsonTime object. If no parameters are given, this instance represents the concurrent execution of both, the wall-clock and the simulation clock.
- Parameters:
wall_clock_reference (float, optional) – The start time of the simulation as wall-clock timestamp (Default value = None)
sim_clock_reference (float, optional) – The start time of the simulation in simulated time, i.e., the simulated timestamp that corresponds to the wall-clock timestamp (Default value = None)
speed (float, optional) – The speed factor between wall-clock and simulation clock. A value of 2 indicates that for each wall-clock second, two simulated seconds pass. (Default value = 1)
- enable_synchronization(wattson_client: WattsonClient, enable_pull: bool = True, enable_push: bool = True, prefer_local: bool = False)#
Synchronize this time instance with other participants in the simulation.
- Parameters:
wattson_client ('WattsonClient') – The WattsonClient to use for simulation
enable_pull (bool, optional) – Whether to apply received time updates locally (Default value = True)
enable_push (bool, optional) – Whether to submit local time to the WattsonServer (Default value = True)
prefer_local (bool, optional) – Whether to initially submit the local time to the WattsonServer (Default value = False)
- file_name(time_type: WattsonTimeType, as_local: bool = False, with_time: bool = True, with_milliseconds: bool = False, with_timestamp: bool = False, force_dashes: bool = True) str #
Returns the current wall time as a datetime string for usage as a file name in ISO 8601.
- Parameters:
time_type (WattsonTimeType) – The time type to return (wall or simulation)
as_local (bool, optional) – Whether to use the local timezone or UTC. (Default value = False)
with_time (bool, optional) – Whether to include the time besides the date in the string (Default value = True)
with_milliseconds (bool, optional) – Whether to add milliseconds to the string (requires with_time = True) (Default value = False)
with_timestamp (bool, optional) – Whether to add the timestamp to the string (Default value = False)
force_dashes (bool, optional) – Replace dots and colons with dashes for better file system compatibility (Default value = True)
- Returns:
A String representation of the current time to be used as a filename
- Return type:
str
- passed_seconds(time_type: WattsonTimeType) float #
Returns the number of seconds passed since the start of the simulation in wall clock time
- Parameters:
time_type (WattsonTimeType) – The time type to return (wall or simulation)
- Returns:
The number of seconds passed since the start of the simulation
- Return type:
float
- passed_sim_clock_seconds() float #
Returns the number of seconds passed since the start of the simulation in simulation clock time
- sim_clock_time() float #
Returns the current simulation clock timestamp
- sim_start_time() float #
Returns the timestamp the simulation started at in sim-clock time
- start_datetime(time_type: WattsonTimeType, timezone: tzinfo = datetime.timezone.utc) datetime #
Returns a datetime object representing the simulation start time of the given time type
- Parameters:
time_type (WattsonTimeType) – The time type to return (wall or simulation)
timezone (datetime.tzinfo, optional) – The timezone (tzinfo) to use. (Default value = datetime.timezone.utc)
- Returns:
The datetime object representing the simulation’s start time
- Return type:
datetime.datetime
- start_timestamp(time_type: WattsonTimeType) float #
The timestamp the simulation started at in wall-clock time
- Parameters:
time_type (WattsonTimeType) – The time type to return (wall or simulation)
- Returns:
The wall-clock timestamp that the simulation started
- Return type:
float
- time(time_type: WattsonTimeType = WattsonTimeType.WALL) float #
Returns the current timestamp for the selected time type
- Parameters:
time_type (WattsonTimeType, optional) – The type to return (wall or simulated) (Default value = WattsonTimeType.WALL)
- Returns:
The current timestamp
- Return type:
float
- to_datetime(time_type: WattsonTimeType, timezone: tzinfo = datetime.timezone.utc) datetime #
Returns the represented time as a datetime.datetime object.
- Parameters:
time_type (WattsonTimeType) – The time type to return (wall or simulation)
timezone (datetime.tzinfo, optional) – The timezone (tzinfo) to use. (Default value = datetime.timezone.utc)
- Returns:
The datetime object representing the current time
- Return type:
datetime.datetime
- wall_clock_time() float #
Returns the current (wall-clock) timestamp
- wall_start_time() float #
Returns the timestamp the simulation started at in wall-clock time