sprint-2: rule engine + auto-assigner + equipment editor + biblioteca
Wizard pasos 5-7 ahora funcionales (1-4 ya estaban en Sprint 1).
vmssailor/studio/designer/rule_engine.py
- RuleContext, RuleEngine, EquipmentProposal
- Lee library/rules/*.yaml y aplica reglas heuristicas
- Filtra por vessel_type, vessel_subtype, length_overall_m range
- Selecciona candidato segun condiciones 'when' (loa min/max)
- Genera tag_prefix con sustitucion {side}/{idx}
vmssailor/studio/designer/port_auto_assigner.py
- auto_assign() greedy: 1 bus Modbus RTU + tarjetas dedicadas para motores/gensets
- Tarjeta auxiliar compartida para resto de equipos
- Mapea SignalType -> ChannelType (AI/DI/DO/RPM)
- Genera TagBindings con scaling apropiado por tipo de senal
- Respeta capacidades 10/5/4/1 de AR-NMEA-IO-v1.0
- AssignmentReport con cards + tags + warnings
vmssailor/studio/wizard/step_05_equipment.py
- Tabla con propuestas del rule engine
- Checkboxes accept/reject + edicion inline de columnas
- Boton 'Regenerar' para re-aplicar reglas
vmssailor/studio/wizard/step_06_refinement.py
- Vista resumen de equipos aceptados
vmssailor/studio/wizard/step_07_topology.py
- Llama auto_assign sobre los equipos materializados
- Muestra tabla de tarjetas con uso por canal (DO/DI/AI/RPM)
- Lista warnings de capacidad
vmssailor/studio/editors/equipment_editor.py
- CRUD de Equipment del proyecto activo
- Tabla editable inline (tag_prefix, name, model_ref, system_id, coords, deck)
- Dialog modal para agregar equipos
- Senal projectMutated para refrescar canvas + sidebar
vmssailor/studio/main_window.py
- Layout actualizado: splitter vertical en panel derecho
(canvas arriba + equipment editor abajo)
- _on_project_mutated() re-distribuye al sidebar y canvas
Biblioteca expandida (Sprint 2 brief: 5-7 yates, 10+ motores, gensets, bombas):
- vessels: + azimut_grande_32m, princess_y85, trawler_32m_offshore, patrol_coastal_30m (total: 6)
- engines: + cat_c32_acert, mtu_16v_2000_m96, yanmar_8lv_370 (total: 5)
- gensets: + kohler_28efkozd, onan_qd13500 (total: 3)
- pumps: + jabsco_36800, grundfos_cm10 (NUEVO categoria pumps)
Tests (tests/studio/test_designer.py, 10 nuevos, total 120/120):
- Rule engine: load default, propose engines, candidate picking por LOA
- auto_assign builds topology compatible with Project (Pydantic validation)
- Equipment editor smoke
VesselWizard.build_project() ahora materializa equipment + topology + tags
desde las propuestas y la asignacion automatica del paso 7.
Criterios Sprint 2:
- uv run vms-studio crea proyecto completo desde wizard con equipos + tags + topologia
- vms-validate-library: OK 6 vessels, 10 equipment, 1 rules
- 120/120 pytest verde, ruff clean
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
"""QWizard contenedor + builder de Project a partir del estado del wizard."""
|
||||
"""QWizard contenedor + builder de Project a partir del estado del wizard.
|
||||
|
||||
Sprint 1: pasos 1-4 funcionales, 5-7 placeholders, 8 confirm.
|
||||
Sprint 2: pasos 5-7 funcionales con rule engine + auto-assigner.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -7,6 +11,7 @@ import logging
|
||||
from PySide6.QtWidgets import QWidget, QWizard
|
||||
|
||||
from vmssailor.core import (
|
||||
Equipment,
|
||||
Project,
|
||||
SystemId,
|
||||
Vessel,
|
||||
@@ -15,16 +20,15 @@ from vmssailor.core import (
|
||||
)
|
||||
from vmssailor.core.vessel import Bulkhead, Deck
|
||||
from vmssailor.shared.ids import make_project_id
|
||||
from vmssailor.studio.theme import (
|
||||
C_ABYSS,
|
||||
C_SAND,
|
||||
)
|
||||
from vmssailor.studio.theme import C_ABYSS, C_SAND
|
||||
from vmssailor.studio.wizard.step_01_vessel_type import Step01VesselType
|
||||
from vmssailor.studio.wizard.step_02_template import Step02Template
|
||||
from vmssailor.studio.wizard.step_03_dimensions import Step03Dimensions
|
||||
from vmssailor.studio.wizard.step_04_systems import Step04Systems
|
||||
from vmssailor.studio.wizard.step_05_equipment import Step05Equipment
|
||||
from vmssailor.studio.wizard.step_06_refinement import Step06Refinement
|
||||
from vmssailor.studio.wizard.step_07_topology import Step07Topology
|
||||
from vmssailor.studio.wizard.step_08_confirm import Step08Confirm
|
||||
from vmssailor.studio.wizard.step_57_placeholder import Step57Placeholder
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -42,6 +46,8 @@ F_DRAFT = "vessel.draft_m"
|
||||
F_BULKHEAD_FWD = "vessel.bulkhead_fwd_m"
|
||||
F_BULKHEAD_AFT = "vessel.bulkhead_aft_m"
|
||||
F_SYSTEMS = "systems.enabled"
|
||||
F_PROPOSALS = "equipment.proposals"
|
||||
F_ASSIGNMENT = "topology.assignment"
|
||||
|
||||
|
||||
class VesselWizard(QWizard):
|
||||
@@ -61,9 +67,9 @@ class VesselWizard(QWizard):
|
||||
self.addPage(Step02Template())
|
||||
self.addPage(Step03Dimensions())
|
||||
self.addPage(Step04Systems())
|
||||
self.addPage(Step57Placeholder(index=5, title="Equipos sugeridos (Sprint 2)"))
|
||||
self.addPage(Step57Placeholder(index=6, title="Refinamiento manual (Sprint 2)"))
|
||||
self.addPage(Step57Placeholder(index=7, title="Topología I/O AR-NMEA-IO (Sprint 2)"))
|
||||
self.addPage(Step05Equipment())
|
||||
self.addPage(Step06Refinement())
|
||||
self.addPage(Step07Topology())
|
||||
self.addPage(Step08Confirm())
|
||||
|
||||
# Style
|
||||
@@ -75,7 +81,6 @@ class VesselWizard(QWizard):
|
||||
"""
|
||||
)
|
||||
|
||||
# Localización de botones (QWizard usa textos del sistema)
|
||||
self.setButtonText(QWizard.NextButton, "Siguiente >")
|
||||
self.setButtonText(QWizard.BackButton, "< Atrás")
|
||||
self.setButtonText(QWizard.FinishButton, "Crear proyecto")
|
||||
@@ -97,7 +102,6 @@ class VesselWizard(QWizard):
|
||||
bh_aft = float(self.field(F_BULKHEAD_AFT) or (loa * 0.15))
|
||||
systems_raw = self.field(F_SYSTEMS) or [SystemId.MAIN_ENGINE.value]
|
||||
|
||||
# Build vessel
|
||||
decks = [
|
||||
Deck(id="lower", name="Cubierta inferior", z_bl_bottom=0.4, z_bl_top=draft + 1.0),
|
||||
Deck(
|
||||
@@ -111,37 +115,65 @@ class VesselWizard(QWizard):
|
||||
Bulkhead(id="er_aft", name="Mamparo popa SM", x_pp=bh_aft),
|
||||
Bulkhead(id="er_fwd", name="Mamparo proa SM", x_pp=bh_fwd),
|
||||
]
|
||||
try:
|
||||
vessel = Vessel(
|
||||
id=f"wizard_{int(loa * 10)}m",
|
||||
name=vessel_name,
|
||||
type=VesselType(v_type),
|
||||
subtype=VesselSubtype(v_sub),
|
||||
length_overall_m=loa,
|
||||
beam_max_m=beam,
|
||||
draft_m=draft,
|
||||
decks=decks,
|
||||
bulkheads=bulkheads,
|
||||
data_source="user_input",
|
||||
)
|
||||
except Exception as exc:
|
||||
logger.error("Vessel build failed: %s", exc)
|
||||
raise
|
||||
vessel = Vessel(
|
||||
id=f"wizard_{int(loa * 10)}m",
|
||||
name=vessel_name,
|
||||
type=VesselType(v_type),
|
||||
subtype=VesselSubtype(v_sub),
|
||||
length_overall_m=loa,
|
||||
beam_max_m=beam,
|
||||
draft_m=draft,
|
||||
decks=decks,
|
||||
bulkheads=bulkheads,
|
||||
data_source="user_input",
|
||||
)
|
||||
|
||||
# Equipment + tags llegan en Sprint 2 (rule engine). Por ahora, vacío.
|
||||
try:
|
||||
systems_enabled = [SystemId(s) for s in systems_raw]
|
||||
except ValueError:
|
||||
systems_enabled = [SystemId.MAIN_ENGINE]
|
||||
|
||||
# Sprint 2: materializar Equipment desde las propuestas aceptadas
|
||||
proposals = self.field(F_PROPOSALS) or []
|
||||
equipment_list: list[Equipment] = []
|
||||
for idx, p in enumerate(proposals):
|
||||
equipment_list.append(
|
||||
Equipment(
|
||||
id=f"eq_{idx:03d}_{p.tag_prefix.lower()}",
|
||||
model_ref=p.model_ref,
|
||||
tag_prefix=p.tag_prefix,
|
||||
display_name=p.display_name,
|
||||
location=p.to_ship_coord(),
|
||||
system_id=p.system_id,
|
||||
)
|
||||
)
|
||||
|
||||
# Topología + tags del auto-assigner
|
||||
assignment = self.field(F_ASSIGNMENT)
|
||||
topology = assignment.topology() if assignment is not None else None
|
||||
tags = list(assignment.tags) if assignment is not None else []
|
||||
|
||||
project_id = make_project_id(customer or "cliente", vessel.id)
|
||||
|
||||
if topology is not None:
|
||||
return Project(
|
||||
id=project_id,
|
||||
name=project_name,
|
||||
customer=customer,
|
||||
vessel=vessel,
|
||||
systems_enabled=systems_enabled,
|
||||
equipment=equipment_list,
|
||||
tags=tags,
|
||||
topology=topology,
|
||||
notes="Creado desde wizard (Sprint 2 — rule engine + auto-assigner).",
|
||||
)
|
||||
return Project(
|
||||
id=project_id,
|
||||
name=project_name,
|
||||
customer=customer,
|
||||
vessel=vessel,
|
||||
systems_enabled=systems_enabled,
|
||||
equipment=[],
|
||||
tags=[],
|
||||
notes="Creado desde wizard Sprint 1. Sprint 2 agregará equipos sugeridos.",
|
||||
equipment=equipment_list,
|
||||
tags=tags,
|
||||
notes="Creado desde wizard (Sprint 2 — rule engine + auto-assigner).",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user