mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-09-19 14:03:50 +08:00
a4454721ea
* feat(params): add support for parameter metadata retrieval - Introduced `getKeyMetadata` method for accessing metadata associated with params. - Enhanced `getParamsAllKeysV1` to include metadata parsing and optional dynamic enum generation. - Extended unit tests to verify metadata parsing, enum mapping, and edge cases. * Revert "feat(params): add support for parameter metadata retrieval" This reverts commit 865b695ff966bfab7dab4d211fb2d91f06fe92db. * update: integrate params metadata management and unit tests - Added `update_params_metadata.py` to manage and update parameters metadata. - Enhanced `getParamsAllKeysV1` to include metadata for params. - Created comprehensive tests (`test_params_metadata.py`, `test_params_sync.py`) to validate metadata integrity and params consistency. * update: improve params metadata readability and enhance enums - Renamed params titles for clarity and consistency. - Added enum options and mappings to selected params for better usability. * update: enhance params metadata with improved enum structures - Replaced plain enum lists with detailed objects (`value`, `label`) for clarity. - Standardized parameter options for consistency across metadata. * update: add validation constraints to params metadata - Introduced `min`, `max`, and `step` attributes for improved parameter range validation. - Enhances user input handling and ensures consistency in metadata. * lint * more lint stuff and permissions * does this suffice? * more lint * update: refine params type hinting and remove unused shebang - Adjusted type annotation in `params_dict` for better compatibility. - Removed unnecessary shebang from `test_params_metadata.py`. * update: expand test coverage for params metadata validation - Added detailed test cases to ensure metadata consistency (`options`, `constraints`, `titles`). - Validates API response alignment with `params_metadata.json`. * the finals * names --------- Co-authored-by: Jason Wen <haibin.wen3@gmail.com>
57 lines
1.3 KiB
Python
Executable File
57 lines
1.3 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""
|
|
Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors.
|
|
|
|
This file is part of sunnypilot and is licensed under the MIT License.
|
|
See the LICENSE.md file in the root directory for more details.
|
|
"""
|
|
import json
|
|
import os
|
|
|
|
from openpilot.common.params import Params
|
|
|
|
METADATA_PATH = os.path.join(os.path.dirname(__file__), "../params_metadata.json")
|
|
|
|
|
|
def main():
|
|
params = Params()
|
|
all_keys = params.all_keys()
|
|
|
|
if os.path.exists(METADATA_PATH):
|
|
with open(METADATA_PATH) as f:
|
|
try:
|
|
data = json.load(f)
|
|
except json.JSONDecodeError:
|
|
data = {}
|
|
else:
|
|
data = {}
|
|
|
|
# Add new keys
|
|
for key in all_keys:
|
|
key_str = key.decode("utf-8")
|
|
if key_str not in data:
|
|
print(f"Adding new key: {key_str}")
|
|
data[key_str] = {
|
|
"title": key_str,
|
|
"description": "",
|
|
}
|
|
|
|
# Remove deleted keys
|
|
# keys_to_remove = [k for k in data.keys() if k.encode("utf-8") not in all_keys]
|
|
# for k in keys_to_remove:
|
|
# print(f"Removing deleted key: {k}")
|
|
# del data[k]
|
|
|
|
# Sort keys
|
|
sorted_data = dict(sorted(data.items()))
|
|
|
|
with open(METADATA_PATH, "w") as f:
|
|
json.dump(sorted_data, f, indent=2)
|
|
f.write("\n")
|
|
|
|
print(f"Updated {METADATA_PATH}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|