Files
AidsMonitoring/backend/models/lamp.py
T
alro65 cfd94f905a security: CORS hardening, path traversal fix, WebSocket auth + cleanup
- Restrict CORS to localhost origins (was allow_origins=[*])
- Require valid JWT on WebSocket /ws (anonymous no longer gets admin view)
- Fix path traversal in delete_cell(): resolve() + parent check
- Validate cell_id format in /charts/download-noaa/{cell_id}
- Exclude charts/ and Cartas/ from git (keep US1GC09M world overview)
- Add NOAA ENC Portal external link in charts catalog tab
- Untrack __pycache__/, .db, .claude/ session files

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-03 12:45:43 -04:00

30 lines
1.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from sqlalchemy import Column, String, Float, Integer, Text, DateTime
from sqlalchemy.sql import func
from database import Base
class Lamp(Base):
"""Marine navigation lamp catalog. Aids reference a Lamp by id; the
battery warning/alarm thresholds for each Aid are computed from the
lamp's voltage_min / voltage_max:
warn = voltage_min + (voltage_max - voltage_min) * 0.20
alarm = voltage_min + (voltage_max - voltage_min) * 0.10
"""
__tablename__ = "lamps"
id = Column(String, primary_key=True)
manufacturer = Column(String, nullable=False)
model = Column(String, nullable=False)
lamp_count = Column(Integer, default=1)
voltage_min = Column(Float, nullable=False) # discharged threshold (V)
voltage_max = Column(Float, nullable=False) # fully-charged nominal (V)
# Battery alert thresholds as % of usable voltage range.
# warn_pct=20 means: alert when remaining capacity ≤ 20% of (maxmin).
# Defaults match the original hardcoded values (20% / 10%).
# Override per lamp model — e.g. Sabik recommends 30%/15%.
warn_pct = Column(Float, default=20.0) # % of range → warning
alarm_pct = Column(Float, default=10.0) # % of range → alarm
notes = Column(Text, nullable=True)
creado_en = Column(DateTime, server_default=func.now())
modificado_en = Column(DateTime, onupdate=func.now())