teste_docs / document /evo_adjustments.py
gui-sparim's picture
Publica gerador evolutivo e carrega modelos do repositório MESA
55d9355 verified
Raw History Blame Contribute Delete
2.94 kB
"""Select adjustments from saved effects, never from a checkbox alone."""
from .fundamentacao import number
REDUCERS = {
'redutor88I': ('Art. 88, inciso I', 'Art. 88, inciso I — total'),
'redutor6061': ('Art. 60 e 61', 'Art. 60 e 61 — aplicado'),
'redutorTopografia': ('Topografia', 'Topografia — total'),
'redutorAgua': ('Inundação e ação da água', 'Inundação — aplicado'),
'redutor88II': ('Art. 88, inciso II', 'Redução total do imóvel'),
}
def saved_result(row):
return (row.get('evolutivo') or {}).get('resultadoComposicao') or {}
def saved_step(row, code):
return next((s for s in saved_result(row).get('memoria') or []
if isinstance(s, dict) and s.get('codigo') == code), {})
def step_has_effect(step):
# The applied factor takes precedence over a selected/reference percentage.
factor = number(step.get('fator'))
if factor is not None:
return factor != 1
rate = number(step.get('percentualReducao'))
return rate != 0 if rate is not None else True # Unknown is not zero.
def visible_memory(row):
return [s for s in saved_result(row).get('memoria') or [] if isinstance(s, dict)
and (s.get('codigo') not in ('redutores_terreno', 'redutores_imovel') or step_has_effect(s))]
def reducer_rate(row, key):
values = saved_result(row)
if key in values:
return number(values[key])
if key == 'redutor88II' and 'redutorImovel' in values:
return number(values['redutorImovel'])
code = 'redutores_imovel' if key == 'redutor88II' else 'redutores_terreno'
for component in saved_step(row, code).get('componentes') or []:
if isinstance(component,dict) and component.get('rotulo') == REDUCERS[key][0]:
return number(component.get('reducao'))
return None
def applied_reducers(row, territorial):
code = 'redutores_terreno' if territorial else 'redutores_imovel'
step = saved_step(row, code)
# Explicitly neutral execution wins over selected components, including caps.
if step and not step_has_effect(step):
return []
keys = list(REDUCERS)[:4] if territorial else ['redutor88II']
items = [(key, REDUCERS[key][0], reducer_rate(row, key)) for key in keys
if reducer_rate(row, key) is not None and reducer_rate(row, key) > 0]
if items:
return items
aggregate_key = 'redutorTerreno' if territorial else 'redutorImovel'
rate = number(saved_result(row).get(aggregate_key))
if rate is None and step:
factor = number(step.get('fator'))
rate = 1-factor if factor is not None else number(step.get('percentualReducao'))
if rate is not None and rate <= 0:
return []
if (rate is not None and rate > 0) or (step and step_has_effect(step)):
return [(aggregate_key, 'Redução territorial registrada' if territorial else 'Redução do imóvel registrada', rate)]
return []