o
    2h                     @   sn   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddl	mZ ddlmZ G d	d
 d
ejZdS )zThe TensorBoard Distributions (a.k.a. compressed histograms) plugin.

See `http_api.md` in this directory for specifications of the routes for
this plugin.
    )wrappers)plugin_util)	http_util)base_plugin)
compressor)metadata)histograms_pluginc                   @   sz   e Zd ZdZejZdZdd Zdd Z	dd Z
d	d
 Zdd Zdd Zdd Zdd Zejjdd Zejjdd ZdS )DistributionsPlugina  Distributions Plugin for TensorBoard.

    This supports both old-style summaries (created with TensorFlow ops
    that output directly to the `histo` field of the proto) and new-
    style summaries (as created by the
    `tensorboard.plugins.histogram.summary` module).
    i  c                 C   s   t || _dS )zInstantiates DistributionsPlugin via TensorBoard core.

        Args:
          context: A base_plugin.TBContext instance.
        N)r   HistogramsPlugin_histograms_plugin)selfcontext r   p/var/www/html/chatgem/venv/lib/python3.10/site-packages/tensorboard/plugins/distribution/distributions_plugin.py__init__/   s   zDistributionsPlugin.__init__c                 C   s   | j | jdS )N)z/distributionsz/tags)distributions_route
tags_router   r   r   r   get_plugin_apps7   s   z#DistributionsPlugin.get_plugin_appsc                 C   s
   | j  S )zThis plugin is active iff any run has at least one histogram tag.

        (The distributions plugin uses the same data source as the
        histogram plugin.)
        )r   	is_activer   r   r   r   r   =   s   
zDistributionsPlugin.is_activec                 C   s
   | j jfS N)r   plugin_namer   r   r   r   data_plugin_namesE   s   
z%DistributionsPlugin.data_plugin_namesc                 C   s   t jddS )Nztf-distribution-dashboard)element_name)r   FrontendMetadatar   r   r   r   frontend_metadataH   s   z%DistributionsPlugin.frontend_metadatac                    s2    j j|||| jd\}} fdd|D |fS )zResult of the form `(body, mime_type)`.

        Raises:
          tensorboard.errors.PublicError: On invalid request.
        )
experimentdownsample_toc                    s   g | ]}  |qS r   )	_compress).0	histogramr   r   r   
<listcomp>W   s    z:DistributionsPlugin.distributions_impl.<locals>.<listcomp>)r   histograms_implSAMPLE_SIZE)r   ctxtagrunr   
histograms	mime_typer   r   r   distributions_implM   s   
z&DistributionsPlugin.distributions_implc                 C   s   |\}}}t |}|||gS r   )r   compress_histogram)r   r    	wall_timestepbucketsconverted_bucketsr   r   r   r   [   s   


zDistributionsPlugin._compressc                 C   s   | j j||dS )Nr   )r   
index_impl)r   r$   r   r   r   r   r0   `   s   zDistributionsPlugin.index_implc                 C   s4   t |j}t |j}| j||d}t||dS )Nr/   zapplication/json)r   r   environexperiment_idr0   r   Respond)r   requestr$   r   indexr   r   r   r   c   s   zDistributionsPlugin.tags_routec                 C   sT   t |j}t |j}|jd}|jd}| j||||d\}}t|||S )zMGiven a tag and single run, return an array of compressed
        histograms.r%   r&   r/   )	r   r   r1   r2   argsgetr)   r   r3   )r   r4   r$   r   r%   r&   bodyr(   r   r   r   r   j   s   
z'DistributionsPlugin.distributions_routeN)__name__
__module____qualname____doc__r   PLUGIN_NAMEr   r#   r   r   r   r   r   r)   r   r0   r   Requestapplicationr   r   r   r   r   r   r	       s     
r	   N)r<   werkzeugr   tensorboardr   tensorboard.backendr   tensorboard.pluginsr    tensorboard.plugins.distributionr   r   tensorboard.plugins.histogramr   TBPluginr	   r   r   r   r   <module>   s   