
                             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      Blib/googlecloudsdk/command_lib/run/printers/profiles_printer_ga.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   )costPerMillionOutputTokensr   costPerMillionInputTokens)costsoutput_token_costinput_token_costs      r   get_decimal_costr   %   si     
uQx22)a++ 
uQx11(q)K)KL
-	..r   c                    g d}|g}| D ]  }t        |j                  r|j                  d   j                  nd      \  }}|j                  |j                  |||j                  d   r|j                  d   j
                  nd|j                  r|j                  d   j                  nd|j                  r|j                  d   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.)
zInstance TypeAcceleratorzCost/M Input TokenszCost/M Output TokenszOutput Tokens/sz	NTPOT(ms)zTTFT(ms)zModel ServerzModel Server VersionModelr   N<   )max_column_width)r   performanceStatsr   instanceTypeacceleratorTypeoutputTokensPerSecondntpotMillisecondsttftMillisecondsmodelServerInfomodelServermodelServerVersionmodelappendcpTableSection)profilesheaderrowspr   r   rowprofiles_tables           r   _transform_profilesr1   6   s+   & $a*:&'&8&81""d+'' 	
	a  	
133343E3E1//4232D2D1..$	%%	,,	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)superr3   Print)self	resourcessingleintermediate	__class__s       r   r6   zProfilePrinter.Printc   s    	.$%i|Dr   c                     t        |      S )z@Transforms a List[TrafficTargetPair] into a marker class format.)r1   )r7   r+   s     r   	TransformzProfilePrinter.Transformg   s    x((r   )TF)__name__
__module____qualname____doc__r6   r=   __classcell__)r;   s   @r   r3   r3   `   s    EE)r   r3   N)rA   
__future__r   r   r   r   googlecloudsdk.core.resourcer   r(   PROFILES_PRINTER_FORMATr   r   r1   CustomPrinterBaser3    r   r   <module>rH      sD    M &  % ' B $  /"';T	)R)) 	)r   