package com.mvc.model.aihcxd;

import java.text.NumberFormat;
import java.util.ArrayList;
import com.mvc.entity.TAiTargetbox;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * LED表服务侧识别的输出对象
 */
public class LedOutModel {
    private static Logger LedLogger  = LoggerFactory.getLogger(LedOutModel.class);//输出日志log的类
    //
    private String outImagePath;//存放结果图片的绝对路径
    private double aiValue; //本次服务器AI识别结果

    public String getAiValueStr() {
        return aiValueStr;
    }

    public void setAiValueStr(String aiValueStr) {
        this.aiValueStr = aiValueStr;
    }

    private String aiValueStr; //本次服务器AI识别结果
    private int serverAiValueIsOk;//本次服务器AI识别结果是否可靠；1、2、7、8代表可靠，3、4、5、6、91、92等代表不可靠
    private int[][] debugInfo;//AI调试信息，值域是 0-255，[1][11]用于存储本次用概率阈值*100；[1][10]用于存储本次识别后小数点后有几个目标（用于补0）

    public void setLastNumNumbers(int lastNumNumbers) {
        this.lastNumNumbers = lastNumNumbers;
    }

    public int getLastNumNumbers() {
        return lastNumNumbers;
    }

    private int lastNumNumbers;//水表数字个数，这里用成整数部分了,qjz加的参数
    private ArrayList<TAiTargetbox> finalList;//最终的数字目标列表

    public String getOutImagePath() {
        return outImagePath;
    }

    public void setOutImagePath(String outImagePath) {
        this.outImagePath = outImagePath;
    }

    public double getAiValue() {
        return aiValue;
    }

    public void setAiValue(double aiValue) {
        this.aiValue = aiValue;
    }

    public int[][] getDebugInfo() {
        return debugInfo;
    }

    /*public void setDebugInfo(int i, int j, int param_value) {
        this.debugInfo[i][j] = param_value;
    }*/
    public void setDebugInfo(int[][] debugInfo) {
        this.debugInfo = debugInfo;
    }

    public ArrayList<TAiTargetbox> getFinalList() {
        return finalList;
    }

    public void setFinalList(ArrayList<TAiTargetbox> finalList) {
        this.finalList = finalList;
    }

    public int getServerAiValueIsOk() {
        return serverAiValueIsOk;
    }

    public void setServerAiValueIsOk(int serverAiValueIsOk) {
        this.serverAiValueIsOk = serverAiValueIsOk;
    }

    /**
     * 构造函数
     */
    public LedOutModel() {
        this.outImagePath = "";
        this.aiValue = 0.0;
        this.aiValueStr = "";//qjz
        this.debugInfo = new int[][]{{888, 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, 888}, {888, 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, 888}};;
        this.finalList = new ArrayList<TAiTargetbox>();
        this.serverAiValueIsOk =92;
        this.lastNumNumbers=0;
    }

    /**
     * 将结果输出到logger文件中
     * @param param_LedAiInput
     */
    public void loggerLedOutModel(LedInModel param_LedAiInput)
    {

        LedLogger.info("----LED表检测，本次输出信息如下--------------------------------");
        LedLogger.info("输出结果图像的路径 : {}",this.outImagePath);
        //
        int numFractionDigits = 0;//显示几位小数
        if(param_LedAiInput.getNumberUnit() >=1)
            numFractionDigits = 0;
        else
            numFractionDigits = (int)Math.abs(Math.log10(param_LedAiInput.getNumberUnit()));

        NumberFormat nf = NumberFormat.getInstance();
        nf.setGroupingUsed(false);
        nf.setMaximumFractionDigits(numFractionDigits);
        LedLogger.info("识别结果 : {}",nf.format(this.aiValue));//根据配置设置小数位数
        //
        LedLogger.info("检测结果的调试信息如下");
        String debugInfo = String.format("%5d %5d %5d %5d %5d %5d %5d %5d %5d %5d %5d %5d", 1,2,3,4,5,6,7,8,9,10,11,12);
        LedLogger.info(debugInfo);
        //
        debugInfo = String.format("%5d %5d %5d %5d %5d %5d %5d %5d %5d %5d %5d %5d",
                this.debugInfo[0][0],this.debugInfo[0][1],this.debugInfo[0][2],this.debugInfo[0][3],this.debugInfo[0][4],this.debugInfo[0][5],
                this.debugInfo[0][6],this.debugInfo[0][7],this.debugInfo[0][8],this.debugInfo[0][9],this.debugInfo[0][10],this.debugInfo[0][11]);
        LedLogger.info(debugInfo);
        //
        debugInfo = String.format("%5d %5d %5d %5d %5d %5d %5d %5d %5d %5d %5d %5d",
                this.debugInfo[1][0],this.debugInfo[1][1],this.debugInfo[1][2],this.debugInfo[1][3],this.debugInfo[1][4],this.debugInfo[1][5],
                this.debugInfo[1][6],this.debugInfo[1][7],this.debugInfo[1][8],this.debugInfo[1][9],this.debugInfo[1][10],this.debugInfo[1][11]);
        LedLogger.info(debugInfo);
        //
        LedLogger.info("");
    }

    public String loggerLedOutModel_toString(LedInModel param_LedAiInput)
    {
        StringBuffer return_string = new StringBuffer();
        return_string.append("\n----LED表检测，本次输出信息如下--------------------------------\n");
        return_string.append(String.format("输出结果图像的路径 : %s\n",this.outImagePath));
        //
        int numFractionDigits = 0;//显示几位小数
        if(param_LedAiInput.getNumberUnit() >=1)
            numFractionDigits = 0;
        else
            numFractionDigits = (int)Math.abs(Math.log10(param_LedAiInput.getNumberUnit()));

        NumberFormat nf = NumberFormat.getInstance();
        nf.setGroupingUsed(false);
        nf.setMaximumFractionDigits(numFractionDigits);
        return_string.append(String.format("识别结果 : %s\n",nf.format(this.aiValue)));//根据配置设置小数位数
        //
        return_string.append("检测结果的调试信息如下:\n");
        String debugInfo = String.format("%5d %5d %5d %5d %5d %5d %5d %5d %5d %5d %5d %5d", 1,2,3,4,5,6,7,8,9,10,11,12);
        return_string.append(debugInfo+ "\n");
        //
        debugInfo = String.format("%5d %5d %5d %5d %5d %5d %5d %5d %5d %5d %5d %5d",
                this.debugInfo[0][0],this.debugInfo[0][1],this.debugInfo[0][2],this.debugInfo[0][3],this.debugInfo[0][4],this.debugInfo[0][5],
                this.debugInfo[0][6],this.debugInfo[0][7],this.debugInfo[0][8],this.debugInfo[0][9],this.debugInfo[0][10],this.debugInfo[0][11]);
        return_string.append(debugInfo + "\n");
        //
        debugInfo = String.format("%5d %5d %5d %5d %5d %5d %5d %5d %5d %5d %5d %5d",
                this.debugInfo[1][0],this.debugInfo[1][1],this.debugInfo[1][2],this.debugInfo[1][3],this.debugInfo[1][4],this.debugInfo[1][5],
                this.debugInfo[1][6],this.debugInfo[1][7],this.debugInfo[1][8],this.debugInfo[1][9],this.debugInfo[1][10],this.debugInfo[1][11]);
        return_string.append(debugInfo + "\n");
        //
        return return_string.toString();
    }

}
