custom_metric_test.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. ##################################################################
  4. #
  5. # Copyright (c) 2024 CICV, Inc. All Rights Reserved
  6. #
  7. ##################################################################
  8. """
  9. @Authors: yangzihao(yangzihao@china-icv.cn)
  10. @Data: 2024/09/03
  11. @Last Modified: 2024/09/03
  12. @Summary: Custom metric test module.
  13. """
  14. import os
  15. import importlib.util
  16. from collections import defaultdict
  17. from custom_config import CSV_DATA_PATH, METRIC_FILE_PATH, CUSTOM_METRIC_LIST
  18. # main
  19. def main():
  20. all_data = get_all_data(CSV_DATA_PATH)
  21. metric_result = custom_run(METRIC_FILE_PATH, all_data, CUSTOM_METRIC_LIST, "0903TEST")
  22. get_custom_score(metric_result)
  23. data_detect(metric_result)
  24. def data_process(data_path):
  25. return {}
  26. def get_all_data(data_path):
  27. result = data_process(data_path)
  28. return result
  29. def custom_run(folder_path, all_data, metric_list, case_name):
  30. # 初始化一个字典来存储结果
  31. results = defaultdict(dict)
  32. # metric_list = all_data.config.metric_list
  33. # metric_list = ['ldw_miss_warning_count', 'ldw_miss_warning_count2', 'ldw_miss_warning_count3']
  34. # 遍历文件夹中的所有文件
  35. for filename in os.listdir(folder_path):
  36. if filename.endswith('.py') and not filename.startswith('__') and filename[
  37. :-3] in metric_list: # 过滤掉非Python文件或特殊文件
  38. # 构造模块的完整路径
  39. module_path = os.path.join(folder_path, filename)
  40. # 使用importlib来动态导入模块
  41. spec = importlib.util.spec_from_file_location(filename[:-3], module_path)
  42. module = importlib.util.module_from_spec(spec)
  43. spec.loader.exec_module(module)
  44. # 假设每个模块都有一个CustomMetric类
  45. if hasattr(module, 'CustomMetric'):
  46. CustomMetric = getattr(module, 'CustomMetric')
  47. # 实例化CustomMetric类
  48. metric_instance = CustomMetric(all_data, case_name)
  49. metric_result = metric_instance.result
  50. # 将结果存储到字典中,key为文件名,value为各个方法的结果
  51. results[filename[:-3]] = metric_result
  52. return results
  53. def get_custom_score(metric_result):
  54. # cython
  55. # use the executive code
  56. # dimension, type, metric
  57. score_dict = {}
  58. print(score_dict)
  59. def data_detect(metric_result):
  60. print("error/warning")
  61. if __name__ == '__main__':
  62. main()