
    /ۨh                         d dl Zd dlmZ d dlmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZm	Z	mZ d Zd Zd Zy)    N)fox_descripcfox_leyendasfox_a_tiposbfox_a_caractfox_a_segmtofox_divisionesfox_a_concomfox_a_materlfox_a_colorfox_a_lineafox_cmp_aperfox_prove_pffox_indices_indecfox_ifx_calendariofox_empresafox_r_cateptfox_catehogfox_r_subdivfox_a_subdivr   fox_cmpc                    t         j                  j                  | |      j                  dddd      }t        j
                  j                  |      }|j                  r
g g ddddddS t	        j                  |d   d	      |d<   t	        j                  |d   d	      |d<   t	        j                  |d   d	      |d<   t	        j                  |d   d	      |d<   |j                  g d
d       ||d   | kD  |d   | k(  |d   |k\  z  z     }||d   |k  |d   |k(  |d   |k  z  z     }|j                  r
g g ddddddS t        |      }t        |      }i ||S )N)ano__gteano__lteanocampunidadesunid_estr   )
categoriesseriesmax_axistotal_unidadestotal_estimadaspromedio_unidadespromedio_estimadascoerce)errors)r   r   r   r   T)subsetinplace)r   objectsfiltervaluespd	DataFramefrom_recordsempty
to_numericdropnagenerar_datos_graficocalcular_resumen_estadistico)ano_from	camp_fromano_tocamp_toqsdfdata_graficodata_resumens           <C:\xampp\htdocs\Repo\fox2\Fox\app\services\testingService.pycalcular_estadisticas_unidadesr=   "   s   			 
  
 fUFJ
3 
 
	"	"2	&B	xx !""#
 	
 ]]2j>(CBzN]]2j>(CBzNr&z(;BvJbi9BuIII<dIK 
	EX	2e9#8RZ9=T"UV
B 
	EV	Ef!4Fw9N OP
B 
xx !""#
 	
 ),L 03L ,l+l++    c                    | d   j                  t              dz   | d   j                  t              z   | d<   | j                  d      j                  ddd      j	                         }|d   j                         }|d   j                  d      j                         }|d	   j                  d      j                         }|d
|dd|dgt        t        ||z               dz   dS )Nr   -r   
camp_labelsum)r   r   r      r   Unidades)namedatazUnid Estimada
   )r   r   r    )	astypestrgroupbyaggreset_indextolistroundintmax)r9   groupedr   unidades_sumunid_est_sums        r<   r2   r2   Y   s    %y'',s2RZ5F5Fs5KKB|jj&**,  {} 
 &--/J:&,,Q/668L:&,,Q/668L !6$l;
 L<789B> r>   c                    | d   j                         }| d   j                         }| d   j                         j                  d      }| d   j                         j                  d      }t        |      t        |      ||dS )Nr   r   rC   )r!   r"   r#   r$   )rB   meanrN   rO   )r9   r!   r"   r#   r$   s        r<   r3   r3   o   s    
^'')Nn((*O:++-33A6J,,.44Q7 n-/.0	 r>   )pandasr,   matplotlib.pyplotpyplotpltapp.Models.fox_products_modelsr   r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r=   r2   r3    r>   r<   <module>r\      s9     2 2 2 2 2 2>4,n,r>   