fix: add outer exception handling to motion helpers in axis_classifier
This commit is contained in:
+26
-16
@@ -185,16 +185,20 @@ def _project_motions(
|
||||
|
||||
Returns {motion_id: (x_score, y_score)}.
|
||||
"""
|
||||
projections: Dict[int, Tuple[float, float]] = {}
|
||||
for mid, vec in motion_vecs.items():
|
||||
try:
|
||||
centered = vec - global_mean
|
||||
x_score = float(np.dot(centered, x_axis))
|
||||
y_score = float(np.dot(centered, y_axis))
|
||||
projections[mid] = (x_score, y_score)
|
||||
except Exception:
|
||||
continue
|
||||
return projections
|
||||
try:
|
||||
projections: Dict[int, Tuple[float, float]] = {}
|
||||
for mid, vec in motion_vecs.items():
|
||||
try:
|
||||
centered = vec - global_mean
|
||||
x_score = float(np.dot(centered, x_axis))
|
||||
y_score = float(np.dot(centered, y_axis))
|
||||
projections[mid] = (x_score, y_score)
|
||||
except Exception:
|
||||
continue
|
||||
return projections
|
||||
except Exception as exc:
|
||||
_logger.debug("Failed to project motions: %s", exc)
|
||||
return {}
|
||||
|
||||
|
||||
def _top_motion_ids(
|
||||
@@ -208,11 +212,17 @@ def _top_motion_ids(
|
||||
Returns {'+': [motion_ids], '-': [motion_ids]} (highest positive first,
|
||||
most negative first in the '-' list).
|
||||
"""
|
||||
idx = 0 if axis == "x" else 1
|
||||
sorted_ids = sorted(projections, key=lambda mid: projections[mid][idx])
|
||||
neg_ids = sorted_ids[:n] # most negative
|
||||
pos_ids = sorted_ids[-n:][::-1] # most positive
|
||||
return {"+": pos_ids, "-": neg_ids}
|
||||
try:
|
||||
if axis not in ("x", "y"):
|
||||
raise ValueError("axis must be 'x' or 'y'")
|
||||
idx = 0 if axis == "x" else 1
|
||||
sorted_ids = sorted(projections, key=lambda mid: projections[mid][idx])
|
||||
neg_ids = sorted_ids[:n]
|
||||
pos_ids = sorted_ids[-n:][::-1]
|
||||
return {"+": pos_ids, "-": neg_ids}
|
||||
except Exception as exc:
|
||||
_logger.debug("Failed to compute top_motion_ids: %s", exc)
|
||||
return {"+": [], "-": []}
|
||||
|
||||
|
||||
def _fetch_motion_titles(
|
||||
@@ -229,7 +239,7 @@ def _fetch_motion_titles(
|
||||
try:
|
||||
import duckdb
|
||||
|
||||
placeholders = ", ".join("?" * len(motion_ids))
|
||||
placeholders = ", ".join("?" for _ in motion_ids)
|
||||
conn = duckdb.connect(db_path, read_only=True)
|
||||
rows = conn.execute(
|
||||
f"SELECT id, title, date FROM motions WHERE id IN ({placeholders})",
|
||||
|
||||
Reference in New Issue
Block a user