<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.platform.mapper.AutoMlDao">
    <insert id="save">
        insert into auto_ml(ml_name, ml_description, task_type, dataset, time_left_for_this_task,
                            per_run_time_limit, ensemble_size, ensemble_class, ensemble_nbest, max_models_on_disc, seed,
                            memory_limit,
                            include_classifier, include_feature_preprocessor, include_regressor, exclude_classifier,
                            exclude_regressor, exclude_feature_preprocessor, test_size, resampling_strategy, train_size,
                            shuffle, folds, target_columns, metric_name, metrics, greater_is_better, scoring_functions,
                            tmp_folder,
                            create_by, update_by)
        values (#{autoMl.mlName}, #{autoMl.mlDescription}, #{autoMl.taskType}, #{autoMl.dataset},
                #{autoMl.timeLeftForThisTask}, #{autoMl.perRunTimeLimit},
                #{autoMl.ensembleSize}, #{autoMl.ensembleClass}, #{autoMl.ensembleNbest},
                #{autoMl.maxModelsOnDisc}, #{autoMl.seed},
                #{autoMl.memoryLimit}, #{autoMl.includeClassifier}, #{autoMl.includeFeaturePreprocessor},
                #{autoMl.includeRegressor}, #{autoMl.excludeClassifier},
                #{autoMl.excludeRegressor}, #{autoMl.excludeFeaturePreprocessor}, #{autoMl.testSize},
                #{autoMl.resamplingStrategy},
                #{autoMl.trainSize}, #{autoMl.shuffle},
                #{autoMl.folds},
                #{autoMl.targetColumns}, #{autoMl.metricName}, #{autoMl.metrics}, #{autoMl.greaterIsBetter},
                #{autoMl.scoringFunctions}, #{autoMl.tmpFolder},
                #{autoMl.createBy}, #{autoMl.updateBy})
    </insert>

    <update id="edit">
        update auto_ml
        <set>
            <if test="autoMl.mlName != null and autoMl.mlName !=''">
                ml_name = #{autoMl.mlName},
            </if>
            <if test="autoMl.mlDescription != null and autoMl.mlDescription !=''">
                ml_description = #{autoMl.mlDescription},
            </if>
            <if test="autoMl.statusList != null and autoMl.statusList !=''">
                status_list = #{autoMl.statusList},
            </if>
            <!--            <if test="autoMl.progress != null">-->
            <!--                progress = #{autoMl.progress},-->
            <!--            </if>-->
            <if test="autoMl.taskType != null and autoMl.taskType !=''">
                task_type = #{autoMl.taskType},
            </if>
            <if test="autoMl.dataset != null and autoMl.dataset !=''">
                dataset = #{autoMl.dataset},
            </if>
            <if test="autoMl.timeLeftForThisTask != null">
                time_left_for_this_task = #{autoMl.timeLeftForThisTask},
            </if>
            <if test="autoMl.perRunTimeLimit != null">
                per_run_time_limit = #{autoMl.perRunTimeLimit},
            </if>
            <if test="autoMl.ensembleSize != null">
                ensemble_size = #{autoMl.ensembleSize},
            </if>
            <if test="autoMl.ensembleClass != null and autoMl.ensembleClass !=''">
                ensemble_class = #{autoMl.ensembleClass},
            </if>
            <if test="autoMl.ensembleNbest != null">
                ensemble_nbest = #{autoMl.ensembleNbest},
            </if>
            <if test="autoMl.maxModelsOnDisc != null">
                max_models_on_disc = #{autoMl.maxModelsOnDisc},
            </if>
            <if test="autoMl.seed != null">
                seed = #{autoMl.seed},
            </if>
            <if test="autoMl.memoryLimit != null">
                memory_limit = #{autoMl.memoryLimit},
            </if>
            include_classifier = #{autoMl.includeClassifier},
            include_feature_preprocessor = #{autoMl.includeFeaturePreprocessor},
            include_regressor = #{autoMl.includeRegressor},
            exclude_classifier = #{autoMl.excludeClassifier},
            exclude_regressor = #{autoMl.excludeRegressor},
            exclude_feature_preprocessor = #{autoMl.excludeFeaturePreprocessor},
            scoring_functions = #{autoMl.scoringFunctions},
            metrics = #{autoMl.metrics},
            <if test="autoMl.testSize != null and autoMl.testSize !=''">
                test_size = #{autoMl.testSize},
            </if>
            <if test="autoMl.resamplingStrategy != null and autoMl.resamplingStrategy !=''">
                resampling_strategy = #{autoMl.resamplingStrategy},
            </if>
            <if test="autoMl.trainSize != null and autoMl.trainSize !=''">
                train_size = #{autoMl.trainSize},
            </if>
            <if test="autoMl.shuffle != null">
                shuffle = #{autoMl.shuffle},
            </if>
            <if test="autoMl.folds != null">
                folds = #{autoMl.folds},
            </if>
            <if test="autoMl.tmpFolder != null and autoMl.tmpFolder !=''">
                tmp_folder = #{autoMl.tmpFolder},
            </if>
            <if test="autoMl.metricName != null and autoMl.metricName !=''">
                metric_name = #{autoMl.metricName},
            </if>
            <if test="autoMl.greaterIsBetter != null">
                greater_is_better = #{autoMl.greaterIsBetter},
            </if>
            <if test="autoMl.targetColumns != null and autoMl.targetColumns !=''">
                target_columns = #{autoMl.targetColumns},
            </if>
            <if test="autoMl.state != null">
                state = #{autoMl.state},
            </if>
        </set>
        where id = #{autoMl.id}
    </update>

    <select id="count" resultType="java.lang.Long">
        select count(1) from auto_ml
        <include refid="common_condition"></include>
    </select>

    <select id="queryByPage" resultType="com.ruoyi.platform.domain.AutoMl">
        select * from auto_ml
        <include refid="common_condition"></include>
    </select>

    <select id="getAutoMlById" resultType="com.ruoyi.platform.domain.AutoMl">
        select *
        from auto_ml
        where id = #{id}
    </select>

    <select id="getAutoMlByName" resultType="com.ruoyi.platform.domain.AutoMl">
        select *
        from auto_ml
        where ml_name = #{mlName}
          and state = 1
    </select>

    <select id="queryByDatasetId" resultType="com.ruoyi.platform.domain.AutoMl">
        select *
        from auto_ml
        where JSON_CONTAINS(dataset, #{datasetId})
          and state = 1
    </select>

    <sql id="common_condition">
        <where>
            state = 1
            <if test="mlName != null and mlName != ''">
                and ml_name like concat('%', #{mlName}, '%')
            </if>
        </where>
    </sql>
</mapper>