8000 Newest stats scripts by Giaccomole · Pull Request #453 · COVESA/vss-tools · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Newest stats scripts #453

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
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
819562a
Cllick exporter script and Py scripts with data.
Giaccomole Jan 29, 2025
0019f66
Scripts with generated test data
Giaccomole Jan 29, 2025
adf1a8d
pie chart stats exporter
Giaccomole Feb 5, 2025
1c4ee3b
Cleanup
Giaccomole Feb 5, 2025
2bb595b
statistics moved to new command group
Giaccomole Feb 5, 2025
bf8fb3a
stats cli ready-redundancies removed
Giaccomole Feb 5, 2025
f671c92
Redundancies removed
Giaccomole Feb 5, 2025
9a1a219
path change
Giaccomole Feb 12, 2025
aa71e43
path change
Giaccomole Feb 12, 2025
07bf1b3
path changes
Giaccomole Feb 12, 2025
4d3403d
path change
Giaccomole Feb 13, 2025
4029151
removed default outputs
Giaccomole Feb 13, 2025
ed817a4
ran pre-commit
Giaccomole Feb 13, 2025
ddfe9dc
Better error message for implicit branches (#437)
erikbosch Mar 10, 2025
0caa136
feat: Add support for extended attributes to the CSV exporter.
jdacoello Feb 19, 2025
a132d7f
Add stdint include to cparserlib.h
eric-hologic Feb 15, 2025
997e7fb
Don't automatically call printReadMetaData() on call to VSSReadTree
eric-hologic Feb 25, 2025
ec9b3c7
fix: added missing types option for franca exporter
sschleemilch Apr 1, 2025
8e2b1bb
fix: removed min/max array limitation
sschleemilch Mar 26, 2025
d80db12
feat: added round off model min max comparison
sschleemilch Apr 2, 2025
ff9d8a7
feat: improved go exporter type names
sschleemilch Apr 7, 2025
f0342a7
feat: bumped dependencies
sschleemilch Apr 7, 2025
ffcda2c
logging - old chart as cli argument
Giaccomole Apr 29, 2025
959959e
error handling for major version
Giaccomole Apr 29, 2025
164c248
feat: refactor CSV export for Sankey and Pie Chart, using subprocess …
Giaccomole Jun 11, 2025
3a6cd7e
pre-commit
Giaccomole Jun 11, 2025
4b5684f
pre-commit
Giaccomole Jun 11, 2025
0d96cda
pre-commit
Giaccomole Jun 11, 2025
7ef367d
Merge branch 'COVESA:master' into newest-stats-scripts
Giaccomole Jun 12, 2025
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
17 changes: 17 additions & 0 deletions src/vss_tools/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,20 @@ def export(ctx: click.Context):
"""
if ctx.invoked_subcommand is None:
click.echo(ctx.get_help())


@cli.group(
cls=LazyGroup,
lazy_subcommands={
"radial": "vss_tools.stats.radial:cli",
"sankey": "vss_tools.stats.sankey:cli",
"piechart": "vss_tools.stats.piechart:cli",
},
)
@click.pass_context
def stats(ctx: click.Context):
"""
Generate statistical data for the documentation
"""
if ctx.invoked_subcommand is None:
click.echo(ctx.get_help())
8 changes: 8 additions & 0 deletions src/vss_tools/cli_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ def validate_attribute(value):
required=True,
)

old_chart_opt = option(
"--old-chart",
"-old",
type=click.Path(dir_okay=False, writable=True, path_type=Path),
help="Output file.",
required=True,
)

output_opt = option(
"--output",
"-o",
Expand Down
7 changes: 7 additions & 0 deletions src/vss_tools/stats/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Copyright (c) 2022 Contributors to COVESA
#
# This program and the accompanying materials are made available under the
# terms of the Mozilla Public License 2.0 which is available at
# https://www.mozilla.org/en-US/MPL/2.0/
#
# SPDX-License-Identifier: MPL-2.0
84 changes: 84 additions & 0 deletions src/vss_tools/stats/piechart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Copyright (c) 2021 Contributors to COVESA
#
# This program and the accompanying materials are made available under the
# terms of the Mozilla Public License 2.0 which is available at
# https://www.mozilla.org/en-US/MPL/2.0/
#
# SPDX-License-Identifier: MPL-2.0

# Export CSV Statistics for Pie Chart.

import os
import subprocess
from collections import Counter
from pathlib import Path

import pandas as pd
import rich_click as click

import vss_tools.cli_options as clo
from vss_tools import log


@click.command()
@clo.vspec_opt
@clo.output_required_opt
@clo.old_chart_opt
def cli(
vspec: Path,
output: Path,
old_chart: Path,
):
"""
Export CSV Statistics for Pie Chart.
"""

interim_file = output.parent / "interim_vss_data.csv"
subprocess.run(["vspec", "export", "csv", "-s", str(vspec), "-o", str(interim_file), "--no-expand"], check=True)
log.info(f"Interim CSV file generated: {interim_file}")

data_metadata = pd.read_csv(interim_file)

latest = pd.read_csv(old_chart)

metadata = data_metadata # Use the imported CSV content

metadata["Default"] = pd.to_numeric(metadata["Default"], errors="coerce")

major_version = None
for index, row in metadata.iterrows():
if "Vehicle.VersionVSS.Major" in row["Signal"] and row["Default"] > 5:
major_version = int(row["Default"])
break

if major_version is not None:
type_counts = Counter(metadata["Type"])
counts = {
"Branches": type_counts.get("branch", 0),
"Sensors": type_counts.get("sensor", 0),
"Actuators": type_counts.get("actuator", 0),
"Attributes": type_counts.get("attribute", 0),
}

column_name = f"V{major_version}"
if column_name not in latest.columns:
latest[column_name] = pd.Series(
[counts["Attributes"], counts["Branches"], counts["Sensors"], counts["Actuators"]]
)
version_cols = [col for col in latest.columns if col.startswith("V")]
for i in range(len(version_cols) - 1):
v1 = int(version_cols[i][1])
v2 = int(version_cols[i + 1][1])
if v2 != v1 + 1:
log.warning(f"MISSING VERSION: V{v1+1}")
else:
raise ValueError("No valid major version found. The operation cannot proceed.")

latest.to_csv(output, index=False)
log.info(f"Final CSV file saved: {output}")

try:
os.remove(interim_file)
log.info(f"Interim file removed: {interim_file}")
except OSError as e:
log.error(f"Error removing interim file: {e}")
97 changes: 97 additions & 0 deletions src/vss_tools/stats/radial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Copyright (c) 2022 Contributors to COVESA
#
# This program and the accompanying materials are made available under the
# terms of the Mozilla Public License 2.0 which is available at
# https://www.mozilla.org/MPL/2.0/
#
# SPDX-License-Identifier: MPL-2.0

# Export JSON Data for Radial Tree.

import json
import os
import subprocess
from pathlib import Path

import rich_click as click

import vss_tools.cli_options as clo
from vss_tools import log


@click.command()
@clo.vspec_opt
@clo.output_required_opt
def cli(
vspec: Path,
output: Path,
):
"""
Export JSON Data for Radial Tree.
"""

interim_file = output.parent / "interim_vss_data.json"
subprocess.run(
[
"vspec",
"export",
"json",
"-s",
str(vspec),
"-o",
str(interim_file),
],
check=True,
)
log.info(f"Interim JSON file generated: {interim_file}")

with open(interim_file, "r") as f:
signals_data = json.load(f)

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

while stack:
current = stack.pop()
key, value, parent = current["key"], current["value"], current["parent"]

item = {"name": key}
if "children" in value:
item["children"] = []
stack.extend(
{"key": child_key, "value": child_value, "parent": item["children"]}
for child_key, child_value in value["children"].items()
)
else:
for prop, prop_value in value.items():
if prop != "children":
item[prop] = prop_value

if parent is not None:
parent.append(item)
else:
children.append(item)

stack = [{"children": children}]

while stack:
current = stack.pop()
if "children" in current:
current["children"].sort(key=lambda x: (x.get("type", ""), x.get("name", "")))
stack.extend(child for child in current["children"] if "children" in child)

radial_tree_data = {
"name": "Vehicle",
"type": "Vehicle",
&qu AE8F ot;children": children,
}

with open(output, "w") as f:
json.dump(radial_tree_data, f, indent=2)
log.info(f"Final JSON file saved: {output}")

try:
os.remove(interim_file)
log.info(f"Interim file removed: {interim_file}")
except OSError as e:
log.error(f"Error removing interim file: {e}")
57 changes: 57 additions & 0 deletions src/vss_tools/stats/sankey.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Copyright (c) 2021 Contributors to COVESA
#
# This program and the accompanying materials are made available under the
# terms of the Mozilla Public License 2.0 which is available at
# https://www.mozilla.org/MPL/2.0/
#
# SPDX-License-Identifier: MPL-2.0

# Export CSV Stats for Sankey Diagram.

import os
import subprocess
from pathlib import Path

import pandas as pd
import rich_click as click

import vss_tools.cli_options as clo
from vss_tools import log


@click.command()
@clo.vspec_opt
@clo.output_required_opt
def cli(
vspec: Path,
output: Path,
):
"""
Export CSV Stats for Sankey Diagram.
"""
interim_file = output.parent / "interim_vss_data.csv"
subprocess.run(["vspec", "export", "csv", "-s", str(vspec), "-o", str(interim_file), "--no-expand"], check=True)
log.info(f"Interim CSV file generated: {interim_file}")

data_metadata = pd.read_csv(interim_file)

data_metadata = data_metadata[~data_metadata.isin(["branch"]).any(axis=1)]

data_metadata["Property"] = data_metadata["Type"].apply(
lambda x: "dynamic" if x in ["sensor", "actuator"] else "static"
)

if "Dummy" not in data_metadata.columns:
data_metadata["Dummy"] = 0

columns_order = ["Property", "Type", "DataType", "Dummy"]
data_metadata = data_metadata.loc[:, columns_order]

data_metadata.to_csv(output, index=False)
log.info(f"Final CSV file saved: {output}")

try:
os.remove(interim_file)
log.info(f"Interim file removed: {interim_file}")
except OSError as e:
log.error(f"Error removing interim file: {e}")
0