(weights: Dict[str, Any])
| 131 | |
| 132 | def _normalize_weight_map(weights: Dict[str, Any]) -> Dict[str, float]: |
| 133 | normalized: Dict[str, float] = {} |
| 134 | for key, value in (weights or {}).items(): |
| 135 | topic = str(key or "").strip() |
| 136 | if not topic: |
| 137 | continue |
| 138 | try: |
| 139 | numeric = float(value) |
| 140 | except (TypeError, ValueError): |
| 141 | continue |
| 142 | if numeric <= 0: |
| 143 | continue |
| 144 | normalized[topic] = round(min(1.0, numeric), 4) |
| 145 | |
| 146 | max_score = max(normalized.values(), default=0.0) |
| 147 | if max_score > 1.0: |
| 148 | normalized = {key: round(value / max_score, 4) for key, value in normalized.items()} |
| 149 | |
| 150 | return normalized |
| 151 | |
| 152 | |
| 153 | def _ensure_anchor_state(profile: Dict[str, Any]) -> Dict[str, Any]: |
| 154 | drift_state = copy.deepcopy(profile.get("drift_state", {}) or {}) |
no outgoing calls
no test coverage detected