diff --git a/app/services/diagnose.py b/app/services/diagnose.py index 4d1c887..2f0c4c7 100644 --- a/app/services/diagnose.py +++ b/app/services/diagnose.py @@ -25,16 +25,20 @@ except ImportError: _RELATIVE_RE = re.compile( - r"\b(?:last|past)\s+(\d+)?\s*(minute|hour|day|week)s?\b", + r"\b(?:last|past)\s+(?:(?P\d+)|(?Pa\s+few|few|couple(?:\s+of)?|several))?\s*(?Pminute|hour|day|week)s?\b", re.IGNORECASE, ) _RELATIVE_UNITS = {"minute": 1, "hour": 60, "day": 1440, "week": 10080} +# Fuzzy quantifiers map to a reasonable span so "last few hours" → 3h window +_APPROX_N = 3 def _relative_window(match: re.Match) -> tuple[str, str]: """Convert a relative time match to (since_iso, until_iso).""" - n = int(match.group(1) or 1) - unit = match.group(2).lower() + n_str = match.group("n") + approx = match.group("approx") + unit = match.group("unit").lower() + n = int(n_str) if n_str else (_APPROX_N if approx else 1) minutes = n * _RELATIVE_UNITS[unit] return _last_n_minutes(minutes), _now_iso()