Skip to content

Commit 4eacc59

Browse files
committed
Fix spacer feedback specificity
1 parent 399e55a commit 4eacc59

File tree

2 files changed

+57
-11
lines changed

2 files changed

+57
-11
lines changed

evaluation_function/evaluation.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
},
110110
"spacer": {
111111
"pass": "Good. The spacer setup looks correct.",
112+
"none_detected": "No spacers were detected clearly. Please make sure both spacers are installed and clearly visible in the photo.",
112113
"short_missing": "The short spacer may be missing or not detected. Please check whether the short spacer is installed and retake the photo if needed.",
113114
"long_missing": "The long spacer may be missing or not detected. Please check whether the long spacer is installed and retake the photo if needed.",
114115
"count_fail": "A spacer may be missing or not detected. Please check whether both spacers are installed and retake the photo if needed.",
@@ -397,6 +398,8 @@ def _get_shaft_counts(out: Dict[str, Any]) -> Tuple[int, int, int]:
397398

398399
def _get_spacer_counts(out: Dict[str, Any]) -> Tuple[int, int, int]:
399400
counts = out.get("spacer_counts", {}) if isinstance(out.get("spacer_counts"), dict) else {}
401+
if not counts:
402+
counts = out.get("counts", {}) if isinstance(out.get("counts"), dict) else {}
400403

401404
n_long = _safe_int(counts.get("spacer_long", 0))
402405
n_short = _safe_int(counts.get("spacer_short", 0))
@@ -680,9 +683,18 @@ def advice_text() -> str:
680683
n_long, n_short, n_total = _get_spacer_counts(out)
681684
counts_dict = _get_counts_dict(out)
682685

686+
if "E_SPACER_SHORT_MISSING" in codes:
687+
return False, MESSAGE_POLICY["spacer"]["short_missing"]
688+
689+
if "E_SPACER_LONG_MISSING" in codes:
690+
return False, MESSAGE_POLICY["spacer"]["long_missing"]
691+
692+
if "E_SPACER_TYPE_CONFUSION" in codes:
693+
return False, MESSAGE_POLICY["spacer"]["type_confusion"]
694+
683695
if ("spacer_long" in counts_dict) or ("spacer_short" in counts_dict):
684696
if n_total == 0:
685-
return False, MESSAGE_POLICY["spacer"]["count_fail"]
697+
return False, MESSAGE_POLICY["spacer"]["none_detected"]
686698

687699
if n_short == 0 and n_long >= 1:
688700
return False, MESSAGE_POLICY["spacer"]["short_missing"]
@@ -693,18 +705,11 @@ def advice_text() -> str:
693705
if n_short != 1 or n_long != 1 or n_total != 2:
694706
return False, MESSAGE_POLICY["spacer"]["count_fail"]
695707

696-
if "E_SPACER_SHORT_MISSING" in codes:
697-
return False, MESSAGE_POLICY["spacer"]["short_missing"]
698-
699-
if "E_SPACER_LONG_MISSING" in codes:
700-
return False, MESSAGE_POLICY["spacer"]["long_missing"]
701-
702708
if "E_SPACER_COUNT_MISMATCH" in codes:
709+
if n_total == 0:
710+
return False, MESSAGE_POLICY["spacer"]["none_detected"]
703711
return False, MESSAGE_POLICY["spacer"]["count_fail"]
704712

705-
if "E_SPACER_TYPE_CONFUSION" in codes:
706-
return False, MESSAGE_POLICY["spacer"]["type_confusion"]
707-
708713
if (
709714
"E_SPACER_ASSIGNMENT_FAIL" in codes
710715
or "E_SPACER2_MISSING" in codes

evaluation_function/evaluation_test.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import cv2
66
import numpy as np
77
from lf_toolkit.evaluation import Params
8-
from .evaluation import evaluation_function
8+
from .evaluation import _build_student_message, evaluation_function
99
from .yolo_pipeline import _quality_advice, compute_image_quality_metrics
1010

1111

@@ -193,6 +193,47 @@ def test_quality_advice_soft_warnings_cover_all_components(self):
193193
self.assertIn("little noisy", advice)
194194
self.assertNotIn("retake", advice)
195195

196+
def test_spacer_feedback_reports_short_missing_from_counts(self):
197+
is_correct, message = _build_student_message(
198+
task="spacer",
199+
img_bgr=np.zeros((10, 10, 3), dtype=np.uint8),
200+
out={"counts": {"spacer_long": 1, "spacer_short": 0}},
201+
errors=[],
202+
selected_errors=[],
203+
part_type="",
204+
)
205+
206+
self.assertFalse(is_correct)
207+
self.assertIn("short spacer", message.lower())
208+
209+
def test_spacer_feedback_reports_long_missing_from_counts(self):
210+
is_correct, message = _build_student_message(
211+
task="spacer",
212+
img_bgr=np.zeros((10, 10, 3), dtype=np.uint8),
213+
out={"counts": {"spacer_long": 0, "spacer_short": 1}},
214+
errors=[],
215+
selected_errors=[],
216+
part_type="",
217+
)
218+
219+
self.assertFalse(is_correct)
220+
self.assertIn("long spacer", message.lower())
221+
222+
def test_spacer_feedback_reports_no_spacers_detected(self):
223+
errors = [{"code": "E_SPACER_COUNT_MISMATCH", "message": "No spacers detected."}]
224+
225+
is_correct, message = _build_student_message(
226+
task="spacer",
227+
img_bgr=np.zeros((10, 10, 3), dtype=np.uint8),
228+
out={"counts": {"spacer_long": 0, "spacer_short": 0}, "errors": errors},
229+
errors=errors,
230+
selected_errors=errors,
231+
part_type="",
232+
)
233+
234+
self.assertFalse(is_correct)
235+
self.assertIn("no spacers", message.lower())
236+
196237

197238
if __name__ == "__main__":
198239
unittest.main()

0 commit comments

Comments
 (0)