single_run_test.py 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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. 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. # import warnings
  176. # warnings.filterwarnings("ignore")
  177. from warnings import simplefilter
  178. # simplefilter(action="ignore", category=FutureWarning)
  179. simplefilter(action="ignore")
  180. # if len(sys.argv) >= 6:
  181. # configPath = sys.argv[1]
  182. # dataPath = sys.argv[2]
  183. # reportPath = sys.argv[3]
  184. # csvPath = sys.argv[4]
  185. # logPath = sys.argv[5]
  186. # customMetricPath = sys.argv[6]
  187. # customScorePath = sys.argv[7]
  188. # playbackPath = sys.argc[8]
  189. # case_name = sys.argc[9]
  190. # # case_name = os.path.basename(os.path.dirname(dataPath))
  191. # log.setup_logger(logPath)
  192. # logger = log.get_logger()
  193. # if not os.path.exists(configPath):
  194. # print('Invalid configPath!')
  195. # logger.error(f"[case:{case_name}] SINGLE_CASE_EVAL: Invalid configPath!")
  196. # sys.exit(-1)
  197. # elif not os.path.exists(dataPath):
  198. # print('Invalid dataPath!')
  199. # logger.error(f"[case:{case_name}] SINGLE_CASE_EVAL: Invalid dataPath!")
  200. # sys.exit(-1)
  201. # elif not os.path.exists(customMetricPath):
  202. # print('Invalid customMetricPath!')
  203. # logger.error(f"[case:{case_name}] SINGLE_CASE_EVAL: Invalid customMetricPath!")
  204. # sys.exit(-1)
  205. # elif not os.path.exists(customScorePath):
  206. # print('Invalid customScorePath!')
  207. # logger.error(f"[case:{case_name}] SINGLE_CASE_EVAL: Invalid customScorePath!")
  208. # sys.exit(-1)
  209. # else:
  210. # try:
  211. # logger.info(f"[case:{case_name}] SINGLE_CASE_EVAL: Start evaluating:")
  212. # print("SINGLE_CASE_EVAL程序开始运行:")
  213. # print(f" configPath: {configPath},\n dataPath: {dataPath},\n reportPath: {reportPath},\n "
  214. # f"csvPath: {csvPath},\n logPath: {logPath},\n customMetricPath: {customMetricPath}\n customScorePath: {customScorePath}")
  215. # t1 = time.time()
  216. # single_case_eval(configPath, dataPath, reportPath, csvPath, playbackPath, customMetricPath, customScorePath)
  217. # t2 = time.time()
  218. # print(f"程序结束,执行时间:{int(t2 - t1)} s")
  219. # logger.info(f"[case:{case_name}] SINGLE_CASE_EVAL: End.")
  220. # sys.exit(0)
  221. # except Exception as e:
  222. # print("异常,退出...")
  223. # print(repr(e))
  224. # sys.exit(-1)
  225. # else:
  226. # logPath = sys.argv[5]
  227. # log.setup_logger(logPath)
  228. # logger = log.get_logger()
  229. # print('SINGLE_CASE_EVAL: No enough arguments!')
  230. # logger.error(f"SINGLE_CASE_EVAL: No enough arguments!")
  231. # sys.exit(-1)
  232. # configPath = rf"./config/config.json"
  233. # configPath = rf"./config/config0531.json"
  234. # configPath = rf"./config/config0612_ica+lka.json"
  235. # configPath = rf"./config/config_ica_0730.json"
  236. # configPath = rf"./config/config_lka_0730.json"
  237. # configPath = rf"./config/config_lka_0730-2.json"
  238. # configPath = rf"./config/config_ica_0731-2.json"
  239. configPath = rf"./config/config_nofunction.json"
  240. # dataPath = r"./task_20240401_replace/alc_zicheyouganraobiandao_30/data/"
  241. # dataPath = r"./task_0430/zuozhuan_cheliangchongtutongxiang/data"
  242. # dataPath = r"./task_0430/case0415/data"
  243. # dataPath = r"./task_0515/case0528/data"
  244. # dataPath = r"./task_0515/data0529-2/data"
  245. # dataPath = r"./task_0515/case0529-1"
  246. # dataPath = r"./task_0515/VOYAH-H53-AEB-01/data"
  247. # dataPath = r"./task_0515/case0529-LKA/data"
  248. # dataPath = r"./task_0515/case0530-ica-post/data"
  249. # dataPath = r"./task_0515/0805-7/data"
  250. # dataPath = r"./task_0515/0806a-2/data"
  251. dataPath = r"./task_0515/accident_0716_6/data"
  252. case_name = os.path.basename(os.path.dirname(os.path.normpath(dataPath)))
  253. casePath = os.path.join("./result", case_name)
  254. if not os.path.exists(casePath):
  255. os.makedirs(casePath)
  256. customMetricPath = './custom'
  257. # customMetricPath = './custom/cicv_LKA'
  258. # customMetricPath = './custom/cicv_ICA_lateral_control'
  259. # customMetricPath = './demoICA'
  260. # customMetricPath = './custom/cicv_ICA'
  261. customScorePath = './customScore'
  262. logPath = './log.log'
  263. reportPath = rf"{casePath}/report.json"
  264. csvPath = rf"{casePath}/evalData.csv"
  265. playbackPath = f"{casePath}/playback.csv"
  266. log.setup_logger(logPath)
  267. logger = log.get_logger()
  268. if not os.path.exists(configPath):
  269. print('Invalid configPath!')
  270. logger.error(f"[case:{case_name}] SINGLE_CASE_EVAL: Invalid configPath!")
  271. elif not os.path.exists(dataPath):
  272. print('Invalid dataPath!')
  273. logger.error(f"[case:{case_name}] SINGLE_CASE_EVAL: Invalid dataPath!")
  274. elif not os.path.exists(customMetricPath):
  275. print('Invalid dataPath!')
  276. logger.error(f"[case:{case_name}] SINGLE_CASE_EVAL: Invalid dataPath!")
  277. else:
  278. try:
  279. logger.info(f"[case:{case_name}] SINGLE_CASE_EVAL: Start evaluating:")
  280. print("SINGLE_CASE_EVAL程序开始运行:")
  281. print(f" configPath: {configPath}, \n dataPath: {dataPath}, \n reportPath: {reportPath}")
  282. t1 = time.time()
  283. single_case_eval(configPath, dataPath, reportPath, csvPath, playbackPath, customMetricPath, customScorePath,
  284. case_name)
  285. t2 = time.time()
  286. print(f"程序结束,执行时间:{int(t2 - t1)} s")
  287. logger.info(f"[case:{case_name}] SINGLE_CASE_EVAL: End.")
  288. except Exception as e:
  289. guarantee_result(reportPath, csvPath, playbackPath)
  290. print("异常如下:")
  291. print(repr(e))
  292. # traceback.print_exc()