Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/vss_tools/exporters/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def get_data(node: VSSNode, with_extra_attributes: bool = True, extended_attribu
@click.option(
"--stats-radial",
type=click.Path(path_type=Path),
default=None,
Comment thread
sschleemilch marked this conversation as resolved.
help="Generate radial tree statistics into following JSON file",
)
@click.pass_context
Expand Down
16 changes: 13 additions & 3 deletions src/vss_tools/exporters/stats_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,13 @@ def process_piechart_stats(data_metadata: pd.DataFrame, output: Path, old_chart:
def process_radial_stats(signals_data: dict[str, Any], output: Path) -> None:
"""Process data for radial tree statistics."""

root_key: str | None
root_key = next(iter(signals_data))
if root_key is None:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So here we take first name found right? Do we need to check that there are not more names/roots or is that already covered by some other checks?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Signals data will look like that:

    signals_data = {tree.name: get_data(tree, extend_all_attributes, extended_attributes)}

But yeah, we probably should check for the size and throw an error when its > 1 to notice that something is going wrong

raise KeyError("No root node with children found in signals data")

children = []
stack = [{"key": key, "value": value, "parent": None} for key, value in signals_data["Vehicle"]["children"].items()]
stack = [{"key": key, "value": value, "parent": None} for key, value in signals_data[root_key]["children"].items()]

while stack:
current = stack.pop()
Expand All @@ -91,6 +96,11 @@ def process_radial_stats(signals_data: dict[str, Any], output: Path) -> None:
item = {"name": key}
if "children" in value:
item["children"] = []
# Copy type and description for branches too
if "type" in value:
item["type"] = value["type"]
if "description" in value:
item["description"] = value["description"]
stack.extend(
{"key": child_key, "value": child_value, "parent": item["children"]}
for child_key, child_value in value["children"].items()
Expand All @@ -113,8 +123,8 @@ def process_radial_stats(signals_data: dict[str, Any], output: Path) -> None:
stack.extend(child for child in current["children"] if "children" in child)

radial_tree_data = {
"name": "Vehicle",
"type": "Vehicle",
"name": root_key,
"type": root_key,
"children": children,
}

Expand Down