1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- from sqlalchemy import Column, Integer, Float
- from sqlalchemy import ForeignKeyConstraint
- from app.database import Base # 统一的基础模型
- class CropCdOutputData(Base):
- """
- 作物镉预测模型输出数据模型
- 存储作物镉富集预测模型的计算结果,核心输出为:
- LnCropCd - 籽粒镉浓度的自然对数值
- 实际籽粒镉浓度 = exp(LnCropCd) [单位:mg/kg]
- """
- __tablename__ = 'CropCd_output_data'
- # 主键配置
- id = Column('ID', Integer, primary_key=True, autoincrement=True,
- comment='自增主键')
- # 外键字段
- farmland_id = Column('Farmland_ID', Integer, nullable=False,
- comment='关联农地ID')
- sample_id = Column('Sample_ID', Integer, nullable=False,
- comment='关联样点ID')
- # 模型输出结果
- ln_crop_cd = Column('LnCropCd', Float, nullable=False,
- comment='籽粒镉浓度的自然对数值[ln(mg/kg)]')
- # 复合外键约束
- __table_args__ = (
- ForeignKeyConstraint(
- ['Farmland_ID', 'Sample_ID'],
- ['Farmland_data.Farmland_ID', 'Farmland_data.Sample_ID']
- ),
- {'comment': '作物镉预测模型输出数据'}
- )
- # 转换方法:实际籽粒镉浓度
- def crop_cd_value(self):
- """
- 计算实际作物籽粒镉浓度(单位:mg/kg)
- 公式:CropCd = exp(LnCropCd)
- """
- import math
- return math.exp(self.ln_crop_cd)
|