Files
smart-project-pricing/后端服务/app/models/sensitivity_analysis.py
2026-01-31 21:33:06 +08:00

56 lines
1.4 KiB
Python

"""敏感性分析模型
记录价格变动对利润的敏感性分析结果
"""
from typing import TYPE_CHECKING
from decimal import Decimal
from sqlalchemy import BigInteger, ForeignKey, DECIMAL
from sqlalchemy.orm import Mapped, mapped_column, relationship
from app.models.base import BaseModel
if TYPE_CHECKING:
from app.models.profit_simulation import ProfitSimulation
class SensitivityAnalysis(BaseModel):
"""敏感性分析表"""
__tablename__ = "sensitivity_analyses"
simulation_id: Mapped[int] = mapped_column(
BigInteger,
ForeignKey("profit_simulations.id"),
nullable=False,
index=True,
comment="模拟ID"
)
price_change_rate: Mapped[Decimal] = mapped_column(
DECIMAL(5, 2),
nullable=False,
comment="价格变动率(%):如 -20, -10, 0, 10, 20"
)
adjusted_price: Mapped[Decimal] = mapped_column(
DECIMAL(12, 2),
nullable=False,
comment="调整后价格"
)
adjusted_profit: Mapped[Decimal] = mapped_column(
DECIMAL(14, 2),
nullable=False,
comment="调整后利润"
)
profit_change_rate: Mapped[Decimal] = mapped_column(
DECIMAL(5, 2),
nullable=False,
comment="利润变动率(%)"
)
# 关系
simulation: Mapped["ProfitSimulation"] = relationship(
"ProfitSimulation",
back_populates="sensitivity_analyses"
)