File size: 856 Bytes
6835659
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from __future__ import annotations

from typing import Dict

from src.coherence.stats import CoherenceStats


class CoherenceProfiler:
    """
    Assigns coherence bands to a run using learned statistics.
    """

    def __init__(self, stats: CoherenceStats):
        self.stats = stats.stats

    def band(self, metric: str, value: float) -> str:
        s = self.stats.get(metric)
        if not s:
            return "unknown"

        if value < s["p25"]:
            return "low"
        if value < s["p75"]:
            return "medium"
        return "high"

    def profile(self, scores: Dict[str, float]) -> Dict[str, str]:
        """
        Return coherence band per metric.
        """
        return {
            metric: self.band(metric, value)
            for metric, value in scores.items()
            if metric in self.stats
        }