Files
PROJECT-CONTORL/backend/app/models/workload_snapshot.py
beabigegg 61fe01cb6b feat: implement workload heatmap module
- Backend (FastAPI):
  - Workload heatmap API with load level calculation
  - User workload detail endpoint with task breakdown
  - Redis caching for workload calculations (1hr TTL)
  - Department isolation and access control
  - WorkloadSnapshot model for historical data
  - Alembic migration for workload_snapshots table

- API Endpoints:
  - GET /api/workload/heatmap - Team workload overview
  - GET /api/workload/user/{id} - User workload detail
  - GET /api/workload/me - Current user workload

- Load Levels:
  - normal: <80%, warning: 80-99%, overloaded: >=100%

- Tests:
  - 26 unit/API tests
  - 15 E2E automated tests
  - 77 total tests passing

- OpenSpec:
  - add-resource-workload change archived
  - resource-management spec updated

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-29 01:13:21 +08:00

30 lines
1.3 KiB
Python

import uuid
from sqlalchemy import Column, String, ForeignKey, Date, Integer, Numeric, DateTime, UniqueConstraint, Index
from sqlalchemy.sql import func
from sqlalchemy.orm import relationship
from app.core.database import Base
class WorkloadSnapshot(Base):
"""Stores historical workload snapshots for trend analysis."""
__tablename__ = "pjctrl_workload_snapshots"
id = Column(String(36), primary_key=True, default=lambda: str(uuid.uuid4()))
user_id = Column(String(36), ForeignKey("pjctrl_users.id", ondelete="CASCADE"), nullable=False)
week_start = Column(Date, nullable=False)
allocated_hours = Column(Numeric(8, 2), nullable=False, default=0)
capacity_hours = Column(Numeric(8, 2), nullable=False, default=40)
load_percentage = Column(Numeric(5, 2), nullable=False, default=0)
task_count = Column(Integer, nullable=False, default=0)
created_at = Column(DateTime, server_default=func.now(), nullable=False)
updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now(), nullable=False)
# Relationships
user = relationship("User", backref="workload_snapshots")
# Constraints
__table_args__ = (
UniqueConstraint('user_id', 'week_start', name='uk_user_week'),
Index('idx_workload_week_start', 'week_start'),
)