adicionado modulo trajetoria no health
This commit is contained in:
parent
7b9b815308
commit
9a638aa7a6
|
|
@ -0,0 +1,63 @@
|
|||
import time
|
||||
from shared.contexto_global_redis import ContextoGlobalRedis
|
||||
from shared.enums import StatusModulo, T_Code
|
||||
from health_worker.modulos.base import ModuloDiagnosticoBase
|
||||
|
||||
class ModuloTrajetorira(ModuloDiagnosticoBase):
|
||||
def __init__(self):
|
||||
self.t_code = T_Code.Trj
|
||||
self.nome = "Trajetoria"
|
||||
self.timeout = 5
|
||||
|
||||
def atualizar_saude(self):
|
||||
try:
|
||||
m = ContextoGlobalRedis.get_modulo(self.t_code) or {}
|
||||
_operacao = ContextoGlobalRedis.get_operacao()
|
||||
|
||||
SAUDE_MIN_ALERTA = 50
|
||||
|
||||
op_iniciada = bool(_operacao.get("iniciado", False))
|
||||
carregado = bool(m.get("carregado", False))
|
||||
liberado = bool(m.get("liberado", False))
|
||||
bateria_ok = bool(m.get("bateria_ok", False))
|
||||
herbicida_ok = bool(m.get("herbicida_ok", False))
|
||||
motivo = m.get("motivo", "")
|
||||
|
||||
saude = 100
|
||||
motivos = []
|
||||
|
||||
if op_iniciada:
|
||||
if not carregado:
|
||||
saude -= 100
|
||||
motivos.append("mapa não carregado")
|
||||
else:
|
||||
if not bateria_ok:
|
||||
saude -= 50
|
||||
if not herbicida_ok:
|
||||
saude -= 50
|
||||
motivos.append(motivo)
|
||||
|
||||
saude = max(saude, 0)
|
||||
|
||||
status = StatusModulo.OPERANTE
|
||||
if op_iniciada and not carregado:
|
||||
status = StatusModulo.DESCONECTADO
|
||||
elif saude < SAUDE_MIN_ALERTA:
|
||||
status = StatusModulo.ALERTA
|
||||
|
||||
payload = {
|
||||
"carregado": carregado,
|
||||
"status": status.value,
|
||||
"saude": saude,
|
||||
"motivos": motivos,
|
||||
"saude_individual": [],
|
||||
"condicoes_operacionais": []
|
||||
}
|
||||
|
||||
ContextoGlobalRedis.atualizar_ctx_dict(
|
||||
ContextoGlobalRedis.ModKey(self.t_code),
|
||||
saude=payload
|
||||
)
|
||||
except Exception as e:
|
||||
print(f"Erro ao atualizar saude do modulo {self.t_code.name}: {e}")
|
||||
|
||||
Loading…
Reference in New Issue