
    %g                     H    d dl mZ d dlmZ d dlmZ d dlmZ 	 	 	 	 	 	 ddZy)    )reduce)groupby)add)htmlNc                 2   ddl }	ddl}
||j                  dd|f   };|j                  dg      j                  D ]  }||   j                  fd      ||<    ;|j                  dg      j                  D ]  }||   j                  fd      ||<    |r&|j                         }||j                  d|i      }|rGt        |t        t        |	j                  |
j                  f      r		 ||_        n"t        |t              r|j                  |      }|j                  j                  }t!        |      D cg c]&  }t        |j                  j#                  |            ( }}|D cg c]2  }t%        |      D cg c]  \  }}t'        t        |             c}}4 }}}}|D cg c]4  }t!        d
t'        |      d
z         D cg c]  }t)        |d|        c}6 }}}t!        d
|d
z         D cg c]7  }t+        t-        t/        t0        |d|             j3                  dh            9 }}|D cg c]>  }t5        t!        t'        |      d
z
  dd      D cg c]  }||   ||d
z
     z
   c}      @ }}}t7        j8                  t!        |      D cg c]V  }t7        j:                  t=        ||   ||         D cg c]"  \  }}t7        j>                  ||   |   |      $ c}}      X c}}}      g}ng }|jA                  t7        jB                  t!        t'        |            D cg c]c  }t7        j:                  t!        t'        |j                              D cg c]&  }t7        jD                  |jF                  ||f         ( c}      e c}}              | |fi |S # t        $ r t        d	      w xY wc c}w c c}}w c c}}}w c c}w c c}}w c c}w c c}w c c}}w c c}}w c c}}}w c c}w c c}}w )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                 (    dj                  |       S )Nz{1:{0}})format)xfloat_formats    ]/var/www/dash_apps/app1/venv/lib/python3.12/site-packages/dash_bootstrap_components/_table.py<lambda>z)_generate_table_from_df.<locals>.<lambda>7   s    	(8(8q(I     datetimec                 &    | j                        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.   )colSpan)children)$numpypandaslocselect_dtypesr   mapreset_indexrename
isinstancetuplelistndarrayIndex
ValueErrordictnlevelsrangeget_level_valuesr   lensumsortedsetr   r   unionreversedr   TheadTrzipThappendTbodyTdiloc)clsdfr   r   headerr   index_labelr   table_kwargsnppdcn_levelslevelheader_valueslevel_values_groupheader_spanslevel_spansiheader_breakslevel_breaksposspantablejs     `    `                   r   _generate_table_from_dfrP      s   N VVAwJ!!7),44 	KAqEIIIJBqE	K !!:,/77 	AAqEII?@BqE	A ^^"G[#9:BfudBJJAB#
 %6*B ::%% x
 ,,U34
 
 !.
 
 /6l.CD(!USeD
 
  ,
 ,1C4Dq4H+IJaSRa!J
 
 q(Q,/
 3vc=%#89:@@!EF
 
 !.
   #3|#4q#8!R@ !Ol1q5&99
 
 JJ "'x   GG .1 -e 4l56I."
 !*T	 !GG -e 4S 9(,"

& 	LL


 s2w	  5:3rzz?5KLTWWRWWQT]+L	
	 u%%%U   I 
 E
 K


", Ms   2N< ?+O2OO#O2O+O&&O+?<O1%O;'O6<	O;&)P'P6P?4P3+P	P<OO&O+6O;PP)NNTFNN)		functoolsr   	itertoolsr   operatorr   dashr   rP    r   r   <module>rV      s+        
H&r   