runtimepy.channel.environment package

Contents

runtimepy.channel.environment package#

Subpackages#

Submodules#

runtimepy.channel.environment.array module#

A channel-environment extension for creating arrays of primitives.

class runtimepy.channel.environment.array.ArrayChannelEnvironment(channels: ChannelRegistry = None, enums: EnumRegistry = None, values: dict[str | int, bool | int | float | str] = None, fields: Iterable[BitFields] = None, namespace: Namespace = None, namespace_delim: str = '.')[source]#

Bases: BaseChannelEnvironment

A channel-environment extension for working with arrays of primitives.

array(keys: Iterable[str | int] = None, **kwargs) ChannelArray[source]#

Create a primitive array from an in-order iterable of registry keys.

property names: Iterator[str]#

Iterate over registered names in the environment.

class runtimepy.channel.environment.array.ChannelArray(names: list[str], array: PrimitiveArray)[source]#

Bases: NamedTuple

A class for managing an array of channels and bit-fields.

array: PrimitiveArray#

Alias for field number 1

static create(**kwargs) ChannelArray[source]#

Create a new, empty channel array.

names: list[str]#

Alias for field number 0

runtimepy.channel.environment.base module#

A module implementing a base channel environment.

class runtimepy.channel.environment.base.BaseChannelEnvironment(channels: ChannelRegistry = None, enums: EnumRegistry = None, values: dict[str | int, bool | int | float | str] = None, fields: Iterable[BitFields] = None, namespace: Namespace = None, namespace_delim: str = '.')[source]#

Bases: NamespaceMixin, FinalizeMixin

A class integrating channel and enumeration registries.

add_field(field: BitField, namespace: Namespace = None) str[source]#

Add a bit field to the environment.

add_int(key: str | int, amount: int) int[source]#

Modify an integer channel.

age_ns(key: str | int) int[source]#

Get the age of an entity based on registry key.

apply(values: dict[str | int, bool | int | float | str]) None[source]#

Apply a map of values to the environment.

exists(val: str | int) bool[source]#

Determine if a channel exists.

field_or_channel(val: str | int) BitField | Channel[Int8Primitive] | Channel[Int16Primitive] | Channel[Int32Primitive] | Channel[Int64Primitive] | Channel[Uint8Primitive] | Channel[Uint16Primitive] | Channel[Uint32Primitive] | Channel[Uint64Primitive] | Channel[FloatPrimitive] | Channel[DoublePrimitive] | Channel[BooleanPrimitive] | None[source]#

Attempt to look up a field or channel for a given registry key.

finalize(strict: bool = True) None[source]#

Finalize this instance.

get(val: str | int) tuple[Channel[Int8Primitive] | Channel[Int16Primitive] | Channel[Int32Primitive] | Channel[Int64Primitive] | Channel[Uint8Primitive] | Channel[Uint16Primitive] | Channel[Uint32Primitive] | Channel[Uint64Primitive] | Channel[FloatPrimitive] | Channel[DoublePrimitive] | Channel[BooleanPrimitive], RuntimeEnum | None] | None[source]#

Attempt to get a channel and its enumeration (if it has one).

get_bool(key: str | int) tuple[Channel[BooleanPrimitive], RuntimeEnum | None][source]#

Get a boolean channel.

get_float(key: str | int) Channel[FloatPrimitive] | Channel[DoublePrimitive][source]#

Get a floating-point channel.

get_int(key: str | int) tuple[Channel[Int8Primitive] | Channel[Int16Primitive] | Channel[Int32Primitive] | Channel[Int64Primitive] | Channel[Uint8Primitive] | Channel[Uint16Primitive] | Channel[Uint32Primitive] | Channel[Uint64Primitive], RuntimeEnum | None][source]#

Get an integer channel.

async sample_bool_for(key: str | int, timeout: float, count: int = -1, current: bool = True) AsyncIterator[tuple[bool, int]][source]#

Sample a boolean channel.

async sample_enum_for(key: str | int, timeout: float, count: int = -1, current: bool = True) AsyncIterator[tuple[str, int]][source]#

Sample an enumeration channel.

async sample_float_for(key: str | int, timeout: float, count: int = -1, current: bool = True, scale: bool = True) AsyncIterator[tuple[float, int]][source]#

Sample a floating-point channel.

async sample_int_for(key: str | int, timeout: float, count: int = -1, current: bool = True, scale: bool = True) AsyncIterator[tuple[int | float, int]][source]#

Sample an integer channel.

set(key: str | int, value: bool | int | float | str, scaled: bool = True) None[source]#

Attempt to set an arbitrary channel value.

value(key: str | int, resolve_enum: bool = True, scaled: bool = True) bool | int | float | str[source]#

