o
    QDi"                     @  s   d dl mZ d dlmZmZmZmZmZmZm	Z	 d dl
Z
d dlmZ ddlmZ ddlmZmZ ddlmZ dd	lmZ d
dlmZ d
dlmZ erPddlmZ e
jdddG dd deZdS )    )annotations)TYPE_CHECKINGAnyClassVarDictListOptionalUnionN)tabulate   )settings)ErrorReportError)FrictionlessException)Metadata   )types)
ReportTask)ResourceTF)kw_onlyreprc                   @  sx  e Zd ZU dZdZded< 	 dZded< 	 dZded< 	 dZded< 	 d	ed
< 	 ded< 	 e	j
edZded< 	 e	j
edZded< 	 e	j
edZded< 	 edd Zedd Zg dfd:ddZedg g g dd;d d!Zeg g g d"d<d&d'Zed=d*d+Zd,d- Zd.ZeZd/g d0d1ejd2d1ejd2dd1idd1idd3idd/idd4idd4idd4id5	d6Zed>d8d9Z dS )?Reportz[Report representation.

    A class that stores the summary of the validation action.

    NzOptional[str]namezClassVar[Union[str, None]]typetitledescriptionboolvalidztypes.IReportStatsstats)factory	List[str]warningsList[Error]errorsList[ReportTask]tasksc                 C  s6   | j d dkrd}t|| jr| jd jS | jd S )z'Validation error (if there is only one)r#   r   z8The "report.error" is available for single error reportsr   )r   r   r%   errorr#   selfnote r*   S/var/www/Datamplify/venv/lib/python3.10/site-packages/frictionless/report/report.pyr&   J   s   zReport.errorc                 C  s$   | j d dkrd}t|| jd S )z&Validation task (if there is only one)r%   r   z6The "report.task" is available for single task reportsr   )r   r   r%   r'   r*   r*   r+   taskR   s   
zReport.task)
taskNumber	rowNumberfieldNumberr   specc                   s   g }| j D ]}i   |  | fdd|D  qt| jddD ]!\}}|j D ]}d|i  |  | fdd|D  q+q$|S )zFlatten the report

        Parameters
            spec (str[]): flatten specification

        Returns:
            any[]: flatten report
        c                      g | ]}  |qS r*   get.0propcontextr*   r+   
<listcomp>k       z"Report.flatten.<locals>.<listcomp>r   )startr-   c                   r1   r*   r2   r4   r7   r*   r+   r9   p   r:   )r#   updateto_descriptorappend	enumerater%   )r(   r0   resultr&   countr,   r*   r7   r+   flatten\   s   

zReport.flattenr   )timer%   r#   r!   rC   floatc                 C  s`   |  }|  }|  }t|tdd |D  }tjt||t|| d}t| ||||dS )z!Create a report from a validationc                 s  s    | ]
}|j d  p
dV  qdS )r#   r   N)r   )r5   r,   r*   r*   r+   	<genexpr>   s    z)Report.from_validation.<locals>.<genexpr>r%   r#   r!   secondsr   r   r!   r#   r%   )copylensumr   IReportStatsr   )rC   r%   r#   r!   error_countr   r*   r*   r+   from_validationu   s"   	zReport.from_validation)labelsr#   r!   resourcer   rO   c                C  s   |  }|  }tjt|t||d}| jjr| jj|d< | jjr(| jj|d< | jjr2| jj|d< | jjr<| jj|d< | jj	rF| jj	|d< tj
dt|t||d}t| |g g t| | j| j| j||||d	gd
S )z&Create a report from a validation task)r#   r!   rG   md5sha256bytesfieldsrowsr   rF   )r   r   r   placerO   r   r#   r!   rH   )rI   r   IReportTaskStatsrJ   r   rQ   rR   rS   rT   rU   rL   r   r   r   r   rV   )rP   rC   rO   r#   r!   
task_statsreport_statsr*   r*   r+   from_validation_task   sL   
zReport.from_validation_taskreportsList[Report]c                 C  sL   g }g }g }|D ]}| |j | |j | |j qtj| |||dS )z0Create a report from a set of validation reports)rC   r!   r#   r%   )extendr%   r#   r!   r   rN   )rC   r[   r%   r#   r!   reportr*   r*   r+   from_validation_reports   s   zReport.from_validation_reportsc              	   C  s&  d}| j D ]}|jrdnd}|jrdnd}|ddt|  7 }|d| d|j d| 7 }|ddt|  7 }g }|jr[|jD ]}| }||d	d|d
d|j	|j
g qA|d7 }|d7 }|d7 }|| 7 }|d7 }|jr|d7 }|d7 }|tt|g ddg dd7 }|d7 }q|S )zSSummary of the report

        Returns:
            str: validation report
         r   invalidz(non-tabular)z
# -z:  r.   r/   z

z## Summary z
## Errors )RowFieldTypeMessagegrid)   ri      Z   )headerstablefmtmaxcolwidths)r%   r   tabularrJ   rV   r#   r=   r>   r3   r   message
to_summarystrr
   )r(   validation_contentr,   prefixsuffixerror_contentr&   error_descriptorr*   r*   r+   rq      sJ   



		zReport.to_summaryr^   objectrH   string)r   patternbooleanarray)	r   r   r   r   r   r   r!   r#   r%   )r   required
propertiesrr   c                 C  s   |dkrt S |dkrtS d S )Nr#   r%   )r   r   )clsr   r*   r*   r+   metadata_select_property_class  s
   z%Report.metadata_select_property_class)r0   r    )rC   rD   r%   r$   r#   r"   r!   r    )
rP   r   rC   rD   rO   r    r#   r"   r!   r    )rC   rD   r[   r\   )r   rr   )!__name__
__module____qualname____doc__r   __annotations__r   r   r   attrsfieldlistr!   r#   r%   propertyr&   r,   rB   staticmethodrN   rZ   r_   rq   metadata_typer   metadata_Errorr   NAME_PATTERNTYPE_PATTERNmetadata_profileclassmethodr   r*   r*   r*   r+   r      sr   
 


12

r   )
__future__r   typingr   r   r   r   r   r   r	   r   r
   r`   r   r#   r   r   	exceptionr   metadatar   r   r,   r   rP   r   definer   r*   r*   r*   r+   <module>   s    $