ems-core v1.0.0: Standard EMS platform core
Shared backend + frontend for multi-customer EMS deployments. - 12 enterprise modules: quota, cost, charging, maintenance, analysis, etc. - 120+ API endpoints, 37 database tables - Customer config mechanism (CUSTOMER env var + YAML config) - Collectors: Modbus TCP, MQTT, HTTP API, Sungrow iSolarCloud - Frontend: React 19 + Ant Design + ECharts + Three.js - Infrastructure: Redis cache, rate limiting, aggregation engine Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
81
backend/app/models/energy_strategy.py
Normal file
81
backend/app/models/energy_strategy.py
Normal file
@@ -0,0 +1,81 @@
|
||||
from sqlalchemy import Column, Integer, String, Float, Boolean, DateTime, ForeignKey, JSON, Date
|
||||
from sqlalchemy.sql import func
|
||||
from app.core.database import Base
|
||||
|
||||
|
||||
class TouPricing(Base):
|
||||
"""分时电价配置 (Time-of-Use pricing)"""
|
||||
__tablename__ = "tou_pricing"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
name = Column(String(200), nullable=False)
|
||||
region = Column(String(100), default="北京")
|
||||
effective_date = Column(Date)
|
||||
end_date = Column(Date)
|
||||
is_active = Column(Boolean, default=True)
|
||||
created_by = Column(Integer, ForeignKey("users.id"))
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
||||
|
||||
|
||||
class TouPricingPeriod(Base):
|
||||
"""分时电价时段 (TOU pricing periods)"""
|
||||
__tablename__ = "tou_pricing_periods"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
pricing_id = Column(Integer, ForeignKey("tou_pricing.id", ondelete="CASCADE"), nullable=False)
|
||||
period_type = Column(String(20), nullable=False) # sharp_peak, peak, flat, valley
|
||||
start_time = Column(String(10), nullable=False) # HH:MM
|
||||
end_time = Column(String(10), nullable=False) # HH:MM
|
||||
price_yuan_per_kwh = Column(Float, nullable=False)
|
||||
month_range = Column(String(50)) # e.g. "1-3,11-12" for winter, null=all
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
|
||||
|
||||
class EnergyStrategy(Base):
|
||||
"""能源优化策略"""
|
||||
__tablename__ = "energy_strategies"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
name = Column(String(200), nullable=False)
|
||||
strategy_type = Column(String(50), nullable=False) # heat_storage, load_shift, pv_priority
|
||||
description = Column(String(500))
|
||||
parameters = Column(JSON, default=dict)
|
||||
is_enabled = Column(Boolean, default=False)
|
||||
priority = Column(Integer, default=0)
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
||||
|
||||
|
||||
class StrategyExecution(Base):
|
||||
"""策略执行记录"""
|
||||
__tablename__ = "strategy_executions"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
strategy_id = Column(Integer, ForeignKey("energy_strategies.id"), nullable=False)
|
||||
date = Column(Date, nullable=False)
|
||||
actions_taken = Column(JSON, default=list)
|
||||
savings_kwh = Column(Float, default=0)
|
||||
savings_yuan = Column(Float, default=0)
|
||||
status = Column(String(20), default="planned") # planned, executing, completed
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
|
||||
|
||||
class MonthlyCostReport(Base):
|
||||
"""月度电费分析报告"""
|
||||
__tablename__ = "monthly_cost_reports"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
year_month = Column(String(7), nullable=False, unique=True) # YYYY-MM
|
||||
total_consumption_kwh = Column(Float, default=0)
|
||||
total_cost_yuan = Column(Float, default=0)
|
||||
peak_consumption = Column(Float, default=0)
|
||||
valley_consumption = Column(Float, default=0)
|
||||
flat_consumption = Column(Float, default=0)
|
||||
sharp_peak_consumption = Column(Float, default=0)
|
||||
pv_self_consumption = Column(Float, default=0)
|
||||
pv_feed_in = Column(Float, default=0)
|
||||
optimized_cost = Column(Float, default=0)
|
||||
baseline_cost = Column(Float, default=0)
|
||||
savings_yuan = Column(Float, default=0)
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
Reference in New Issue
Block a user