Repository navigation
Expose ModelRepo editor metadata #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tony-xmelon
wants to merge
15
commits into
stokes-audio:main
Choose a base branch
from
tony-xmelon:codex/catalog-ui-metadata
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
696f2f0
Expose catalog editor metadata
tony-xmelon 2bec083
Merge remote-tracking branch 'upstream/main' into codex/catalog-ui-me…
tony-xmelon cac6220
Merge remote-tracking branch 'upstream/main' into codex/catalog-ui-me…
tony-xmelon 4a05091
Merge remote-tracking branch 'upstream/main' into codex/catalog-ui-me…
tony-xmelon 45195dc
fix: ground editor metadata in catalog evidence
tony-xmelon ef95034
Merge remote-tracking branch 'upstream/main' into codex/catalog-ui-me…
tony-xmelon a8d026c
Merge remote-tracking branch 'upstream/main' into codex/catalog-ui-me…
tony-xmelon 579a244
Merge remote-tracking branch 'upstream/main' into codex/catalog-ui-me…
tony-xmelon b57e163
Merge remote-tracking branch 'upstream/main' into codex/catalog-ui-me…
tony-xmelon d97fa63
Pin editor metadata to real 4.0.1 catalog rows
tony-xmelon fe83a50
Ground editor metadata in extracted catalog evidence
tony-xmelon 200864c
Address editor metadata review feedback
tony-xmelon 466587c
Merge remote-tracking branch 'upstream/main' into codex/catalog-ui-me…
tony-xmelon 88f0176
Pin editor metadata to its captured ModelRepo
tony-xmelon 3aec9f5
Reuse main catalog integer-list parser
tony-xmelon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,172 @@ | ||
| #!/usr/bin/env python3 | ||
| """Distil editor-layout evidence from a device ModelRepo. | ||
|
|
||
| python scripts/extract_editor_metadata_fixture.py --payload model_repo.bin | ||
|
|
||
| The full vendor catalog is not redistributed. The fixture contains only the | ||
| raw attributes needed to reproduce the midpoint, display-position, and | ||
| conditional-editor facts asserted by the offline suite. | ||
| """ | ||
|
|
||
| import argparse | ||
| import collections | ||
| import json | ||
| import pathlib | ||
| import sys | ||
| import xml.etree.ElementTree as ET | ||
|
|
||
| sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent.parent)) | ||
|
|
||
| from pyquadcortex.protocol import catalog # noqa: E402 | ||
|
|
||
|
|
||
| EDITOR_ATTRIBUTES = { | ||
| "name", "min_string", "mid_string", "max_string", "skew", "displayPos", | ||
| "isplayPos", "toggleOn", "toggleOff", "toggleStep", | ||
| } | ||
|
|
||
|
|
||
| def _row(model, index, parameter): | ||
| return { | ||
| "model_id": int(model.get("id")), | ||
| "model": model.get("name"), | ||
| "index": index, | ||
| "raw": { | ||
| key: value for key, value in parameter.attrib.items() | ||
| if key in EDITOR_ATTRIBUTES | ||
| }, | ||
| } | ||
|
|
||
|
|
||
| def extract(payload: bytes) -> dict: | ||
| """Build the committed evidence shape from one raw ModelRepo payload.""" | ||
| root = ET.fromstring(catalog._extract_xml(payload)) | ||
| models = list(root.iter("Model")) | ||
| all_parameters = [ | ||
| (model, index, parameter) | ||
| for model in models | ||
| for index, parameter in enumerate(model.findall("Parameter")) | ||
| ] | ||
|
|
||
| midpoint_rows = [ | ||
| _row(model, index, parameter) | ||
| for model, index, parameter in all_parameters | ||
| if parameter.get("mid_string") is not None | ||
| ] | ||
|
|
||
| collision_rows = [] | ||
| gap_models = [] | ||
| display_carriers = 0 | ||
| for model in models: | ||
| positions = collections.defaultdict(list) | ||
| for index, parameter in enumerate(model.findall("Parameter")): | ||
| raw = parameter.get("displayPos") | ||
| if raw is None: | ||
| continue | ||
| display_carriers += 1 | ||
| try: | ||
| positions[int(raw)].append(_row(model, index, parameter)) | ||
| except ValueError: | ||
| continue | ||
| duplicates = { | ||
| str(position): rows for position, rows in positions.items() | ||
| if len(rows) > 1 | ||
| } | ||
| if duplicates: | ||
| collision_rows.append({ | ||
| "model_id": int(model.get("id")), | ||
| "model": model.get("name"), | ||
| "positions": duplicates, | ||
| }) | ||
| # Use the explicit all-parameter basis: every missing integer in | ||
| # 0..max(displayPos) is a gap. This counts all 533 CorOS 4.0.1 models, | ||
| # including the two hidden models PCOM Tape Delay (ST) and Chief DC2W | ||
| # PCOM; excluding them gives 19 rather than 21 gap models. | ||
| if positions: | ||
| missing = sorted(set(range(max(positions) + 1)) - set(positions)) | ||
| if missing: | ||
| gap_models.append({ | ||
| "model_id": int(model.get("id")), | ||
| "model": model.get("name"), | ||
| "missing": missing, | ||
| }) | ||
|
|
||
| toggle_rows = { | ||
| attribute: [ | ||
| _row(model, index, parameter) | ||
| for model, index, parameter in all_parameters | ||
| if parameter.get(attribute) is not None | ||
| ] | ||
| for attribute in ("toggleOn", "toggleOff", "toggleStep") | ||
| } | ||
| self_references = [] | ||
| for attribute in ("toggleOn", "toggleOff"): | ||
| for row in toggle_rows[attribute]: | ||
| indexes = { | ||
| int(part.strip()) for part in row["raw"][attribute].split(",") | ||
| if part.strip().lstrip("-").isdigit() | ||
| } | ||
| if row["index"] in indexes: | ||
| self_references.append({ | ||
| **row, "attribute": attribute, | ||
| }) | ||
|
|
||
| typo = next( | ||
| _row(model, index, parameter) | ||
| for model, index, parameter in all_parameters | ||
| if parameter.get("isplayPos") is not None | ||
| ) | ||
|
|
||
| fixture = { | ||
| "source": "Quad Cortex CorOS 4.0.1 ModelRepo payload", | ||
| "firmware": "CorOS 4.0.1", | ||
| "parameters": len(all_parameters), | ||
| "mid_string": { | ||
| "rows": midpoint_rows, | ||
| }, | ||
| "displayPos": { | ||
| "carriers": display_carriers, | ||
| "collision_models": collision_rows, | ||
| "gap_models": gap_models, | ||
| "device_typo": typo, | ||
| }, | ||
| "toggle": { | ||
| "counts": { | ||
| attribute: len(rows) | ||
| for attribute, rows in toggle_rows.items() | ||
| }, | ||
| "step_rows": toggle_rows["toggleStep"], | ||
| "all_step_carriers_have_on_or_off": all( | ||
| "toggleOn" in row["raw"] or "toggleOff" in row["raw"] | ||
| for row in toggle_rows["toggleStep"] | ||
| ), | ||
| "self_references": self_references, | ||
| }, | ||
| } | ||
|
|
||
| return fixture | ||
|
|
||
|
|
||
| def main(): | ||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument("--payload", required=True) | ||
| parser.add_argument( | ||
| "--out", default="tests/fixtures/catalog/editor_metadata.json") | ||
| args = parser.parse_args() | ||
|
|
||
| payload = pathlib.Path(args.payload).read_bytes() | ||
| fixture = extract(payload) | ||
| out = pathlib.Path(args.out) | ||
| out.parent.mkdir(parents=True, exist_ok=True) | ||
| out.write_text(json.dumps(fixture, indent=2) + "\n", encoding="utf-8") | ||
| midpoint_rows = fixture["mid_string"]["rows"] | ||
| collision_rows = fixture["displayPos"]["collision_models"] | ||
| self_references = fixture["toggle"]["self_references"] | ||
| print( | ||
| f"wrote {len(midpoint_rows)} midpoint rows, " | ||
| f"{len(collision_rows)} collision models, and " | ||
| f"{len(self_references)} self-references to {out}") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.