Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8ccb97afae | |||
| 13d91d566b |
+4
-4
@@ -39,10 +39,10 @@ def plot_freq(stats_df: pd.DataFrame, title: str) -> go.Figure:
|
||||
return fig
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description="Analyze CAN bus frequency.")
|
||||
parser.add_argument("-i", "--input", type=Path, required=True)
|
||||
parser.add_argument("-o", "--output", type=Path, default=Path("freq_report.html"))
|
||||
parser.add_argument("-t", "--title", type=str, default="CAN Bus Message Frequency")
|
||||
parser = argparse.ArgumentParser(description="Analyze CAN bus message frequency")
|
||||
parser.add_argument("input", type=Path, help="Path to the input CAN log file")
|
||||
parser.add_argument("output", type=Path, nargs="?", default=Path("freq_report.html"), help="Path to the output HTML report")
|
||||
parser.add_argument("title", nargs="?", default="CAN Bus Message Frequency", help="Title for the HTML report")
|
||||
args = parser.parse_args()
|
||||
|
||||
df = load_data(args.input)
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import json
|
||||
from pathlib import Path
|
||||
import pandas as pd
|
||||
|
||||
def extract_id(row: pd.Series) -> str:
|
||||
"""Extracts PGN from metadata or falls back to CAN ID."""
|
||||
meta = row.get('j1939_metadata')
|
||||
if pd.isna(meta):
|
||||
return f"ID: {row['ID']}"
|
||||
if isinstance(meta, str):
|
||||
try:
|
||||
meta = json.loads(meta)
|
||||
except json.JSONDecodeError:
|
||||
return f"ID: {row['ID']}"
|
||||
if isinstance(meta, dict) and 'PGN' in meta:
|
||||
return f"PGN: {meta['PGN']}"
|
||||
return f"ID: {row['ID']}"
|
||||
|
||||
def load_data(file_path: Path) -> pd.DataFrame:
|
||||
"""Loads Parquet file and adds an Identifier column."""
|
||||
df = pd.read_parquet(file_path)
|
||||
df['Identifier'] = df.apply(extract_id, axis=1)
|
||||
return df
|
||||
Reference in New Issue
Block a user