ASSIGN-001: reject unrelated actuator sensors
This commit is contained in:
@@ -45,6 +45,8 @@ _STOPWORDS = frozenset(
|
||||
"humidity",
|
||||
"illuminance",
|
||||
"light",
|
||||
"licht",
|
||||
"lichtschalter",
|
||||
"power",
|
||||
"sensor",
|
||||
"state",
|
||||
@@ -54,8 +56,10 @@ _STOPWORDS = frozenset(
|
||||
}
|
||||
)
|
||||
_NUMERIC_AUTO_ACCEPT_SCORE = 0.82
|
||||
_NUMERIC_AUTO_ACCEPT_MIN_SCORE = 0.5
|
||||
_NUMERIC_MIN_MARGIN = 0.18
|
||||
_CONTEXT_AUTO_ACCEPT_SCORE = 0.78
|
||||
_CONTEXT_AUTO_ACCEPT_MIN_SCORE = 0.3
|
||||
_MAX_CONTEXT_SELECTIONS = 5
|
||||
_AUDIT_LIMIT = 20
|
||||
|
||||
@@ -231,10 +235,14 @@ class ActuatorReconciliationService:
|
||||
numeric_candidates: list[AssignmentCandidate],
|
||||
context_candidates: list[AssignmentCandidate],
|
||||
) -> AssignmentSelection:
|
||||
top_numeric = numeric_candidates[0] if numeric_candidates else None
|
||||
top_numeric = next(
|
||||
(candidate for candidate in numeric_candidates if candidate.auto_accepted),
|
||||
None,
|
||||
)
|
||||
top_contexts = [
|
||||
candidate.entity_id
|
||||
for candidate in context_candidates
|
||||
if candidate.auto_accepted
|
||||
][: _MAX_CONTEXT_SELECTIONS]
|
||||
if top_numeric is None:
|
||||
return AssignmentSelection(
|
||||
@@ -433,8 +441,15 @@ class ActuatorReconciliationService:
|
||||
confidence = candidate.score / highest if highest else 0.0
|
||||
margin = candidate.score - second_score if index == 0 else 0.0
|
||||
auto_score = _CONTEXT_AUTO_ACCEPT_SCORE if context else _NUMERIC_AUTO_ACCEPT_SCORE
|
||||
auto_accepted = confidence >= auto_score and (
|
||||
context or margin >= _NUMERIC_MIN_MARGIN
|
||||
minimum_score = (
|
||||
_CONTEXT_AUTO_ACCEPT_MIN_SCORE
|
||||
if context
|
||||
else _NUMERIC_AUTO_ACCEPT_MIN_SCORE
|
||||
)
|
||||
auto_accepted = (
|
||||
candidate.score >= minimum_score
|
||||
and confidence >= auto_score
|
||||
and (context or margin >= _NUMERIC_MIN_MARGIN)
|
||||
)
|
||||
sorted_candidates[index] = candidate.model_copy(
|
||||
update={
|
||||
@@ -510,6 +525,9 @@ def _score_candidate(
|
||||
if entity.device_class in preferred_device_classes:
|
||||
score += 0.2
|
||||
evidence.append(f"Passende device_class: {entity.device_class}")
|
||||
if not context and actuator.domain == "light" and entity.device_class == "illuminance":
|
||||
score += 0.2
|
||||
evidence.append("Beleuchtungsstärke wird für Lichtaktoren bevorzugt.")
|
||||
if not context and entity.unit_of_measurement is not None:
|
||||
score += 0.05
|
||||
evidence.append(f"Numerische Einheit vorhanden: {entity.unit_of_measurement}")
|
||||
|
||||
Reference in New Issue
Block a user