
    .Pht                     j   d Z ddlZddlmZmZ ddlmZ  G d d          Z G d d          Zdd	Z	d
 Z
 eej                                                  D ]S\  ZZ eee          rBedv redv r e
e          Zej        j         e_         e e            e<    eedez              T[[[ddZdS )aE  ``statsutils`` provides tools aimed primarily at descriptive
statistics for data analysis, such as :func:`mean` (average),
:func:`median`, :func:`variance`, and many others,

The :class:`Stats` type provides all the main functionality of the
``statsutils`` module. A :class:`Stats` object wraps a given dataset,
providing all statistical measures as property attributes. These
attributes cache their results, which allows efficient computation of
multiple measures, as many measures rely on other measures. For
example, relative standard deviation (:attr:`Stats.rel_std_dev`)
relies on both the mean and standard deviation. The Stats object
caches those results so no rework is done.

The :class:`Stats` type's attributes have module-level counterparts for
convenience when the computation reuse advantages do not apply.

>>> stats = Stats(range(42))
>>> stats.mean
20.5
>>> mean(range(42))
20.5

Statistics is a large field, and ``statsutils`` is focused on a few
basic techniques that are useful in software. The following is a brief
introduction to those techniques. For a more in-depth introduction,
`Statistics for Software
<https://www.paypal-engineering.com/2016/04/11/statistics-for-software/>`_,
an article I wrote on the topic. It introduces key terminology vital
to effective usage of statistics.

Statistical moments
-------------------

Python programmers are probably familiar with the concept of the
*mean* or *average*, which gives a rough quantitiative middle value by
which a sample can be can be generalized. However, the mean is just
the first of four `moment`_-based measures by which a sample or
distribution can be measured.

The four `Standardized moments`_ are:

  1. `Mean`_ - :func:`mean` - theoretical middle value
  2. `Variance`_ - :func:`variance` - width of value dispersion
  3. `Skewness`_ - :func:`skewness` - symmetry of distribution
  4. `Kurtosis`_ - :func:`kurtosis` - "peakiness" or "long-tailed"-ness

For more information check out `the Moment article on Wikipedia`_.

.. _moment: https://en.wikipedia.org/wiki/Moment_(mathematics)
.. _Standardized moments: https://en.wikipedia.org/wiki/Standardized_moment
.. _Mean: https://en.wikipedia.org/wiki/Mean
.. _Variance: https://en.wikipedia.org/wiki/Variance
.. _Skewness: https://en.wikipedia.org/wiki/Skewness
.. _Kurtosis: https://en.wikipedia.org/wiki/Kurtosis
.. _the Moment article on Wikipedia: https://en.wikipedia.org/wiki/Moment_(mathematics)

Keep in mind that while these moments can give a bit more insight into
the shape and distribution of data, they do not guarantee a complete
picture. Wildly different datasets can have the same values for all
four moments, so generalize wisely.

Robust statistics
-----------------

Moment-based statistics are notorious for being easily skewed by
outliers. The whole field of robust statistics aims to mitigate this
dilemma. ``statsutils`` also includes several robust statistical methods:

  * `Median`_ - The middle value of a sorted dataset
  * `Trimean`_ - Another robust measure of the data's central tendency
  * `Median Absolute Deviation`_ (MAD) - A robust measure of
    variability, a natural counterpart to :func:`variance`.
  * `Trimming`_ - Reducing a dataset to only the middle majority of
    data is a simple way of making other estimators more robust.

.. _Median: https://en.wikipedia.org/wiki/Median
.. _Trimean: https://en.wikipedia.org/wiki/Trimean
.. _Median Absolute Deviation: https://en.wikipedia.org/wiki/Median_absolute_deviation
.. _Trimming: https://en.wikipedia.org/wiki/Trimmed_estimator


Online and Offline Statistics
-----------------------------

Unrelated to computer networking, `online`_ statistics involve
calculating statistics in a `streaming`_ fashion, without all the data
being available. The :class:`Stats` type is meant for the more
traditional offline statistics when all the data is available. For
pure-Python online statistics accumulators, look at the `Lithoxyl`_
system instrumentation package.

.. _Online: https://en.wikipedia.org/wiki/Online_algorithm
.. _streaming: https://en.wikipedia.org/wiki/Streaming_algorithm
.. _Lithoxyl: https://github.com/mahmoud/lithoxyl

    N)floorceil)Counterc                       e Zd Zd ZddZdS )_StatsPropertyc                     || _         || _        d|z   | _        |j        pd}|                    d          \  }}}|| _        d S )N_ z>>>)namefuncinternal_name__doc__	partition)selfr   r   docpre_doctest_docr	   s         R/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/boltons/statsutils.py__init__z_StatsProperty.__init__   sK    		 4Zl b #e 4 4A&    Nc                     || S |j         s|j        S 	 t          || j                  S # t          $ rA t          || j        |                     |                     t          || j                  cY S w xY wN)datadefaultgetattrr   AttributeErrorsetattrr   )r   objobjtypes      r   __get__z_StatsProperty.__get__   s    ;Kx 	;	43 2333 	4 	4 	4C+TYYs^^<<<3 233333	4s   ) AA43A4r   )__name__
