
    Mf                     J    d dl mZ d dlmZ d dlmZ d dlmZ 	 	 	 	 	 	 d	dZdS )
    )reducegroupby)add)htmlNTFc           
         ddl }	ddl}
|j        dd|f         ?                    dg          j        D ]#}|                             fd          |<   $?                    dg          j        D ]#}|                             fd          |<   $|r.                                |                    d|i          |rt          |t          t          |	j        |
j        f          r&	 |_        nH# t          $ r t          d	          w xY wt          |t                    r                    |          j        j        }fd
t!          |          D             d D             d D             fdt!          d|dz             D             d D             t#          j        fdt!          |          D                       g}ng }|                    t#          j        fdt!          t+                              D                                   | |fi |S )a  
    Generate a Table component from a dataframe.

    Parameters
    ----------
    df : pandas.DataFrame
        DataFrame to render as a table.
    float_format : str, optional
        Format to use for floating point numbers.
    columns : sequence, optional
        Columns to render.
    header : boolean or list(str) or dict(str: str), optional
        Write out the column names. If a list of strings is given it is assumed
        to be aliases for the columns names (and hence must be the same length
        as df.columns). A dict can be passed to rename some columns, the format
        is {'<current_name>': '<new_name>'}. The dictionary need not have an
        entry for every column.
    index : boolean, optional
        Render the row names (index).
    index_label : str, optional
        Column label for index column if desired. If None is passed, but both
        header and index are True, then the index name is used.
    date_format : str, optional
        Format string for datetime objects.
    **table_kwargs : Keyword arguments
        Additional arguments to pass to the table component. See
        dash_bootstrap_components.Table for details.
    r   Nfloatc                 0    d                     |           S )Nz{1:{0}})format)xfloat_formats    _/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/dash_bootstrap_components/_table.py<lambda>z)_generate_table_from_df.<locals>.<lambda>7   s    	(8(8q(I(I     datetimec                 .    |                                S N)strftime)r   date_formats    r   r   z)_generate_table_from_df.<locals>.<lambda>;   s    

;(?(? r   index)columnsziIf specifying column names with a sequence, the number of names must exactly match the number of columns.c                 ^    g | ])}t          j                            |                    *S  )listr   get_level_values).0leveldfs     r   
<listcomp>z+_generate_table_from_df.<locals>.<listcomp>P   sA     
 
 
 ,,U3344
 
 
r   c                 @    g | ]}d  t          |          D             S )c                 L    g | ]!\  }}t          t          |                    "S r   )lenr   )r   _groups      r   r   z6_generate_table_from_df.<locals>.<listcomp>.<listcomp>W   s*    DDD(!USeDDDr   r   )r   level_valuess     r   r   z+_generate_table_from_df.<locals>.<listcomp>V   s?     
 
 
 EDgl.C.CDDD
 
 
r   c           	      h    g | ].fd t          dt                    dz             D             /S )c                 >    g | ]}t          d |                   S r   )sum)r   ilevel_spanss     r   r   z6_generate_table_from_df.<locals>.<listcomp>.<listcomp>]   s)    JJJaSRaR!!JJJr      )ranger"   )r   r*   s    @r   r   z+_generate_table_from_df.<locals>.<listcomp>\   sU     
 
 
 KJJJ5C4D4Dq4H+I+IJJJ
 
 
r   c                     g | ]M}t          t          t          t          d |                                                 dh                    NS )Nr   )sortedsetr   r   union)r   r   header_breakss     r   r   z+_generate_table_from_df.<locals>.<listcomp>b   s\     
 
 
 3vc=%#899::@@!EEFF
 
 
r   r+   c           
          g | ]<t          fd t          t                    dz
  dd          D                       =S )c                 8    g | ]}|         |d z
           z
  S )r+   r   )r   r)   level_breakss     r   r   z6_generate_table_from_df.<locals>.<listcomp>.<listcomp>j   s;        !Ol1q5&99  r   r+   r   )reversedr,   r"   )r   r4   s    @r   r   z+_generate_table_from_df.<locals>.<listcomp>h   st     
 
 
     "3|#4#4q#8!R@@   
 
 
r   c           
          g | ]>t          j        fd t                                      D                       ?S )c                 Z    g | ]'\  }}t          j                 |         |           (S ))colSpan)r   Th)r   posspanheader_valuesr   s      r   r   z6_generate_table_from_df.<locals>.<listcomp>.<listcomp>v   sP     " " "
 !*T	 !G -e 4S 9(,  " " "r   )children)r   Trzip)r   r   r1   header_spansr=   s    @r   r   z+_generate_table_from_df.<locals>.<listcomp>t   s         G" " " " "
 .1 -e 4l56I. ." " "
 
 
  r   c           
          g | ]Bt          j        fd t          t          j                            D                       CS )c                 R    g | ]#}t          j        j        |f                   $S r   )r   Tdiloc)r   jr   r)   s     r   r   z6_generate_table_from_df.<locals>.<listcomp>.<listcomp>   s-    LLLTWRWQT]++LLLr   )r   r?   r,   r"   r   )r   r)   r   s    @r   r   z+_generate_table_from_df.<locals>.<listcomp>   sb         LLLLLU3rz??5K5KLLL   r   )numpypandaslocselect_dtypesr   mapreset_indexrename
isinstancetupler   ndarrayIndex
ValueErrordictnlevelsr,   r   TheadappendTbodyr"   )clsr   r   r   headerr   index_labelr   table_kwargsnppdcn_levelstabler1   rA   r=   s    ``    `      @@@r   _generate_table_from_dfra      s8   N VAAAwJ!!7),,4 	K 	KAqEIIIIIIJJBqEE!!:,//7 	A 	AAqEII????@@BqEE ;^^"G[#9::B CfudBJABB 		+#

    I  
 %% 	+6**B :%
 
 
 
x
 
 

 
 -
 
 

 
+
 
 

 
 
 
q(Q,//
 
 

 
 !.
 
 
 J      "'x   
& 	LL
    s2ww	  	
 	
	 	 	 3u%%%%%s    D D")NNTFNN)		functoolsr   	itertoolsr   operatorr   dashr   ra   r   r   r   <module>rf      s                            
H& H& H& H& H& H&r   