#!/usr/bin/env python
# -*- coding: utf-8 -*-
##################################################################
#
# Copyright (c) 2023 CICV, Inc. All Rights Reserved
#
##################################################################
"""
@Authors:           yangzihao(yangzihao@china-icv.cn)
@Data:              2024/01/30
@Last Modified:     2024/01/30
@Summary:           Evaluateion functions
"""

import os
import sys
import time
from multiple_case_eval import multiple_cases_eval
import log

# logger = log.get_logger()

if __name__ == "__main__":

    from warnings import simplefilter

    # simplefilter(action="ignore", category=FutureWarning)
    simplefilter(action="ignore")

    if len(sys.argv) >= 5:
        configPath = sys.argv[1]
        singleReportPath = sys.argv[2]
        reportPath = sys.argv[3]
        logPath = sys.argv[4]
        log.setup_logger(logPath)
        logger = log.get_logger()

        if not os.path.exists(configPath):
            print('Invalid configPath!')
            logger.error("MULTIPLE_CASES_EVAL: Invalid configPath!")
            sys.exit(-1)
        elif not os.path.exists(singleReportPath):
            print('Invalid singleReportPath!')
            logger.error("MULTIPLE_CASES_EVAL: Invalid singleReportPath!")
            sys.exit(-1)
        else:
            try:
                logger.info("MULTIPLE_CASES_EVAL: Start evaluating:")
                print("MULTIPLE_CASES_EVAL程序开始运行：")
                print(f"   configPath: {configPath},\n   singleReportPath: {singleReportPath},\n   reportPath: {reportPath}")
                t1 = time.time()
                multiple_cases_eval(configPath, singleReportPath, reportPath)
                t2 = time.time()
                print(f"程序结束，执行时间：{int(t2 - t1)} s")
                logger.info("MULTIPLE_CASES_EVAL: End.")
                sys.exit(0)
            except Exception as e:
                print("异常，退出...")
                print(repr(e))
                sys.exit(-1)
    else:
        print('No enough arguments!')
        logPath = sys.argv[4]
        log.setup_logger(logPath)
        logger = log.get_logger()
        logger.error("MULTIPLE_CASES_EVAL: No enough arguments!")
        sys.exit(-1)

    # num = "0123"
    # configPath = rf"./config_combined/config{num}.json"
    # singleReportPath = rf"./demoReportCombine/cases_dict-0423-{num}.json"
    # reportPath = rf"./result/report_mul-0423-{num}.json"

    # configPath = r"./config.json"
    # singleReportPath = r"./reportTest/cases_dict-0419.json"
    # reportPath = r"./result/report_mul-0419.json"
    #
    # logPath = './log.log'
    # log.setup_logger(logPath)
    # logger = log.get_logger()
    #
    # if not os.path.exists(configPath):
    #     print('Invalid configPath!')
    #     logger.error("MULTIPLE_CASES_EVAL: Invalid configPath!")
    # elif not os.path.exists(singleReportPath):
    #     print('Invalid singleReportPath!')
    #     logger.error("MULTIPLE_CASES_EVAL: Invalid singleReportPath!")
    # else:
    #     # logger.info("MULTIPLE_CASES_EVAL: Start evaluating:")
    #     print("MULTIPLE_CASES_EVAL程序开始运行：")
    #     print(f"  configPath: {configPath}, \n  singleReportPath: {singleReportPath}, \n  reportPath: {reportPath}")
    #     t1 = time.time()
    #     multiple_cases_eval(configPath, singleReportPath, reportPath)
    #     t2 = time.time()
    #     print(f"程序结束，执行时间：{int(t2 - t1)} s")
    #     logger.info("MULTIPLE_CASES_EVAL: End.")
