Use utility function instead of internal
This commit is contained in:
+2
-14
@@ -10,19 +10,7 @@ import pandas as pd
|
||||
import plotly.graph_objects as go
|
||||
|
||||
from utils.extractor import load_data
|
||||
|
||||
|
||||
def _to_int(x):
|
||||
"""Convert a hex string or integer to int, returning NaN on failure."""
|
||||
if isinstance(x, (int, np.integer)):
|
||||
return int(x)
|
||||
if isinstance(x, str):
|
||||
try:
|
||||
return int(x, 16)
|
||||
except ValueError:
|
||||
return np.nan
|
||||
return np.nan
|
||||
|
||||
from utils.extractor import to_int
|
||||
|
||||
def calculate_correlation(df: pd.DataFrame, method: str, target_id: str | None = None) -> pd.DataFrame:
|
||||
"""Calculates inter-byte correlation grouped by identifier."""
|
||||
@@ -34,7 +22,7 @@ def calculate_correlation(df: pd.DataFrame, method: str, target_id: str | None =
|
||||
|
||||
df_bytes = df[["Identifier"] + available_cols].copy()
|
||||
for col in available_cols:
|
||||
df_bytes[col] = df_bytes[col].apply(_to_int)
|
||||
df_bytes[col] = df_bytes[col].apply(to_int)
|
||||
|
||||
if target_id:
|
||||
group = df_bytes[df_bytes["Identifier"] == target_id]
|
||||
|
||||
+2
-14
@@ -10,19 +10,7 @@ import pandas as pd
|
||||
import plotly.graph_objects as go
|
||||
|
||||
from utils.extractor import load_data
|
||||
|
||||
|
||||
def _to_int(x):
|
||||
"""Convert a hex string or integer to int, returning NaN on failure."""
|
||||
if isinstance(x, (int, np.integer)):
|
||||
return int(x)
|
||||
if isinstance(x, str):
|
||||
try:
|
||||
return int(x, 16)
|
||||
except ValueError:
|
||||
return np.nan
|
||||
return np.nan
|
||||
|
||||
from utils.extractor import to_int
|
||||
|
||||
def calculate_byte_entropy(df: pd.DataFrame) -> pd.DataFrame:
|
||||
"""Calculates Shannon entropy per byte position for each identifier."""
|
||||
@@ -33,7 +21,7 @@ def calculate_byte_entropy(df: pd.DataFrame) -> pd.DataFrame:
|
||||
|
||||
df_bytes = df[available_cols].copy()
|
||||
for col in available_cols:
|
||||
df_bytes[col] = df_bytes[col].apply(_to_int)
|
||||
df_bytes[col] = df_bytes[col].apply(to_int)
|
||||
|
||||
def entropy(s: pd.Series) -> float:
|
||||
s = s.dropna()
|
||||
|
||||
Reference in New Issue
Block a user