
    1Vhf                         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 d	Z G d
 dej                        Zy)zzThe TensorBoard Histograms plugin.

See `http_api.md` in this directory for specifications of the routes for
this plugin.
    )wrappers)errors)plugin_util)	http_util)provider)base_plugin)metadatai  c                       e Zd ZdZej
                  ZdZd Zd Z	d Z
d Zd Zdd	Zej                  j                   d
        Zej                  j                   d        Zy)HistogramsPlugina  Histograms 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).
    3   c                     |j                   xs i j                  | j                  t              | _        |j
                  | _        t        j                  dd      | _	        y)zInstantiates HistogramsPlugin via TensorBoard core.

        Args:
          context: A base_plugin.TBContext instance.
        	histogramr   )	data_kindlatest_known_versionN)
sampling_hintsgetplugin_name_DEFAULT_DOWNSAMPLING_downsample_todata_provider_data_providerr   _MetadataVersionChecker_version_checker)selfcontexts     _/home/dcms/DCMS/lib/python3.12/site-packages/tensorboard/plugins/histogram/histograms_plugin.py__init__zHistogramsPlugin.__init__2   sW      '55;@@3
 &33 + C C!!"!
    c                 4    | j                   | j                  dS )N)z/histogramsz/tags)histograms_route
tags_router   s    r   get_plugin_appsz HistogramsPlugin.get_plugin_appsA   s    00__
 	
r   c                      y)NF r"   s    r   	is_activezHistogramsPlugin.is_activeG   s    r   c                    | j                   j                  ||t        j                        }|D ci c]  }|i  }}|j	                         D ]  \  }}|j	                         D ]  \  }}t        j                  |j                        }	t        j                  |j                        }
| j                  j                  |
j                  ||      sl|j                  |	d||   |<     |S c c}w )zJReturn {runName: {tagName: {displayName: ..., description:
        ...}}}.)experiment_idr   )displayNamedescription)r   list_tensorsr	   PLUGIN_NAMEitemsr   markdown_to_safe_htmlr*   parse_plugin_metadataplugin_contentr   okversiondisplay_name)r   ctx
experimentmappingrunresulttag_to_contenttag	metadatumr*   mds              r   
index_implzHistogramsPlugin.index_implJ   s     %%22$ ,, 3 

 &--c#r'--#*==? 	C"0"6"6"8 
Y)??)) 33I4L4LM,,//

CE#,#9#9#.$sC 
	  .s   
C*c                 .    t        j                  d      S )Nztf-histogram-dashboard)element_name)r   FrontendMetadatar"   s    r   frontend_metadataz"HistogramsPlugin.frontend_metadataa   s    ++1
 	
r   Nc           
         ||n| j                   }| j                  j                  ||t        j                  |t        j                  |g|g            }|j                  |i       j                  |d      }|t        j                  d|d|      |D 	cg c]3  }	|	j                  |	j                  |	j                  j                         f5 }
}	|
dfS c c}	w )a  Result of the form `(body, mime_type)`.

        At most `downsample_to` events will be returned. If this value is
        `None`, then default downsampling will be performed.

        Raises:
          tensorboard.errors.PublicError: On invalid request.
        N)runstags)r(   r   
downsamplerun_tag_filterzNo histogram tag z	 for run application/json)r   r   read_tensorsr	   r,   r   RunTagFilterr   r   NotFoundError	wall_timestepnumpytolist)r   r4   r:   r7   r5   downsample_tosample_countall_histograms
histogramseeventss              r   histograms_implz HistogramsPlugin.histograms_implf   s     +6MD<O<O 	 ,,99$ ,,##00se3%H : 
 $''R044S$?
&&47=  DNNa1;;(89NN*++ Os   8Cc                     t        j                  |j                        }t        j                  |j                        }| j	                  ||      }t        j                  ||d      S )N)r5   rG   )r   r   environr(   r=   r   Respond)r   requestr4   r5   indexs        r   r!   zHistogramsPlugin.tags_route   sR    !!'//2 ..w?

;  %1CDDr   c                 ^   t        j                  |j                        }t        j                  |j                        }|j                  j                  d      }|j                  j                  d      }| j                  ||||| j                        \  }}t        j                  |||      S )z=Given a tag and single run, return array of histogram values.r:   r7   )r5   rO   )
r   r   rW   r(   argsr   rU   SAMPLE_SIZEr   rX   )r   rY   r4   r5   r:   r7   body	mime_types           r   r    z!HistogramsPlugin.histograms_route   s     !!'//2 ..w?
llu%llu% 00cj@P@P 1 
y   $	::r   )N)__name__
__module____qualname____doc__r	   r,   r   r]   r   r#   r&   r=   rA   rU   r   Requestapplicationr!   r    r%   r   r   r   r   #   s{     &&K K

.

,6 !!E "E !!	; "	;r   r   N)rc   werkzeugr   tensorboardr   r   tensorboard.backendr   tensorboard.datar   tensorboard.pluginsr   tensorboard.plugins.histogramr	   r   TBPluginr   r%   r   r   <module>rm      s=      # ) % + 2  o;{++ o;r   