Normalize CAN IDs number of bits

This commit is contained in:
2026-07-14 00:03:34 +02:00
parent 9ddc6ea0d5
commit d8105e2da3
4 changed files with 72 additions and 10 deletions
+21 -2
View File
@@ -9,10 +9,29 @@ import plotly.express as px
import plotly.graph_objects as go
from utils.extractor import load_data
def _format_can_id(x):
"""Safely cleans CAN ID strings without altering their length or value."""
if pd.isna(x):
return "UNKNOWN"
s = str(x).strip()
if not s:
return "UNKNOWN"
if s.lower().startswith('0x'):
s = s[2:]
return s.upper()
def calc_freq(df: pd.DataFrame) -> pd.DataFrame:
"""Calculates frequency counts and percentages for identifiers."""
freq_df = df['Identifier'].value_counts().reset_index()
can_id_col = 'ID' if 'ID' in df.columns else 'Identifier'
df['Formatted_ID'] = df[can_id_col].apply(_format_can_id)
freq_df = df['Formatted_ID'].value_counts().reset_index()
freq_df.columns = ['Identifier', 'Count']
total = freq_df['Count'].sum()
freq_df['Percentage'] = (freq_df['Count'] / total * 100).round(2)
return freq_df.sort_values('Count', ascending=True)
@@ -43,7 +62,6 @@ def plot_freq(stats_df: pd.DataFrame, title: str) -> go.Figure:
),
yaxis=dict(
title=dict(text="PGN or CAN ID", font=dict(size=13, color="#1a1a1a")),
#autorange="",
showgrid=False,
linecolor="#bdbdbd",
tickfont=dict(size=12, color="#2a2a2a"),
@@ -51,6 +69,7 @@ def plot_freq(stats_df: pd.DataFrame, title: str) -> go.Figure:
ticklen=4,
tickcolor="#cccccc",
automargin=True,
type='category'
),
font=dict(family="Segoe UI, Arial, sans-serif", size=12, color='#2a2a2a'),
hoverlabel=dict(bgcolor="white", font_size=13, font_family="Segoe UI",