__module____qualname__r   r    r   r   r   r      s7        ' ' '	4 	4 	4 	4 	4 	4r   r   c                   *   e Zd ZdZd1dZd Zd Zd Zd	 Zd
 Z	 e
de	          Zd Z e
de          Zd Z e
de          Zd Z e
de          Zd Z e
de          Zd Z e
de          Zd Z e
de          Zd Z e
de          Zd Z e
de          Zd Z e
de          ZeZd Z e
de          Z d  Z! e
d!e!          Z"d" Z# e
d#e#          Z$d$ Z% e
d%e%          Z&e'd&             Z(d' Z)d( Z*d2d*Z+d+ Z,d3d-Z-d4d.Z.d4d/Z/d5d0Z0d,S )6Statsa  The ``Stats`` type is used to represent a group of unordered
    statistical datapoints for calculations such as mean, median, and
    variance.

    Args:

        data (list): List or other iterable containing numeric values.
        default (float): A value to be returned when a given
            statistical measure is not defined. 0.0 by default, but
            ``float('nan')`` is appropriate for stricter applications.
        use_copy (bool): By default Stats objects copy the initial
            data into a new list to avoid issues with
            modifications. Pass ``False`` to disable this behavior.
        is_sorted (bool): Presorted data can skip an extra sorting
            step for a little speed boost. Defaults to False.

            TFc                     || _         || _        |rt          |          | _        n|| _        || _        | j        fdt          |           D             | _        d| _        d S )Nc           	      \    g | ](}t          t          |d           t                    &|)S r   )
isinstancer   r   ).0aclss     r   
<listcomp>z"Stats.__init__.<locals>.<listcomp>   sO     !@ !@ !@q$.wsAt/D/D/=%? %?!@ !@ !@ !@r   r   )		_use_copy
_is_sortedlistr   r   	__class__dir_prop_attr_names_pearson_precision)r   r   r   use_copy	is_sortedr,   s        @r   r   zStats.__init__   s    !# 	T

