import random def category_weight(category_id: int | None) -> float: """A fake but deterministic-ish stand-in for merchant_categories.risk_weight (fraud has no direct DB access -- Redis only, per phase-0-base-project-spec.md ยง4). The business logic does not need to be correct, only to produce a plausible spread of scores.""" if category_id is None: return 0.3 return 0.01 + (category_id % 45) / 44 * 0.94 def score(category_id: int | None, matched: bool) -> float: base = category_weight(category_id) * random.uniform(0.05, 0.3) if matched: return min(1.0, base + random.uniform(0.55, 0.9)) return min(1.0, base)