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
|
import plotly.graph_objects as go
|
||||||
|
|
||||||
from utils.extractor import load_data
|
from utils.extractor import load_data
|
||||||
|
from utils.extractor import to_int
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
def calculate_correlation(df: pd.DataFrame, method: str, target_id: str | None = None) -> pd.DataFrame:
|
def calculate_correlation(df: pd.DataFrame, method: str, target_id: str | None = None) -> pd.DataFrame:
|
||||||
"""Calculates inter-byte correlation grouped by identifier."""
|
"""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()
|
df_bytes = df[["Identifier"] + available_cols].copy()
|
||||||
for col in available_cols:
|
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:
|
if target_id:
|
||||||
group = df_bytes[df_bytes["Identifier"] == 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
|
import plotly.graph_objects as go
|
||||||
|
|
||||||
from utils.extractor import load_data
|
from utils.extractor import load_data
|
||||||
|
from utils.extractor import to_int
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
def calculate_byte_entropy(df: pd.DataFrame) -> pd.DataFrame:
|
def calculate_byte_entropy(df: pd.DataFrame) -> pd.DataFrame:
|
||||||
"""Calculates Shannon entropy per byte position for each identifier."""
|
"""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()
|
df_bytes = df[available_cols].copy()
|
||||||
for col in available_cols:
|
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:
|
def entropy(s: pd.Series) -> float:
|
||||||
s = s.dropna()
|
s = s.dropna()
|
||||||
|
|||||||
Reference in New Issue
Block a user