DIIDIn!@ !@ !@ !@CII !@ !@ !@ #$r   c                 *    t          | j                  S r   lenr   r   s    r   __len__zStats.__len__   s    49~~r   c                 *    t          | j                  S r   )iterr   r:   s    r   __iter__zStats.__iter__   s    DIr   c                     | j         st          | j                  S | j        s| j                                         | j        S )aM  When using a copy of the data, it's better to have that copy be
        sorted, but we do it lazily using this method, in case no
        sorted measures are used. I.e., if median is never called,
        sorting would be a waste.

        When not using a copy, it's presumed that all optimizations
        are on the user.
        )r.   sortedr   r/   sortr:   s    r   _get_sorted_datazStats._get_sorted_data   sB     ~ 	$)$$$ 	INNyr   c                     | j         D ]=}t          | j        |          j        }t	          | |          s-t          | |           >dS )a  ``Stats`` objects automatically cache intermediary calculations
        that can be reused. For instance, accessing the ``std_dev``
        attribute after the ``variance`` attribute will be
        significantly faster for medium-to-large datasets.

        If you modify the object by adding additional data points,
        call this function to have the cached statistics recomputed.

        N)r3   r   r1   r   hasattrdelattr)r   	attr_names     r   clear_cachezStats.clear_cache   sW     . 	% 	%I	::HI4++ D)$$$$r   c                 *    t          | j                  S )zThe number of items in this Stats object. Returns the same as
        :func:`len` on a Stats object, but provided for pandas terminology
        parallelism.

        >>> Stats(range(20)).count
        20
        r8   r:   s    r   _calc_countzStats._calc_count   s     49~~r   countc                 V    t          | j        d          t          | j                  z  S )z
        The arithmetic mean, or "average". Sum of the values divided by
        the number of values.

        >>> mean(range(20))
        9.5
        >>> mean(list(range(19)) + [949])  # 949 is an arbitrary outlier
        56.0
        r&   )sumr   r9   r:   s    r   
_calc_meanzStats._calc_mean   s#     49c""S^^33r   meanc                 R    | j         r| j        d         S t          | j                  S )zd
        The maximum value present in the data.

        >>> Stats([2, 1, 3]).max
        3
        )r/   r   maxr:   s    r   	_calc_maxzStats._calc_max   s(     ? 	!9R= 49~~r   rQ   c                 R    | j         r| j        d         S t          | j                  S )zd
        The minimum value present in the data.

        >>> Stats([2, 1, 3]).min
        1
        r   )r/   r   minr:   s    r   	_calc_minzStats._calc_min  s(     ? 	 9Q<49~~r   rT   c                 R    |                      |                                 d          S )a  
        The median is either the middle value or the average of the two
        middle values of a sample. Compared to the mean, it's generally
        more resilient to the presence of outliers in the sample.

        >>> median([2, 1, 3])
        2
        >>> median(range(97))
        48
        >>> median(list(range(96)) + [1066])  # 1066 is an arbitrary outlier
        48
              ?)_get_quantilerB   r:   s    r   _calc_medianzStats._calc_median  s&     !!$"7"7"9"93???r   medianc                 X    |                      d          |                      d          z
  S )a`  Inter-quartile range (IQR) is the difference between the 75th
        percentile and 25th percentile. IQR is a robust measure of
        dispersion, like standard deviation, but safer to compare
        between datasets, as it is less influenced by outliers.

        >>> iqr([1, 2, 3, 4, 5])
        2
        >>> iqr(range(1001))
        500
              ?      ?)get_quantiler:   s    r   	_calc_iqrzStats._calc_iqr#  s+       &&):):4)@)@@@r   iqrc                                                         fd} |d          d |d          z  z    |d          z   dz  S )ac  The trimean is a robust measure of central tendency, like the
        median, that takes the weighted average of the median and the
        upper and lower quartiles.

        >>> trimean([2, 1, 3])
        2.0
        >>> trimean(range(97))
        48.0
        >>> trimean(list(range(96)) + [1066])  # 1066 is an arbitrary outlier
        48.0

        c                 0                         |           S r   )rX   )qr   sorted_datas    r   <lambda>z%Stats._calc_trimean.<locals>.<lambda>?  s    t))+q99 r   r]      rW   r\   g      @)rB   )r   gqrd   s   ` @r   _calc_trimeanzStats._calc_trimean1  sY     ++--999994A3K(22d883s::r   trimeanc                 F    t          |                     d                    S )z        Variance is the average of the squares of the difference between
        each value and the mean.

        >>> variance(range(97))
        784.0
        rf   )rN   _get_pow_diffsr:   s    r   _calc_variancezStats._calc_varianceC  s      D''**+++r   variancec                     | j         dz  S )zn        Standard deviation. Square root of the variance.

        >>> std_dev(range(97))
        28.0
        rW   )rm   r:   s    r   _calc_std_devzStats._calc_std_devO  s     }##r   std_devc                     t          | j                  }t          t          |                    t          fd|D                       S )z        Median Absolute Deviation is a robust measure of statistical
        dispersion: http://en.wikipedia.org/wiki/Median_absolute_deviation

        >>> median_abs_dev(range(97))
        24.0
        c                 4    g | ]}t          |z
            S r#   )abs)r*   vxs     r   r-   z.Stats._calc_median_abs_dev.<locals>.<listcomp>d  s#    777as1q5zz777r   )r@   r   floatrZ   )r   sorted_valsru   s     @r   _calc_median_abs_devzStats._calc_median_abs_devY  sL     TY''&%%&&7777;777888r   median_abs_devc                 P    t          | j                  }|r
