File size: 1,184 Bytes
6a6918c
 
 
 
 
f4bcb74
6a6918c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from sqlalchemy import create_engine, Column, Integer, String, Float, DateTime, LargeBinary
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker

# Define the database connection URL
DATABASE_URL = "sqlite:////tmp/ship_draft_reports.db"

# Create the SQLAlchemy engine
engine = create_engine(
    DATABASE_URL, connect_args={"check_same_thread": False} # check_same_thread is for SQLite only
)

# Create a session factory
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)

# Create a base class for declarative models
Base = declarative_base()

# Define the Report model
class Report(Base):
    __tablename__ = "reports"

    id = Column(Integer, primary_key=True, index=True)
    ship_id = Column(String, index=True)
    timestamp = Column(DateTime)
    latitude = Column(Float)
    longitude = Column(Float)
    draft_measurement = Column(Float)
    confidence_score = Column(Float) # New field
    pdf_path = Column(String, unique=True)
    image_bytes = Column(LargeBinary) # New field

def create_db_and_tables():
    """Function to create the database and tables."""
    Base.metadata.create_all(bind=engine)