Parallelize data processing tasks with ThreadPoolExecutor
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
|
||||
import polars as pl
|
||||
import dash
|
||||
@@ -59,9 +60,10 @@ PRECOMPUTED_FIGURES = {}
|
||||
DATA_BY_ID = {}
|
||||
CORR_CACHE = {}
|
||||
|
||||
for bus, df in DATA.items():
|
||||
PRECOMPUTED_FIGURES[f"{bus}_freq"] = plot_frequency(calculate_frequency(df), title=f"{bus} Frequency")
|
||||
PRECOMPUTED_FIGURES[f"{bus}_entropy"] = plot_entropy_heatmap(calculate_byte_entropy(df), title=f"{bus} Byte-Level Entropy")
|
||||
def process_bus_data(bus, df):
|
||||
precomp = {}
|
||||
precomp[f"{bus}_freq"] = plot_frequency(calculate_frequency(df), title=f"{bus} Frequency")
|
||||
precomp[f"{bus}_entropy"] = plot_entropy_heatmap(calculate_byte_entropy(df), title=f"{bus} Byte-Level Entropy")
|
||||
|
||||
can_id_col = 'ID' if 'ID' in df.columns else 'Identifier'
|
||||
formatted = _format_can_id_vec(df[can_id_col])
|
||||
@@ -80,7 +82,15 @@ for bus, df in DATA.items():
|
||||
group = group.iloc[keep]
|
||||
grouped[can_id] = (group, byte_cols)
|
||||
|
||||
DATA_BY_ID[bus] = grouped
|
||||
return precomp, grouped
|
||||
|
||||
with ThreadPoolExecutor() as executor:
|
||||
futures = {executor.submit(process_bus_data, bus, df): bus for bus, df in DATA.items()}
|
||||
for future in futures:
|
||||
bus = futures[future]
|
||||
precomp, grouped = future.result()
|
||||
PRECOMPUTED_FIGURES.update(precomp)
|
||||
DATA_BY_ID[bus] = grouped
|
||||
|
||||
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
|
||||
app.config.suppress_callback_exceptions = True
|
||||
@@ -209,4 +219,4 @@ def update_corr(method, target, bus, tab):
|
||||
return plot_correlation_heatmap(corr_df, target_id=target_id, title=title)
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=False)
|
||||
app.run(debug=True)
|
||||
|
||||
Reference in New Issue
Block a user