
                             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ZddlZddlm	Z
 dZd	 Zd
 Zd Z G d de
j                        Zy)zCProfiles-specific printer and functions for generating CSV formats.    )absolute_import)division)print_function)unicode_literalsN)custom_printer_base
csvprofilec                 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      Clib/googlecloudsdk/command_lib/run/printers/profiles_csv_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   )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 }g d}|j                  |       | D ]  }|j                  s|j                  D ]  }t        |j                        \  }}|j                  |j
                  |j                  j                  |j                  j                  |j                  j                  |j                  |j                  |j                  |j                  ||g}|j                  |         |S )z@Transforms profiles to a CSV format, including cost conversions.)zInstance TypezAccelerator Typez
Model NamezModel Server NamezModel Server VersionzOutput Tokens/sz
NTPOT (ms)z	TTFT (ms)QPSzCost/M Input TokenszCost/M Output Tokens)appendperformanceStatsr   r   instanceTypeacceleratorTypemodelServerInfomodelmodelServermodelServerVersionoutputTokensPerSecondntpotMillisecondsttftMillisecondsqueriesPerSecond)profilescsv_dataheaderprofilestatsr   r   rows           r   _transform_profilesr,   9   s    (& //&g++%.>JJ/
++   ####))##//##66''##""""
 	# , ( 
/r   c                       e Zd ZdZd ZddZy)ProfileCSVPrinterz=Prints a service's profile in a custom human-readable format.c                     t        |      S )z7Transforms a List[TrafficTargetPair] into a CSV format.)r,   )selfr&   s     r   	TransformzProfileCSVPrinter.Transformd   s    x((r   c                     t        j                  t        j                        }|j	                  | j                  |             y)z3Overrides ResourcePrinter.Print to set single=True.N)csvwritersysstdout	writerowsr1   )r0   	resourcessingleintermediater4   s        r   PrintzProfileCSVPrinter.Printh   s+    ZZ

#F
T^^I./r   N)TF)__name__
__module____qualname____doc__r1   r;    r   r   r.   r.   a   s    E)0r   r.   )r?   
__future__r   r   r   r   r3   r5   googlecloudsdk.core.resourcer   cpPROFILES_PRINTER_FORMATr   r   r,   CustomPrinterBaser.   r@   r   r   <module>rF      sJ    J &  % ' 
 
 B '  /"%P
0,, 
0r   