Files
TieMeasureFlow/server/models/measurement.py
Adriano dd2ebf863a feat: FASE 7 - Polish & Testing (security, i18n, test suite, docs)
Security hardening: CORS lockdown, rate limiting middleware con sliding
window e eviction IP stale, security headers (CSP, HSTS, X-Frame-Options),
session cookie hardening, filename sanitization upload.

i18n completion: internazionalizzati barcode.js e csv-export.js con bridge
window.BARCODE_I18N/CSV_I18N, aggiornati .po IT/EN con 27 nuove stringhe.

Tablet UX: touch target 44px per dispositivi coarse pointer.

Test suite: 101 test totali (76 server + 25 client), copertura completa
di tutti i router API, autenticazione, ruoli, CRUD, SPC, file upload,
security integration. Infrastruttura SQLite async in-memory con fixtures.

Fix critici: MissingGreenlet in recipe_service (selectinload eager),
route ordering tasks.py, auth_service bcrypt diretto, Measurement.id
Integer per SQLite.

Documentazione: API.md (riferimento completo 40+ endpoint),
DEPLOYMENT.md (guida produzione con Docker/Nginx/SSL),
USER_GUIDE.md (manuale utente per ruolo).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 17:10:24 +01:00

56 lines
1.9 KiB
Python

"""Measurement model for storing individual measurements."""
from datetime import datetime
from typing import Optional
from sqlalchemy import (
BigInteger, Boolean, DECIMAL, DateTime, Enum, ForeignKey,
Integer, String, func,
)
from sqlalchemy.orm import Mapped, mapped_column
from database import Base
class Measurement(Base):
__tablename__ = "measurements"
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
subtask_id: Mapped[int] = mapped_column(
Integer, ForeignKey("recipe_subtasks.id"), nullable=False, index=True
)
version_id: Mapped[int] = mapped_column(
Integer, ForeignKey("recipe_versions.id"), nullable=False, index=True
)
measured_by: Mapped[int] = mapped_column(
Integer, ForeignKey("users.id"), nullable=False, index=True
)
# Measurement data
value: Mapped[float] = mapped_column(DECIMAL(12, 6), nullable=False)
pass_fail: Mapped[str] = mapped_column(
Enum("pass", "warning", "fail", name="pass_fail_enum"), nullable=False
)
deviation: Mapped[Optional[float]] = mapped_column(DECIMAL(12, 6), nullable=True)
# Traceability
lot_number: Mapped[Optional[str]] = mapped_column(String(100), nullable=True, index=True)
serial_number: Mapped[Optional[str]] = mapped_column(String(100), nullable=True, index=True)
# Input method
input_method: Mapped[str] = mapped_column(
Enum("usb_caliper", "manual", name="input_method_enum"),
nullable=False,
default="manual",
)
# Timestamp
measured_at: Mapped[datetime] = mapped_column(
DateTime, nullable=False, server_default=func.now(), index=True
)
# CSV sync flag
synced_to_csv: Mapped[bool] = mapped_column(Boolean, default=False)
def __repr__(self) -> str:
return f"<Measurement subtask={self.subtask_id} value={self.value} {self.pass_fail}>"