Implement lttbc
This commit is contained in:
+10
-2
@@ -7,6 +7,7 @@ from pathlib import Path
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
import plotly.graph_objects as go
|
||||
import lttbc
|
||||
from stats.utils.extractor import load_data
|
||||
|
||||
def _format_can_id_vec(s: pd.Series) -> pd.Series:
|
||||
@@ -43,13 +44,20 @@ def plot_bits(df, byte_cols, can_id, title):
|
||||
fig = go.Figure()
|
||||
colors = ['#e41a1c', '#377eb8', '#4daf4a', '#984ea3', '#ff7f00', '#ffff33', '#a65628', '#f781bf']
|
||||
n = len(byte_cols)
|
||||
max_points = 2000
|
||||
|
||||
x = df['Timestamp'].to_numpy() if not df.empty else np.array([])
|
||||
for i, col in enumerate(byte_cols):
|
||||
y = df[col].to_numpy(dtype=np.float32, copy=False) if not df.empty else np.array([])
|
||||
|
||||
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,
|
||||
y=y,
|
||||
x=x_plot,
|
||||
y=y_plot,
|
||||
mode='lines',
|
||||
line=dict(shape='hv', width=2, color=colors[i % len(colors)]),
|
||||
name=col.upper(),
|
||||
|
||||
Reference in New Issue
Block a user