Attempt to get a channel’s current value.

values(resolve_enum: bool = True) dict[str | int, bool | int | float | str][source]#

Get a new dictionary of current channel values.

async wait_for_bool(key: str | int, state: bool, timeout: float) EvalResult[source]#

wait for a boolean state to reach a provided state within a timeout.

async wait_for_enum(key: str | int, value: str, timeout: float) EvalResult[source]#

Wait for an enumeration channel to reach a specific value.

async wait_for_numeric(key: str | int, value: int | float, timeout: float, operation: Operator = Operator.EQUAL) EvalResult[source]#

Wait for a numeric event.

async wait_for_numeric_isclose(key: str | int, value: float, timeout: float, rel_tol: float = 1e-09, abs_tol: float = 0.0) EvalResult[source]#

Wait for a numeric event.

runtimepy.channel.environment.create module#

A module for creating channels at runtime.

class runtimepy.channel.environment.create.CreateChannelEnvironment(channels: ChannelRegistry = None, enums: EnumRegistry = None, values: dict[str | int, bool | int | float | str] = None, fields: Iterable[BitFields] = None, namespace: Namespace = None, namespace_delim: str = '.')[source]#

Bases: BaseChannelEnvironment

An environment extension for creating channels.

bool_channel(name: str, kind: Primitive[Any] | type[Int8Primitive | Int16Primitive | Int32Primitive | Int64Primitive | Uint8Primitive | Uint16Primitive | Uint32Primitive | Uint64Primitive | HalfPrimitive | FloatPrimitive | DoublePrimitive | BooleanPrimitive] | str = 'bool', commandable: bool = False, enum: str | int | RuntimeEnum = None, namespace: Namespace = None, **kwargs) tuple[Channel[BooleanPrimitive], RuntimeEnum | None][source]#

Create a boolean channel.

channel(name: str, kind: Primitive[Any] | type[Int8Primitive | Int16Primitive | Int32Primitive | Int64Primitive | Uint8Primitive | Uint16Primitive | Uint32Primitive | Uint64Primitive | HalfPrimitive | FloatPrimitive | DoublePrimitive | BooleanPrimitive] | str, commandable: bool = False, enum: str | int | RuntimeEnum = None, namespace: Namespace = None, scaling: list[float | int] = None, min_period_s: float = None, **kwargs) tuple[Channel[Int8Primitive] | Channel[Int16Primitive] | Channel[Int32Primitive] | Channel[Int64Primitive] | Channel[Uint8Primitive] | Channel[Uint16Primitive] | Channel[Uint32Primitive] | Channel[Uint64Primitive] | Channel[FloatPrimitive] | Channel[DoublePrimitive] | Channel[BooleanPrimitive], RuntimeEnum | None][source]#

Create a new channel from the environment.

enum(name: str, kind: str | EnumType, items: MutableMapping[str | int, str | int] | MutableMapping[str | bool, str | bool] | MutableMapping[str, bool] | MutableMapping[str, int] = None, namespace: Namespace = None, primitive: str = 'uint8') RuntimeEnum[source]#

Create a new enum from the environment.

float_channel(name: str, kind: Primitive[Any] | type[Int8Primitive | Int16Primitive | Int32Primitive | Int64Primitive | Uint8Primitive | Uint16Primitive | Uint32Primitive | Uint64Primitive | HalfPrimitive | FloatPrimitive | DoublePrimitive | BooleanPrimitive] | str = 'float', commandable: bool = False, namespace: Namespace = None, scaling: list[float | int] = None, **kwargs) Channel[FloatPrimitive] | Channel[DoublePrimitive][source]#

Create a floating-point channel.

int_channel(name: str, kind: Primitive[Any] | type[Int8Primitive | Int16Primitive | Int32Primitive | Int64Primitive | Uint8Primitive | Uint16Primitive | Uint32Primitive | Uint64Primitive | HalfPrimitive | FloatPrimitive | DoublePrimitive | BooleanPrimitive] | str = 'uint32', commandable: bool = False, enum: str | int | RuntimeEnum = None, namespace: Namespace = None, scaling: list[float | int] = None, **kwargs) tuple[Channel[Int8Primitive] | Channel[Int16Primitive] | Channel[Int32Primitive] | Channel[Int64Primitive] | Channel[Uint8Primitive] | Channel[Uint16Primitive] | Channel[Uint32Primitive] | Channel[Uint64Primitive], RuntimeEnum | None][source]#

Create an integer channel.

runtimepy.channel.environment.file module#

A channel-environment extension for loading and saving files.

class runtimepy.channel.environment.file.FileChannelEnvironment(channels: ChannelRegistry = None, enums: EnumRegistry = None, values: dict[str | int, bool | int | float | str] = None, fields: Iterable[BitFields] = None, namespace: Namespace = None, namespace_delim: str = '.')[source]#

