CoolFace
Apppublic

pylord/API-BFSI

sourceHugging Faceupdated 11mo agoView on Hugging Face
0likes
models.py46 linesDownload Raw Back to root
1from sqlalchemy import Column, String, Float, Integer, DateTime, JSON, ForeignKey, Text2from sqlalchemy.orm import relationship3from database import Base4from datetime import datetime5 6# ==================== USERS TABLE ====================7class User(Base):8    """9    User table for authentication and user management10    """11    __tablename__ = "users"12 13    email = Column(String(100), primary_key=True, index=True)14    full_name = Column(String(100), nullable=False)15    password = Column(String(150), nullable=False)16    created_at = Column(DateTime, default=datetime.utcnow)17 18    # Relationship to predictions19    predictions = relationship("Prediction", back_populates="user", cascade="all, delete-orphan")20 21    def __repr__(self):22        return f"<User(email={self.email}, full_name={self.full_name})>"23 24 25# ==================== PREDICTIONS TABLE ====================26class Prediction(Base):27    """28    Predictions table for storing fraud detection results29    """30    __tablename__ = "predictions"31 32    id = Column(Integer, primary_key=True, autoincrement=True, index=True)33    customer_id = Column(String(50), nullable=False, index=True)34    transaction_id = Column(String(50), nullable=False, unique=True, index=True)35    email = Column(String(100), ForeignKey("users.email", ondelete="CASCADE"), nullable=False)36    risk_score = Column(Float, nullable=False)37    is_fraud = Column(Integer, nullable=False)38    derived_features = Column(JSON, nullable=False)39    explanation = Column(Text, nullable=True)40    timestamp = Column(DateTime, default=datetime.utcnow, index=True)41 42    # Relationship43    user = relationship("User", back_populates="predictions")44 45    def __repr__(self):46        return f"<Prediction(id={self.id}, transaction_id={self.transaction_id}, is_fraud={self.is_fraud})>"