fix: add outer exception handling to motion helpers in axis_classifier

main
Sven Geboers 1 month ago
parent 96224be6ee
commit 62daad321e
  1. 42
      analysis/axis_classifier.py

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

Loading…
Cancel
Save