B
    â‹da  ã               @   sP   d Z ddlZddlmZ ddd„Zdd„ Zdd	d
„Zdd„ ZG dd„ de	ƒZ
dS )zH This module contains result page layout and numbering helper functions
é    N)Úzip_longestÚ c             K   s:   t j t  ¡ | d |¡¡} ddlm} || d|f|Ž dS )a¾   Make a well layout in a two column format

    Parameters
    ----------
    path: str
        Location to make the well html file
    unique: str
        String to add to end of well name. Used if you want more than one well.
    cols: list of tuples
        The format of the items on the well result section. Each tuple
        contains the two files that are shown in the left and right hand
        side of a row in the well.html page.
    zwell{}.htmlr   )Úrender_workflow_html_templateztwo_column.htmlN)ÚosÚpathÚjoinÚgetcwdÚformatZpycbc.results.renderr   )r   ÚcolsÚuniqueÚkwargsr   © r   úa/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/site-packages/pycbc/results/layout.pyÚtwo_column_layout   s    r   c             K   s   t | dd„ |D ƒf|Ž dS )zè Make a well layout in  single column format

    path: str
        Location to make the well html file
    files: list of pycbc.workflow.core.Files
        This list of images to show in order within the well layout html file.
    c             S   s   g | ]
}|f‘qS r   r   )Ú.0Úfr   r   r   ú
<listcomp>/   s    z!single_layout.<locals>.<listcomp>N)r   )r   Úfilesr   r   r   r   Úsingle_layout'   s    r   c             C   s   t | ƒg| }t|d|iŽS )z) Group items into chunks of n length
    Ú	fillvalue)Úiterr   )ÚiterableÚnr   Úargsr   r   r   Úgrouper1   s    r   c             K   s(   t |ƒdkr$t| tt|dƒƒf|Ž dS )a#   Make a well layout in chunks of two from a list of files

    path: str
        Location to make the well html file
    files: list of pycbc.workflow.core.Files
        This list of images to show in order within the well layout html file.
        Every two are placed on the same row.
    r   é   N)Úlenr   Úlistr   )r   r   r   r   r   r   Úgroup_layout7   s    	r   c               @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚSectionNumberz> Class to help with numbering sections in an output page.
    c             C   sb   || _ || _i | _i | _i | _x>t|ƒD ]2\}}d|d |f | j|< || j|< d| j|< q(W dS )zü Create section numbering instance

        Parameters
        ----------
        base: path
            The path of the of output html results directory
        secs: list of strings
            List of the subsections of the output html page
        z%s._%sé   N)ÚbaseÚsecsÚnameÚcountÚnumÚ	enumerate)Úselfr!   r"   r%   Úsecr   r   r   Ú__init__F   s    

zSectionNumber.__init__c             C   sˆ   || j kr| j | }nX| d¡\}}| j| }| j| }d| j | |d ||f }| j|  d7  < || j |< tj t ¡ | j|¡}|S )zÚ Return the path to use for the given subsection with numbering
        included. The numbering increments for each new subsection request. If
        a section is re-requested, it gets the original numbering.
        ú/z%s/%s.%02d_%sr    )	r#   Úsplitr$   r%   r   r   r   r   r!   )r'   r   r#   r(   ZsubsecZsubnumr%   r   r   r   Ú__getitem__[   s    



zSectionNumber.__getitem__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r)   r,   r   r   r   r   r   C   s   r   )r   )N)r0   Úos.pathr   Ú	itertoolsr   r   r   r   r   Úobjectr   r   r   r   r   Ú<module>   s   


