o
    zNh=	                     @   sX   d dl mZ d dlZd dlZd dlmZ d dlmZ dd Z	dd Z
dd	 Zd
d ZdS )    N)Presentation)Inchesc                 C   s   dd | D }dd | D }dd | D }t jdd tt|}t j||dd t j|||d	d
 t j||ddd t   t   tj	dddj
}t j|dd t   |S )Nc                 S      g | ]}|d  qS label .0rr   r   !/var/www/html/ai_worker/report.py
<listcomp>       zmake_charts.<locals>.<listcomp>c                 S   r   companyr   r   r   r   r   r      r   c                 S   $   g | ]}|d  dur|d  ndqS 	benchmarkNr   r   r   r   r   r   r         $ 
      figsizeAziendar   	Benchmarkbottomr   -   rightrotationhaF.png)deletesuffix   )dpi)pltfigurerangelenbarxtickslegendtight_layouttempfileNamedTemporaryFilenamesavefigclose)tablelabelscompbenchxpng_barr   r   r   make_charts   s   r:   c                 C   st   t d}|jd }|j|tdtdtdtd |jd }|jd j}|  ||_d|  d	}|| |S )
Nz'templates/smartweek_template_ready.pptx      g      ?   r      z'/var/www/html/ai_worker/reports/report_z.pptx)	r   slidesshapesadd_picturer   
text_framecleartextsave)	answer_id	narrativer9   prsslide7slide8tfoutr   r   r   
build_pptx   s   
$

rM   c                 C   s   dd | D }dd | D }dd | D }dd l m} dd l}|jdd\}}tt|}	|j|	|dd	 |j|	||d
d ||	 |j|ddd |	  |
  d| d}
||
 |  |
S )Nc                 S   r   r   r   r   r   r   r   r   '   r   z"save_chart_png.<locals>.<listcomp>c                 S   r   r   r   r   r   r   r   r   (   r   c                 S   r   r   r   r   r   r   r   r   )   r   r   r   r   r   r   r   r   r   r   r   z&/var/www/html/ai_worker/exports/chart_r"   )matplotlib.pyplotpyplotossubplotsr)   r*   r+   
set_xticksset_xticklabelsr-   r.   r2   r3   )r4   rF   r5   r6   r7   r'   rP   figaxr8   pathr   r   r   save_chart_png&   s    

rW   c              	   C   sZ   d}| D ] }|d d ur|d nd}|d|d  d|d  d| d7 }qd	| d
}|S )N r   -z<tr><td>r   z	</td><td>r   z
</td></tr>z
    <table class='table table-striped'>
      <thead><tr><th>Fattore</th><th>Azienda</th><th>Benchmark</th></tr></thead>
      <tbody>z</tbody>
    </table>
    r   )r4   rowsr
   bmkhtmlr   r   r   render_html_table;   s   &r]   )rN   rO   r'   r/   rP   pptxr   	pptx.utilr   r:   rM   rW   r]   r   r   r   r   <module>   s    