Spaces:
Sleeping
Sleeping
File size: 2,937 Bytes
55d9355 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | """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 []
|