o
    `fR                     @   sL   d dl mZ d dlZd dlmZ d dlmZ d dlmZ dd Zdd	 Z	dS )
    )DocumentN)WD_ALIGN_PARAGRAPH)WD_ALIGN_VERTICAL)WD_COLORc           
   
   C   s   t | }i }t| |D ]E}z|j| }W n ty)   td| d|  d Y qw t| |jdd D ]}|j}|d j }t| |d j }	|	||< q5q|S )a	  
    Extract labels and T-scores from specific tables within a document.
    :param doc_path: Path to the Word document.
    :param table_indices: List of table indices to extract data from.
    :return: A dictionary with labels as keys and T-scores as values.
    zTable index z is out of range for .   Nr      )r   printtables
IndexErrorrowscellstextstrip)
doc_pathtable_indicesdoct_scoresindextablerowr   labelt_score r   $/home/ubuntu/flask/bascIndividual.pyextract_t_scores   s&   
	r   c                 C   s   |dkr	d}d}n!|dkrd}d}n|dkrd}d}n|dkr$d}d	}nt d
 dS t| }|j| }|jdd D ]}|j}	|	d j }
|
dkrKq:|
|v r|	| }d|_|	| jd }tj	|_
tj	|_||
 }|
dv r| rt|dkr||d }tj|j_q:| rt|dkr||d }tj|j_q:||}q:| rt|dkr||d }tj|j_q:| rt|dkr||d }tj|j_q:||}q:|	| }d|_tj	|jd _
tj	|_q:tjdkr|tjd|}dS ||}dS )z
    Update the template document with T-scores from the source data.
    :param template_path: Path to the template Word document.
    :param source_data: Dictionary with labels as keys and T-scores as values.
    prs1      prs2   trssrp   r   zInvalid prs_trs_srpNr    r   )zAdaptive SkillsAdaptabilityzSocial Skills
LeadershipzActivities of Daily LivingzFunctional Communication(   *   z**F   <   z--posixz/home/ubuntu/flask/files/)r	   r   r
   r   r   r   r   
paragraphsr   CENTER	alignmentr   vertical_alignmentisdigitintadd_runr   YELLOWfonthighlight_colorREDosnamesavepathjoin)template_pathsource_dataprs_trs_srp
reportFiletable_numbercolumn_numberr   r   r   r   r   cellparascorerun	save_pathr   r   r   update_template$   sd   


rH   )
docxr   r8   docx.enum.textr   docx.enum.tabler   r   r   rH   r   r   r   r   <module>   s    