
    &Vf                     b    d Z ddlZddlZddlZddlmZ  G d d          Z G d d          ZdS )z=Classes and functions for handling the DownloadData API call.    N)errorc                       e Zd ZdZdZdZdZdS )OutputFormatz<An enum used to list the valid output formats for API calls.jsoncsvlatexN)__name__
__module____qualname____doc__JSONCSVLATEX     f/var/www/html/software/conda/lib/python3.11/site-packages/tensorboard/plugins/hparams/download_data.pyr   r      s#        FFD
CEEEr   r   c                       e Zd ZdZd Zd ZdS )HandlerzHandles a DownloadData request.c                 L    || _         || _        || _        || _        || _        dS )aF  Constructor.

        Args:
          context: A backend_context.Context instance.
          experiment: Experiment proto.
          session_groups: ListSessionGroupsResponse proto.
          response_format: A string in the OutputFormat enum.
          columns_visibility: A list of boolean values to filter columns.
        N)_context_experiment_session_groups_response_format_columns_visibility)selfcontext
experimentsession_groupsresponse_formatcolumns_visibilitys         r   __init__zHandler.__init__$   s1    "  %- /#5   r   c                 *   | j         }| j        }| j        }| j        g }|j        D ]#}|                    |j        p|j                   $|j        D ](}|                    |j        p|j        j	                   )fd} ||          }g }d }	d }
|j
        D ]}g }|j        D ]0}|                     |	|j        |j                                      1i }|j        D ]} |
|j                  }|j        ||<   |j        D ]:} |
|j                  }|                    |                    |                     ;|                     ||                     |t          j        k    rd}t#          ||          }n|t          j        k    rod d}dd	t'          |          z  z  }d
                    t+          |                    dz   }d                    fd|D                       }d}||z   |z   |z   }n|t          j        k    rht/          j                    }t3          j        |          }|                    |           |                    |           |                                }d}nt=          j        d|z            ||fS )zHandles the request specified on construction.

        Returns:
          A response body.
          A mime type (string) for the response.
        c                 8    d t          |           D             S )Nc                     g | ]	\  }}||
S r   r   ).0valuevisibles      r   
<listcomp>z8Handler.run.<locals>._filter_columns.<locals>.<listcomp>O   s!    PPPneWPEPPPr   )zip)row
visibilitys    r   _filter_columnsz$Handler.run.<locals>._filter_columnsN   s!    PPC0D0DPPPPr   c                     |                      d          r| j        S |                      d          r| j        S |                      d          r| j        S dS )Nnumber_valuestring_value
bool_value )HasFieldr.   r/   r0   )r&   s    r   
_get_valuezHandler.run.<locals>._get_valueU   s^    ~~n-- *))~~n-- *))~~l++ (''2r   c                 &    | j         dz   | j        z   S )N.)grouptag)metrics    r   _get_metric_idz#Handler.run.<locals>._get_metric_id_   s    <#%
22r   zapplication/json)headerrowsc                    | dS t          | t                    rd| z  S t          | t                    r}t          j        |           rdS | t          d          t          d          fv rd| dk     rdndz  S d	| z  }d
|v r,|                    d
          \  }}d|t          |          fz  S d|z  S |                     dd                              dd          S )N-z$%d$z$\mathrm{NaN}$infz-infz
$%s\infty$r   +z%.3gez$%s\cdot 10^{%d}$z$%s$_z\_%z\%)
isinstanceintfloatmathisnansplitreplace)r&   
scientificcoefficientexponents       r   latex_formatz!Handler.run.<locals>.latex_formatt   s    =3s++ /!E>)u-- /z%(( 100uuV}} ===,uqyycJJ!'%Jj((0:0@0@0E0E-X3'MM7    "J..}}S%0088eDDDr   zapplication/x-latexz'\begin{table}[tbp]
\begin{tabular}{%s}
l & z \\ \hline
r1   c              3   d   K   | ]*}d                      t          |                    dz   V  +dS )rO   z \\
N)joinmap)r%   r*   rM   s     r   	<genexpr>zHandler.run.<locals>.<genexpr>   sO       " "CF

3|S1122Y>" " " " " "r   z!\hline
\end{tabular}
\end{table}
ztext/csvzInvalid reponses format: %s) r   r   r   r   hparam_infosappenddisplay_namenamemetric_infosr7   r   hparamsmetric_valuesr&   getr   r   dictr   lenrQ   rR   r   ioStringIOr   writerwriterow	writerowsgetvaluer   HParamsError)r   r   r   r   r:   hparam_infometric_infor,   r;   r3   r9   r6   r*   rZ   metric_value	metric_id	mime_typebodytop_partheader_partmiddle_partbottom_part	string_ior`   rM   r+   s                           @@r   runzHandler.run;   sQ    %
-/-
%2 	H 	HKMM+2Fk6FGGGG%2 	L 	LKMM+2Jk6F6JKKKK	Q 	Q 	Q 	Q 	Q !((	 	 		3 	3 	3 $2 	. 	.EC)6 H H

::emK4D&EFFGGGGM % 3 > >*N<+<==	+7+=i(()6 9 9*N;+;<<	

=,,Y778888KK,,----l///*IvD111DD 222E E E( .IDc&kk!H 

3|V44558II  '' " " " "JN" " "  K DKk)K7+EDD 000IZ	**FOOF###T"""%%''D"II$-?   Yr   N)r	   r
   r   r   r!   rp   r   r   r   r   r   !   s=        ))6 6 6.d d d d dr   r   )r   r   r^   rF   tensorboard.plugins.hparamsr   r   r   r   r   r   <module>rr      s    D C 


 				  - - - - - -       ~ ~ ~ ~ ~ ~ ~ ~ ~ ~r   