| j        |z  S | j        S )z        Standard deviation divided by the absolute value of the average.

        http://en.wikipedia.org/wiki/Relative_standard_deviation

        >>> print('%1.3f' % rel_std_dev(range(97)))
        0.583
        )rs   rN   rp   r   )r   abs_means     r   _calc_rel_std_devzStats._calc_rel_std_devh  s.     ty>> 	 <(**<r   rel_std_devc                     | j         | j        }}t          |          dk    rN|dk    rHt          |                     d                    t          t          |          dz
  |dz  z            z  S | j        S )a<          Indicates the asymmetry of a curve. Positive values mean the bulk
        of the values are on the left side of the average and vice versa.

        http://en.wikipedia.org/wiki/Skewness

        See the module docstring for more about statistical moments.

        >>> skewness(range(97))  # symmetrical around 48.0
        0.0
        >>> left_skewed = skewness(list(range(97)) + list(range(10)))
        >>> right_skewed = skewness(list(range(97)) + list(range(87, 97)))
        >>> round(left_skewed, 3), round(right_skewed, 3)
        (0.114, -0.114)
           r      )r   rp   r9   rL   rk   rv   r   r   r   s_devs      r   _calc_skewnesszStats._calc_skewnessx  ss      iet99q==UQYY++A..//3t99q=UaZ899: ; <r   skewnessc                     | j         | j        }}t          |          dk    rN|dk    rHt          |                     d                    t          t          |          dz
  |dz  z            z  S dS )a          Indicates how much data is in the tails of the distribution. The
        result is always positive, with the normal "bell-curve"
        distribution having a kurtosis of 3.

        http://en.wikipedia.org/wiki/Kurtosis

        See the module docstring for more about statistical moments.

        >>> kurtosis(range(9))
        1.99125

        With a kurtosis of 1.99125, [0, 1, 2, 3, 4, 5, 6, 7, 8] is more
        centrally distributed than the normal curve.
        r   r      r&   )r   rp   r9   rL   rk   rv   r   s      r   _calc_kurtosiszStats._calc_kurtosis  sp      iet99q==UQYY++A..//3t99q=UaZ899: ; 3r   kurtosisc                 n   | j         }| j        }| j        }|dz  }|dz  }d|z  d|z  z
  }||dz   z  }d|z  d|z  z
  dz
  }t          ||          dk    r't          ||          dk    rdS |dk     rdS |dk    rdS n,t          ||          dk    rdS |dz  d|z  |z  z  }	|	dk     rd	S t	          d
          )Ng       @      ?r   r   rf      r      r   zmissed a spot)r4   r   r   roundRuntimeError)
r   	precisionr   r   beta1beta2c0c1c2ks
             r   _calc_pearson_typezStats._calc_pearson_type  s    +	==C3 %iAI&#%iAI&*Y1$$UI&&!++q1991QYY1 2y!!Q&&1a1r6B;'A1uuq?+++r   pearson_typec                     | t          |           }}|dz  |dz
  z  }t          t          |                    t          t          |                    }}||k    r||         S ||         ||z
  z  ||         ||z
  z  z   S )Nr   r   )r9   intr   r   )rd   rc   r   nidxidx_fidx_cs          r   rX   zStats._get_quantile  s~    s;//a#gQ5::DIIuE>>;Uus{+UsU{0KLLr   c                     t          |          }d|cxk    rdk    sn t          d|z            | j        s| j        S |                     |                                 |          S )a@  Get a quantile from the dataset. Quantiles are floating point
        values between ``0.0`` and ``1.0``, with ``0.0`` representing
        the minimum value in the dataset and ``1.0`` representing the
        maximum. ``0.5`` represents the median:

        >>> Stats(range(100)).get_quantile(0.5)
        49.5
        r&   r   z&expected q between 0.0 and 1.0, not %r)rv   
