Visione: quota non prodotta salvata come NaN (value NULL, fail) invece del 422; migrazione 022

Refs #118

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-28 21:21:54 +01:00
parent 4485803122
commit 06f308be6f
15 changed files with 317 additions and 71 deletions
+13 -5
View File
@@ -302,7 +302,7 @@ async def current_cycle_measurements(
return [
{
"subtask_id": m.subtask_id,
"value": float(m.value),
"value": float(m.value) if m.value is not None else None, # #118: NaN
"pass_fail": m.pass_fail,
"measured_at": m.measured_at,
}
@@ -355,7 +355,7 @@ async def save_measurement(
subtask_id: int,
version_id: int,
measured_by: int,
value: float,
value: float | None,
lot_number: str | None = None,
serial_number: str | None = None,
input_method: str = "manual",
@@ -372,8 +372,12 @@ async def save_measurement(
batch of quotes taken at the same instant (see Ruling R10 / vision_service):
the gate models "moving on" between measurements taken one after another,
which does not exist inside a single camera acquisition.
#118: ``value=None`` is a quote the vision graph did not produce (shown as
NaN): saved as a ``fail`` with no deviation. Only the vision path passes it.
"""
_validate_measured_value(value)
if value is not None: # #118: una quota non misurata non ha un valore da validare
_validate_measured_value(value)
# Get subtask for tolerance values
result = await db.execute(
@@ -421,8 +425,12 @@ async def save_measurement(
# Rounded once, here, so the stored value is exactly the one the verdict
# above was computed on - calculate_pass_fail rounds internally too, but
# matching it here keeps the persisted row from disagreeing with itself.
value = round(value, 6)
pass_fail, deviation = calculate_pass_fail(value, subtask)
if value is None:
# #118: quota non prodotta dal grafo -> NaN: fail, nessuna deviazione
pass_fail, deviation = "fail", None
else:
value = round(value, 6)
pass_fail, deviation = calculate_pass_fail(value, subtask)
measurement = Measurement(
subtask_id=subtask_id,