#!D:\IDE\Anaconda3\envs\Microscope_Scan python
# -*- coding: UTF-8 -*-
"""
 @Author: Administrator
 @FileName: Previewsettings.py
 @DateTime: 2025/6/22 15:25
 @SoftWare: PyCharm
 @Author  ：xsh
"""
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
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 *

class Previewsettings(CoreModel):
    __tablename__ = 't_previewsettings'
    ID                  : Mapped[int ] = mapped_column   (primary_key=True                                  , nullable=False, doc='数据序号　　　　', comment='数据序号　　　　') # 数据库号
    objective_level     : Mapped[int ] = mapped_column   (      default=2                                   , nullable=True , doc='物镜类型　　　　', comment='物镜类型　　　　') # 物镜类型
    classifier          : Mapped[str ] = mapped_column   (Text, default='Karyotyping'                       , nullable=True , doc='分类模型　　　　', comment='分类模型　　　　') # 分类模型
    flat_scan_mode      : Mapped[int ] = mapped_column   (      default=1                                   , nullable=True , doc='扫描模式　　　　', comment='扫描模式　　　　') # 扫描模式 1 快速 0 慢速
    path_mode           : Mapped[int ] = mapped_column   (      default=0                                   , nullable=True , doc='扫描模式　　　　', comment='扫描模式　　　　') # 扫描模式Z, N
    in_situ_cultivation : Mapped[int ] = mapped_column   (      default=0                                   , nullable=True , doc='训练模式　　　　', comment='　　　　　　　　') # int
    optimal_selector    : Mapped[int ] = mapped_column   (      default=0                                   , nullable=True , doc='数据选择模型类型', comment='数据选择模型类型') # 数据选择模型类型
    is_warning_scan     : Mapped[int ] = mapped_column   (      default=0                                   , nullable=True , doc='低于预警扫描开关', comment='低于预警扫描开关') # 低于预警扫描开关
    warning_value       : Mapped[int ] = mapped_column   (      default=50                                  , nullable=True , doc='最小数据个数　　', comment='最小数据个数　　') # 最小数据个数
    target_quantity     : Mapped[int ] = mapped_column   (      default=0                                   , nullable=True , doc='扫描数据个数　　', comment='扫描数据个数　　') # 扫描数据个数
    is_save             : Mapped[int ] = mapped_column   (      default=1                                   , nullable=True , doc='是否保存　　　　', comment='是否保存　　　　') # 是否保存
    image_format        : Mapped[str ] = mapped_column   (Text, default='jpg'                               , nullable=True , doc='数据格式　　　　', comment='数据格式　　　　') # 数据格式
    save_address        : Mapped[str ] = mapped_column   (Text, default='d:\\DeepLearning_data'             , nullable=True , doc='保存路径　　　　', comment='保存路径　　　　') # 保存路径
    def __init__(self, **args):
        super(Previewsettings, self).__init__()
        self.initialize()
        self.initParameter(**args)

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

    def isMicronucleus        (self) -> bool:
        return False if not self.has_classifier else self.classifier == 'Micronucleus'

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









    def initValue(self):
        super(Previewsettings, self).initValue()
        self.ID                   = None
        self.objective_level      = 2
        self.classifier           = 'Aberration'
        self.flat_scan_mode       = 1
        self.path_mode            = 0
        self.in_situ_cultivation  = 0
        self.optimal_selector     = 0
        self.is_warning_scan      = 0
        self.warning_value        = 50
        self.target_quantity      = 0
        self.is_save              = 1
        self.image_format         = 'jpg'
        self.save_address         = 'd:\\DeepLearning_data'

    @classmethod
    def initModels(cls):
        return [
            cls.instance(ID                   = 1                              ,objective_level      = ObjectiveLevel.Objective10   ,classifier           = 'Aberration'                       ,flat_scan_mode       = 1                                 ,path_mode            = 0                                 ,in_situ_cultivation  = 0                                 ,optimal_selector     = 0                                 ,is_warning_scan      = 0                                 ,warning_value        = 50                                ,target_quantity      = 0                                 ,is_save              = 1                                 ,image_format         = 'jpg'                             ,save_address         = 'd:\\DeepLearning_data\\' ),
            cls.instance(ID                   = 2                              ,objective_level      = ObjectiveLevel.Objective20   ,classifier           = 'Micronucleus'                     ,flat_scan_mode       = 1                                 ,path_mode            = 0                                 ,in_situ_cultivation  = 0                                 ,optimal_selector     = 0                                 ,is_warning_scan      = 0                                 ,warning_value        = 50                                ,target_quantity      = 0                                 ,is_save              = 1                                 ,image_format         = 'jpg'                             ,save_address         = 'd:\\DeepLearning_data\\' ),
            cls.instance(ID                   = 3                              ,objective_level      = ObjectiveLevel.Objective10   ,classifier           = 'Karyotyping'                      ,flat_scan_mode       = 1                                 ,path_mode            = 0                                 ,in_situ_cultivation  = 0                                 ,optimal_selector     = 0                                 ,is_warning_scan      = 0                                 ,warning_value        = 50                                ,target_quantity      = 0                                 ,is_save              = 1                                 ,image_format         = 'jpg'                             ,save_address         = 'd:\\DeepLearning_data\\' ),
        ]
    @property
    def has_ID                  (self) -> bool:
        return hasattr(self, 'ID'                      ) and isinstance(self.ID                  , int)

    @property
    def has_objective_level     (self) -> bool:
        return hasattr(self, 'objective_level'         ) and isinstance(self.objective_level     , int)

    @property
    def has_classifier          (self) -> bool:
        return hasattr(self, 'classifier'              ) and isinstance(self.classifier          , str)

    @property
    def has_flat_scan_mode      (self) -> bool:
        return hasattr(self, 'flat_scan_mode'          ) and isinstance(self.flat_scan_mode      , int)

    @property
    def has_path_mode           (self) -> bool:
        return hasattr(self, 'path_mode'               ) and isinstance(self.path_mode           , int)

    @property
    def has_in_situ_cultivation (self) -> bool:
        return hasattr(self, 'in_situ_cultivation'     ) and isinstance(self.in_situ_cultivation , int)

    @property
    def has_optimal_selector    (self) -> bool:
        return hasattr(self, 'optimal_selector'        ) and isinstance(self.optimal_selector    , int)

    @property
    def has_is_warning_scan     (self) -> bool:
        return hasattr(self, 'is_warning_scan'         ) and isinstance(self.is_warning_scan     , int)

    @property
    def has_warning_value       (self) -> bool:
        return hasattr(self, 'warning_value'           ) and isinstance(self.warning_value       , int)

    @property
    def has_target_quantity     (self) -> bool:
        return hasattr(self, 'target_quantity'         ) and isinstance(self.target_quantity     , int)

    @property
    def has_is_save             (self) -> bool:
        return hasattr(self, 'is_save'                 ) and isinstance(self.is_save             , int)

    @property
    def has_image_format        (self) -> bool:
        return hasattr(self, 'image_format'            ) and isinstance(self.image_format        , str)

    @property
    def has_save_address        (self) -> bool:
        return hasattr(self, 'save_address'            ) and isinstance(self.save_address        , str)

    __field__ = (
        'ID'                      ,
        'objective_level'         ,
        'classifier'              ,
        'flat_scan_mode'          ,
        'path_mode'               ,
        'in_situ_cultivation'     ,
        'optimal_selector'        ,
        'is_warning_scan'         ,
        'warning_value'           ,
        'target_quantity'         ,
        'is_save'                 ,
        'image_format'            ,
        'save_address'            ,
    )
    __types__ = (
        int                        ,
        int                        ,
        str                        ,
        int                        ,
        int                        ,
        int                        ,
        int                        ,
        int                        ,
        int                        ,
        int                        ,
        int                        ,
        str                        ,
        str                        ,
    )
