DavidSB commited on
Commit
75d2e54
·
1 Parent(s): 58aed0b

Create mqc.py

Browse files
Files changed (1) hide show
  1. mqc.py +128 -0
mqc.py ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # importando as bibliotecas necessárias
2
+ import gradio as gr
3
+ import pandas as pd
4
+ from datetime import datetime
5
+ from gradio.components import Number, Textbox, Dropdown, Button
6
+ import warnings
7
+ from gradio import Interface # Certifique-se de importar o módulo corretamente
8
+
9
+ # Suprimir todos os avisos durante a execução do script
10
+ warnings.filterwarnings("ignore")
11
+
12
+ def calcular_valor_imovel(area=100, data_refer_str=None, data_const_str="12/2022", tipo_cub="R 1-N (Res. Unifamiliar)", data_cub_str=None, percentual_cub=1, BDI=22.5, tipologia="APARTAMENTOS", estado="B - entre novo e regular", VR=0.2):
13
+ # Carregar dados dos arquivos Excel
14
+ df_cub = pd.read_excel('TABELAS.xlsx', sheet_name='CUB')
15
+ df_vida = pd.read_excel('TABELAS.xlsx', sheet_name='VUTIL')
16
+ df_dep = pd.read_excel('TABELAS.xlsx', sheet_name='DEP')
17
+
18
+ # Converter datas de entrada
19
+ if data_refer_str is None or data_refer_str == "":
20
+ data_refer = datetime.now()
21
+ else:
22
+ data_refer = datetime.strptime(data_refer_str, "%m/%Y")
23
+ data_const = datetime.strptime(data_const_str, "%m/%Y")
24
+ if data_cub_str is None or data_cub_str == "":
25
+ data_cub = datetime.now()
26
+ else:
27
+ data_cub = datetime.strptime(data_cub_str, "%m/%Y")
28
+
29
+ # Filtrar por tipo_cub
30
+ df_tipo_cub = df_cub[df_cub['CÓDIGO'] == tipo_cub]
31
+
32
+ # Obter o valor do CUB na coluna correspondente à data
33
+ valor_cub_column = data_cub.strftime("%m/%Y")
34
+ valor_cub = df_tipo_cub.at[df_tipo_cub.index[0], valor_cub_column]
35
+
36
+ # Idade
37
+ idade = data_refer.toordinal() - data_const.toordinal()
38
+ if idade > 1:
39
+ idade = idade // 365
40
+ else:
41
+ idade = 1
42
+
43
+ # Filtrar por %de Vida
44
+ vdu = df_vida.loc[(df_vida['FINAL'] == tipologia)]
45
+
46
+ # % de vida útil
47
+ percentual_vdu = (idade / vdu['VIDAUTIL']) * 100
48
+ percentual_vdu = int(round(percentual_vdu, 0))
49
+
50
+ if percentual_vdu != 1:
51
+ percentual_vdu = percentual_vdu
52
+ else:
53
+ percentual_vdu = 2
54
+ print(percentual_vdu,"%")
55
+
56
+ # Filtrar conforme o % de vida útil
57
+ df_conserv = df_dep.loc[df_dep['%deVida'] == percentual_vdu]
58
+
59
+ # Converter o valor residual de string para número (float)
60
+ if VR and VR.strip() != "":
61
+ VR = float(VR)
62
+ else:
63
+ VR = 0.0
64
+ # Obter da depreciação
65
+ coef_HH = float(df_conserv[estado]/100)
66
+ coef_HH = round(coef_HH, 2)
67
+
68
+ # Valor do "Kd"
69
+ kd = VR + (1 - coef_HH) * (1 - VR)
70
+ kd = round(kd, 2)
71
+
72
+ # Cálculos
73
+ Valor_sem_deprec = area * valor_cub * percentual_cub * (1 + BDI / 100)
74
+ Valor_sem_deprec = round(Valor_sem_deprec, 2)
75
+ Valor_com_deprec = Valor_sem_deprec * kd
76
+ Valor_com_deprec = round(Valor_com_deprec, 2)
77
+
78
+ resumo = {
79
+ "01":"-------VALOR INICIAL-------",
80
+ "Área construída (m²)": area,
81
+ "Data de referência": data_refer.strftime("%m/%Y"),
82
+ "Data da construção": data_const_str,
83
+ "Data do CUB": data_cub.strftime("%m/%Y"),
84
+ "Tipo de CUB": tipo_cub,
85
+ "Percentual para adequação do CUB (%)": percentual_cub,
86
+ "BDI (%)": BDI,
87
+ "Valor CUB": round(valor_cub, 2),
88
+ "Valor_sem_deprec": Valor_sem_deprec,
89
+ "02":"-----VALOR DEPRECIADO-----",
90
+ "Tipologia": tipologia,
91
+ "Vida útil da tipologia": int(vdu['VIDAUTIL']),
92
+ "Estado de conservação": estado,
93
+ "% de Vida Útil": percentual_vdu,
94
+ "Coeficiente de Depreciação": coef_HH,
95
+ "Valor residual (0, 0.1 ou 0.2)": VR,
96
+ "Kd": kd,
97
+ "Valor final": Valor_com_deprec
98
+ }
99
+
100
+ return resumo
101
+
102
+ # # Define a function to print the outputs
103
+ # def print_outputs(outputs):
104
+ # print(outputs)
105
+
106
+ entradas = [
107
+ gr.inputs.Number(label="Área construída (m²)", default=100),
108
+ gr.inputs.Textbox(label="Data de referência (mm/aaaa)", default=""),
109
+ gr.inputs.Textbox(label="Data da construção (mm/aaaa)", default=""),
110
+ # gr.inputs.Textbox(label="Tipo de CUB", default="R 1-N (Res. Unifamiliar)"),
111
+ gr.inputs.Dropdown(label="Tipo de CUB", choices=["R 1-B (Res. Unifamiliar)", "R 1-N (Res. Unifamiliar)", "R 1-A (Res. Unifamiliar)", "PP 4-B (Prédio Popular)", "PP 4-N (Prédio Popular)", "R 8-B (Res. Multifamiliar)", "R 8-N (Res. Multifamiliar)", "R 8-A (Res. Multifamiliar)", "R 16-N (Res. Multifamiliar)", "R 16-A (Res. Multifamiliar)", "PIS (Projeto Inter. Social)", "RP1Q (Residência Popular)", "CAL 8-N (Com. Andar Livres)", "CAL 8-A (Com. Andar Livres)", "CSL 8-N (Com.Salas e Lojas)", "CSL 8-A (Com.Salas e Lojas)", "CSL 16-N (Com.Salas e Lojas)", "CSL 16-A (Com.Salas e Lojas)", "GI (Galpão Industrial)"]),
112
+ gr.inputs.Textbox(label="Data do CUB (mm/aaaa)", default=""),
113
+ gr.inputs.Number(label="Percentual para adequação do CUB (%)", default=1),
114
+ gr.inputs.Number(label="BDI (%)", default=22.5),
115
+ # gr.inputs.Textbox(label="Tipologia", default="APARTAMENTOS"),
116
+ gr.inputs.Dropdown(label="Tipologia", choices=["APARTAMENTOS", "BANCOS", "CASAS DE ALVENARIA", "CASAS DE MADEIRA", "HOTÉIS", "LOJAS", "TEATROS", "ARMAZÉNS", "FÁBRICAS", "CONST. RURAIS", "GARAGENS", "EDIFÍCIOS DE ESCRITÓRIOS", "GALPÕES (DEPÓSITOS)", "SILOS"]),
117
+ gr.inputs.Dropdown(label="Estado de conservação", choices=["A - novo", "B - entre novo e regular", "C - regular", "D - entre regular e reparos simples", "E - reparos simples", "F - entre reparos simples e importantes", "G - reparos importantes", "H - entre reparos importantes e sem valor"]),
118
+ # gr.inputs.Number(label="Valor residual (0, 0.1 ou 0.2)", default=0.2)
119
+ gr.inputs.Dropdown(label="Valor residual (0, 0.1 ou 0.2)", choices=["0", "0.1", "0.2"])
120
+ ]
121
+
122
+ saida = gr.outputs.JSON()
123
+
124
+ # # Add a button to print the outputs
125
+ # button_print = Button(label="Print Outputs", onclick=print_outputs)
126
+
127
+ interface = gr.Interface(fn=calcular_valor_imovel, inputs=entradas, outputs=saida)
128
+ interface.launch()