123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- ##################################################################
- #
- # Copyright (c) 2024 CICV, Inc. All Rights Reserved
- #
- ##################################################################
- """
- @Authors: yangzihao(yangzihao@china-icv.cn)
- @Data: 2024/09/03
- @Last Modified: 2024/09/03
- @Summary: Custom metric test module.
- """
- import os
- import importlib.util
- from collections import defaultdict
- from custom_config import CSV_DATA_PATH, METRIC_FILE_PATH, CUSTOM_METRIC_LIST
- # main
- def main():
- all_data = get_all_data(CSV_DATA_PATH)
- metric_result = custom_run(METRIC_FILE_PATH, all_data, CUSTOM_METRIC_LIST, "0903TEST")
- get_custom_score(metric_result)
- data_detect(metric_result)
- def data_process(data_path):
- return {}
- def get_all_data(data_path):
- result = data_process(data_path)
- return result
- def custom_run(folder_path, all_data, metric_list, case_name):
- # 初始化一个字典来存储结果
- results = defaultdict(dict)
- # metric_list = all_data.config.metric_list
- # metric_list = ['ldw_miss_warning_count', 'ldw_miss_warning_count2', 'ldw_miss_warning_count3']
- # 遍历文件夹中的所有文件
- for filename in os.listdir(folder_path):
- if filename.endswith('.py') and not filename.startswith('__') and filename[
- :-3] in metric_list: # 过滤掉非Python文件或特殊文件
- # 构造模块的完整路径
- module_path = os.path.join(folder_path, filename)
- # 使用importlib来动态导入模块
- spec = importlib.util.spec_from_file_location(filename[:-3], module_path)
- module = importlib.util.module_from_spec(spec)
- spec.loader.exec_module(module)
- # 假设每个模块都有一个CustomMetric类
- if hasattr(module, 'CustomMetric'):
- CustomMetric = getattr(module, 'CustomMetric')
- # 实例化CustomMetric类
- metric_instance = CustomMetric(all_data, case_name)
- metric_result = metric_instance.result
- # 将结果存储到字典中,key为文件名,value为各个方法的结果
- results[filename[:-3]] = metric_result
- return results
- def get_custom_score(metric_result):
- # cython
- # use the executive code
- # dimension, type, metric
- score_dict = {}
- print(score_dict)
- def data_detect(metric_result):
- print("error/warning")
- if __name__ == '__main__':
- main()
|