
    5g:                     F   d dl mZmZmZ d dlmZ d dlm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 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 Z d dl!Z"d dl#m$Z$ d dl%Z&d Z'd Z(d Z)d dl mZmZ d dl*m+Z+ d Z,d Z-d dl mZmZmZ d dlmZ d Z.d Z/y)    )renderredirectget_object_or_404)messages)Projeto)
ParedeForm)	VidroForm)PortaMadeiraFormPortaVidroForm)TelhadoForm)DadosTermicosForm)Parede)Vidro)PortaMadeira
PortaVidro)Telhado)DadosTermicos   )AmbienteN)settingsc                 |    d}|dz   }dt        j                  d|z  |dz   z        z  }| |z  }d|z  d|z
  z  dz  }|S )	Ng     |@gfffffq@g r@gQ1@g     pn@gCl?g     @i  )npexp)umidade_relativatemperatura_internaRvTeseumidade_absolutas          'C:\grfgraph\atual\cag\ctermica\views.pycalcular_umidade_absolutar"      s]    	Bf$A	!449Lu9TUV	VB2A	gk2T9    c                 	   t         j                  j                  t        j                  d| j
                   d      }t        j                  |d       i d|gd|j                  gd|j                  gd|j                  gd	|j                  gd
|j                  gd|j                  gd|j                  gd|j                  gd|j                  gd|j                   gd|j"                  gd|j$                  gd|j&                  gd|j(                  gd|j*                  gd|j,                  gi d|j.                  gd|j0                  gd|j2                  gd|j4                  gd|j6                  gd|j8                  gd|j:                  gd|j<                  gd|j>                  gd|j@                  gd |jB                  gd!|jD                  gd"|jF                  gd#|jH                  gd$|jJ                  gd%|jL                  gd&|jN                  gi d'|jP                  gd(|jR                  gd)|jT                  gd*|jV                  gd+|jX                  gd,|jZ                  gd-|j\                  gd.|j>                  gd/|j@                  gd0|jB                  gd1|jD                  gd2|jF                  gd3|jH                  gd4|jJ                  gd5|jL                  gd6|jN                  gd7|jP                  gi d8|jR                  gd9|jT                  gd:|jV                  gd;|jX                  gd<|jZ                  gd=|j\                  gd>|j^                  gd?|j`                  gd@|jb                  gdA|jd                  gdB|jf                  gdC|jh                  gdD|jj                  gdE|jl                  gdF|jn                  gdG|jp                  gdH|jr                  g|jt                  g|jv                  g|jx                  gdI}	t{        j|                  |	      }
t         j                  j                  || dJ      }|
j                  |dKL       t        dM|        y )NNarquivos_climaticos/projeto_/T)exist_oknome_ambientearea_parede_nortecoeficiente_parede_nortetipo_parede_nortearea_parede_sulcoeficiente_parede_sultipo_parede_sularea_parede_lestecoeficiente_parede_lestetipo_parede_lestearea_parede_oestecoeficiente_parede_oestetipo_parede_oestearea_vidro_nortecoeficiente_vidro_nortetipo_vidro_nortearea_vidro_sulcoeficiente_vidro_sultipo_vidro_sularea_vidro_lestecoeficiente_vidro_lestetipo_vidro_lestearea_vidro_oestecoeficiente_vidro_oestetipo_vidro_oestearea_porta_madeira_nortecoeficiente_porta_madeira_nortetipo_porta_madeira_norte#diferencial_insolacao_madeira_nortearea_porta_madeira_sulcoeficiente_porta_madeira_sultipo_porta_madeira_sul!diferencial_insolacao_madeira_sularea_porta_madeira_lestecoeficiente_porta_madeira_lestetipo_porta_madeira_leste#diferencial_insolacao_madeira_lestearea_porta_madeira_oestecoeficiente_porta_madeira_oestetipo_porta_madeira_oeste#diferencial_insolacao_madeira_oestearea_porta_vidro_nortecoeficiente_porta_vidro_nortetipo_porta_vidro_norte!diferencial_insolacao_vidro_nortearea_porta_vidro_sulcoeficiente_porta_vidro_sultipo_porta_vidro_suldiferencial_insolacao_vidro_sularea_porta_vidro_lestecoeficiente_porta_vidro_lestetipo_porta_vidro_leste!diferencial_insolacao_vidro_lestearea_porta_vidro_oestecoeficiente_porta_vidro_oestetipo_porta_vidro_oeste!diferencial_insolacao_vidro_oestetipo_telhadocoeficiente_transmissao_telhadoarea_telhadocalor_sensivel_pessoacalor_latente_pessoanumero_pessoastaxa_iluminacaodissipacao_equipamentos
pe_direito	area_pisor   )umidade_relativa_internaumidade_absoluta_internataxa_renovacaoz
_dados.csvF)indexz"Arquivo CSV salvo com sucesso em: )Aospathjoinr   BASE_DIRnome_projetomakedirsr)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   area_porta_nortecoeficiente_porta_nortetipo_porta_nortediferencial_insolacao_nortearea_porta_sulcoeficiente_porta_sultipo_porta_suldiferencial_insolacao_sularea_porta_lestecoeficiente_porta_lestetipo_porta_lestediferencial_insolacao_lestearea_porta_oestecoeficiente_porta_oestetipo_porta_oestediferencial_insolacao_oestera   coeficiente_transmissaorc   rd   re   rf   rg   rh   ri   rj   r   rk   rl   rm   pd	DataFrameto_csvprint)projetor(   paredevidroporta_vidroporta_madeiratelhadotermicocaminho_basedadosdfcaminho_csvs               r!   salvar_dados_em_csvr       s   77<< 1 15QRYRfRfQggh3ijLKKt,T-T 	f667	T
 	#V%D%D$ET 	f667T 	F223T 	!6#@#@"AT 	F223T 	f667T 	#V%D%D$ET 	f667T 	f667T 	#V%D%D$ET 	f667T$ 	U334%T& 	"E$A$A#B'T( 	U334)T* 	5//0+T, 	 %"="=!>-T. 	5//0/T0 	U3341T2 	"E$A$A#B3T4 	U3345T6 	U3347T8 	"E$A$A#B9T: 	U334;T@ 	#]%C%C$DATB 	*M,Q,Q+RCTD 	#]%C%C$DETF 	.0Y0Y/ZGTH 	!=#?#?"@ITJ 	(-*M*M)NKTL 	!=#?#?"@MTN 	,m.U.U-VOTP 	#]%C%C$DQTR 	*M,Q,Q+RSTT 	#]%C%C$DUTV 	.0Y0Y/ZWTX 	#]%C%C$DYTZ 	*M,Q,Q+R[T\ 	#]%C%C$D]T^ 	.0Y0Y/Z_Td 	!;#?#?"@eTf 	(+*M*M)NgTh 	!;#?#?"@iTj 	,k.U.U-VkTl 	!;!; <mTn 	&(I(I'JoTp 	!;!; <qTr 	*K,Q,Q+RsTt 	!;#?#?"@uTv 	(+*M*M)NwTx 	!;#?#?"@yTz 	,k.U.U-V{T| 	!;#?#?"@}T~ 	(+*M*M)NT@ 	!;#?#?"@ATB 	,k.U.U-VCTH 	--.ITJ 	*G,K,K+LKTL 	--.MTR 	 '"?"?!@STT 	!=!= >UTV 	7112WTX 	G334YTZ 	"G$C$C#D[T\ 	w))*]T^ 	g''(_T` 	 ; ;<aTb &-%E%E$F%,%E%E$F"112gTEn 
