single_run_test.py 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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: Evaluation functions
  13. """
  14. import os
  15. import sys
  16. import time
  17. import json
  18. import pandas as pd
  19. from single_case_eval import single_case_eval
  20. import log
  21. def guarantee_result(reportPath, csvPath, playbackPath):
  22. result = {
  23. "details": {
  24. "safe": {
  25. "name": "安全性",
  26. "weight": "100.00%",
  27. "collisionRisk": 0,
  28. "noObjectCar": "false",
  29. "score": 100,
  30. "level": "优秀",
  31. "weightDistribution": {
  32. "name": "安全性",
  33. "safeTime": {
  34. "weight": "时间类型(27.71%)",
  35. "indexes": {
  36. "TTC": "TTC(18.34%)",
  37. "MTTC": "MTTC(50.01%)",
  38. "THW": "THW(31.65%)"
  39. }
  40. },
  41. "safeDistance": {
  42. "weight": "距离类型(44.37%)",
  43. "indexes": {
  44. "LonSD": "LonSD(76.80%)",
  45. "LatSD": "LatSD(23.20%)"
  46. }
  47. },
  48. "safeAcceleration": {
  49. "weight": "加速度类型(2.60%)",
  50. "indexes": {
  51. "DRAC": "DRAC(66.67%)",
  52. "BTN": "BTN(6.22%)",
  53. "STN": "STN(27.11%)"
  54. }
  55. },
  56. "safeProbability": {
  57. "weight": "概率类型(25.32%)",
  58. "indexes": {
  59. "collisionRisk": "碰撞风险概率(50.00%)",
  60. "collisionSeverity": "碰撞严重程度(50.00%)"
  61. }
  62. }
  63. },
  64. "details": {
  65. "safeTime": {
  66. "name": "时间类型",
  67. "score": 100,
  68. "level": "较差",
  69. "description1": "TTC和THW指标表现良好,MTTC指标表现不佳,MTTC极值超过合理范围73.59%",
  70. "description2": "TTC和THW指标均在合理范围内,表现良好,MTTC指标共有0.32秒超出合理范围,算法应加强在该时间段对跟车距离的控制",
  71. "indexes": {
  72. "TTC": {
  73. "name": "TTC",
  74. "meaning": "TTC",
  75. "score": 100,
  76. "extremum": "3.76",
  77. "range": "[2.86, inf)",
  78. "rate": "100%"
  79. },
  80. "MTTC": {
  81. "name": "MTTC",
  82. "meaning": "MTTC",
  83. "score": 100,
  84. "extremum": "0.32",
  85. "range": "[1.2, inf)",
  86. "rate": "98.9%"
  87. },
  88. "THW": {
  89. "name": "THW",
  90. "meaning": "THW",
  91. "score": 100,
  92. "extremum": "2.98",
  93. "range": "[0.4, inf)",
  94. "rate": "100%"
  95. }
  96. },
  97. "builtin": {
  98. "MTTC": {
  99. "name": "MTTC",
  100. "data": [],
  101. "range": "[1.2, inf)"
  102. },
  103. "THW": {
  104. "name": "THW",
  105. "data": [],
  106. "range": "[0.4, inf)"
  107. }
  108. },
  109. "custom": {}
  110. },
  111. },
  112. "description1": "未满足设计指标要求。算法在本轮测试中有碰撞风险,需要提高算法在时间类型和距离类型上的表现。在时间类型和距离类型中,MTTC指标共有0.32秒超出合理范围;LonSD指标共有3.93秒超出合理范围;STN指标共有0.07秒超出合理范围;",
  113. "description2": "安全性在时间类型和距离类型上存在严重风险,需要重点优化。",
  114. },
  115. "commonData": {
  116. "per": {
  117. "name": "脚刹/油门踏板开度(百分比)",
  118. "legend": [
  119. "刹车踏板开度",
  120. "油门踏板开度"
  121. ],
  122. "data": []
  123. },
  124. "ang": {
  125. "name": "方向盘转角(角度°)",
  126. "data": []
  127. },
  128. "spe": {
  129. "name": "速度(km/h)",
  130. "legend": [
  131. "自车速度",
  132. "目标车速度",
  133. "自车与目标车相对速度"
  134. ],
  135. "data": []
  136. },
  137. "acc": {
  138. "name": "加速度(m/s²)",
  139. "legend": [
  140. "横向加速度",
  141. "纵向加速度"
  142. ],
  143. "data": []
  144. },
  145. "dis": {
  146. "name": "前车距离(m)",
  147. "data": []
  148. },
  149. "ttc": {
  150. "name": "TTC(m)",
  151. "data": []
  152. }
  153. },
  154. "commonMarkLine": []
  155. },
  156. "algorithmComprehensiveScore": 100,
  157. "algorithmLevel": "优秀",
  158. "testMileage": "0.00米",
  159. "testDuration": "0.00秒",
  160. "algorithmResultDescription1": "车辆在本轮测试中,未出现违反交通规则行为、跟停行为和不舒适行为。",
  161. "algorithmResultDescription2": "综上所述,算法表现良好。"
  162. }
  163. with open(f'{reportPath}', 'w', encoding='utf-8') as f:
  164. f.write(json.dumps(result, ensure_ascii=False))
  165. eval_data_columns = ['simTime', 'simFrame', 'playerId', 'type', 'posX', 'posY', 'posZ', 'posH', 'speedX', 'speedY',
  166. 'speedZ', 'accelX', 'accelY', 'accelZ', 'dimX', 'dimY', 'dimZ', 'offX', 'speedH', 'accelH',
  167. 'travelDist']
  168. eval_data_df = pd.DataFrame(columns=eval_data_columns)
  169. eval_data_df.to_csv(f'{csvPath}', index=False)
  170. playback_data_columns = ['simTime', 'simFrame', 'speed', 'curvHor', 'rollRel', 'pitchRel', 'latSpeedRel',
  171. 'lonSpeedRel', 'latDistanceRel', 'lonDistanceRel']
  172. playback_data_df = pd.DataFrame(columns=playback_data_columns)
  173. playback_data_df.to_csv(f'{playbackPath}', index=False)
  174. if __name__ == "__main__":
  175. from warnings import simplefilter
  176. simplefilter(action="ignore")
  177. configPath = r"D:\Cicv\Lantu\cicv_evaluate_master-single_eval_1016_latest\close_beta_test\config_test\config.json"
  178. dataPath = r"D:\Cicv\Lantu\cicv_evaluate_master-single_eval_1016_latest\close_beta_test\case_test\beiqi_repot_json"
  179. # dataPath = r"D:/Cicv/Lantu/cicv_evaluate_master-single_eval_1016_latest/cicv_evaluate_master-single_eval_1117/close_beta_test/case_test/data_PGVIL_1121"
  180. # dataPath = r'/home/kevin/kevin/pingjia/cicv_evaluate_master-single_eval/close_beta_test/case_test/ACC/ACC_following_car_good'
  181. case_name = os.path.basename(os.path.dirname(os.path.normpath(dataPath)))
  182. print("case_name is", case_name)
  183. casePath = os.path.join("./result", case_name)
  184. if not os.path.exists(casePath):
  185. os.makedirs(casePath)
  186. # customMetricPath = './custom'
  187. customMetricPath = './custom/all_pyfiles'
  188. # customMetricPath = './custom/cicv_ICA_lateral_control'
  189. # customMetricPath = './demoICA'
  190. # customMetricPath = './custom/cicv_ICA'
  191. customScorePath = './customScore'
  192. logPath = './log.log'
  193. reportPath = rf"{casePath}/report.json"
  194. csvPath = rf"{casePath}/evalData.csv"
  195. playbackPath = f"{casePath}/playback.csv"
  196. log.setup_logger(logPath)
  197. logger = log.get_logger()
  198. if not os.path.exists(configPath):
  199. print('Invalid configPath!')
  200. logger.error(f"[case:{case_name}] SINGLE_CASE_EVAL: Invalid configPath!")
  201. elif not os.path.exists(dataPath):
  202. print('Invalid dataPath!')
  203. logger.error(f"[case:{case_name}] SINGLE_CASE_EVAL: Invalid dataPath!")
  204. elif not os.path.exists(customMetricPath):
  205. print('Invalid dataPath!')
  206. logger.error(f"[case:{case_name}] SINGLE_CASE_EVAL: Invalid dataPath!")
  207. else:
  208. try:
  209. logger.info(f"[case:{case_name}] SINGLE_CASE_EVAL: Start evaluating:")
  210. print("SINGLE_CASE_EVAL程序开始运行:")
  211. print(f" configPath: {configPath}, \n dataPath: {dataPath}, \n reportPath: {reportPath}")
  212. t1 = time.time()
  213. single_case_eval(configPath, dataPath, reportPath, csvPath, playbackPath, customMetricPath, customScorePath,
  214. case_name)
  215. t2 = time.time()
  216. print(f"程序结束,执行时间:{int(t2 - t1)} s")
  217. logger.info(f"[case:{case_name}] SINGLE_CASE_EVAL: End.")
  218. except Exception as e:
  219. guarantee_result(reportPath, csvPath, playbackPath)
  220. print("异常如下:")
  221. print(repr(e))
  222. # traceback.print_exc()