livingproof-scenario-parameters 3.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- livingproof_scenario_parameters-3.3.0/LICENSE +201 -0
- livingproof_scenario_parameters-3.3.0/MANIFEST.in +4 -0
- livingproof_scenario_parameters-3.3.0/PKG-INFO +28 -0
- livingproof_scenario_parameters-3.3.0/README.md +15 -0
- livingproof_scenario_parameters-3.3.0/livingproof_build.py +88 -0
- livingproof_scenario_parameters-3.3.0/livingproof_scenario_parameters/__init__.py +48 -0
- livingproof_scenario_parameters-3.3.0/livingproof_scenario_parameters/_version.py +3 -0
- livingproof_scenario_parameters-3.3.0/livingproof_scenario_parameters/geometry.py +152 -0
- livingproof_scenario_parameters-3.3.0/livingproof_scenario_parameters/parameters.py +378 -0
- livingproof_scenario_parameters-3.3.0/livingproof_scenario_parameters/versioning.py +110 -0
- livingproof_scenario_parameters-3.3.0/livingproof_scenario_parameters.egg-info/PKG-INFO +28 -0
- livingproof_scenario_parameters-3.3.0/livingproof_scenario_parameters.egg-info/SOURCES.txt +14 -0
- livingproof_scenario_parameters-3.3.0/livingproof_scenario_parameters.egg-info/dependency_links.txt +1 -0
- livingproof_scenario_parameters-3.3.0/livingproof_scenario_parameters.egg-info/top_level.txt +1 -0
- livingproof_scenario_parameters-3.3.0/pyproject.toml +26 -0
- livingproof_scenario_parameters-3.3.0/setup.cfg +4 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: livingproof-scenario-parameters
|
|
3
|
+
Version: 3.3.0
|
|
4
|
+
Summary: Reference resolver for livingproof-scenario-parameters/0.1 and route geometry
|
|
5
|
+
Author: Living Proof Labs contributors
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/Living-Proof-Labs/robot-capability-specs
|
|
8
|
+
Project-URL: Source, https://github.com/Living-Proof-Labs/robot-capability-specs
|
|
9
|
+
Requires-Python: >=3.10
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Dynamic: license-file
|
|
13
|
+
|
|
14
|
+
# Living Proof Scenario Parameters
|
|
15
|
+
|
|
16
|
+
A dependency-free Python reference resolver for the Living Proof Scenario
|
|
17
|
+
Parameters contract. It resolves declarative scenario inputs and computes route
|
|
18
|
+
geometry without requiring a robot, simulator, or network at runtime.
|
|
19
|
+
|
|
20
|
+
```python
|
|
21
|
+
from livingproof_scenario_parameters import distance_to_route, resolve_input
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
The installed package version follows the exact catalog release tag. Install
|
|
25
|
+
the wheel or source archive from a verified
|
|
26
|
+
[robot capability specifications release](https://github.com/Living-Proof-Labs/robot-capability-specs/releases).
|
|
27
|
+
The Python code is available under Apache-2.0; a copy of the license is included
|
|
28
|
+
in both distributions.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Living Proof Scenario Parameters
|
|
2
|
+
|
|
3
|
+
A dependency-free Python reference resolver for the Living Proof Scenario
|
|
4
|
+
Parameters contract. It resolves declarative scenario inputs and computes route
|
|
5
|
+
geometry without requiring a robot, simulator, or network at runtime.
|
|
6
|
+
|
|
7
|
+
```python
|
|
8
|
+
from livingproof_scenario_parameters import distance_to_route, resolve_input
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
The installed package version follows the exact catalog release tag. Install
|
|
12
|
+
the wheel or source archive from a verified
|
|
13
|
+
[robot capability specifications release](https://github.com/Living-Proof-Labs/robot-capability-specs/releases).
|
|
14
|
+
The Python code is available under Apache-2.0; a copy of the license is included
|
|
15
|
+
in both distributions.
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
"""Build backend that stamps the release-tag version before setuptools runs."""
|
|
3
|
+
import importlib.util
|
|
4
|
+
import shutil
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
from setuptools.build_meta import (
|
|
8
|
+
build_sdist as _build_sdist,
|
|
9
|
+
build_wheel as _build_wheel,
|
|
10
|
+
get_requires_for_build_sdist as _requires_sdist,
|
|
11
|
+
get_requires_for_build_wheel as _requires_wheel,
|
|
12
|
+
prepare_metadata_for_build_wheel as _prepare_metadata,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _versioning():
|
|
17
|
+
path = Path(__file__).resolve().parent / "livingproof_scenario_parameters" / "versioning.py"
|
|
18
|
+
spec = importlib.util.spec_from_file_location("livingproof_versioning", path)
|
|
19
|
+
module = importlib.util.module_from_spec(spec)
|
|
20
|
+
spec.loader.exec_module(module)
|
|
21
|
+
return module
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
LICENSE = Path(__file__).resolve().with_name("LICENSE")
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _prepare():
|
|
28
|
+
versioning = _versioning()
|
|
29
|
+
version = versioning.resolve_version()
|
|
30
|
+
if versioning.in_git_checkout():
|
|
31
|
+
shutil.copyfile(LICENSE.parent.parent / "LICENSE", LICENSE)
|
|
32
|
+
elif not LICENSE.is_file():
|
|
33
|
+
raise ValueError("The source distribution is missing its Apache license")
|
|
34
|
+
versioning.STAMP.write_text(
|
|
35
|
+
"# SPDX-License-Identifier: Apache-2.0\n"
|
|
36
|
+
"# Generated when the package is built. Do not edit.\n"
|
|
37
|
+
f'__version__ = "{version}"\n',
|
|
38
|
+
encoding="utf-8",
|
|
39
|
+
)
|
|
40
|
+
return versioning
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _cleanup(versioning):
|
|
44
|
+
# A Git checkout can derive the version again. A source distribution has
|
|
45
|
+
# no tag, so its generated module is the version and must stay in place.
|
|
46
|
+
if versioning.in_git_checkout():
|
|
47
|
+
versioning.STAMP.unlink(missing_ok=True)
|
|
48
|
+
LICENSE.unlink(missing_ok=True)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def get_requires_for_build_wheel(config_settings=None):
|
|
52
|
+
versioning = _prepare()
|
|
53
|
+
try:
|
|
54
|
+
return _requires_wheel(config_settings)
|
|
55
|
+
finally:
|
|
56
|
+
_cleanup(versioning)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def get_requires_for_build_sdist(config_settings=None):
|
|
60
|
+
versioning = _prepare()
|
|
61
|
+
try:
|
|
62
|
+
return _requires_sdist(config_settings)
|
|
63
|
+
finally:
|
|
64
|
+
_cleanup(versioning)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def prepare_metadata_for_build_wheel(metadata_directory, config_settings=None):
|
|
68
|
+
versioning = _prepare()
|
|
69
|
+
try:
|
|
70
|
+
return _prepare_metadata(metadata_directory, config_settings)
|
|
71
|
+
finally:
|
|
72
|
+
_cleanup(versioning)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def build_wheel(wheel_directory, config_settings=None, metadata_directory=None):
|
|
76
|
+
versioning = _prepare()
|
|
77
|
+
try:
|
|
78
|
+
return _build_wheel(wheel_directory, config_settings, metadata_directory)
|
|
79
|
+
finally:
|
|
80
|
+
_cleanup(versioning)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def build_sdist(sdist_directory, config_settings=None):
|
|
84
|
+
versioning = _prepare()
|
|
85
|
+
try:
|
|
86
|
+
return _build_sdist(sdist_directory, config_settings)
|
|
87
|
+
finally:
|
|
88
|
+
_cleanup(versioning)
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
"""Reference resolver for livingproof-scenario-parameters/0.1.
|
|
3
|
+
|
|
4
|
+
This package matches ``tooling/scenario-parameters.mjs`` and the route measures
|
|
5
|
+
in ``tooling/world-layout.mjs``. A failure is a :class:`ScenarioParameterError`
|
|
6
|
+
with ``status == "ERROR"``: a test-system error, never a robot grade.
|
|
7
|
+
|
|
8
|
+
Install a released catalog tag, never a branch::
|
|
9
|
+
|
|
10
|
+
pip install "git+https://github.com/Living-Proof-Labs/robot-capability-specs@vX.Y.Z#subdirectory=python"
|
|
11
|
+
|
|
12
|
+
That tag is the package version: ``vX.Y.Z`` installs as ``X.Y.Z``. A checkout
|
|
13
|
+
that is not exactly one release tag installs a development version instead.
|
|
14
|
+
"""
|
|
15
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
16
|
+
|
|
17
|
+
try:
|
|
18
|
+
__version__ = version("livingproof-scenario-parameters")
|
|
19
|
+
except PackageNotFoundError:
|
|
20
|
+
from livingproof_scenario_parameters.versioning import resolve_version
|
|
21
|
+
__version__ = resolve_version()
|
|
22
|
+
|
|
23
|
+
from livingproof_scenario_parameters.geometry import crosses_exit, distance_to_route, route_length
|
|
24
|
+
from livingproof_scenario_parameters.parameters import (
|
|
25
|
+
ScenarioParameterError,
|
|
26
|
+
evaluate,
|
|
27
|
+
quantize_half_up_decimal_text,
|
|
28
|
+
read_inputs,
|
|
29
|
+
reference_errors,
|
|
30
|
+
resolve,
|
|
31
|
+
resolve_input,
|
|
32
|
+
round_half_even_binary,
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
__all__ = [
|
|
36
|
+
'__version__',
|
|
37
|
+
'ScenarioParameterError',
|
|
38
|
+
'crosses_exit',
|
|
39
|
+
'distance_to_route',
|
|
40
|
+
'evaluate',
|
|
41
|
+
'quantize_half_up_decimal_text',
|
|
42
|
+
'read_inputs',
|
|
43
|
+
'reference_errors',
|
|
44
|
+
'resolve',
|
|
45
|
+
'resolve_input',
|
|
46
|
+
'round_half_even_binary',
|
|
47
|
+
'route_length',
|
|
48
|
+
]
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
"""Route length, distance to a route, and exit crossing.
|
|
3
|
+
|
|
4
|
+
``route_length`` matches ``routeLength`` in ``tooling/world-layout.mjs``.
|
|
5
|
+
``distance_to_route`` and ``crosses_exit`` match ``distanceToRoute`` and
|
|
6
|
+
``crossesExit`` there, and the cases in
|
|
7
|
+
``specs/scenarios/route-geometry-cases.json``.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import math
|
|
11
|
+
|
|
12
|
+
from livingproof_scenario_parameters.parameters import ScenarioParameterError
|
|
13
|
+
|
|
14
|
+
EPS = 1e-9
|
|
15
|
+
|
|
16
|
+
def _fail(message):
|
|
17
|
+
raise ScenarioParameterError(message)
|
|
18
|
+
|
|
19
|
+
def _xy(point):
|
|
20
|
+
return (point[0], point[1])
|
|
21
|
+
|
|
22
|
+
def _sub(a, b):
|
|
23
|
+
return (a[0] - b[0], a[1] - b[1])
|
|
24
|
+
|
|
25
|
+
def _dot(a, b):
|
|
26
|
+
return a[0] * b[0] + a[1] * b[1]
|
|
27
|
+
|
|
28
|
+
def _len(vector):
|
|
29
|
+
# sqrt(x*x + y*y), not math.hypot: the four IEEE 754 operations give the same bits as
|
|
30
|
+
# Math.sqrt(x * x + y * y) in tooling/world-layout.mjs. hypot routines differ in the
|
|
31
|
+
# last bit between Python and V8 (and across Python versions), which can move a
|
|
32
|
+
# distance across a rounded limit such as 0.49.
|
|
33
|
+
return math.sqrt(vector[0] * vector[0] + vector[1] * vector[1])
|
|
34
|
+
|
|
35
|
+
def _nearest_on_leg(point, start, end):
|
|
36
|
+
"""Nearest point on the finite segment start-end. Returns distance and fraction."""
|
|
37
|
+
leg = _sub(end, start)
|
|
38
|
+
fraction = max(0.0, min(1.0, _dot(_sub(point, start), leg) / _dot(leg, leg)))
|
|
39
|
+
nearest = (start[0] + fraction * leg[0], start[1] + fraction * leg[1])
|
|
40
|
+
return _len(_sub(point, nearest)), fraction
|
|
41
|
+
|
|
42
|
+
def _station_of(points, point):
|
|
43
|
+
"""Distance along the finite polyline from its first point to the point nearest ``point``."""
|
|
44
|
+
best_distance, best_station, walked = math.inf, 0.0, 0.0
|
|
45
|
+
query = _xy(point)
|
|
46
|
+
for index in range(len(points) - 1):
|
|
47
|
+
start, end = _xy(points[index]), _xy(points[index + 1])
|
|
48
|
+
distance, fraction = _nearest_on_leg(query, start, end)
|
|
49
|
+
leg_length = _len(_sub(end, start))
|
|
50
|
+
if distance < best_distance - EPS:
|
|
51
|
+
best_distance = distance
|
|
52
|
+
best_station = walked + fraction * leg_length
|
|
53
|
+
walked += leg_length
|
|
54
|
+
return best_distance, best_station, walked
|
|
55
|
+
|
|
56
|
+
def route_length(world, places):
|
|
57
|
+
"""Distance along the route from the point nearest the start pose to the route's last point.
|
|
58
|
+
|
|
59
|
+
``places`` is the parameter file's places object and must name ``start`` and ``route``.
|
|
60
|
+
The layout contract puts the route's last point on the exit reference point.
|
|
61
|
+
"""
|
|
62
|
+
named = {place['name']: place for place in world['places']}
|
|
63
|
+
route = named[places['route']]
|
|
64
|
+
_distance, station, length = _station_of(route['points'], named[places['start']]['position'])
|
|
65
|
+
return length - station
|
|
66
|
+
|
|
67
|
+
def distance_to_route(points, point):
|
|
68
|
+
"""Floor-plane distance from ``point`` to the route polyline.
|
|
69
|
+
|
|
70
|
+
The first leg extends backward past the route start and the last leg extends
|
|
71
|
+
forward past the route end, so a point just past the exit is measured sideways.
|
|
72
|
+
A route of one leg is that line in both directions. Interior ends of the first
|
|
73
|
+
and last legs are not extended, and every middle leg stays a finite segment.
|
|
74
|
+
"""
|
|
75
|
+
route = [_xy(item) for item in points]
|
|
76
|
+
query = _xy(point)
|
|
77
|
+
legs = len(route) - 1
|
|
78
|
+
if legs < 1:
|
|
79
|
+
_fail('route needs at least 2 points')
|
|
80
|
+
best = math.inf
|
|
81
|
+
for index in range(legs):
|
|
82
|
+
start, end = route[index], route[index + 1]
|
|
83
|
+
leg = _sub(end, start)
|
|
84
|
+
denom = _dot(leg, leg)
|
|
85
|
+
if denom == 0:
|
|
86
|
+
distance = _len(_sub(query, start))
|
|
87
|
+
else:
|
|
88
|
+
fraction = _dot(_sub(query, start), leg) / denom
|
|
89
|
+
if legs != 1:
|
|
90
|
+
if index == 0:
|
|
91
|
+
fraction = min(fraction, 1.0)
|
|
92
|
+
elif index == legs - 1:
|
|
93
|
+
fraction = max(fraction, 0.0)
|
|
94
|
+
else:
|
|
95
|
+
fraction = min(1.0, max(0.0, fraction))
|
|
96
|
+
nearest = (start[0] + fraction * leg[0], start[1] + fraction * leg[1])
|
|
97
|
+
distance = _len(_sub(query, nearest))
|
|
98
|
+
if distance < best:
|
|
99
|
+
best = distance
|
|
100
|
+
return best
|
|
101
|
+
|
|
102
|
+
def crosses_exit(p0, p1, points, exit):
|
|
103
|
+
"""Whether the step from ``p0`` to ``p1`` crosses the exit segment.
|
|
104
|
+
|
|
105
|
+
``u`` is the direction of the route's last leg. The exit line passes through
|
|
106
|
+
the exit reference and is perpendicular to ``u``. The step crosses when
|
|
107
|
+
``p0`` is strictly before that line and ``p1`` is on or past it, and the
|
|
108
|
+
second sample is within half the segment's length of the reference along
|
|
109
|
+
the segment (endpoints included): ``|dot(p1 - ref, u_perp)| <= half``.
|
|
110
|
+
The point where the step meets the line is not tested. A step that starts
|
|
111
|
+
already on or past the line does not cross again: that arrival belongs to
|
|
112
|
+
the earlier step, and a first sample already past the line is judged on
|
|
113
|
+
its own, not as a step. Landing on the line counts. ``exit`` is
|
|
114
|
+
``{"points": [a, b], "reference": midpoint}``; a missing reference is the
|
|
115
|
+
midpoint of the two points. On hallway-open this is ``x >= 3`` with
|
|
116
|
+
``|y| <= 0.75`` at the second sample.
|
|
117
|
+
"""
|
|
118
|
+
if len(points) < 2:
|
|
119
|
+
_fail('route needs at least 2 points')
|
|
120
|
+
start, end = _xy(points[-2]), _xy(points[-1])
|
|
121
|
+
leg = _sub(end, start)
|
|
122
|
+
if _dot(leg, leg) == 0:
|
|
123
|
+
_fail('route last leg has zero length')
|
|
124
|
+
edge_start, edge_end = _xy(exit['points'][0]), _xy(exit['points'][1])
|
|
125
|
+
edge = _sub(edge_end, edge_start)
|
|
126
|
+
edge_length = _len(edge)
|
|
127
|
+
if edge_length == 0:
|
|
128
|
+
_fail('exit segment has zero length')
|
|
129
|
+
# along_unit is u_perp: the unit vector along the exit segment.
|
|
130
|
+
along_unit = (edge[0] / edge_length, edge[1] / edge_length)
|
|
131
|
+
reference = exit.get('reference')
|
|
132
|
+
if reference is None:
|
|
133
|
+
reference = ((edge_start[0] + edge_end[0]) / 2, (edge_start[1] + edge_end[1]) / 2)
|
|
134
|
+
else:
|
|
135
|
+
reference = _xy(reference)
|
|
136
|
+
# normal is u, the direction of the last leg, when the segment is perpendicular
|
|
137
|
+
# to that leg. The exit line is the line through the segment, perpendicular to u.
|
|
138
|
+
normal_left = (-along_unit[1], along_unit[0])
|
|
139
|
+
normal_right = (along_unit[1], -along_unit[0])
|
|
140
|
+
normal = normal_left if _dot(normal_left, leg) > 0 else normal_right
|
|
141
|
+
if _dot(normal, leg) == 0:
|
|
142
|
+
_fail("exit line is parallel to the route's last leg")
|
|
143
|
+
|
|
144
|
+
def signed(sample):
|
|
145
|
+
return _dot(_sub(_xy(sample), reference), normal)
|
|
146
|
+
|
|
147
|
+
before, after = signed(p0), signed(p1)
|
|
148
|
+
if not (before < 0 <= after):
|
|
149
|
+
return False
|
|
150
|
+
# Lateral test on the second sample, along the segment. Not the meeting point.
|
|
151
|
+
offset = _dot(_sub(_xy(p1), reference), along_unit)
|
|
152
|
+
return abs(offset) <= edge_length / 2
|
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
"""Resolve a livingproof-scenario-parameters/0.1 file.
|
|
3
|
+
|
|
4
|
+
Argument order matches ``tooling/scenario-parameters.mjs``:
|
|
5
|
+
``evaluate(expr, parameters, inputs)``, ``resolve(parameters, raw)``,
|
|
6
|
+
``resolve_input(name, spec, raw)``.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import json
|
|
10
|
+
import math
|
|
11
|
+
from decimal import Context, Decimal, ROUND_HALF_UP, localcontext
|
|
12
|
+
|
|
13
|
+
_ARITHMETIC = {
|
|
14
|
+
'add': lambda a, b: a + b,
|
|
15
|
+
'sub': lambda a, b: a - b,
|
|
16
|
+
'mul': lambda a, b: a * b,
|
|
17
|
+
}
|
|
18
|
+
_COMPARE = {
|
|
19
|
+
'le': lambda a, b: a <= b,
|
|
20
|
+
'lt': lambda a, b: a < b,
|
|
21
|
+
'ge': lambda a, b: a >= b,
|
|
22
|
+
'gt': lambda a, b: a > b,
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class ScenarioParameterError(Exception):
|
|
27
|
+
"""A test-system error. ``status`` is ``ERROR``, never a robot grade."""
|
|
28
|
+
|
|
29
|
+
def __init__(self, message):
|
|
30
|
+
super().__init__(message)
|
|
31
|
+
self.status = 'ERROR'
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _fail(message):
|
|
35
|
+
raise ScenarioParameterError(message)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _is_number(value):
|
|
39
|
+
return isinstance(value, (int, float)) and not isinstance(value, bool)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _finite(value):
|
|
43
|
+
if not _is_number(value):
|
|
44
|
+
return False
|
|
45
|
+
try:
|
|
46
|
+
return math.isfinite(value)
|
|
47
|
+
except OverflowError: # an int beyond the double range: JavaScript reads it as Infinity
|
|
48
|
+
return False
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _js_integer(value):
|
|
52
|
+
if isinstance(value, bool):
|
|
53
|
+
return False
|
|
54
|
+
if isinstance(value, int):
|
|
55
|
+
return True
|
|
56
|
+
return isinstance(value, float) and math.isfinite(value) and value.is_integer()
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def _js_number(value):
|
|
60
|
+
"""The text JavaScript's String(number) gives, so messages match the JS reference."""
|
|
61
|
+
if isinstance(value, float) and math.isnan(value):
|
|
62
|
+
return 'NaN'
|
|
63
|
+
if value == math.inf:
|
|
64
|
+
return 'Infinity'
|
|
65
|
+
if value == -math.inf:
|
|
66
|
+
return '-Infinity'
|
|
67
|
+
if isinstance(value, int) and not isinstance(value, bool) and abs(value) < 2 ** 53:
|
|
68
|
+
return str(value)
|
|
69
|
+
value = float(value)
|
|
70
|
+
if value == 0:
|
|
71
|
+
return '0'
|
|
72
|
+
sign = '-' if value < 0 else ''
|
|
73
|
+
# repr gives the shortest round-trip digits, as JavaScript does; only the layout differs.
|
|
74
|
+
mantissa, _, exponent = repr(abs(value)).partition('e')
|
|
75
|
+
whole, _, fraction = mantissa.partition('.')
|
|
76
|
+
point = len(whole) + int(exponent or 0) # decimal point position relative to the digits
|
|
77
|
+
digits = whole + fraction
|
|
78
|
+
stripped = digits.lstrip('0')
|
|
79
|
+
point -= len(digits) - len(stripped)
|
|
80
|
+
digits = stripped.rstrip('0')
|
|
81
|
+
count = len(digits)
|
|
82
|
+
if count <= point <= 21:
|
|
83
|
+
return sign + digits + '0' * (point - count)
|
|
84
|
+
if 0 < point <= 21:
|
|
85
|
+
return sign + digits[:point] + '.' + digits[point:]
|
|
86
|
+
if -6 < point <= 0:
|
|
87
|
+
return sign + '0.' + '0' * -point + digits
|
|
88
|
+
shown = digits[0] + ('.' + digits[1:] if count > 1 else '')
|
|
89
|
+
return f'{sign}{shown}e{"+" if point > 0 else "-"}{abs(point - 1)}'
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def _js_json(value):
|
|
93
|
+
return json.dumps(value, separators=(',', ':'), ensure_ascii=False)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def _div(left, right):
|
|
97
|
+
# JavaScript 1/0 is Infinity and 1/-0 is -Infinity. Python raises, so the non-finite
|
|
98
|
+
# result is made here, with the sign of the zero.
|
|
99
|
+
if right == 0:
|
|
100
|
+
if left == 0 or math.isnan(left):
|
|
101
|
+
return math.nan
|
|
102
|
+
return math.copysign(math.inf, left) * math.copysign(1.0, right)
|
|
103
|
+
return left / right
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def round_half_even_binary(value, decimals):
|
|
107
|
+
"""Python ``round(value, decimals)``: half to even on the exact binary value.
|
|
108
|
+
|
|
109
|
+
``0.40625`` to 4 decimal places is ``0.4062``. ``0.21875`` is ``0.2188``.
|
|
110
|
+
"""
|
|
111
|
+
if not _finite(value):
|
|
112
|
+
_fail(f'cannot round a non-finite value {_js_number(value)}')
|
|
113
|
+
result = round(float(value), decimals)
|
|
114
|
+
if result == 0:
|
|
115
|
+
return 0.0
|
|
116
|
+
return float(result)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def quantize_half_up_decimal_text(value, decimals):
|
|
120
|
+
"""Whole units of ``10^-decimals``, half up from the shortest decimal text.
|
|
121
|
+
|
|
122
|
+
This is ``Decimal(str(value)).quantize(..., ROUND_HALF_UP)``. With
|
|
123
|
+
``decimals`` 3 it is whole millimetres, so ``1.0295`` m is 1030 mm and
|
|
124
|
+
``1.0305`` m is 1031 mm. The result is an ``int``.
|
|
125
|
+
"""
|
|
126
|
+
if not _finite(value):
|
|
127
|
+
_fail(f'cannot quantize a non-finite value {_js_number(value)}')
|
|
128
|
+
# Enough precision for any finite double at 9 decimals (the default 28 digits raises
|
|
129
|
+
# decimal.InvalidOperation from about 1e19 m at 9 decimals).
|
|
130
|
+
with localcontext(Context(prec=400)):
|
|
131
|
+
quantum = Decimal(1).scaleb(-int(decimals))
|
|
132
|
+
quantized = Decimal(str(value)).quantize(quantum, rounding=ROUND_HALF_UP)
|
|
133
|
+
return int(quantized.scaleb(int(decimals)))
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def resolve_input(name, spec, raw):
|
|
137
|
+
"""Resolve one raw input against its declaration."""
|
|
138
|
+
if raw is None:
|
|
139
|
+
_fail(f'input {name} is missing')
|
|
140
|
+
if spec['kind'] == 'category':
|
|
141
|
+
if not isinstance(raw, str) or not raw:
|
|
142
|
+
_fail(f'input {name} is not a category name')
|
|
143
|
+
return raw
|
|
144
|
+
value = raw
|
|
145
|
+
if isinstance(raw, dict):
|
|
146
|
+
if 'unit' not in raw or raw['unit'] != spec['unit']:
|
|
147
|
+
shown = 'undefined' if 'unit' not in raw else _js_json(raw['unit'])
|
|
148
|
+
_fail(f'input {name} has unit {shown}, expected {spec["unit"]}')
|
|
149
|
+
value = raw.get('value')
|
|
150
|
+
if not _finite(value):
|
|
151
|
+
_fail(f'input {name} is not a finite number')
|
|
152
|
+
if isinstance(value, int) and abs(value) > 2 ** 53:
|
|
153
|
+
value = float(value) # JavaScript holds the nearest double, so hold the same
|
|
154
|
+
return value
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def _get_path(document, path):
|
|
158
|
+
current = document
|
|
159
|
+
for key in path.split('.'):
|
|
160
|
+
if not isinstance(current, dict) or key not in current:
|
|
161
|
+
return None
|
|
162
|
+
current = current[key]
|
|
163
|
+
return current
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def read_inputs(parameters, sources):
|
|
167
|
+
"""Read every input from ``sources`` (``world``, ``robot``, ``configuration``)."""
|
|
168
|
+
documents = {
|
|
169
|
+
'world': sources.get('world'),
|
|
170
|
+
'robot-profile': sources.get('robot'),
|
|
171
|
+
'configuration-profile': sources.get('configuration'),
|
|
172
|
+
}
|
|
173
|
+
raw = {}
|
|
174
|
+
for name, spec in parameters['inputs'].items():
|
|
175
|
+
if spec.get('rule') == 'route-length-from-start-to-exit':
|
|
176
|
+
from livingproof_scenario_parameters.geometry import route_length
|
|
177
|
+
raw[name] = route_length(sources.get('world'), parameters['places'])
|
|
178
|
+
else:
|
|
179
|
+
raw[name] = _get_path(documents[spec['source']], spec['path'])
|
|
180
|
+
return raw
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def _parameter_value(parameters, name, inputs):
|
|
184
|
+
parameter = parameters['parameters'].get(name)
|
|
185
|
+
if isinstance(parameter, dict) and _is_number(parameter.get('value')):
|
|
186
|
+
if name == 'command_speed' and not parameter['value'] > 0:
|
|
187
|
+
_fail('command_speed must be greater than 0')
|
|
188
|
+
return parameter['value']
|
|
189
|
+
if isinstance(parameter, dict) and parameter.get('by') and isinstance(parameter.get('values'), dict):
|
|
190
|
+
key = inputs[parameter['by']]
|
|
191
|
+
if key not in parameter['values']:
|
|
192
|
+
_fail(f'no {name} for {parameter["by"]} {_js_json(key)}')
|
|
193
|
+
return parameter['values'][key]
|
|
194
|
+
_fail(f'parameter {name} is not numeric')
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def _numeric_input(parameters, name, inputs):
|
|
198
|
+
spec = parameters['inputs'].get(name)
|
|
199
|
+
if not spec or spec.get('kind') != 'quantity':
|
|
200
|
+
_fail(f'input {name} is not a quantity input')
|
|
201
|
+
return inputs[name]
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
def evaluate(expr, parameters, inputs):
|
|
205
|
+
"""Evaluate one expression. Same argument order as the JavaScript reference."""
|
|
206
|
+
if _is_number(expr):
|
|
207
|
+
if isinstance(expr, int) and abs(expr) > 2 ** 53:
|
|
208
|
+
return float(expr) # JavaScript holds the nearest double
|
|
209
|
+
return expr
|
|
210
|
+
if not isinstance(expr, dict):
|
|
211
|
+
_fail('not an expression')
|
|
212
|
+
if 'input' in expr:
|
|
213
|
+
return _numeric_input(parameters, expr['input'], inputs)
|
|
214
|
+
if 'parameter' in expr:
|
|
215
|
+
return _parameter_value(parameters, expr['parameter'], inputs)
|
|
216
|
+
if expr.get('op') not in _ARITHMETIC and expr.get('op') != 'div':
|
|
217
|
+
shown = 'undefined' if 'op' not in expr else ('null' if expr['op'] is None else expr['op'])
|
|
218
|
+
_fail(f'unknown operator {shown}')
|
|
219
|
+
operation = _div if expr['op'] == 'div' else _ARITHMETIC[expr['op']]
|
|
220
|
+
args = [evaluate(arg, parameters, inputs) for arg in expr.get('args', [])]
|
|
221
|
+
value = args[0]
|
|
222
|
+
for arg in args[1:]:
|
|
223
|
+
value = operation(value, arg)
|
|
224
|
+
if not _finite(value):
|
|
225
|
+
_fail(f'expression gives a non-finite value {_js_number(value)}')
|
|
226
|
+
return value
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
def _evaluate_quantized(expr, parameters, inputs, decimals):
|
|
230
|
+
if _is_number(expr):
|
|
231
|
+
if not _js_integer(expr):
|
|
232
|
+
_fail(f'bare number {_js_number(expr)} under quantize must be an integer')
|
|
233
|
+
return {'units': int(expr), 'quantity': False}
|
|
234
|
+
if isinstance(expr, dict) and ('input' in expr or 'parameter' in expr):
|
|
235
|
+
return {
|
|
236
|
+
'units': quantize_half_up_decimal_text(evaluate(expr, parameters, inputs), decimals),
|
|
237
|
+
'quantity': True,
|
|
238
|
+
}
|
|
239
|
+
args = [_evaluate_quantized(arg, parameters, inputs, decimals) for arg in expr['args']]
|
|
240
|
+
total = args[0]
|
|
241
|
+
for other in args[1:]:
|
|
242
|
+
if expr['op'] == 'mul':
|
|
243
|
+
if total['quantity'] and other['quantity']:
|
|
244
|
+
_fail('quantize allows mul by a bare integer only')
|
|
245
|
+
total = {
|
|
246
|
+
'units': total['units'] * other['units'],
|
|
247
|
+
'quantity': total['quantity'] or other['quantity'],
|
|
248
|
+
}
|
|
249
|
+
elif expr['op'] in ('add', 'sub'):
|
|
250
|
+
if total['quantity'] != other['quantity']:
|
|
251
|
+
_fail(f'quantize cannot {expr["op"]} a quantity and a bare number')
|
|
252
|
+
units = total['units'] + other['units'] if expr['op'] == 'add' else total['units'] - other['units']
|
|
253
|
+
total = {'units': units, 'quantity': total['quantity']}
|
|
254
|
+
else:
|
|
255
|
+
_fail(f'quantize does not allow {expr["op"]}')
|
|
256
|
+
return total
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
def _evaluate_condition(precondition, parameters, inputs):
|
|
260
|
+
operation = precondition['condition']['op']
|
|
261
|
+
compare = _COMPARE.get(operation)
|
|
262
|
+
if compare is None:
|
|
263
|
+
_fail(f'unknown comparison {operation}')
|
|
264
|
+
args = precondition['condition']['args']
|
|
265
|
+
if precondition.get('quantize'):
|
|
266
|
+
decimals = precondition['quantize']['decimals']
|
|
267
|
+
quantized = [_evaluate_quantized(arg, parameters, inputs, decimals) for arg in args]
|
|
268
|
+
return compare(quantized[0]['units'], quantized[1]['units'])
|
|
269
|
+
values = [evaluate(arg, parameters, inputs) for arg in args]
|
|
270
|
+
return compare(values[0], values[1])
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
def resolve(parameters, raw):
|
|
274
|
+
"""Resolve every input, limit and precondition. ``raw`` holds values as read from their sources."""
|
|
275
|
+
problems = reference_errors(parameters)
|
|
276
|
+
if problems:
|
|
277
|
+
_fail('; '.join(problems))
|
|
278
|
+
inputs = {
|
|
279
|
+
name: resolve_input(name, spec, raw.get(name) if isinstance(raw, dict) else None)
|
|
280
|
+
for name, spec in parameters['inputs'].items()
|
|
281
|
+
}
|
|
282
|
+
for name, parameter in parameters['parameters'].items():
|
|
283
|
+
if isinstance(parameter, dict) and (parameter.get('by') or name == 'command_speed'):
|
|
284
|
+
_parameter_value(parameters, name, inputs)
|
|
285
|
+
limits = {}
|
|
286
|
+
for name, limit in parameters['limits'].items():
|
|
287
|
+
value = evaluate(limit['expression'], parameters, inputs)
|
|
288
|
+
if limit.get('round'):
|
|
289
|
+
value = round_half_even_binary(value, limit['round']['decimals'])
|
|
290
|
+
limits[name] = value
|
|
291
|
+
preconditions = {
|
|
292
|
+
name: _evaluate_condition(precondition, parameters, inputs)
|
|
293
|
+
for name, precondition in parameters['preconditions'].items()
|
|
294
|
+
}
|
|
295
|
+
return {'inputs': inputs, 'limits': limits, 'preconditions': preconditions}
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
def _shown_operator(expr):
|
|
299
|
+
if 'op' not in expr:
|
|
300
|
+
return 'undefined'
|
|
301
|
+
if expr['op'] is None:
|
|
302
|
+
return 'null'
|
|
303
|
+
return expr['op']
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
def reference_errors(parameters):
|
|
307
|
+
"""Problems in references. Empty when every name in the file points at something real."""
|
|
308
|
+
errors = []
|
|
309
|
+
inputs = parameters.get('inputs') or {}
|
|
310
|
+
parameters_table = parameters.get('parameters') or {}
|
|
311
|
+
limits = parameters.get('limits') or {}
|
|
312
|
+
|
|
313
|
+
for name, parameter in parameters_table.items():
|
|
314
|
+
if isinstance(parameter, dict) and 'by' in parameter:
|
|
315
|
+
named = inputs.get(parameter['by'])
|
|
316
|
+
if not isinstance(named, dict) or named.get('kind') != 'category':
|
|
317
|
+
errors.append(f'parameters.{name}.by names {parameter["by"]}, which is not a category input')
|
|
318
|
+
|
|
319
|
+
def numeric(name):
|
|
320
|
+
parameter = parameters_table.get(name)
|
|
321
|
+
if not isinstance(parameter, dict):
|
|
322
|
+
return False
|
|
323
|
+
if _is_number(parameter.get('value')):
|
|
324
|
+
return True
|
|
325
|
+
return 'by' in parameter and isinstance(parameter.get('values'), dict)
|
|
326
|
+
|
|
327
|
+
def walk(expr, where, quantized):
|
|
328
|
+
if _is_number(expr):
|
|
329
|
+
if quantized and not _js_integer(expr):
|
|
330
|
+
errors.append(f'{where}: bare number {_js_number(expr)} under quantize must be an integer')
|
|
331
|
+
return
|
|
332
|
+
if not isinstance(expr, dict):
|
|
333
|
+
errors.append(f'{where}: not an expression')
|
|
334
|
+
return
|
|
335
|
+
if 'input' in expr:
|
|
336
|
+
if expr['input'] not in inputs:
|
|
337
|
+
errors.append(f'{where}: unknown input {expr["input"]}')
|
|
338
|
+
elif inputs[expr['input']].get('kind') != 'quantity':
|
|
339
|
+
errors.append(f'{where}: input {expr["input"]} is not a quantity')
|
|
340
|
+
return
|
|
341
|
+
if 'parameter' in expr:
|
|
342
|
+
if expr['parameter'] not in parameters_table:
|
|
343
|
+
errors.append(f'{where}: unknown parameter {expr["parameter"]}')
|
|
344
|
+
elif not numeric(expr['parameter']):
|
|
345
|
+
errors.append(f'{where}: parameter {expr["parameter"]} is not numeric')
|
|
346
|
+
return
|
|
347
|
+
if expr.get('op') not in _ARITHMETIC and expr.get('op') != 'div':
|
|
348
|
+
errors.append(f'{where}: unknown operator {_shown_operator(expr)}')
|
|
349
|
+
if quantized and expr.get('op') == 'div':
|
|
350
|
+
errors.append(f'{where}: quantize does not allow div')
|
|
351
|
+
for index, arg in enumerate(expr.get('args') or []):
|
|
352
|
+
walk(arg, f'{where}.args[{index}]', quantized)
|
|
353
|
+
|
|
354
|
+
command = parameters.get('command') or {}
|
|
355
|
+
for key in ('forward', 'sideways', 'turn_rate'):
|
|
356
|
+
if key in command:
|
|
357
|
+
walk(command[key], f'command.{key}', False)
|
|
358
|
+
for name, limit in limits.items():
|
|
359
|
+
expression = limit.get('expression') if isinstance(limit, dict) else None
|
|
360
|
+
walk(expression, f'limits.{name}.expression', False)
|
|
361
|
+
for name, precondition in (parameters.get('preconditions') or {}).items():
|
|
362
|
+
condition = precondition.get('condition') if isinstance(precondition, dict) else None
|
|
363
|
+
if not isinstance(condition, dict) or condition.get('op') not in _COMPARE:
|
|
364
|
+
if not isinstance(condition, dict) or 'op' not in condition:
|
|
365
|
+
shown = 'undefined'
|
|
366
|
+
elif condition.get('op') is None:
|
|
367
|
+
shown = 'null'
|
|
368
|
+
else:
|
|
369
|
+
shown = condition['op']
|
|
370
|
+
errors.append(f'preconditions.{name}: unknown comparison {shown}')
|
|
371
|
+
args = condition.get('args') if isinstance(condition, dict) and condition.get('args') is not None else []
|
|
372
|
+
quantized = bool(isinstance(precondition, dict) and precondition.get('quantize'))
|
|
373
|
+
for index, arg in enumerate(args):
|
|
374
|
+
walk(arg, f'preconditions.{name}.condition.args[{index}]', quantized)
|
|
375
|
+
for index, check in enumerate(parameters.get('checks') or []):
|
|
376
|
+
if isinstance(check, dict) and 'limit' in check and check['limit'] not in limits:
|
|
377
|
+
errors.append(f'checks[{index}].limit names no limit: {check["limit"]}')
|
|
378
|
+
return errors
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
"""Resolve the package version when it is built.
|
|
3
|
+
|
|
4
|
+
A release build uses one stable catalog tag, ``vX.Y.Z``, or the shared
|
|
5
|
+
resolver's PEP 440 version when that tag does not exist yet. Any other
|
|
6
|
+
checkout, including a pull request or a local tree, gets a development
|
|
7
|
+
version that is not a stable release.
|
|
8
|
+
"""
|
|
9
|
+
import os
|
|
10
|
+
import re
|
|
11
|
+
import subprocess
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
PROJECT = Path(__file__).resolve().parents[1]
|
|
16
|
+
STAMP = Path(__file__).with_name("_version.py")
|
|
17
|
+
ENV_NAME = "LIVINGPROOF_PACKAGE_VERSION"
|
|
18
|
+
STABLE = r"(?:0|[1-9][0-9]*)(?:\.(?:0|[1-9][0-9]*)){2}"
|
|
19
|
+
PEP440 = re.compile(
|
|
20
|
+
STABLE + r"(?:\.dev(?:0|[1-9][0-9]*))?" + r"(?:\+[0-9A-Za-z]+(?:\.[0-9A-Za-z]+)*)?"
|
|
21
|
+
)
|
|
22
|
+
TAG = re.compile(rf"v({STABLE})")
|
|
23
|
+
STAMPED = re.compile(r'(?m)^__version__ = "([^"]+)"$')
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _git(*args):
|
|
27
|
+
try:
|
|
28
|
+
return subprocess.check_output(
|
|
29
|
+
["git", *args], cwd=PROJECT, text=True, stderr=subprocess.DEVNULL,
|
|
30
|
+
).strip()
|
|
31
|
+
except (OSError, subprocess.CalledProcessError):
|
|
32
|
+
return None
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def in_git_checkout():
|
|
36
|
+
return _git("rev-parse", "--is-inside-work-tree") == "true"
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _clean_checkout():
|
|
40
|
+
if not in_git_checkout():
|
|
41
|
+
return False
|
|
42
|
+
return _git("status", "--porcelain", "--untracked-files=all") == ""
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def exact_release_versions():
|
|
46
|
+
raw = _git("tag", "--points-at", "HEAD")
|
|
47
|
+
if not raw:
|
|
48
|
+
return []
|
|
49
|
+
found = []
|
|
50
|
+
for line in raw.splitlines():
|
|
51
|
+
match = TAG.fullmatch(line.strip())
|
|
52
|
+
if match:
|
|
53
|
+
found.append(match.group(1))
|
|
54
|
+
return sorted(set(found))
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _local_version():
|
|
58
|
+
sha = _git("rev-parse", "--short=12", "HEAD")
|
|
59
|
+
if sha and re.fullmatch(r"[0-9a-f]{12,}", sha):
|
|
60
|
+
version = f"0.0.0.dev0+g{sha}"
|
|
61
|
+
else:
|
|
62
|
+
version = "0.0.0.dev0+local"
|
|
63
|
+
if re.fullmatch(STABLE, version):
|
|
64
|
+
raise RuntimeError("A development version must not look like a stable release")
|
|
65
|
+
return version
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _stamped_version():
|
|
69
|
+
if not STAMP.is_file():
|
|
70
|
+
return ""
|
|
71
|
+
match = STAMPED.search(STAMP.read_text(encoding="utf-8"))
|
|
72
|
+
if not match or not PEP440.fullmatch(match.group(1)):
|
|
73
|
+
raise ValueError("Stamped package version is not a supported PEP 440 version")
|
|
74
|
+
return match.group(1)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def resolve_version():
|
|
78
|
+
"""Return the version for this build.
|
|
79
|
+
|
|
80
|
+
The shared resolver's PEP 440 output wins when it is supplied, but it
|
|
81
|
+
must agree with an exact release tag on HEAD. A source distribution that
|
|
82
|
+
was already stamped keeps that version when it is rebuilt without Git.
|
|
83
|
+
"""
|
|
84
|
+
env = os.environ.get(ENV_NAME, "").strip()
|
|
85
|
+
if env and not PEP440.fullmatch(env):
|
|
86
|
+
raise ValueError(
|
|
87
|
+
f"{ENV_NAME} {env!r} must be a stable X.Y.Z release or a development version "
|
|
88
|
+
"such as 0.0.0.dev0+local"
|
|
89
|
+
)
|
|
90
|
+
clean = _clean_checkout()
|
|
91
|
+
if env and re.fullmatch(STABLE, env) and in_git_checkout() and not clean:
|
|
92
|
+
raise ValueError(
|
|
93
|
+
f"Refusing to stamp stable version {env} onto a checkout with uncommitted changes"
|
|
94
|
+
)
|
|
95
|
+
tags = exact_release_versions() if clean else []
|
|
96
|
+
if len(tags) > 1:
|
|
97
|
+
names = ", ".join(f"v{item}" for item in tags)
|
|
98
|
+
raise ValueError(f"HEAD has more than one stable release tag: {names}")
|
|
99
|
+
tagged = tags[0] if tags else ""
|
|
100
|
+
if env and tagged and env != tagged:
|
|
101
|
+
raise ValueError(f"Resolver version {env!r} does not match the release tag v{tagged}")
|
|
102
|
+
if env:
|
|
103
|
+
return env
|
|
104
|
+
if tagged:
|
|
105
|
+
return tagged
|
|
106
|
+
if not in_git_checkout():
|
|
107
|
+
stamped = _stamped_version()
|
|
108
|
+
if stamped:
|
|
109
|
+
return stamped
|
|
110
|
+
return _local_version()
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: livingproof-scenario-parameters
|
|
3
|
+
Version: 3.3.0
|
|
4
|
+
Summary: Reference resolver for livingproof-scenario-parameters/0.1 and route geometry
|
|
5
|
+
Author: Living Proof Labs contributors
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/Living-Proof-Labs/robot-capability-specs
|
|
8
|
+
Project-URL: Source, https://github.com/Living-Proof-Labs/robot-capability-specs
|
|
9
|
+
Requires-Python: >=3.10
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Dynamic: license-file
|
|
13
|
+
|
|
14
|
+
# Living Proof Scenario Parameters
|
|
15
|
+
|
|
16
|
+
A dependency-free Python reference resolver for the Living Proof Scenario
|
|
17
|
+
Parameters contract. It resolves declarative scenario inputs and computes route
|
|
18
|
+
geometry without requiring a robot, simulator, or network at runtime.
|
|
19
|
+
|
|
20
|
+
```python
|
|
21
|
+
from livingproof_scenario_parameters import distance_to_route, resolve_input
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
The installed package version follows the exact catalog release tag. Install
|
|
25
|
+
the wheel or source archive from a verified
|
|
26
|
+
[robot capability specifications release](https://github.com/Living-Proof-Labs/robot-capability-specs/releases).
|
|
27
|
+
The Python code is available under Apache-2.0; a copy of the license is included
|
|
28
|
+
in both distributions.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
MANIFEST.in
|
|
3
|
+
README.md
|
|
4
|
+
livingproof_build.py
|
|
5
|
+
pyproject.toml
|
|
6
|
+
livingproof_scenario_parameters/__init__.py
|
|
7
|
+
livingproof_scenario_parameters/_version.py
|
|
8
|
+
livingproof_scenario_parameters/geometry.py
|
|
9
|
+
livingproof_scenario_parameters/parameters.py
|
|
10
|
+
livingproof_scenario_parameters/versioning.py
|
|
11
|
+
livingproof_scenario_parameters.egg-info/PKG-INFO
|
|
12
|
+
livingproof_scenario_parameters.egg-info/SOURCES.txt
|
|
13
|
+
livingproof_scenario_parameters.egg-info/dependency_links.txt
|
|
14
|
+
livingproof_scenario_parameters.egg-info/top_level.txt
|
livingproof_scenario_parameters-3.3.0/livingproof_scenario_parameters.egg-info/dependency_links.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
livingproof_scenario_parameters
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
[build-system]
|
|
3
|
+
requires = ["setuptools>=77"]
|
|
4
|
+
build-backend = "livingproof_build"
|
|
5
|
+
backend-path = ["."]
|
|
6
|
+
|
|
7
|
+
[project]
|
|
8
|
+
name = "livingproof-scenario-parameters"
|
|
9
|
+
dynamic = ["version"]
|
|
10
|
+
description = "Reference resolver for livingproof-scenario-parameters/0.1 and route geometry"
|
|
11
|
+
requires-python = ">=3.10"
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
license = "Apache-2.0"
|
|
14
|
+
license-files = ["LICENSE"]
|
|
15
|
+
authors = [{ name = "Living Proof Labs contributors" }]
|
|
16
|
+
dependencies = []
|
|
17
|
+
|
|
18
|
+
[project.urls]
|
|
19
|
+
Homepage = "https://github.com/Living-Proof-Labs/robot-capability-specs"
|
|
20
|
+
Source = "https://github.com/Living-Proof-Labs/robot-capability-specs"
|
|
21
|
+
|
|
22
|
+
[tool.setuptools.dynamic]
|
|
23
|
+
version = {attr = "livingproof_scenario_parameters._version.__version__"}
|
|
24
|
+
|
|
25
|
+
[tool.setuptools.packages.find]
|
|
26
|
+
include = ["livingproof_scenario_parameters*"]
|