rydiqule.sensor_utils.match_states¶
- rydiqule.sensor_utils.match_states(statespec: int | str | Tuple[float, ...] | List[int | str | Tuple[float, ...]] | Tuple[float | List[float], ...], compare_list: List[int | str | Tuple[float, ...]]) List[int | str | Tuple[float, ...]] [source]¶
Return all states in a list matching the pattern described by a given specification.
A
StateSpec
is described by a tuple containing floats or strings, or lists of floats or strings. A states
incompare_list
is considered a match tostatespec
ifs
andstatespec
are the same length and for each element instatespec
, :- The corresponding element in
s
is equal to the element instatespec
(in the case of a single value)
- The corresponding element in
- The element is
s
is an element of the list which is an element ofstatespec
(in the case of a list element of
statespec
).
- The element is
The element of
statespec
is the string"all"
- Parameters:
statespec (StateSpec) – The state specification against which to compare elements of the list.
compare_list (List[State]) – The list of individual states to compare.
- Returns:
Sublist of
compare_list
containing all elements ofcompare_list
matchingstatespec
.- Return type:
list of State
Examples
While primarily intended for internal use,
match_states
can be accessed directly throughsensor_utils
.>>> compare_states = [(0,0), ... (1,0),(1,1), ... (2,0),(2,1),(2,2) ... ] >>> spec = (2,[0,1,2]) >>> print(rq.sensor_utils.match_states(spec, compare_states)) [(2, 0), (2, 1), (2, 2)] >>> wildcard_spec = (2,"all") >>> print(rq.sensor_utils.match_states(wildcard_spec, compare_states)) [(2, 0), (2, 1), (2, 2)]