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:
@@ -0,0 +1,153 @@
|
||||
"""Paso 7: topología AR-NMEA-IO + asignación automática de I/O.
|
||||
|
||||
Genera tarjetas + bindings físicos de cada sensor declarado en
|
||||
EquipmentModel.default_sensors. El integrador puede ajustar después en el
|
||||
editor de topología (Sprint 3+).
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from PySide6.QtCore import Property, Signal
|
||||
from PySide6.QtWidgets import (
|
||||
QHeaderView,
|
||||
QLabel,
|
||||
QTableWidget,
|
||||
QTableWidgetItem,
|
||||
QVBoxLayout,
|
||||
QWidget,
|
||||
QWizardPage,
|
||||
)
|
||||
|
||||
from vmssailor.core.equipment import Equipment
|
||||
from vmssailor.library import load_library
|
||||
from vmssailor.studio.designer.port_auto_assigner import (
|
||||
AssignmentReport,
|
||||
auto_assign,
|
||||
)
|
||||
from vmssailor.studio.designer.rule_engine import EquipmentProposal
|
||||
from vmssailor.studio.theme import C_FOG, mono_font, ui_font
|
||||
|
||||
|
||||
class Step07Topology(QWizardPage):
|
||||
"""Vista previa de la topología auto-asignada."""
|
||||
|
||||
def __init__(self, parent: QWidget | None = None) -> None:
|
||||
super().__init__(parent)
|
||||
self.setTitle("Paso 7 · Topología AR-NMEA-IO")
|
||||
self.setSubTitle(
|
||||
"Asignación automática de tarjetas y canales físicos. "
|
||||
"Capacidad por tarjeta: 10 DO · 5 DI · 1 RPM · 4 AI."
|
||||
)
|
||||
|
||||
layout = QVBoxLayout(self)
|
||||
layout.setSpacing(10)
|
||||
|
||||
self._summary = QLabel("")
|
||||
self._summary.setFont(ui_font(11))
|
||||
layout.addWidget(self._summary)
|
||||
|
||||
self._table = QTableWidget(0, 4)
|
||||
self._table.setHorizontalHeaderLabels(
|
||||
["Tarjeta", "Slot · Addr", "DO/DI/AI/RPM usados", "Ubicación"]
|
||||
)
|
||||
self._table.horizontalHeader().setSectionResizeMode(
|
||||
3, QHeaderView.ResizeMode.Stretch
|
||||
)
|
||||
self._table.verticalHeader().setVisible(False)
|
||||
layout.addWidget(self._table, 1)
|
||||
|
||||
self._warnings = QLabel("")
|
||||
self._warnings.setWordWrap(True)
|
||||
self._warnings.setFont(mono_font(9))
|
||||
self._warnings.setStyleSheet(f"color: {C_FOG};")
|
||||
layout.addWidget(self._warnings)
|
||||
|
||||
self._assignment: AssignmentReport | None = None
|
||||
|
||||
from vmssailor.studio.wizard.wizard import F_ASSIGNMENT
|
||||
|
||||
self.registerField(F_ASSIGNMENT, self, "assignment", "assignmentChanged")
|
||||
|
||||
# Property API
|
||||
assignmentChanged = Signal()
|
||||
|
||||
def get_assignment(self) -> AssignmentReport | None:
|
||||
return self._assignment
|
||||
|
||||
def set_assignment(self, value: AssignmentReport) -> None:
|
||||
self._assignment = value
|
||||
self.assignmentChanged.emit()
|
||||
|
||||
assignment = Property(
|
||||
object, fget=get_assignment, fset=set_assignment, notify=assignmentChanged
|
||||
)
|
||||
|
||||
def initializePage(self) -> None:
|
||||
from vmssailor.studio.wizard.wizard import F_PROPOSALS
|
||||
|
||||
proposals: list[EquipmentProposal] = self.field(F_PROPOSALS) or []
|
||||
if not proposals:
|
||||
self._summary.setText("Sin equipos. Vuelve al paso 5.")
|
||||
self._table.setRowCount(0)
|
||||
return
|
||||
|
||||
# Materialize Equipment objects so we can run the assigner
|
||||
equipment_list: list[Equipment] = []
|
||||
for idx, p in enumerate(proposals):
|
||||
from vmssailor.core.coords import ShipCoord
|
||||
|
||||
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=ShipCoord(
|
||||
x_pp=p.location_x_pp,
|
||||
y_cl=p.location_y_cl,
|
||||
z_bl=p.location_z_bl,
|
||||
),
|
||||
system_id=p.system_id,
|
||||
)
|
||||
)
|
||||
|
||||
# Cargar modelos de biblioteca
|
||||
try:
|
||||
lib = load_library()
|
||||
model_lookup = {m.id: m for m in lib.equipment_models}
|
||||
except Exception:
|
||||
model_lookup = {}
|
||||
|
||||
report = auto_assign(equipment_list, model_lookup)
|
||||
self._assignment = report
|
||||
|
||||
self._summary.setText(
|
||||
f"<b>{len(report.cards)}</b> tarjetas · "
|
||||
f"<b>{len(report.tags)}</b> tags asignados · "
|
||||
f"<b>{report.n_skipped}</b> sin tipo de señal · "
|
||||
f"bus: <b>{report.bus.id if report.bus else '—'}</b>"
|
||||
)
|
||||
|
||||
self._table.setRowCount(len(report.cards))
|
||||
capacities: dict[str, dict[str, int]] = {}
|
||||
for t in report.tags:
|
||||
if t.physical_binding:
|
||||
cid = t.physical_binding.card_id
|
||||
ch = t.physical_binding.channel_type.value.upper()
|
||||
capacities.setdefault(cid, {"DO": 0, "DI": 0, "AI": 0, "RPM": 0})
|
||||
capacities[cid][ch] = capacities[cid].get(ch, 0) + 1
|
||||
|
||||
for row, c in enumerate(report.cards):
|
||||
self._table.setItem(row, 0, QTableWidgetItem(c.id))
|
||||
self._table.setItem(row, 1, QTableWidgetItem(f"slot {c.slot_number} · addr {c.modbus_address}"))
|
||||
cap = capacities.get(c.id, {})
|
||||
usage = f"DO {cap.get('DO', 0)}/10 · DI {cap.get('DI', 0)}/5 · AI {cap.get('AI', 0)}/4 · RPM {cap.get('RPM', 0)}/1"
|
||||
self._table.setItem(row, 2, QTableWidgetItem(usage))
|
||||
self._table.setItem(row, 3, QTableWidgetItem(c.physical_location))
|
||||
self._table.resizeColumnsToContents()
|
||||
|
||||
if report.warnings:
|
||||
self._warnings.setText("\n".join(report.warnings[:6]))
|
||||
else:
|
||||
self._warnings.setText("✓ Sin conflictos de capacidad detectados.")
|
||||
self.assignmentChanged.emit()
|
||||
Reference in New Issue
Block a user