
    o                         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Z	d Z
d	 Zd
 Z G d dej                        Zy)zFTraffic-specific printer and functions for generating traffic formats.    )absolute_import)division)print_function)unicode_literals)custom_printer_baseprofilec                 P    | j                   }|sd}|| j                  dz  z   }|dS )z*Converts cost to a decimal representation.r   g    eAz.3f)unitsnanos)costr
   decimal_values      ?lib/googlecloudsdk/command_lib/run/printers/profiles_printer.pyamount_to_decimalr      s4    
**%	EDJJ,,--#    c                     d}| r'| d   j                   rt        | d   j                         }d}| r'| d   j                  rt        | d   j                        }||fS )zpReturns the cost per million normalized output tokens as a decimal.

  Args:
    costs: The costs to convert.
  zN/Ar   )$costPerMillionNormalizedOutputTokensr   costPerMillionInputTokens)costsoutput_token_costinput_token_costs      r   get_decimal_costr   %   si     
uQx<<)a55 
uQx11(q)K)KL
-	..r   c           
      h   g d}|g}| D ]  }t        |j                  r|j                  j                  nd      \  }}|j                  |||j                  r|j                  j                  nd|j                  r|j                  j
                  nd|j                  r|j                  j                  nd|j                  j                  |j                  j                  |j                  j                  g	}|j                  |        t        j                  |      }t        j                  |gd      S )zVTransforms a List[AcceleratorOption] into a table with decimal representation of cost.)	AcceleratorzCost/M Input TokenszCost/M Output TokenszOutput Tokens/sz	NTPOT(ms)zAccelerator CountzModel ServerzModel Server VersionModelN<   max_column_width)r   performanceStatsr   acceleratorTypeoutputTokensPerSecondntpotMillisecondsresourcesUsedacceleratorCountmodelAndModelServerInfomodelServerNamemodelServerVersion	modelNameappendcpTableSection)profilesheaderrowspr   r   rowprofiles_tables           r   _transform_profilesr2   6   s   
& $a*:#$#5#54+'' 	
 	
00010B0B,,,-OO((	!!11	!!44	!!++C 	KK# & 88D>.	^$r	::r   c                   *     e Zd ZdZd fd	Zd Z xZS )ProfilePrinterz=Prints a service's profile in a custom human-readable format.c                 0    t         t        |   |d|       y)z3Overrides ResourcePrinter.Print to set single=True.TN)superr4   Print)self	resourcessingleintermediate	__class__s       r   r7   zProfilePrinter.Printa   s    	.$%i|Dr   c                     t        |j                        g}|j                  |j                         t	        j
                  |d      S )z@Transforms a List[TrafficTargetPair] into a marker class format.r   r   )r2   acceleratorOptionsr(   commentsr)   r+   )r8   responser,   s      r   	TransformzProfilePrinter.Transforme   s8    #H$?$?@AHOOH%%&::h44r   )TF)__name__
__module____qualname____doc__r7   rA   __classcell__)r<   s   @r   r4   r4   ^   s    EE5r   r4   N)rE   
__future__r   r   r   r   googlecloudsdk.core.resourcer   r)   PROFILES_PRINTER_FORMATr   r   r2   CustomPrinterBaser4    r   r   <module>rL      sD    M &  % ' B $  /"%;P5R)) 5r   