fix: add outer exception handling to motion helpers in axis_classifier
This commit is contained in:
@@ -185,6 +185,7 @@ def _project_motions(
|
|||||||
|
|
||||||
Returns {motion_id: (x_score, y_score)}.
|
Returns {motion_id: (x_score, y_score)}.
|
||||||
"""
|
"""
|
||||||
|
try:
|
||||||
projections: Dict[int, Tuple[float, float]] = {}
|
projections: Dict[int, Tuple[float, float]] = {}
|
||||||
for mid, vec in motion_vecs.items():
|
for mid, vec in motion_vecs.items():
|
||||||
try:
|
try:
|
||||||
@@ -195,6 +196,9 @@ def _project_motions(
|
|||||||
except Exception:
|
except Exception:
|
||||||
continue
|
continue
|
||||||
return projections
|
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).
|
||||||
"""
|
"""
|
||||||
|
try:
|
||||||
|
if axis not in ("x", "y"):
|
||||||
|
raise ValueError("axis must be 'x' or 'y'")
|
||||||
idx = 0 if axis == "x" else 1
|
idx = 0 if axis == "x" else 1
|
||||||
sorted_ids = sorted(projections, key=lambda mid: projections[mid][idx])
|
sorted_ids = sorted(projections, key=lambda mid: projections[mid][idx])
|
||||||
neg_ids = sorted_ids[:n] # most negative
|
neg_ids = sorted_ids[:n]
|
||||||
pos_ids = sorted_ids[-n:][::-1] # most positive
|
pos_ids = sorted_ids[-n:][::-1]
|
||||||
return {"+": pos_ids, "-": neg_ids}
|
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})",
|
||||||
|
|||||||
Reference in New Issue
Block a user