e	B'',,|j-IJKIIkI'	.{m
<=r#   c           
      .   t        t        |      }| j                  dk(  r| j                  j	                  d      }|s-t        j                  | d       t        d|j                        S t        j                  j                  ||      }t        | j                  d	      }t        | j                  d
	      }t        | j                  d	      }t        | j                  d	      }t!        | j                  d	      }	t#        | j                  d	      }
t%        |j'                         |j'                         |j'                         |j'                         |	j'                         |
j'                         g      r|j)                  d      }||_        |j)                          |j)                  d      }||_        |j)                          |j)                  d      }||_        |j)                          |j)                  d      }||_        |j)                          |	j)                  d      }||_        |j)                          |
j)                  d      }||_        t-        |j.                  |j0                        |_        |j)                          t        j4                  | d       t        d|j                  |j                        S t        d	      }t        d
	      }t        d	      }t        d	      }t!        d	      }	t#        d	      }
g d}|D ci c]"  }||d|    |d|    |d|    |d|    d$ }}|D ci c]"  }||d|    |d|    |d|    |d|    d$ }}||||||	|
d}t7        | d|      S c c}w c c}w )NidPOSTr(   u#   O nome do ambiente é obrigatório.cadastrar_ambiente
projeto_id)r(   r   r   )prefixr   r   r   r   r   F)commitz Ambiente cadastrado com sucesso!resultados_ambiente)r   ambiente_id)nortesullesteoestearea_porta_coeficiente_porta_tipo_porta_diferencial_insolacao_)areacoeficientetipodiferencial)r   parede_form
vidro_formcampos_porta_madeiracampos_porta_vidrotelhado_formtermico_formz ctermica/cadastrar_ambiente.html)r   r   methodr   getr   errorr   r   r   objectscreater   r	   r
   r   r   r   allis_validsaveambienter"   rk   r   rl   successr   )requestr   r   r(   r   r   r   porta_madeira_formporta_vidro_formr   r   r   r   r   r   r   r   orientacoes