ValueErrorr   r   rX   rB   )r   rc   s     r   r^   zStats.get_quantile  sn     !HHa3EIJJJ 	 <!!$"7"7"9"91===r   c                     | j         }| j        dk    r2||k    rdS ||k    rt          d          S ||k     rt          d          S t          |          |z
  | j        z  S )zGet the z-score for *value* in the group. If the standard deviation
        is 0, 0 inf or -inf will be returned to indicate whether the value is
        equal to, greater than or below the group's mean.
        r   infz-inf)rN   rp   rv   )r   valuerN   s      r   
get_zscorezStats.get_zscore  sh    
 y<1}}qt||U||#t||V}}$et#t|33r   333333?c                 .   t          |          }d|cxk    rdk     sn t          d|z            t          | j                  }t	          ||z            }|dk    rdS |                                 ||          | _        |                                  dS )a  A utility function used to cut a proportion of values off each end
        of a list of values. This has the effect of limiting the
        effect of outliers.

        Args:
            amount (float): A value between 0.0 and 0.5 to trim off of
                each side of the data.

        .. note:

            This operation modifies the data in-place. It does not
            make or return a copy.

        r&   rW   z+expected amount between 0.0 and 0.5, not %rN)rv   r   r9   r   r   rB   rG   )r   amounttrimsize	size_diffs        r   trim_relativezStats.trim_relative  s     V}}d    S    J#$ % % %49~~t$$	F))++Iyj,@A	r   c                 <    | j         fd| j        D             S )zN
        A utility function used for calculating statistical moments.
        c                      g | ]
}|z
  z  S r#   r#   )r*   rt   mpowers     r   r-   z(Stats._get_pow_diffs.<locals>.<listcomp>  s"    444QQ5 444r   )rN   r   )r   r   r   s    `@r   rk   zStats._get_pow_diffs  s,     I44444$)4444r   Nc           	        	
 | j         sdgS | j         }t          |          t          |          t          |          c}
|dk     r6|s|}
z
  t	          |          z  		fdt          |          D             }n||                     d          |                     d          }}d||z
  z  |dz  z  	t          dt          t          
z
  	z                                }	fd	t          |dz             D             }
fd
|D             }n1
z
  t	          |          z  		fdt          |          D             }|r"|	                    t	          
                     |S )Nr&   r   c                      g | ]
}|z  z   S r#   r#   r*   idxmin_datas     r   r-   z)Stats._get_bin_bounds.<locals>.<listcomp>  "    >>>AHQ'>>>r   r]   r\   rf   gUUUUUU?r   c                      g | ]
}|z  z   S r#   r#   r   s     r   r-   z)Stats._get_bin_bounds.<locals>.<listcomp>   s"    FFFAHQ'FFFr   c                      g | ]
}|k     |S r#   r#   )r*   bmax_datas     r   r-   z)Stats._get_bin_bounds.<locals>.<listcomp>!  s    444!q8||A|||r   c                      g | ]
}|z  z   S r#   r#   r   s     r   r-   z)Stats._get_bin_bounds.<locals>.<listcomp>$  r   r   )
r   r9   rT   rQ   rv   ranger^   r   r   append)r   rJ   with_maxr   len_databinsq25q75	bin_countr   r   r   s            @@@r   _get_bin_boundszStats._get_bin_bounds  s   y 	5Ly'*4yy#d))SYY$(Ha<< ! X%u5B>>>>>u>>>DD]((..0A0A$0G0GCcCiH$9:BAs4H)<(B#C#CDDEEIFFFFFy1}1E1EFFFD4444t444DDX%u5B>>>>>u>>>D 	)KKh(((r   c                    t          |                    dd                    }|r$t          d|                                z            s|                                 n	 t                    }|                     |          nZ# t          $ rM 	 d D             n # t
          $ r t          dz            w xY w| j        d         k     r| j        gz   Y nw xY wd|z  fdD             t          t                              fd	| j
        D             }t          |          fd
