Squashed 'core/' content from commit 92ec910
git-subtree-dir: core git-subtree-split: 92ec910a132e379a3a6e442a75bcb07cac0f0010
This commit is contained in:
48
backend/app/models/prediction.py
Normal file
48
backend/app/models/prediction.py
Normal file
@@ -0,0 +1,48 @@
|
||||
from sqlalchemy import Column, Integer, String, Float, DateTime, ForeignKey, JSON, Text
|
||||
from sqlalchemy.sql import func
|
||||
from app.core.database import Base
|
||||
|
||||
|
||||
class PredictionTask(Base):
|
||||
"""AI预测任务元数据"""
|
||||
__tablename__ = "prediction_tasks"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
device_id = Column(Integer, ForeignKey("devices.id"))
|
||||
prediction_type = Column(String(50), nullable=False) # pv, load, heatpump, optimization
|
||||
horizon_hours = Column(Integer, default=24)
|
||||
status = Column(String(20), default="pending") # pending, running, completed, failed
|
||||
parameters = Column(JSON) # extra config for the prediction run
|
||||
error_message = Column(Text)
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
completed_at = Column(DateTime(timezone=True))
|
||||
|
||||
|
||||
class PredictionResult(Base):
|
||||
"""AI预测结果时序数据"""
|
||||
__tablename__ = "prediction_results"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
task_id = Column(Integer, ForeignKey("prediction_tasks.id"), nullable=False, index=True)
|
||||
timestamp = Column(DateTime(timezone=True), nullable=False, index=True)
|
||||
predicted_value = Column(Float, nullable=False)
|
||||
confidence_lower = Column(Float)
|
||||
confidence_upper = Column(Float)
|
||||
actual_value = Column(Float) # filled later for accuracy tracking
|
||||
unit = Column(String(20))
|
||||
|
||||
|
||||
class OptimizationSchedule(Base):
|
||||
"""AI优化调度建议"""
|
||||
__tablename__ = "optimization_schedules"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
device_id = Column(Integer, ForeignKey("devices.id"))
|
||||
date = Column(DateTime(timezone=True), nullable=False, index=True)
|
||||
schedule_data = Column(JSON) # hourly on/off + setpoints
|
||||
expected_savings_kwh = Column(Float, default=0)
|
||||
expected_savings_yuan = Column(Float, default=0)
|
||||
status = Column(String(20), default="pending") # pending, approved, executed, rejected
|
||||
approved_by = Column(Integer, ForeignKey("users.id"))
|
||||
approved_at = Column(DateTime(timezone=True))
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
Reference in New Issue
Block a user