Etichette uscite visione: count/n_points/area non ereditano la quantità del tool, ratio in %. Refs #112
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -217,6 +217,14 @@ def _is_number(value: Any) -> bool:
|
|||||||
return isinstance(value, (int, float)) and not isinstance(value, bool)
|
return isinstance(value, (int, float)) and not isinstance(value, bool)
|
||||||
|
|
||||||
|
|
||||||
|
# #112: quantity/unit delle uscite che il tool non dichiara in value_quantities
|
||||||
|
_ETICHETTE_EXTRA = {
|
||||||
|
"count": ("count", "pz"),
|
||||||
|
"n_points": ("count", "punti"),
|
||||||
|
"area": ("area", "px²"),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def validate_graph(
|
def validate_graph(
|
||||||
graph: dict, recipe_dir: Any = None
|
graph: dict, recipe_dir: Any = None
|
||||||
) -> tuple[bool, list[str], list[dict]]:
|
) -> tuple[bool, list[str], list[dict]]:
|
||||||
@@ -245,7 +253,11 @@ def validate_graph(
|
|||||||
for prop in tool.outputs():
|
for prop in tool.outputs():
|
||||||
if not (_is_number(prop.default) or prop.name in values):
|
if not (_is_number(prop.default) or prop.name in values):
|
||||||
continue
|
continue
|
||||||
|
if prop.name in values:
|
||||||
quantity = value_quantities.get(prop.name, getattr(tool, "quantity", None))
|
quantity = value_quantities.get(prop.name, getattr(tool, "quantity", None))
|
||||||
|
else:
|
||||||
|
# #112: fuori da values mai ereditare tool.quantity (count/area non sono lunghezze)
|
||||||
|
quantity = value_quantities.get(prop.name)
|
||||||
if not isinstance(quantity, str):
|
if not isinstance(quantity, str):
|
||||||
quantity = None
|
quantity = None
|
||||||
unit = None
|
unit = None
|
||||||
@@ -254,6 +266,11 @@ def validate_graph(
|
|||||||
unit = nominal_unit if isinstance(nominal_unit, str) else None
|
unit = nominal_unit if isinstance(nominal_unit, str) else None
|
||||||
elif quantity == "angle":
|
elif quantity == "angle":
|
||||||
unit = "deg"
|
unit = "deg"
|
||||||
|
elif quantity == "ratio":
|
||||||
|
unit = "%" # #112: rapporti (points_in_pct) in percentuale
|
||||||
|
if quantity is None and prop.name not in values:
|
||||||
|
# #112: etichette delle uscite note non dichiarate dal tool
|
||||||
|
quantity, unit = _ETICHETTE_EXTRA.get(prop.name, (None, None))
|
||||||
outputs.append({
|
outputs.append({
|
||||||
"key": f"{tool.id}.{prop.name}",
|
"key": f"{tool.id}.{prop.name}",
|
||||||
"quantity": quantity,
|
"quantity": quantity,
|
||||||
|
|||||||
@@ -288,3 +288,28 @@ def test_validate_reports_a_missing_file(tmp_path):
|
|||||||
ok, errors, outputs = runner.validate_graph(_dxf_recipe(), tmp_path)
|
ok, errors, outputs = runner.validate_graph(_dxf_recipe(), tmp_path)
|
||||||
|
|
||||||
assert not ok and errors and outputs == []
|
assert not ok and errors and outputs == []
|
||||||
|
|
||||||
|
|
||||||
|
def test_validate_labels_wizard_outputs(tmp_path):
|
||||||
|
"""#112: count/n_points/area non ereditano la quantita' del tool, ratio in %."""
|
||||||
|
from src.vision import costruttori
|
||||||
|
|
||||||
|
dxf_bytes = _SAMPLE_DXF.read_bytes()
|
||||||
|
cal_bytes = b'{"px_per_mm": 4.0}'
|
||||||
|
(tmp_path / costruttori.DXF_FILE).write_bytes(dxf_bytes)
|
||||||
|
(tmp_path / costruttori.CALIBRATION_FILE).write_bytes(cal_bytes)
|
||||||
|
graph = costruttori._graph(
|
||||||
|
hashlib.sha256(dxf_bytes).hexdigest(), hashlib.sha256(cal_bytes).hexdigest(),
|
||||||
|
1.0, 95.0, "dark", {"row": 0.0, "col": 0.0, "angle_deg": 0.0},
|
||||||
|
(0.0, 0.0, 0.0),
|
||||||
|
)
|
||||||
|
|
||||||
|
ok, errors, outputs = runner.validate_graph(graph, tmp_path)
|
||||||
|
|
||||||
|
assert ok, errors
|
||||||
|
by_key = {o["key"]: (o["quantity"], o["unit"]) for o in outputs}
|
||||||
|
assert by_key["pezzo.count"] == ("count", "pz")
|
||||||
|
assert by_key["pezzo.area"] == ("area", "px²")
|
||||||
|
assert by_key["dxf.n_points"] == ("count", "punti")
|
||||||
|
assert by_key["dxf.points_in_pct"] == ("ratio", "%")
|
||||||
|
assert by_key["dxf.distance_max"] == ("length", "mm")
|
||||||
|
|||||||
Reference in New Issue
Block a user