single_case_eval.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. ##################################################################
  4. #
  5. # Copyright (c) 2023 CICV, Inc. All Rights Reserved
  6. #
  7. ##################################################################
  8. """
  9. @Authors: yangzihao(yangzihao@china-icv.cn)
  10. @Data: 2024/01/30
  11. @Last Modified: 2024/01/30
  12. @Summary: Evaluateion functions
  13. """
  14. import os
  15. import sys
  16. sys.path.append('../config')
  17. sys.path.append('../common')
  18. sys.path.append('../modules')
  19. sys.path.append('../results')
  20. import json
  21. import traceback
  22. import log
  23. from config_parser import ConfigParse
  24. from single_case_evaluate import single_case_evaluate
  25. # from data_quality import frame_loss_statistic
  26. # from pdf_report_generate import report_generate
  27. from report_generate import report_generate
  28. def single_case_eval(configPath, dataPath, resultPath, trackPath, case_name):
  29. """
  30. :param configPath: 配置文件路径
  31. :param dataPath: 评价数据路径
  32. :param resultPath: 评价结果路径
  33. :param trackPath: 轨迹图片路径
  34. :param case_name: 用例名称
  35. :return: None
  36. """
  37. logger = log.get_logger()
  38. # 判断文件夹是否为空
  39. if len(os.listdir(dataPath)) == 0:
  40. print("No files in data_path!") # 路径异常
  41. logger.error(f"[case:{case_name}] SINGLE_CASE_EVAL: No files in data_path!")
  42. sys.exit(-1)
  43. # 解析配置文件信息,获得各指标权重及评分系数
  44. try:
  45. config = ConfigParse(configPath)
  46. print("config is", config)
  47. except Exception as e:
  48. print('Config file parsing ERROR!', e)
  49. traceback.print_exc()
  50. logger.error(f"[case:{case_name}] SINGLE_CASE_EVAL: Config file parsing ERROR: {repr(e)}!", exc_info=True)
  51. sys.exit(-1)
  52. # 单用例评价,并生成报告
  53. try:
  54. reportDict = single_case_evaluate(config, dataPath, resultPath, case_name) # 评估单用例
  55. # reportDict = single_case_statistic(case_dict) # 对单用例结果增加内容
  56. # 生成过程文件report.json
  57. with open(f'{resultPath}/report.json', 'w', encoding='utf-8') as f:
  58. f.write(json.dumps(reportDict, ensure_ascii=False))
  59. # 通过report.json生成报告
  60. reportPdf = os.path.join(resultPath, 'report.pdf')
  61. report_generate(reportDict, reportPdf, trackPath)
  62. except Exception as e:
  63. traceback.print_exc()
  64. logger.error(f"[case:{case_name}] SINGLE_CASE_EVAL: Evaluate single case ERROR: {repr(e)}!", exc_info=True)
  65. sys.exit(-1)