Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e35c56c67a | |||
| 4bd0c60d2d |
@@ -56,6 +56,7 @@ DATA = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
|
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
|
||||||
|
app.config.suppress_callback_exceptions = True
|
||||||
|
|
||||||
app.layout = dbc.Container([
|
app.layout = dbc.Container([
|
||||||
html.H1("CAN Bus Analyzer", className="my-4"),
|
html.H1("CAN Bus Analyzer", className="my-4"),
|
||||||
|
|||||||
+12
-4
@@ -7,7 +7,7 @@ from pathlib import Path
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import plotly.graph_objects as go
|
import plotly.graph_objects as go
|
||||||
from plotly_resampler import FigureResampler
|
import lttbc
|
||||||
from stats.utils.extractor import load_data
|
from stats.utils.extractor import load_data
|
||||||
|
|
||||||
def _format_can_id_vec(s: pd.Series) -> pd.Series:
|
def _format_can_id_vec(s: pd.Series) -> pd.Series:
|
||||||
@@ -41,21 +41,29 @@ def prepare_data(df, target_id):
|
|||||||
return filtered, byte_cols
|
return filtered, byte_cols
|
||||||
|
|
||||||
def plot_bits(df, byte_cols, can_id, title):
|
def plot_bits(df, byte_cols, can_id, title):
|
||||||
fig = FigureResampler()
|
fig = go.Figure()
|
||||||
colors = ['#e41a1c', '#377eb8', '#4daf4a', '#984ea3', '#ff7f00', '#ffff33', '#a65628', '#f781bf']
|
colors = ['#e41a1c', '#377eb8', '#4daf4a', '#984ea3', '#ff7f00', '#ffff33', '#a65628', '#f781bf']
|
||||||
n = len(byte_cols)
|
n = len(byte_cols)
|
||||||
|
max_points = 2000
|
||||||
|
|
||||||
x = df['Timestamp'].to_numpy() if not df.empty else np.array([])
|
x = df['Timestamp'].to_numpy() if not df.empty else np.array([])
|
||||||
for i, col in enumerate(byte_cols):
|
for i, col in enumerate(byte_cols):
|
||||||
y = df[col].to_numpy(dtype=np.float32, copy=False) if not df.empty else np.array([])
|
y = df[col].to_numpy(dtype=np.float32, copy=False) if not df.empty else np.array([])
|
||||||
|
|
||||||
fig.add_trace(go.Scatter(
|
if len(x) > max_points and len(x) == len(y):
|
||||||
|
x_plot, y_plot = lttbc.downsample(x, y, max_points)
|
||||||
|
else:
|
||||||
|
x_plot, y_plot = x, y
|
||||||
|
|
||||||
|
fig.add_trace(go.Scattergl(
|
||||||
|
x=x_plot,
|
||||||
|
y=y_plot,
|
||||||
mode='lines',
|
mode='lines',
|
||||||
line=dict(shape='hv', width=2, color=colors[i % len(colors)]),
|
line=dict(shape='hv', width=2, color=colors[i % len(colors)]),
|
||||||
name=col.upper(),
|
name=col.upper(),
|
||||||
legendgroup=col.upper(),
|
legendgroup=col.upper(),
|
||||||
hovertemplate=f"<b>{col.upper()}</b><br>Time: %{{x}}<br>Value: %{{y}}<extra></extra>",
|
hovertemplate=f"<b>{col.upper()}</b><br>Time: %{{x}}<br>Value: %{{y}}<extra></extra>",
|
||||||
), hf_x=x, hf_y=y)
|
))
|
||||||
|
|
||||||
all_button = dict(label='ALL', method='restyle', args=[{'visible': [True] * n}])
|
all_button = dict(label='ALL', method='restyle', args=[{'visible': [True] * n}])
|
||||||
none_button = dict(label='NONE', method='restyle', args=[{'visible': ['legendonly'] * n}])
|
none_button = dict(label='NONE', method='restyle', args=[{'visible': ['legendonly'] * n}])
|
||||||
|
|||||||
Reference in New Issue
Block a user