#!D:\IDE\Anaconda3\envs\Microscope_Scan python
# -*- coding: UTF-8 -*-
"""
@FileName   : PreviewClassifierModel.py
@Account    : Administrator
@Time       : 2025/8/20 10:01
@Author     : xsh
@Description: 低倍识别模型
"""
from PyQt5 import Qt
from datetime import datetime, date
import copy
from AppCore.AppDBModels.CoreModel import (CoreModel, DBManager, dbController)
from sqlalchemy.orm import declarative_base, mapper, sessionmaker, Session
from sqlalchemy.orm import (declarative_base, Mapped, mapped_column, relationship, mapper, sessionmaker)
from sqlalchemy import Table, Engine, create_engine, Column, ForeignKey, and_, or_, insert, delete, update, select, func, ColumnElement,distinct
from sqlalchemy.types import (Text, VARCHAR, REAL, Float, Integer, String, SmallInteger, DateTime, Date, ARRAY,Boolean, JSON)
from sqlalchemy.orm.decl_api import DeclarativeBase, MetaData
from AppUtils.utils import *
from AppCore.Levels import *
from AppCore.AppDBModels.WeightModels.WeightModelInterface import WeightModelInterface

class PreviewClassifierModel(WeightModelInterface):
    __tablename__   = 't_PreviewClassifierModel'
    ID              : Mapped[int    ] = mapped_column   (primary_key=True                                                 , nullable=False, doc='数据序号　', comment='数据序号　') # 数据序号　
    conf_threshold  : Mapped[float  ] = mapped_column   (default=0.5                                                      , nullable=True , doc='置信度阀值', comment='置信度阀值') # 置信度阀值
    iou_threshold   : Mapped[float  ] = mapped_column   (default=0.45                                                     , nullable=True , doc='交并比阀值', comment='交并比阀值') # 交并比阀值
    class_cont      : Mapped[float  ] = mapped_column   (default=0.5                                                      , nullable=True , doc='筛选类别　', comment='筛选类别　')# '筛选类别'
    iou_cont        : Mapped[float  ] = mapped_column   (default=0.1                                                      , nullable=True , doc='筛选类别　', comment='筛选类别　')# '筛选类别'
    model_width     : Mapped[int    ] = mapped_column   (default=960                                                      , nullable=True , doc='图像宽度　', comment='图像宽度　') # 图像宽度　
    model_height    : Mapped[int    ] = mapped_column   (default=960                                                      , nullable=True , doc='图像高度　', comment='图像高度　') # 图像高度　
    Information     : Mapped[str    ] = mapped_column   (Text, default='Aberration'                                       , nullable=True , doc='说明信息　', comment='说明信息　') # 说明信息　
    name            : Mapped[str    ] = mapped_column   (Text, default='Aberration'                                       , nullable=True , doc='分类模型　', comment='分类模型　') # 分类模型　
    save_address    : Mapped[str    ] = mapped_column   (Text, default='Resource/Classifier/Aberration_det_10X_hzh.onnx'  , nullable=True , doc='保存路径　', comment='保存路径　') # 保存路径　

    def __init__(self, **args):
        super(PreviewClassifierModel, self).__init__()
        self.initialize()
        self.initParameter(**args)

    def initValue(self):
        super(PreviewClassifierModel, self).initValue()
        self.ID               = 1
        self.conf_threshold   = 0.5
        self.iou_threshold    = 0.45
        self.class_cont       = 0.5
        self.iou_cont         = 0.1
        self.model_width      = 960
        self.model_height     = 960
        self.Information      = '畸变'
        self.name             = 'Aberration'
        self.save_address     = 'Resource/Classifier/Aberration_det_10X_hzh.onnx'



    def isAberration(self) -> bool:
        return False if not self.has_name else self.name == 'Aberration'

    def Micronucleus(self) -> bool:
        return False if not self.has_name else self.name == 'Micronucleus'

    def isKaryotyping(self) -> bool:
        return False if not self.has_name else self.name == 'Karyotyping'

    @classmethod
    def initModels(cls):
        return [
            cls.instance(ID=1,  name='Aberration'   , save_address='Resource/Classifier/Aberration_det_10X_hzh.onnx'          , conf_threshold = 0.5, iou_threshold = 0.45, Information='畸变', model_width      = 960 , model_height     = 960 ),
            cls.instance(ID=2,  name='Micronucleus' , save_address='Resource/Classifier/Micronucleus_det_10X_hzh.onnx'        , conf_threshold = 0.5, iou_threshold = 0.45, Information='微核', model_width      = 1024, model_height     = 1024),
            cls.instance(ID=3,  name='Karyotyping'  , save_address='Resource/Classifier/Karyotyping_det_10X_hzh.onnx'         , conf_threshold = 0.5, iou_threshold = 0.45, Information='核型', model_width      = 960 , model_height     = 960 ),
        ]
        pass