t                    D             }|S )a  Produces a list of ``(bin, count)`` pairs comprising a histogram of
        the Stats object's data, using fixed-width bins. See
        :meth:`Stats.format_histogram` for more details.

        Args:
            bins (int): maximum number of bins, or list of
                floating-point bin boundaries. Defaults to the output of
                Freedman's algorithm.
            bin_digits (int): Number of digits used to round down the
                bin boundaries. Defaults to 1.

        The output of this method can be stored and/or modified, and
        then passed to :func:`statsutils.format_histogram_counts` to
        achieve the same text formatting as the
        :meth:`~Stats.format_histogram` method. This can be useful for
        snapshotting over time.
        
bin_digitsr   z unexpected keyword arguments: %rc                 ,    g | ]}t          |          S r#   )rv   )r*   ru   s     r   r-   z.Stats.get_histogram_counts.<locals>.<listcomp>H  s    333E!HH333r   zGbins expected integer bin count or list of float bin boundaries, not %rr   g      $@c                 :    g | ]}t          |z            z  S r#   )r   )r*   r   round_factors     r   r-   z.Stats.get_histogram_counts.<locals>.<listcomp>S  s+    EEE1a,&'',6EEEr   c                 @    g | ]}t          j         |          d z
  S )r   )bisect)r*   dr   s     r   r-   z.Stats.get_histogram_counts.<locals>.<listcomp>V  s*    >>>qdA&&*>>>r   c                 F    g | ]\  }}|                     |d           fS )r   )get)r*   r   r   	count_maps      r   r-   z.Stats.get_histogram_counts.<locals>.<listcomp>Y  s0    KKK41aq)--1--.KKKr   )r   pop	TypeErrorkeysr   	Exceptionr   rT   r@   setr   r   	enumerate)	r   r   kwr   r   idxs
bin_countsr   r   s	    `     @@r   get_histogram_countszStats.get_histogram_counts+  s   $ a0011
 	L>JKKK 	7''))DD7II	 ++I66  - - -P33d333DD  P P P$ &HJN&O P P PP 8d1g%% H:,D- z)EEEEEEEc$ii  >>>>DI>>>DMM	KKKK9T??KKK
s*   %B
 

C!B"!C!"B??C! C!c                     |                     dd          }|                     dd          } | j        dd|i|}t          |||          S )a[  Produces a textual histogram of the data, using fixed-width bins,
        allowing for simple visualization, even in console environments.

        >>> data = list(range(20)) + list(range(5, 15)) + [10]
        >>> print(Stats(data).format_histogram(width=30))
         0.0:  5 #########
         4.4:  8 ###############
         8.9: 11 ####################
        13.3:  5 #########
        17.8:  2 ####

        In this histogram, five values are between 0.0 and 4.4, eight
        are between 4.4 and 8.9, and two values lie between 17.8 and
        the max.

        You can specify the number of bins, or provide a list of
        bin boundaries themselves. If no bins are provided, as in the
        example above, `Freedman's algorithm`_ for bin selection is
        used.

        Args:
            bins (int): Maximum number of bins for the
                histogram. Also accepts a list of floating-point
                bin boundaries. If the minimum boundary is still
                greater than the minimum value in the data, that
                boundary will be implicitly added. Defaults to the bin
                boundaries returned by `Freedman's algorithm`_.
            bin_digits (int): Number of digits to round each bin
                to. Note that bins are always rounded down to avoid
                clipping any data. Defaults to 1.
            width (int): integer number of columns in the longest line
               in the histogram. Defaults to console width on Python
               3.3+, or 80 if that is not available.
            format_bin (callable): Called on each bin to create a
               label for the final output. Use this function to add
               units, such as "ms" for milliseconds.

        Should you want something more programmatically reusable, see
        the :meth:`~Stats.get_histogram_counts` method, the output of
        is used by format_histogram. The :meth:`~Stats.describe`
        method is another useful summarization method, albeit less
        visual.

        .. _Freedman's algorithm: https://en.wikipedia.org/wiki/Freedman%E2%80%93Diaconis_rule
        widthN