orientacaor   r   contextos                         r!   r   r      s   J7G~~((9NN7$IJ0WZZHH##**PW*X h?w||G<
-gll?S)',,}M"7<<	B(iH$$&
(;(;(=?Q?Z?Z?\ ))+\-B-B-DlF[F[F]_ ` %%U%3F&FOKKMOO5O1E%ENJJL.3353AM%-M" *//u/=K#+K "''u'5G'GLLN"''u'5G'G 0I00'2M2M0G, LLNW&HI1gjjV^VaVabb !1g.
-_E)?")4(	:4K & &J 	&ZL'AB-0B:,.OP&ZL'AB-0Fzl.ST	
 	
 &  " & &J 	${:,%?@+.@,MN${:,%?@+.DZL,QR	
 	
 &   "  40$$H '=xHH;s    'N'N)r   r   )HttpResponsec                     t        t        |      }t        t        ||      }| j                  dk(  r|j	                          t        d|      S t        d      S )Nr   r   r   r   lista_ambientesr   u!   Confirme a exclusão do ambiente.)r   r   r   r   deleter   r   )r   r   r   r   r   s        r!   deletar_ambienter      sL    J7G k7KH~~)jAA;<<r#   c                    d| j                    d}	 t        j                  t        j                  j                  |d            }t        j                  t        j                  j                  |d            }t        j                  t        j                  j                  |d            }t        j                  t        j                  |d         |d   |d   |d	   d
      }||d   j                  j                  dk\  |d   j                  j                  dk  z     }|d   j                  j                  d      |d<   |j                  d      S # t        $ r Y y w xY w)Nr%   r&   ztemperaturas.csvzumidades_relativas.csvzumidades_absolutas.csvtimetemperature_2mrelative_humidity_2mr    )r   temperaturar   r          z%H:%Mhorarecords)rs   r   read_csvro   rp   rq   r   to_datetimedthourstrftimeto_dictFileNotFoundError)r   r   df_temperaturasdf_umidades_relativasdf_umidades_absolutasdf_climaticos         r!   carregar_dados_climaticosr      s?   1'2F2F1GqIL++bggll<AS&TU "BGGLLG_,` a "BGGLLG_,` a ||NN?6#:;*+;< 56L M 56H I	%
  $&!$$))Q.<3G3J3J3O3OSU3UV

  ,F366??HV##I.. s   D?E 	EE)r   r   r   c                    t        t        |      }t        j                  j	                  |      }|D ci c]-  }|j
                  t        j                  j	                  |      / }}|D ci c]-  }|j
                  t        j                  j	                  |      / }}|D ci c]-  }|j
                  t        j                  j	                  |      / }}|D ci c]-  }|j
                  t        j                  j	                  |      / }}|D ci c]-  }|j
                  t        j                  j	                  |      / }	}|D ci c]-  }|j
                  t        j                  j	                  |      / }
}t        |      }t        | d|||||||	|
|d	      S c c}w c c}w c c}w c c}w c c}w c c}w )Nr   )r   r   zctermica/lista_ambientes.html)	r   	ambientesparedesvidrosportas_madeiraportas_vidrotelhadostermicosdados_climaticos)r   r   r   r   filterr   r   r   r   r   r   r   r   r   )r   r   r   r   r   ambiente_paredesambiente_vidrosambiente_portas_madeiraambiente_portas_vidroambiente_telhadosambiente_termicosr   s               r!   r   r     s   J7G  '''8I^gh^gRZV^^%:%:H%:%MM^gh\ef\ePXx{{EMM$8$8($8$KK\eOfktukt_gx{{L,@,@,G,GQY,G,ZZktugpqgp[cX[[**<*<*C*CX*C*VVgpq`ij`iT\goo&<&<h&<&OO`ijfopfoZbm&;&;&B&BH&B&UUfop09':#!1-%%,
= 
 
 ifuqjps#   2F$.2F)&2F.2F32F82F=c                    t        t        |      }t        t        ||      }t        j                  j                  |      }t        j                  j                  |      }t        j                  j                  |      }t        j                  j                  |      }t        j                  j                  |      }	t        j                  j                  |      j                         }
t        | d|||||||	|
d      S )Nr   r   r   z!ctermica/resultados_ambiente.html)r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   firstr   )r   r   r   r   r   r   r   r   r   r   r   s              r!   r   r   :  s    J7G k7KHnn##X#6G]]!!8!4F!))00(0CN%%,,h,?L%%x%8H$$++X+>DDFH'>($	A 	 	r#   )0django.shortcutsr   r   r   django.contribr   projeto.modelsr   paredes.formsr   vidros.formsr	   portas.formsr
   r   telhados.formsr   termicos.formsr   paredes.modelsr   vidros.modelsr   portas.modelsr   r   telhados.modelsr   termicos.modelsr   modelsr   ro   pandasr   django.confr   numpyr   r"   r   r   django.httpr   r   r   r   r    r#   r!   <module>r     s}    @ @ # " $ " 9 & , !  2 # )  	    ^>BZIH 9 $=D A @ $6r#   