
    g?+                    z   U d dl mZ d dlmZ d dlmZ d dlmZmZm	Z	m
Z
mZ d dlmZ d dlmZ d dlmZmZ d dlmZ d d	lmZ d d
lmZ d dlmZ er
d dlZd dlmZ e
dde e!e"df   Z#de$d<   e
e e!e"df   Z%de$d<   e	d   Z&de$d<    ed       G d d             Z' G d d      Z(d dZ)d!dZ*d"dZ+	 	 	 	 	 	 d#dZ,d$dZ-y)%    )annotations)	dataclass)dedent)TYPE_CHECKINGAnyLiteralUnioncast)	TypeAlias)maybe_raise_label_warnings)LabelVisibility get_label_visibility_proto_value)StreamlitAPIException)Metric)gather_metrics)
clean_textN)DeltaGeneratorznp.integer[Any]znp.floating[Any]r   ValueDelta)normalinverseoff
DeltaColorT)frozenc                  "    e Zd ZU ded<   ded<   y)MetricColorAndDirectionz!MetricProto.MetricColor.ValueTypecolorz%MetricProto.MetricDirection.ValueType	directionN)__name__
__module____qualname____annotations__     N/var/www/openai/venv/lib/python3.12/site-packages/streamlit/elements/metric.pyr   r   ,   s    ,,44r$   r   c                  f    e Zd Z ed      	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Zedd       Zy)MetricMixinmetricNc                   t        ||       t               }t        |      |_        t	        |      |_        t        |      |_        ||_        |t        |      |_
        t        t        t        t        |            |      }	|	j                  |_        |	j                   |_        t#        |      |j$                  _        | j(                  j+                  d|      S )u  Display a metric in big bold font, with an optional indicator of how the metric changed.

        Tip: If you want to display a large number, it may be a good idea to
        shorten it using packages like `millify <https://github.com/azaitsev/millify>`_
        or `numerize <https://github.com/davidsa03/numerize>`_. E.g. ``1234`` can be
        displayed as ``1.2k`` using ``st.metric("Short number", millify(1234))``.

        Parameters
        ----------
        label : str
            The header or title for the metric. The label can optionally
            contain GitHub-flavored Markdown of the following types: Bold, Italics,
            Strikethroughs, Inline Code, Links, and Images. Images display like
            icons, with a max height equal to the font height.

            Unsupported Markdown elements are unwrapped so only their children
            (text contents) render. Display unsupported elements as literal
            characters by backslash-escaping them. E.g.,
            ``"1\. Not an ordered list"``.

            See the ``body`` parameter of |st.markdown|_ for additional,
            supported Markdown directives.

            .. |st.markdown| replace:: ``st.markdown``
            .. _st.markdown: https://docs.streamlit.io/develop/api-reference/text/st.markdown

        value : int, float, str, or None
             Value of the metric. None is rendered as a long dash.

        delta : int, float, str, or None
            Indicator of how the metric changed, rendered with an arrow below
            the metric. If delta is negative (int/float) or starts with a minus
            sign (str), the arrow points down and the text is red; else the
            arrow points up and the text is green. If None (default), no delta
            indicator is shown.

        delta_color : "normal", "inverse", or "off"
             If "normal" (default), the delta indicator is shown as described
             above. If "inverse", it is red when positive and green when
             negative. This is useful when a negative change is considered
             good, e.g. if cost decreased. If "off", delta is  shown in gray
             regardless of its value.

        help : str or None
            A tooltip that gets displayed next to the metric label. Streamlit
            only displays the tooltip when ``label_visibility="visible"``. If
            this is ``None`` (default), no tooltip is displayed.

            The tooltip can optionally contain GitHub-flavored Markdown,
            including the Markdown directives described in the ``body``
            parameter of ``st.markdown``.

        label_visibility : "visible", "hidden", or "collapsed"
            The visibility of the label. The default is ``"visible"``. If this
            is ``"hidden"``, Streamlit displays an empty spacer instead of the
            label, which can help keep the widget alligned with other widgets.
            If this is ``"collapsed"``, Streamlit displays no label or spacer.

        border : bool
            Whether to show a border around the metric container. If this is
            ``False`` (default), no border is shown. If this is ``True``, a
            border is shown.

        Examples
        --------

        **Example 1: Show a metric**

        >>> import streamlit as st
        >>>
        >>> st.metric(label="Temperature", value="70 °F", delta="1.2 °F")

        .. output::
            https://doc-metric-example1.streamlit.app/
            height: 210px

        **Example 2: Create a row of metrics**

        ``st.metric`` looks especially nice in combination with ``st.columns``.

        >>> import streamlit as st
        >>>
        >>> col1, col2, col3 = st.columns(3)
        >>> col1.metric("Temperature", "70 °F", "1.2 °F")
        >>> col2.metric("Wind", "9 mph", "-8%")
        >>> col3.metric("Humidity", "86%", "4%")

        .. output::
            https://doc-metric-example2.streamlit.app/
            height: 210px

        **Example 3: Modify the delta indicator**

        The delta indicator color can also be inverted or turned off.

        >>> import streamlit as st
        >>>
        >>> st.metric(label="Gas price", value=4, delta=-0.5, delta_color="inverse")
        >>>
        >>> st.metric(
        ...     label="Active developers", value=123, delta=123, delta_color="off"
        ... )

        .. output::
            https://doc-metric-example3.streamlit.app/
            height: 320px

        **Example 4: Create a grid of metric cards**

        Add borders to your metrics to create a dashboard look.

        >>> import streamlit as st
        >>>
        >>> a, b = st.columns(2)
        >>> c, d = st.columns(2)
        >>>
        >>> a.metric("Temperature", "30°F", "-9°F", border=True)
        >>> b.metric("Wind", "4 mph", "2 mph", border=True)
        >>>
        >>> c.metric("Humidity", "77%", "5%", border=True)
        >>> d.metric("Pressure", "30.34 inHg", "-2 inHg", border=True)

        .. output::
            https://doc-metric-example4.streamlit.app/
            height: 350px

        r(   )r   MetricProto_parse_valuebody_parse_labellabel_parse_deltadeltashow_borderr   help$_determine_delta_color_and_directionr
   r   r   r   r   r   label_visibilityvaluedg_enqueue)
