o
    i                     @  s   d dl mZ d dlZdZdZdZdZdZdZdZ	d)ddZ
d*ddZd+ddZd,ddZd-ddZd.dd Zd/d#d$Zd0d'd(ZdS )1    )annotationsN)default_render_numberdefault_render_number_diffdefault_render_durationdefault_render_duration_diffdefault_render_percentage      d   g{Gz?
   valuefloat | intreturnstrc                 C  s   t | tr	| dS t| }|dkr| dt dS |dkr/tt|d }tdt| }ntt|}| t d }| d| dS )zThe default logic for formatting numerical values in an Evaluation report.

    * If the value is an integer, format it as an integer.
    * If the value is a float, include at least one decimal place and at least 3 significant figures.
    z,dr   ,.fr	   )
isinstanceintabsVALUE_SIG_FIGSmathfloorlog10max)r   abs_valdigitsdecimalsexponent r   m/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/pydantic_evals/reporting/render_numbers.pyr      s   
r   floatc                 C  s   | dt d  dS )zThe default logic for formatting percentages in an Evaluation report.

    * Include at least one decimal place and at least 3 significant figures.
    r      %)r   )r   r   r   r   r   6   s   r   oldnew
str | Nonec                 C  sh   | |krdS t | trt |tr||  }|dS ||  }t|t}t|| t}|du r-|S | d| S )uO  Return a string representing the difference between old and new values.

    Rules:
      - If the two values are equal, return None.
      - For integers, return the raw difference (with a leading sign), e.g.:
            _default_format_number_diff(3, 4) -> '+1'
      - For floats (or a mix of float and int):
          * Compute the raw delta = new - old and format it with ABS_SIG_FIGS significant figures.
          * If `old` is nonzero, compute a relative change:
              - If |delta|/|old| ≤ 1, render the relative change as a percentage with
                PERC_DECIMALS decimal places, e.g. '+0.7 / +70.0%'.
              - If |delta|/|old| > 1, render a multiplier (new/old). Use one decimal place
                if the absolute multiplier is less than MULTIPLIER_ONE_DECIMAL_THRESHOLD,
                otherwise no decimals.
          * However, if the percentage rounds to 0.0% (e.g. '+0.0%'), return only the absolute diff.
          * Also, if |old| is below BASE_THRESHOLD and |delta| exceeds MULTIPLIER_DROP_FACTOR×|old|,
            drop the relative change indicator.
    Nz+d / )r   r   _render_signedABS_SIG_FIGS_render_relativeBASE_THRESHOLD)r#   r$   diff_intdeltaabs_diff_strrel_diff_strr   r   r   r   >   s   
r   secondsc                 C  s
   t | dS )Format a duration given in seconds to a string.

    If the duration is less than 1 millisecond, show microseconds.
    If it's less than one second, show milliseconds.
    Otherwise, show seconds.
    F)_render_duration)r/   r   r   r   r   a   s   
r   c                 C  s@   | |krdS t ||  d}t|| t}|du r|S | d| S )z@Format a duration difference (in seconds) with an explicit sign.NTr&   )r1   r)   r*   )r#   r$   r-   r.   r   r   r   r   k   s   r   valsig_figsr   c                 C  sF   t t| d| d}d|vrd|vr|d7 }| dkrdnd | S )	zFormat a number with a fixed number of significant figures.

    If the result does not use scientific notation and lacks a decimal point,
    force a '.0' suffix. Always include a leading '+' for nonnegative numbers.
    r   ge.z.0r   +-)formatr   )r2   r3   sr   r   r   r'   x   s   r'   basesmall_base_thresholdc                 C  s   |dkrd S | | }t ||k rt |tt | krd S || d }|dt dd}|dv r2d S t |t | dkr>|S | | }t |tk rP|dd	}|S |d
d	}|S )Nr   r
   z+.r   r"   )z+0.0%z-0.0%r	   z,.1fxz,.0f)r   MULTIPLIER_DROP_FACTORPERC_DECIMALS MULTIPLIER_ONE_DECIMAL_THRESHOLD)r$   r;   r<   r,   
rel_changeperc_str
multipliermult_strr   r   r   r)      s"    r)   force_signedboolc                 C  s   | dkrdS d}t |  }dk r| d }d}t |dkrd}n|dk r*| d }d}n| }d	}|r;|d
| d| S |d| d| S )r0   r   0sr	   gMbP?i@B u   µsi  msr:   z+,.r   r   )r   )r/   rE   	precisionabs_secondsr   unitr   r   r   r1      s"   r1   )r   r   r   r   )r   r    r   r   )r#   r   r$   r   r   r%   )r/   r    r   r   )r#   r    r$   r    r   r%   )r2   r    r3   r   r   r   )r$   r    r;   r    r<   r    r   r%   )r/   r    rE   rF   r   r   )
__future__r   r   __all__r   r(   r?   r@   r*   r>   r   r   r   r   r   r'   r)   r1   r   r   r   r   <module>   s"    	



#



 