Result query¶
A result query references one or more results in a results bundle. Each result has an id, consisting of the
id of the step that generated that result, and optionally one or more task number for steps with multiple tasks.
The id and task numbers are separated with a dot (.
)
For example, the following result ids are valid: step1
, step.1
, step.1.2.3.4.5
Result queries allows selection of these result ids using wildcards and with a replacement for some of the task numbers based on another task number.
The syntax for a result query is
queries ::=query
( ","query
)* query ::= step-id [task_query
] | [ step-id ] "*" [task_query
] | [ step-id ] "**" task_query ::= ( "."task_number
)* | ".$@" task_number ::= integer |task_wildcard
|task_reference
task_wildcard ::= "*" | "?" task_reference ::= "$" integer [oper
integer ] oper ::= "+" | "-" | "*" | "/" | "%"
Where step-id is a (XML) id without periods (.
), and integer is a positive natural number
(including zero).
The most simple result queries are just the result id and will match that single result id:
result query |
|
---|---|
|
Matches exactly one result, with id |
|
Matches exactly one result, with id |
|
Matches exactly one result, with id |
Multiple queries are possible by separating them with a comma (,
)
result query |
|
---|---|
|
Matches exactly two results: |
A *
is a wildcard character that matches one or more elements and is allowed in both the
step-id and task-number sections. In the step-id, the *
wildcard does not have to be used only at the end:
result query |
|
---|---|
|
Matches |
|
Matches any step whose id starts with |
|
Matches any step whose id equals |
|
Combination of the above two: matches |
|
Matches any step whose id starts with |
The task-number section can also contain a ?
wildcard, which will match exactly one element:
result query |
|
---|---|
|
Matches |
|
Matches |
|
Matches |
It is also possible to reference a specific task number based on a current task number. For example, when executing
task step.2.3
it would be useful to reference another based on the current task number 2.3
. This is done using
a $
reference. Where $0
references the first task number element (2
in this example), $1
references
the second element (3
), etc.
The following examples all use current task number 2.3
:
result query |
|
---|---|
|
References result id |
|
References result id |
|
References result id |
|
References result id |
|
Special “shortcut” to replace the full task number, here |
Simple arithmetic is possible on the task number references. Available operations
are +
(addition), -
(subtraction), *
(multiplication), /
(integer floor division) and
%
(modulo). The right-hand side of the operator has to be an integer, it cannot be another reference.
result query |
|
---|---|
|
References result id |
|
References result id |
|
References result id |
|
References result id |
|
References result id |
If a subtraction results in a negative number the value is replaced with #NEG
, and if a division results in
a division by zero the value is replaced with #INF
. Both of these result in invalid result id.
result query |
|
---|---|
|
References result id |
|
References result id |
Methods for querying and filtering results
- momotor.options.result_query.filter_result_query(results, query, task_id=None)¶
Filter an iterable of
Result
objects on a result queryReturns an iterator that iterates all the
Result
objects from results that match the query
- momotor.options.result_query.make_result_id_re(query)¶
Make a regex that matches a result query to the query.
Uses a glob-like pattern matching on the dot-separated elements of the selector. For the first element (the step-id part), a
*
will match zero or more characters except.
For all the other elements (the task number parts), a*
matches one or more elements starting at that position and a?
matches a single element in that position.Special query
**
matches all step-ids and task-numbers, i.e. it produces a regex that matches anything.This method does not apply any task numbers, apply
apply_task_number()
to the selector before calling this function for that if needed.Examples:
>>> make_result_id_re('test').match('test') is not None True
>>> make_result_id_re('test').match('test.1') is not None False
>>> make_result_id_re('test').match('testing') is not None False
>>> make_result_id_re('test.1').match('test.2') is not None False
>>> make_result_id_re('test.2').match('test.2.3') is not None False
>>> make_result_id_re('test.2.3').match('test.2.3') is not None True
>>> make_result_id_re('test.?').match('test.2.3') is not None False
>>> make_result_id_re('test.?.?').match('test.2.3') is not None True
>>> make_result_id_re('test.?.?.?').match('test.2.3') is not None False
>>> make_result_id_re('test.*').match('test.2.3') is not None True
>>> make_result_id_re('test.?.*').match('test.2.3') is not None True
>>> make_result_id_re('test.?.?.*').match('test.2.3') is not None False
>>> make_result_id_re('*').match('test') is not None True
>>> make_result_id_re('*').match('test.2.3') is not None False
>>> make_result_id_re('*.*').match('test.2.3') is not None True
>>> make_result_id_re('test*').match('testing') is not None True
>>> make_result_id_re('*sti*').match('testing') is not None True
>>> make_result_id_re('*sting').match('testing') is not None True
>>> make_result_id_re('te*ng').match('testing') is not None True
>>> make_result_id_re('test*').match('tasting') is not None False
>>> make_result_id_re('test*').match('testing.1') is not None False
>>> make_result_id_re('test**').match('testing.1') is not None True
>>> make_result_id_re('t*t**').match('testing.1') is not None True
>>> make_result_id_re('t*x**').match('testing.1') is not None False
>>> make_result_id_re('test*.*').match('testing.1') is not None True
>>> make_result_id_re('**').match('testing') is not None True
>>> make_result_id_re('**').match('testing.1') is not None True
- Parameters
query (
str
) – the result-id query to convert- Return type
- Returns
a compiled regular expression (a
re.compile()
object) for the query
- momotor.options.result_query.result_query_fn(query, task_id=None)¶
Make a function to match a result with a result query.
The query is either a literal id (e.g.
step
,step.1
etc), or a glob-like query to select multiple id’s, (e.g.*
,step.*
,step.?
). Also applies task numbers if task_id is provided.Multiple queries are possible, separated with a comma.