
    	j                     P    d Z ddlmZmZmZ deeeef      defdZdededefdZy	)
u   
Confidence scorer for AI categorization predictions.

Computes a confidence_score (0.00–100.00) from a set of weighted evidence
signals and derives a confidence_level relative to the configured threshold.
    )ListDictAnyevidence_signalsreturnc           
          | syt        d | D              }|dk  ryt        d | D              }||z  dz  }t        dt        dt        |d                  }|S )u  
    Compute a confidence score from a list of evidence signals.

    Each signal must have a 'weight' (0.0–1.0) and a 'signal_strength'
    (0.0–1.0) that indicates how strongly the signal supports the prediction.

    Returns a score in the range [10.00, 100.00].  The floor of 10 is applied
    when no usable evidence exists so predictions are never scored at zero.

    Args:
        evidence_signals: List of dicts, each with keys:
            - weight (float): relative importance of this signal (0.0–1.0)
            - signal_strength (float): how strongly it supports the category (0.0–1.0)

    Returns:
        float: confidence score in [10.00, 100.00]
    g      $@c              3   @   K   | ]  }|j                  d d        yw)weight        Nget.0ss     :/var/www/html/ai_cats/python/services/confidence_scorer.py	<genexpr>z compute_score.<locals>.<genexpr>    s     FquuXs+Fs   r   c              3   f   K   | ])  }|j                  d d      |j                  dd      z   + yw)r
   r   signal_strengthNr   r   s     r   r   z compute_score.<locals>.<genexpr>$   s4       	
hquu%6<<s   /1g      Y@   )summaxminround)r   total_weightweighted_sum	raw_scorescores        r   compute_scorer      sm    $ F5EFFLq ! L
 ,5Ic%y!!456EL    r   	thresholdc                     | |k\  ry| dk\  ryy)aM  
    Derive a confidence level label from a numeric score.

    Args:
        score:     Confidence score in [0, 100].
        threshold: The configured auto-approval threshold (e.g., 90.0).

    Returns:
        'high'   if score >= threshold
        'medium' if score >= 70 and score < threshold
        'low'    if score < 70
    highg     Q@mediumlow )r   r    s     r   derive_levelr&   .   s     	}r   N)	__doc__typingr   r   r   strfloatr   r&   r%   r   r   <module>r+      sM    # " Dc3h$8  U  F % C r   