selfr.   r5   r0   delta_colorr2   r4   bordermetric_protocolor_and_directions
             r%   r(   zMetricMixin.metric3   s    T 	#5*:;"}(/)%0)%0#)  &tLBZ45u
 166!4!>!>.N/
%%+ ww,77r$   c                    t        d|       S )Nr   )r
   )r8   s    r%   r6   zMetricMixin.dg   s    $d++r$   )Nr   NvisibleF)r.   strr5   r   r0   r   r9   r   r2   z
str | Noner4   r   r:   boolreturnr   )rA   r   )r   r    r!   r   r(   propertyr6   r#   r$   r%   r'   r'   2   s    H
 "*,5\8\8 \8 	\8
  \8 \8 *\8 \8 
\8 \8| , ,r$   r'   c           
         t        | t              s-t        dt        |        dt        t        |              d      | S )N'' is of type zg, which is not an accepted type. label only accepts: str. Please convert the label to an accepted type.)
isinstancer?   	TypeErrortype)r.   s    r%   r-   r-      sG    eS!E
|=T%[)9(: ;V V
 	
 Lr$   c           
        | yt        | t              s t        | t              st        | t              rt        |       S t	        | d      rW	 t        | j                         t              st        | j                         t              rt        | j                               S 	 t        dt        |        dt        t        |              d      # t        $ r Y 8w xY w)Nu   —itemrD   rE   z|, which is not an accepted type. value only accepts: int, float, str, or None. Please convert the value to an accepted type.)	rF   intfloatr?   hasattrrJ   	ExceptionrG   rH   )r5   s    r%   r+   r+      s    }%E5!9Zs=S5z			%**,.*UZZ\32O5::<(( 3P 
CJ<}Se%5$6 79 	9 	  		s   AC 	CCc           
         | | dk(  ryt        | t              rt        |       S t        | t              st        | t              rt        |       S t        dt        |        dt        t        |              d      )N rD   rE   z|, which is not an accepted type. delta only accepts: int, float, str, or None. Please convert the value to an accepted type.)rF   r?   r   rK   rL   rG   rH   r0   s    r%   r/   r/      ss    }%e}	E3	:eU#;5zE
|=T%[)9(: ;= =
 	
r$   c                   | dvrt        dt        |        d      ||dk(  r=t        t        j                  j
                  t        j                  j                        S t        |      ru| dk(  rt        j                  j                  }n:| dk(  rt        j                  j                  }nt        j                  j
                  }t        j                  j                  }nt| dk(  rt        j                  j                  }n:| dk(  rt        j                  j                  }nt        j                  j
                  }t        j                  j                  }t        ||      S )N>   r   r   r   rD   zS' is not an accepted value. delta_color only accepts: 'normal', 'inverse', or 'off'rP   )r   r   r   r   )r   r?   r   r*   MetricColorGRAYMetricDirectionNONE_is_negative_deltaREDGREENDOWNUP)r9   r0   cd_colorcd_directions       r%   r3   r3     s.    66#K ! ", ,
 	

 }&))..!1166
 	

 % (""..22HI%"..44H"..33H"2277(""..44HI%"..22H"..33H"2255" r$   c                H    t        t        |             j                  d      S )N-)r   r?   
startswithrQ   s    r%   rW   rW   ,  s    #e*((--r$   )r.   r?   rA   r?   )r5   r   rA   r?   )r0   r   rA   r?   )r9   r   r0   r   rA   r   )r0   r   rA   r@   ).
__future__r   dataclassesr   textwrapr   typingr   r   r   r	   r
   typing_extensionsr   streamlit.elements.lib.policiesr   streamlit.elements.lib.utilsr   r   streamlit.errorsr   streamlit.proto.Metric_pb2r   r*   streamlit.runtime.metrics_utilr   streamlit.string_utilr   numpynpstreamlit.delta_generatorr   rL   rK   r?   r   r"   r   r   r   r'   r-   r+   r/   r3   rW   r#   r$   r%   <module>ro      s    # !  ; ; ' F 3 < 9 ,8 *,>sCQUUVy VS$./y / :;
I ; $5 5 5
b, b,J,
$$$ $N.r$   