3287d27579
_is_auftrag() auf Wortgrenzen-Prüfung umgestellt (Regex \b<stem>\w*\b): - IMPERATIVE_STEMS + EXCLUDE_WORDS ersetzen Substring-Matching - Infinitive, Partizipien, Indikativ-Formen werden ausgeschlossen - 'bitte' als eigenständiges Wort (Höflichkeitsmarker) - 'füg hinzu' / 'füge hinzu' / 'fügt hinzu' (mehrwortig) DM-Bypass (adapter.py:1443): - is_auftrag aus der Bedingung entfernt — room_type=='d' allein reicht - Counter: is_auftrag_bypass/dm_auftrag_bypass → dm_routing_skipped - is_auftrag dient nur noch Telemetrie/Counter, nicht als Gate Test-Suite (test_is_auftrag.py): - False-Positives (Z.141-285) → Assert is False (V8-SOLL) - Neue SOLL-Tests: Imperativ vs. Frage, Englisch, Konjunktiv - 153 Tests, alle grün (345 total, 1 pre-existing fail) Rainer-Review: Auflage 1 (room_type-Logging) → Bernd-Entscheidung: Bypass entfernen, room_type in Counter-Logik mitloggen.
58 lines
1.6 KiB
Python
58 lines
1.6 KiB
Python
"""
|
|
Routing-Counter für Archivar v7 — empirische Daten für V8-Refactoring.
|
|
|
|
Zählt JEDE Routing-Entscheidung und JEDEN Bypass.
|
|
In-Memory (nicht persistent). Nach Neustart beginnt Zählung neu.
|
|
|
|
Usage::
|
|
|
|
from archivar.routing_counter import routing_counter
|
|
routing_counter.increment('dm_routing_skipped')
|
|
routing_counter.log_counts()
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
import threading
|
|
from typing import Dict
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class RoutingCounter:
|
|
"""Thread-safe In-Memory-Counter für Routing-Entscheidungen."""
|
|
|
|
def __init__(self) -> None:
|
|
self._lock = threading.Lock()
|
|
self._counts: Dict[str, int] = {}
|
|
|
|
def increment(self, reason: str) -> None:
|
|
"""Inkrementiere den Zähler für einen Grund (thread-safe)."""
|
|
with self._lock:
|
|
self._counts[reason] = self._counts.get(reason, 0) + 1
|
|
|
|
def get_counts(self) -> Dict[str, int]:
|
|
"""Gibt eine Kopie aller Zählerstände zurück."""
|
|
with self._lock:
|
|
return dict(self._counts)
|
|
|
|
def log_counts(self) -> None:
|
|
"""Logge alle Zählerstände auf INFO-Level."""
|
|
counts = self.get_counts()
|
|
total = sum(counts.values())
|
|
logger.info(
|
|
"Routing counter (total=%d): %s",
|
|
total,
|
|
", ".join(f"{k}={v}" for k, v in sorted(counts.items())),
|
|
)
|
|
|
|
def reset(self) -> None:
|
|
"""Setze alle Zähler zurück."""
|
|
with self._lock:
|
|
self._counts.clear()
|
|
|
|
|
|
# Modul-Level-Singleton — wird von adapter.py und router.py importiert
|
|
routing_counter = RoutingCounter()
|