Bases: BaseChannelEnvironment

A class integrating file-system operations with channel environments.

export(channels: Path | str | None = 'channels.json', enums: Path | str | None = 'enums.json', values: Path | str | None = 'values.json', fields: Path | str | None = 'fields.json', names: Path | str | None = 'names.json', resolve_enum: bool = True, **kwargs) None[source]#

Write channel and enum registries to disk.

export_directory(path: Path | str | None, resolve_enum: bool = True, **kwargs) None[source]#

Export this channel environment to a directory.

export_json(resolve_enum: bool = True) dict[str, dict[str, str | int | float | bool | None | dict[str, str | int | float | bool | None] | list[str | int | float | bool | None]]][source]#

Get this channel environment as a single dictionary.

classmethod load(channels: Path | str | None = 'channels.json', enums: Path | str | None = 'enums.json', values: Path | str | None = 'values.json', fields: Path | str | None = 'fields.json', names: Path | str | None = 'names.json', finalize: bool = True) T[source]#

Load a channel environment from a pair of files.

classmethod load_directory(path: Path | str | None, finalize: bool = True) T[source]#

Load a channel environment from a directory.

classmethod load_json(data: dict[str, dict[str, str | int | float | bool | None | dict[str, str | int | float | bool | None] | list[str | int | float | bool | None]]], finalize: bool = True) T[source]#

Load a channel environment from JSON data.

runtimepy.channel.environment.sample module#

Interfaces for working with example environment configurations.

runtimepy.channel.environment.sample.long_name_int_enum(env: ChannelEnvironment, name: str = 'InsanelyLongEnumNameForTesting', channel: str = 'sample_enum') RuntimeEnum[source]#

Add an integer enumeration with a long name.

runtimepy.channel.environment.sample.poll_sample_env(env: ChannelEnvironment) None[source]#

Register sample enumerations and channels to an environment.

runtimepy.channel.environment.sample.random() x in the interval [0, 1).#
runtimepy.channel.environment.sample.sample_bool_enum(env: ChannelEnvironment, name: str = 'OnOff', channel: str = 'sample_state') RuntimeEnum[source]#

A sample boolean enumeration.

runtimepy.channel.environment.sample.sample_env(env: ChannelEnvironment = None) ChannelEnvironment[source]#

Register sample enumerations and channels to an environment.

runtimepy.channel.environment.sample.sample_fields(env: ChannelEnvironment, enum: str = 'SampleEnum') None[source]#

Add sample bit-fields to an environment.

runtimepy.channel.environment.sample.sample_float(env: ChannelEnvironment, channel: str = 'sample_float', kind: str = 'double') None[source]#

Add a sample floating-point channel.

runtimepy.channel.environment.sample.sample_int_enum(env: ChannelEnvironment, name: str = 'SampleEnum') RuntimeEnum[source]#

A sample integer enumeration.

runtimepy.channel.environment.telemetry module#

A module implementing channel-environment telemetry registration.

class runtimepy.channel.environment.telemetry.TelemetryChannelEnvironment(channels: ChannelRegistry = None, enums: EnumRegistry = None, values: dict[str | int, bool | int | float | str] = None, fields: Iterable[BitFields] = None, namespace: Namespace = None, namespace_delim: str = '.')[source]#

Bases: BaseChannelEnvironment

A class integrating telemetry streaming.

events: list[str]#
ingest(point: ParsedEvent) None[source]#

Update internal state based on an event. Note that the event timestamp is not respected.

parse_event_stream(stream: BinaryIO) Iterator[ParsedEvent][source]#

Parse individual events from a stream.

registered(stream: BinaryIO, pattern: str = '.*', exact: bool = False, flush: bool = False, channel: ChannelMetrics = None) Iterator[list[str]][source]#

Register a stream as a managed context. Returns a list of all channels registered.

Module contents#

A module implementing a channel environment.

class runtimepy.channel.environment.ChannelEnvironment(channels: ChannelRegistry = None, enums: EnumRegistry = None, values: dict[str | int, bool | int | float | str] = None, fields: Iterable[BitFields] = None, namespace: Namespace = None, namespace_delim: str = '.')[source]#

Bases: TelemetryChannelEnvironment, ArrayChannelEnvironment, FileChannelEnvironment, CreateChannelEnvironment

A class integrating channel and enumeration registries.

property num_defaults: int#

Determine the number of channels in this environment configured with a default value.

search_names(pattern: str, exact: bool = False) Iterator[str][source]#

Search for names belonging to this environment.

set_default(key: str, default: int | float | bool | None) None[source]#

Set a new default value for a channel.