mirror of
https://github.com/maziggy/bambuddy.git
synced 2026-09-30 19:21:33 +02:00
- Add database model for storing AMS sensor history (humidity, temperature) - Record sensor data every 5 minutes via background task - Add API endpoint to retrieve history with min/max/avg statistics - Create AMSHistoryModal component with Recharts line charts - Make humidity/temperature indicators clickable to open history - Support time range selection (6h, 24h, 48h, 7d) - Show threshold reference lines on charts (Good/Fair levels) - Add configurable data retention (default 30 days) in Settings - Auto-cleanup old data daily - Fix dark theme styling in modal using inline styles - Add Escape key to close modal
56 lines
2.4 KiB
Python
56 lines
2.4 KiB
Python
from datetime import datetime
|
|
from sqlalchemy import String, Boolean, DateTime, Float, func
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from backend.app.core.database import Base
|
|
|
|
|
|
class Printer(Base):
|
|
__tablename__ = "printers"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
name: Mapped[str] = mapped_column(String(100))
|
|
serial_number: Mapped[str] = mapped_column(String(50), unique=True)
|
|
ip_address: Mapped[str] = mapped_column(String(45))
|
|
access_code: Mapped[str] = mapped_column(String(20))
|
|
model: Mapped[str | None] = mapped_column(String(50))
|
|
location: Mapped[str | None] = mapped_column(String(100)) # Group/location name
|
|
nozzle_count: Mapped[int] = mapped_column(default=1) # 1 or 2, auto-detected from MQTT
|
|
is_active: Mapped[bool] = mapped_column(Boolean, default=True)
|
|
auto_archive: Mapped[bool] = mapped_column(Boolean, default=True)
|
|
print_hours_offset: Mapped[float] = mapped_column(Float, default=0.0) # Baseline hours to add
|
|
created_at: Mapped[datetime] = mapped_column(
|
|
DateTime, server_default=func.now()
|
|
)
|
|
updated_at: Mapped[datetime] = mapped_column(
|
|
DateTime, server_default=func.now(), onupdate=func.now()
|
|
)
|
|
|
|
# Relationships
|
|
archives: Mapped[list["PrintArchive"]] = relationship(
|
|
back_populates="printer", cascade="all, delete-orphan"
|
|
)
|
|
smart_plug: Mapped["SmartPlug | None"] = relationship(
|
|
back_populates="printer", uselist=False
|
|
)
|
|
notification_providers: Mapped[list["NotificationProvider"]] = relationship(
|
|
back_populates="printer"
|
|
)
|
|
maintenance_items: Mapped[list["PrinterMaintenance"]] = relationship(
|
|
back_populates="printer", cascade="all, delete-orphan"
|
|
)
|
|
kprofile_notes: Mapped[list["KProfileNote"]] = relationship(
|
|
back_populates="printer", cascade="all, delete-orphan"
|
|
)
|
|
ams_history: Mapped[list["AMSSensorHistory"]] = relationship(
|
|
back_populates="printer", cascade="all, delete-orphan"
|
|
)
|
|
|
|
|
|
from backend.app.models.archive import PrintArchive # noqa: E402
|
|
from backend.app.models.ams_history import AMSSensorHistory # noqa: E402
|
|
from backend.app.models.kprofile_note import KProfileNote # noqa: E402
|
|
from backend.app.models.smart_plug import SmartPlug # noqa: E402
|
|
from backend.app.models.notification import NotificationProvider # noqa: E402
|
|
from backend.app.models.maintenance import PrinterMaintenance # noqa: E402
|