format_binr   )r   r   r#   )r   r   format_histogram_counts)r   r   r   r   r   r   s         r   format_histogramzStats.format_histogram]  sg    \ w%%VVL$//
.T.??D?B??
&z-22<> > > 	>r   c                    |d}n|dvrt          d|z            |pg d}g }|D ];}|                     |          }|                    t          |          |f           <d| j        fd| j        fd| j        fd	| j        fd
| j        fg}|	                    |           |                    d| j
        f           |dk    rt          |          }n.|dk    r|}n%|dk    rd                    d |D                       }|S )a  Provides standard summary statistics for the data in the Stats
        object, in one of several convenient formats.

        Args:
            quantiles (list): A list of numeric values to use as
                quantiles in the resulting summary. All values must be
                0.0-1.0, with 0.5 representing the median. Defaults to
                ``[0.25, 0.5, 0.75]``, representing the standard
                quartiles.
            format (str): Controls the return type of the function,
                with one of three valid values: ``"dict"`` gives back
                a :class:`dict` with the appropriate keys and
                values. ``"list"`` is a list of key-value pairs in an
                order suitable to pass to an OrderedDict or HTML
                table. ``"text"`` converts the values to text suitable
                for printing, as seen below.

        Here is the information returned by a default ``describe``, as
        presented in the ``"text"`` format:

        >>> stats = Stats(range(1, 8))
        >>> print(stats.describe(format='text'))
        count:    7
        mean:     4.0
        std_dev:  2.0
        mad:      2.0
        min:      1
        0.25:     2.5
        0.5:      4
        0.75:     5.5
        max:      7

        For more advanced descriptive statistics, check out my blog
        post on the topic `Statistics for Software
        <https://www.paypal-engineering.com/2016/04/11/statistics-for-software/>`_.

        Ndict)r   r0   textzIinvalid format for describe, expected one of "dict"/"list"/"text", not %r)r]   rW   r\   rJ   rN   rp   madrT   rQ   r0   r   
c                 l    g | ]1\  }}d                      |dz                       d          |          2S )z{}{}:
   )formatljust)r*   labelvals      r   r-   z"Stats.describe.<locals>.<listcomp>  sL     6 6 6!+ $]]ECK+>+>r+B+BCHH 6 6 6r   )r   r^   r   strrJ   rN   rp   r   rT   extendrQ   r   join)r   	quantilesr   q_itemsrc   q_valitemsrets           r   describezStats.describe  se   L >FF333 M%& ' ' ' 2!2!2!2	 	, 	,A%%a((ENNCFFE?++++4:&$)$T\*""	$ 	WeTX&'''Vu++CCvCCv)) 6 6/46 6 6 7 7C
r   )r&   TF)r   )NFr   NN)1r    r!   r"   r   r   r;   r>   rB   rG   rI   r   rJ   rM   rN   rR   rQ   rU   rT   rY   rZ   r_   r`   rh   ri   rl   rm   ro   rp   rx   ry   r   r|   r}   r   r   r   r   r   r   staticmethodrX   r^   r   r   rk   r   r   r   r   r#   r   r   r%   r%      s        "$ $ $ $        "   N7K00E
4 
4 
4 >&*--D	 	 	 .	
*
*C	 	 	 .	
*
*C@ @ @ ^Hl33FA A A .	
*
*C; ; ;  nY66G	, 	, 	, ~j.99H$ $ $ nY66G9 9 9 $^$46JKKN
C      !.0ABBK     , ~j.99H  , ~j.99H, , ,8 ">.2DEELM M \M> > > 4 4 4   45 5 5   80 0 0 0d3> 3> 3> 3>jA A A A A Ar   r%   c                 J    t          |                               ||          S )a  A convenience function to get standard summary statistics useful
    for describing most data. See :meth:`Stats.describe` for more
    details.

    >>> print(describe(range(7), format='text'))
    count:    7
    mean:     3.0
    std_dev:  2.0
    mad:      2.0
    min:      0
    0.25:     1.5
    0.5:      3
    0.75:     4.5
    max:      6

    See :meth:`Stats.format_histogram` for another very useful
    summarization that uses textual visualization.
    )r   r   )r%   r   )r   r   r   s      r   r   r     s#    & ;;)FCCCr   c                      d fd	}|S )Nr&   c                 D    t          t          | |d                    S )NF)r   r5   )r   r%   )r   r   rF   s     r   stats_helperz$_get_conv_func.<locals>.stats_helper  s)    uT7UCCC " " 	"r   )r&   r#   )rF   r   s   ` r   _get_conv_funcr     s)    " " " " " " r   )rQ   rT   rJ   )r   _calc_c                    g }sd |s2	 ddl }|                                d         }n# t          $ r d}Y nw xY wd | D             }t          d | D                       }t	          t          |                    }fd|D             }t          d |D                       }	d	                    d
|	z  |          }
t          |t	          |
          z
  d          }t          |          |z  }d}t          ||           D ]]\  }\  }}t          t          ||z                      }d|z  pd}|                    ||	|||          }|                    |           ^d                    |          S )a  The formatting logic behind :meth:`Stats.format_histogram`, which
    takes the output of :meth:`Stats.get_histogram_counts`, and passes
    them to this function.

    Args:
        bin_counts (list): A list of bin values to counts.
        width (int): Number of character columns in the text output,
            defaults to 80 or console width in Python 3.3+.
        format_bin (callable): Used to convert bin values into string
            labels.
    c                     | S r   r#   )rt   s    r   re   z)format_histogram_counts.<locals>.<lambda>  s    q r   r   NP   c                     g | ]\  }}|S r#   r#   )r*   r   r	   s      r   r-   z+format_histogram_counts.<locals>.<listcomp>  s    %%%$!QA%%%r   c                     g | ]\  }}|S r#   r#   )r*   r	   rJ   s      r   r-   z+format_histogram_counts.<locals>.<listcomp>  s    666xq%U666r   c                 ,    g | ]}d  |          z  S )z%sr#   )r*   r   r   s     r   r-   z+format_histogram_counts.<locals>.<listcomp>  s&    111qdZZ]]"111r   c                 ,    g | ]}t          |          S r#   )r9   )r*   ls     r   r-   z+format_histogram_counts.<locals>.<listcomp>  s    ---c!ff---r   z{}: {} #ru   r   z2{label:>{label_cols}}: {count:>{count_cols}} {bar}#|)r   
label_colsrJ   
count_colsbarr   )shutilget_terminal_sizer   rQ   r9   r   r   rv   zipr   r   r   r   )r   r   r   linesr  r   	count_maxr  labelsr  tmp_linebar_colsline_ktmplr   bin_valrJ   bar_lenr  lines     `                 r   r   r     s    E ! [
 	MMM,,..q1EE 	 	 	EEE	 &%*%%%D66:66677IS^^$$J1111D111F--f---..J  z!19==H53x==(!,,H8__y(F?D#&vz#:#:  eEFN++,,W}${{&0!&&0"	  $ $
 	T99Us   + ::r   )r   r   mathr   r   collectionsr   r   r%   r   r   r0   __dict__r   rF   attrr)   r   globalsrE   r   r#   r   r   <module>r     s  >_ _D               4 4 4 4 4 4 4 4,w w w w w w w wtD D D D,   tEN002233 	- 	-OItz$'' -///  ~i((y(#		)x)+,,,+ + + + + +r   