run.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. LST数据处理系统入口文件
  5. 支持多种数据格式和插件扩展
  6. """
  7. import argparse
  8. import sys
  9. import traceback
  10. from pathlib import Path
  11. from core.config_manager import load_config, update_config
  12. from core.optimized_processor import process_lst_data, process_pgvil_data # 新增导入
  13. from core.plugin_manager import PluginManager
  14. from core.resource_manager import ResourceManager
  15. def parse_arguments():
  16. """解析命令行参数"""
  17. parser = argparse.ArgumentParser(
  18. description='数据处理系统,支持多种数据格式和插件扩展'
  19. )
  20. # 新增数据类型参数
  21. parser.add_argument(
  22. '--data-type',
  23. type=str,
  24. choices=['lst', 'pgvil'],
  25. default='pgvil',
  26. help='要处理的数据类型 (lst 或 pgvil)'
  27. )
  28. # 定义参数
  29. parser.add_argument(
  30. '--zip-path',
  31. type=Path,
  32. # nargs = '+',
  33. # default=Path('/home/AD_CSAE285-2022_PedestrianAndTwo-wheelerRecognitionAndResponse_LST_010.zip'),
  34. # default=Path('/home/AD_CSAE285-2022_PedestrianAndTwo-wheelerRecognitionAndResponse_LST_01.zip'),
  35. # default=Path('/home/AD_CSAE285-2022_PedestrianAndTwo-wheelerRecognitionAndResponse_LST_02.zip'),
  36. # default=Path('/home/TSRAR-09_2025-07-14_11-12-48.zip'),
  37. # default=Path('/home/BEI_2025-07-15_17-52-09.zip'),
  38. # default=Path('/home/DONG_2025-07-15_17-48-21.zip'),
  39. # default=Path('/home/DONGCAN_2025-07-17_11-37-45.zip'),
  40. # default=Path('/home/BEICAN_2025-07-17_11-33-48.zip'),
  41. # default=Path('/home/AD_GBT41798-2022_VehiclesIdentifR_PGVL_03.zip'),
  42. # default=Path('/home/YAWCAN_2025-07-17_11-40-03.zip'),
  43. # default=Path('/home/YAWCANUFO_2025-07-17_16-39-37.zip'),
  44. # default=Path('/home/DONGCANUFO_2025-07-17_16-35-49.zip'),
  45. # default=Path('/home/BEICANUFO_2025-07-17_16-30-57.zip'),
  46. # default=Path('/home/all_data_TrafficLightRecognitionAndResponse/AD_CSAE285-2022_TrafficLightRecognitionAndResponse_LST_01.zip'),
  47. # default=Path('/home/AD_GBT41798-2022_TrafficSignalRecognitionAndResponse_LST_03.zip'),
  48. # default=Path('/home/V2I_CSAE53-2020_LeftTurnAssist_PGVIL_ini.zip'),
  49. # default = Path('/home/三轮预处理数据/AD_GBT41798-2022_RoadTraInfraObstRR_LST_14.zip'),
  50. # default = Path('/home/三轮预处理数据/AD_GBT41798-2022_RoadTraInfraObstRR_LST_15.zip'),
  51. # default = Path('/home/三轮预处理数据/AD_GBT41798-2022_TrafficSignalRR_LST_04.zip'),
  52. # default = Path('/home/三轮预处理数据/AD_GBT41798-2022_TrafficSignalRR_LST_05.zip'),
  53. # default = Path('/home/三轮预处理数据/AD_GBT41798-2022_TrafficSignalRR_LST_06.zip'),
  54. # default = Path('/home/三轮预处理数据/AD_GBT41798-2022_TrafficSignalRR_LST_07.zip'),
  55. # default = Path('/home/三轮预处理数据/AD_GBT41798-2022_TrafficSignalRR_LST_08.zip'),
  56. # default = Path('/home/三轮预处理数据/AD_GBT41798-2022_TrafficSignalRR_LST_09.zip'),
  57. # default = Path('/home/三轮预处理数据/V2C_ReferenceArchitecture1.0_LitterW_LST_01.zip'),
  58. # default = Path('/home/三轮预处理数据/V2C_ReferenceArchitecture1.0_LitterW_LST_02.zip'),
  59. # default = Path('/home/三轮预处理数据/V2I_CSAE53-2020_HazardousLocationW_LST_01.zip'),
  60. # default = Path('/home/三轮预处理数据/V2I_CSAE53-2020_HazardousLocationW_LST_02.zip'),
  61. # default = Path('/home/三轮预处理数据/V2I_CSAE53-2020_HazardousLocationW_LST_03.zip'),
  62. # 25-07-26
  63. # default = Path('/home/三轮预处理数据/AD_GBT41798-2022_LeastRiskStrateg_LST_02.zip'),
  64. # default = Path('/home/三轮预处理数据/AD_GBT41798-2022_LeastRiskStrateg_LST_03.zip'),
  65. # default = Path('/home/三轮预处理数据/AD_GBT41798-2022_RoadTraInfraObstRR_LST_01.zip'),
  66. # default = Path('/home/三轮预处理数据/AD_GBT41798-2022_RoadTraInfraObstRR_LST_02.zip'),
  67. # default = Path('/home/三轮预处理数据/V2I_CSAE53-2020_LeftTurnAssist_LST_01.zip'),
  68. # default = Path('/home/三轮预处理数据/V2I_CSAE53-2020_LeftTurnAssist_LST_02.zip'),
  69. # default = Path('/home/三轮预处理数据/V2V_CSAE53-2020_LeftTurnAssist_LST_03.zip'),
  70. # default = Path('/home/三轮预处理数据/V2V_CSAE53-2020_LeftTurnAssist_LST_04.zip'),
  71. # 25-07-27
  72. # default = Path('/home/三轮预处理数据/双车/AD_GBT41798-2022_RoadTraInfraObstRR_LST_08.zip'),
  73. # default = Path('/home/三轮预处理数据/双车/AD_GBT41798-2022_RoadTraInfraObstRR_LST_09.zip'),
  74. # default = Path('/home/三轮预处理数据/双车/AD_GBT41798-2022_RoadTraInfraObstRR_LST_010.zip'),
  75. # default = Path('/home/三轮预处理数据/双车/AD_GBT41798-2022_RoadTraInfraObstRR_LST_011.zip'),
  76. # default = Path('/home/三轮预处理数据/双车/AD_GBT41798-2022_RoadTraInfraObstRR_LST_012.zip'),
  77. # default = Path('/home/三轮预处理数据/双车/AD_GBT41798-2022_RoadTraInfraObstRR_LST_013.zip'),
  78. # default = Path('/home/三轮预处理数据/双车/V2C_ReferenceArchitecture1.0_OtherVehicleRedLightViolationW_LST_01.zip'),
  79. # default = Path('/home/三轮预处理数据/双车/V2C_ReferenceArchitecture1.0_OtherVehicleRedLightViolationW_LST_02.zip'),
  80. # default = Path('/home/三轮预处理数据/双车/V2I_CSAE157-2020_CooperativeIntersectionPassing_LST_02.zip'),
  81. # default = Path('/home/三轮预处理数据/双车/V2V_CSAE53-2020_EmergencyBrakeW_LST_01.zip'),
  82. # default = Path('/home/三轮预处理数据/双车/V2V_CSAE53-2020_EmergencyBrakeW_LST_02.zip'),
  83. # default = Path('/home/三轮预处理数据/双车/V2V_CSAE53-2020_ForwardCollision_LST_01.zip'),
  84. # default = Path('/home/三轮预处理数据/双车/V2V_CSAE53-2020_ForwardCollision_LST_02.zip'),
  85. # default = Path('/home/三轮预处理数据/双车/V2V_CSAE53-2020_ForwardCollision_LST_03.zip'),
  86. # default = Path('/home/三轮预处理数据/双车/V2V_CSAE53-2020_ForwardCollision_LST_04.zip'),
  87. # default = Path('/home/三轮预处理数据/双车/V2V_CSAE53-2020_ForwardCollision_LST_05.zip'),
  88. # default = Path('/home/三轮预处理数据/双车/V2V_CSAE53-2020_ForwardCollision_LST_06.zip'),
  89. # default = Path('/home/三轮预处理数据/双车/V2V_CSAE53-2020_ForwardCollision_LST_07.zip'),
  90. # default = Path('/home/三轮预处理数据/双车/V2V_CSAE53-2020_ForwardCollision_LST_08.zip'),
  91. # default = Path('/home/三轮预处理数据/双车/V2V_CSAE53-2020_ForwardCollision_LST_09.zip'),
  92. # default = Path('/home/三轮预处理数据/双车/V2V_CSAE53-2020_ForwardCollision_LST_016.zip'),
  93. # default = Path('/home/三轮预处理数据/双车/V2V_CSAE53-2020_ForwardCollision_LST_017.zip'),
  94. # default = Path('/home/三轮预处理数据/双车/V2V_CSAE53-2020_ForwardCollision_LST_018.zip'),
  95. # default = Path('/home/三轮预处理数据/双车/V2V_CSAE53-2020_ForwardCollision_LST_019.zip'),
  96. # default = Path('/home/三轮预处理数据/双车/V2V_CSAE53-2020_ForwardCollision_LST_020.zip'),
  97. # default = Path('/home/三轮预处理数据/双车/V2V_CSAE53-2020_ForwardCollision_LST_021.zip'),
  98. # default = Path('/home/三轮预处理数据/双车/V2V_CSAE53-2020_ForwardCollision_LST_022.zip'),
  99. # default = Path('/home/三轮预处理数据/双车/V2V_CSAE53-2020_ForwardCollision_LST_023.zip'),
  100. # default = Path('/home/三轮预处理数据/双车/V2V_CSAE53-2020_ForwardCollision_LST_024.zip'),
  101. # default = Path('/home/三轮预处理数据/双车/V2V_CSAE53-2020_ForwardCollision_LST_025.zip'),
  102. # default = Path('/home/三轮预处理数据/双车/V2V_CSAE53-2020_ForwardCollision_LST_026.zip'),
  103. # default = Path('/home/三轮预处理数据/双车/V2V_CSAE53-2020_ForwardCollision_LST_027.zip'),
  104. # 25-07-29
  105. # default = Path('/home/三轮预处理数据/25-07-29/AD_GBT41798-2022_AutoEmergencyEvacuation_LST_06.zip'),
  106. # default = Path('/home/三轮预处理数据/25-07-29/AD_GBT41798-2022_RoadTraInfraObstRR_LST_16.zip'),
  107. # default = Path('/home/三轮预处理数据/25-07-29/AD_GBT41798-2022_RoadTraInfraObstRR_LST_17.zip'),
  108. # default = Path('/home/三轮预处理数据/25-07-29/AD_GBT41798-2022_VehiclesIdentifyRR_LST_03.zip'),
  109. # default = Path('/home/三轮预处理数据/25-07-29/AD_GBT41798-2022_VehiclesIdentifyRR_LST_04.zip'),
  110. # default = Path('/home/三轮预处理数据/25-07-29/AD_GBT41798-2022_VehiclesIdentifyRR_LST_05.zip'),
  111. # default = Path('/home/三轮预处理数据/25-07-29/AD_GBT41798-2022_VehiclesIdentifyRR_LST_06.zip'),
  112. # default = Path('/home/三轮预处理数据/25-07-29/AD_GBT41798-2022_VehiclesIdentifyRR_LST_07.zip'),
  113. # default = Path('/home/三轮预处理数据/25-07-29/AD_GBT41798-2022_VehiclesIdentifyRR_LST_08.zip'),
  114. # default = Path('/home/三轮预处理数据/25-07-29/AD_GBT41798-2022_VehiclesIdentifyRR_LST_09.zip'),
  115. # default = Path('/home/三轮预处理数据/25-07-29/AD_GBT41798-2022_VehiclesIdentifyRR_LST_010.zip'),
  116. # default = Path('/home/三轮预处理数据/25-07-29/V2C_ReferenceArchitecture1.0_AbnormalVehicleW_LST_01.zip'),
  117. # default = Path('/home/三轮预处理数据/25-07-29/V2C_ReferenceArchitecture1.0_AbnormalVehicleW_LST_02.zip'),
  118. # default = Path('/home/三轮预处理数据/25-07-29/V2C_ReferenceArchitecture1.0_AbnormalVehicleW_LST_03.zip'),
  119. # default = Path('/home/三轮预处理数据/25-07-29/V2C_ReferenceArchitecture1.0_RampMerge_LST_01.zip'),
  120. # default = Path('/home/三轮预处理数据/25-07-29/V2C_ReferenceArchitecture1.0_RampMerge_LST_02.zip'),
  121. # 25-07-31
  122. # default = Path('/home/三轮预处理数据/25-7-31/AD_GBT41798-2022_ParkingT_01.zip'),
  123. # default = Path('/home/三轮预处理数据/25-7-31/AD_GBT41798-2022_ParkingT_02.zip'),
  124. # default = Path('/home/三轮预处理数据/25-7-31/AD_GBT41798-2022_RoadTraInfraObstRR_LST_05.zip'),
  125. # default = Path('/home/三轮预处理数据/25-7-31/AD_GBT41798-2022_RoadTraInfraObstRR_LST_06.zip'),
  126. # default = Path('/home/三轮预处理数据/25-7-31/V2C_ReferenceArchitecture1.0_DrivingLaneRecommendation_LST_01.zip'),
  127. # default = Path('/home/三轮预处理数据/25-7-31/V2C_ReferenceArchitecture1.0_DrivingLaneRecommendation_LST_02.zip'),
  128. # default = Path('/home/三轮预处理数据/25-7-31/V2C_ReferenceArchitecture1.0_DrivingLaneRecommendation_LST_03.zip'),
  129. # default = Path('/home/三轮预处理数据/25-7-31/V2C_ReferenceArchitecture1.0_DynamicSpeedLimitingInformation_LST_01.zip'),
  130. # default = Path('/home/三轮预处理数据/25-7-31/V2C_ReferenceArchitecture1.0_DynamicSpeedLimitingInformation_LST_02.zip'),
  131. # default = Path('/home/三轮预处理数据/25-7-31/V2C_ReferenceArchitecture1.0_EmergencyVehiclesPriority_LST_01.zip'),
  132. # default = Path('/home/三轮预处理数据/25-7-31/V2C_ReferenceArchitecture1.0_SignalLightReminder_LST_01.zip'),
  133. # default = Path('/home/三轮预处理数据/25-7-31/V2C_ReferenceArchitecture1.0_SignalLightReminder_LST_02.zip'),
  134. # default = Path('/home/三轮预处理数据/25-7-31/V2C_ReferenceArchitecture1.0_VisibilityW_LST_01.zip'),
  135. # default = Path('/home/三轮预处理数据/25-7-31/V2C_ReferenceArchitecture1.0_VisibilityW_LST_02.zip'),
  136. # default = Path('/home/三轮预处理数据/25-7-31/V2I_CSAE53-2020_GreenLightOptimalSpeedAdvisory_LST_01.zip'),
  137. # default = Path('/home/三轮预处理数据/25-7-31/V2I_CSAE53-2020_GreenLightOptimalSpeedAdvisory_LST_02.zip'),
  138. # default = Path('/home/三轮预处理数据/25-7-31/V2I_CSAE53-2020_RedLightViolationW_LST_01.zip'),
  139. default = Path('/home/V2X_CSAE53-2020_RedLightViolationW_PGVIL_02_VR.zip'),
  140. # default = Path('/home/三轮预处理数据/25-7-31/V2I_CSAE53-2020_RedLightViolationW_LST_02.zip'),
  141. # default = Path('/home/三轮预处理数据/25-7-31/V2I_CSAE53-2020_RedLightViolationW_LST_03.zip'),
  142. # 25-7-31-2
  143. # default = Path('/home/三轮预处理数据/25-7-31-2/AD_GBT41798-2022_AutoEmergencyEvacuation_LST_01.zip'),
  144. # default = Path('/home/三轮预处理数据/25-7-31-2/AD_GBT41798-2022_AutoEmergencyEvacuation_LST_02.zip'),
  145. # default = Path('/home/三轮预处理数据/25-7-31-2/AD_GBT41798-2022_AutoEmergencyEvacuation_LST_03.zip'),
  146. # default = Path('/home/三轮预处理数据/25-7-31-2/AD_GBT41798-2022_AutoEmergencyEvacuation_LST_04.zip'),
  147. # default = Path('/home/三轮预处理数据/25-7-31-2/AD_GBT41798-2022_DynaDrivTaskInterventionTakeover_LST_01.zip'),
  148. # default = Path('/home/三轮预处理数据/25-7-31-2/AD_GBT41798-2022_PedNonMotoVehIdentifyRR_LST_01.zip'),
  149. # default = Path('/home/三轮预处理数据/25-7-31-2/AD_GBT41798-2022_PedNonMotoVehIdentifyRR_LST_02.zip'),
  150. # default = Path('/home/三轮预处理数据/25-7-31-2/AD_GBT41798-2022_PedNonMotoVehIdentifyRR_LST_03.zip'),
  151. # default = Path('/home/三轮预处理数据/25-7-31-2/AD_GBT41798-2022_PedNonMotoVehIdentifyRR_LST_04.zip'),
  152. # default = Path('/home/三轮预处理数据/25-7-31-2/AD_GBT41798-2022_PedNonMotoVehIdentifyRR_LST_05.zip'),
  153. # default = Path('/home/三轮预处理数据/25-7-31-2/AD_GBT41798-2022_PedNonMotoVehIdentifyRR_LST_06.zip'),
  154. # default = Path('/home/三轮预处理数据/25-7-31-2/AD_GBT41798-2022_PedNonMotoVehIdentifyRR_LST_07.zip'),
  155. # default = Path('/home/三轮预处理数据/25-7-31-2/AD_GBT41798-2022_PedNonMotoVehIdentifyRR_LST_08.zip'),
  156. # default = Path('/home/三轮预处理数据/25-7-31-2/AD_GBT41798-2022_TrafficSignalRR_LST_01.zip'),
  157. # default = Path('/home/三轮预处理数据/25-7-31-2/AD_GBT41798-2022_TrafficSignalRR_LST_02.zip'),
  158. # default = Path('/home/三轮预处理数据/25-7-31-2/AD_GBT41798-2022_TrafficSignalRR_LST_03.zip'),
  159. # default = Path('/home/三轮预处理数据/25-7-31-2/AD_GBT41798-2022_VehiclesIdentifyRR_LST_01.zip'),
  160. # default = Path('/home/三轮预处理数据/25-7-31-2/AD_GBT41798-2022_VehiclesIdentifyRR_LST_02.zip'),
  161. # default = Path('/home/三轮预处理数据/25-7-31-2/V2C_ReferenceArchitecture1.0_NsightVulnerableRoadUserCollisionW_LST_01.zip'),
  162. # default = Path('/home/三轮预处理数据/25-7-31-2/V2C_ReferenceArchitecture1.0_NsightVulnerableRoadUserCollisionW_LST_02.zip'),
  163. # default = Path('/home/三轮预处理数据/25-7-31-2/V2C_ReferenceArchitecture1.0_NsightVulnerableRoadUserCollisionW_LST_03.zip'),
  164. # 25-08-01
  165. # default = Path('/home/三轮预处理数据/25-08-01/AD_GBT41798-2022_RoadTraInfraObstRR_LST_01.zip'),
  166. # default = Path('/home/三轮预处理数据/25-08-01/AD_GBT41798-2022_RoadTraInfraObstRR_LST_02.zip'),
  167. # default = Path('/home/三轮预处理数据/25-08-01/V2C_ReferenceArchitecture1.0_TrafficJamW_LST_01.zip'),
  168. # default = Path('/home/三轮预处理数据/25-08-01/V2C_ReferenceArchitecture1.0_TrafficJamW_LST_02.zip'),
  169. # default = Path('/home/三轮预处理数据/25-08-01/V2I_CSAE157-2020_CooperativeIntersectionPassing_LST_01.zip'),
  170. # default = Path('/home/三轮预处理数据/25-08-01/V2I_CSAE157-2020_CooperativeIntersectionPassing_LST_03.zip'),
  171. # delivery
  172. # default = Path('/home/三轮预处理数据/delivery/AD_GBT41798-2022_TrafficSignalRecognitionAndResponse_LST_01.zip'),
  173. # default = Path('/home/三轮预处理数据/delivery/AD_GBT41798-2022_TrafficSignalRecognitionAndResponse_LST_02.zip'),
  174. # default = Path('/home/三轮预处理数据/delivery/AD_GBT41798-2022_TrafficSignalRecognitionAndResponse_LST_03.zip'),
  175. # default = Path('/home/三轮预处理数据/delivery/AD_GBT41798-2022_TrafficSignalRecognitionAndResponse_LST_04.zip'),
  176. # default = Path('/home/三轮预处理数据/delivery/AD_GBT41798-2022_TrafficSignalRecognitionAndResponse_LST_05.zip'),
  177. # default = Path('/home/三轮预处理数据/delivery/AD_GBT41798-2022_TrafficSignalRecognitionAndResponse_LST_06.zip'),
  178. # default = Path('/home/三轮预处理数据/delivery/AD_GBT41798-2022_TrafficSignalRecognitionAndResponse_LST_07.zip'),
  179. # default = Path('/home/三轮预处理数据/delivery/AD_GBT41798-2022_TrafficSignalRecognitionAndResponse_LST_08.zip'),
  180. # default = Path('/home/三轮预处理数据/delivery/AD_GBT41798-2022_TrafficSignalRecognitionAndResponse_LST_09.zip'),
  181. help='输入的ZIP数据文件路径'
  182. )
  183. parser.add_argument(
  184. '--trafficlight-json',
  185. type=Path,
  186. default='/home/predataprocess_report.json',
  187. # default='/home/RedLightViolationW_LST_01.json',
  188. help='交通信号灯JSON配置文件路径'
  189. )
  190. parser.add_argument(
  191. '--output-dir',
  192. type=Path,
  193. default=Path('/home/output/'),
  194. help='输出目录的基础路径'
  195. )
  196. parser.add_argument(
  197. '--utm-zone',
  198. type=int,
  199. default=51,
  200. help='UTM坐标系区域 (默认: 51)'
  201. )
  202. parser.add_argument(
  203. '--x-offset',
  204. type=float,
  205. # default=0.0,
  206. default=258106.4554485,
  207. help='X坐标偏移量'
  208. )
  209. parser.add_argument(
  210. '--y-offset',
  211. type=float,
  212. # default=0.0,
  213. default=4149956.271320,
  214. help='Y坐标偏移量'
  215. )
  216. parser.add_argument(
  217. '--config',
  218. type=Path,
  219. default=Path('config/config.json'),
  220. help='配置文件路径'
  221. )
  222. parser.add_argument(
  223. '--plugins-dir',
  224. type=Path,
  225. default=Path('plugins'),
  226. help='插件目录路径'
  227. )
  228. parser.add_argument(
  229. '--resources-dir',
  230. type=Path,
  231. default=Path('resources'),
  232. help='资源文件目录路径'
  233. )
  234. parser.add_argument(
  235. '--use-parallel',
  236. action='store_true',
  237. help='启用并行处理'
  238. )
  239. parser.add_argument(
  240. '--no-parallel',
  241. action='store_true',
  242. help='禁用并行处理'
  243. )
  244. parser.add_argument(
  245. '--max-workers',
  246. type=int,
  247. default=None,
  248. help='并行处理的最大工作线程数'
  249. )
  250. parser.add_argument(
  251. '--batch-size',
  252. type=int,
  253. default=10000,
  254. help='处理大数据集时的批处理大小'
  255. )
  256. parser.add_argument(
  257. '--log-level',
  258. type=str,
  259. choices=['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'],
  260. default='INFO',
  261. help='日志级别'
  262. )
  263. parser.add_argument(
  264. '--log-dir',
  265. type=Path,
  266. default=Path('logs'),
  267. help='日志文件目录'
  268. )
  269. parser.add_argument(
  270. '--no-log-file',
  271. action='store_true',
  272. help='禁用文件日志'
  273. )
  274. return parser.parse_args()
  275. def setup_config(args):
  276. """设置配置"""
  277. # 根据ZIP文件名创建输出目录
  278. zip_name = args.zip_path.stem
  279. output_dir = args.output_dir / zip_name
  280. output_dir.mkdir(parents=True, exist_ok=True)
  281. print(f"输出目录: {output_dir}")
  282. # 加载配置
  283. config = load_config(args.config)
  284. # 更新配置中的输出目录为包含zip名称的子目录
  285. config['paths']['output_dir'] = str(output_dir)
  286. config['paths']['data_dir'] = str(output_dir) # 确保数据也输出到同一目录
  287. config['paths']['temp_dir'] = str(output_dir) # 确保临时文件也在同一目录
  288. # 使用命令行参数覆盖配置文件中的设置
  289. if args.use_parallel and args.no_parallel:
  290. print("警告: 同时指定了 --use-parallel 和 --no-parallel,将使用 --use-parallel")
  291. config['processing']['use_parallel'] = True
  292. elif args.use_parallel:
  293. config['processing']['use_parallel'] = True
  294. elif args.no_parallel:
  295. config['processing']['use_parallel'] = False
  296. if args.max_workers is not None:
  297. config['processing']['max_workers'] = args.max_workers
  298. if args.batch_size != 10000: # 不等于默认值
  299. config['processing']['batch_size'] = args.batch_size
  300. # 更新日志配置
  301. config['logging']['level'] = args.log_level
  302. config['logging']['log_dir'] = str(args.log_dir)
  303. config['logging']['log_to_file'] = not args.no_log_file
  304. # 更新坐标系配置
  305. config['coordinates']['utm_zone'] = args.utm_zone
  306. config['coordinates']['x_offset'] = args.x_offset
  307. config['coordinates']['y_offset'] = args.y_offset
  308. # 更新路径配置
  309. config['paths']['plugins_dir'] = str(args.plugins_dir)
  310. config['paths']['resources_dir'] = str(args.resources_dir)
  311. # 应用更新后的配置
  312. update_config(config)
  313. return output_dir
  314. def process_plugins(args, output_dir, final_csv_path):
  315. """处理插件数据"""
  316. # 初始化插件处理管理器
  317. plugin_manager = PluginManager(args.plugins_dir)
  318. resource_manager = ResourceManager(args.resources_dir)
  319. # 处理自定义数据
  320. print("处理并合并自定义数据...")
  321. # for zip_path in args.zip_path:
  322. folders = resource_manager.list_zip_folders(args.zip_path)
  323. for folder in folders:
  324. plugin = plugin_manager.get_plugin_for_data(args.zip_path, folder)
  325. if not plugin:
  326. print(f"未找到文件夹的插件: {folder}")
  327. continue
  328. print(f"使用插件 '{plugin.__name__}' 处理文件夹 '{folder}'")
  329. plugin_instance = plugin()
  330. plugin_output = plugin_instance.process_data(
  331. args.zip_path,
  332. folder,
  333. output_dir
  334. )
  335. if plugin_output is not None and not plugin_output.empty:
  336. output_file = output_dir / f"{folder}_processed.csv"
  337. print(f'插件输出文件: {output_file}')
  338. plugin_output.to_csv(output_file, index=False)
  339. if not resource_manager.validate_plugin_output(output_file):
  340. print(f"警告: 插件输出验证失败: {folder}")
  341. continue
  342. # 合并自定义数据与主数据文件
  343. print(f"合并 {folder} 数据...")
  344. if resource_manager.merge_plugin_data(
  345. final_csv_path,
  346. output_file,
  347. final_csv_path
  348. ):
  349. print(f"成功合并 {folder} 数据")
  350. else:
  351. print(f"警告: 合并 {folder} 数据失败")
  352. else:
  353. print(f"警告: 插件处理失败: {folder}")
  354. def main():
  355. """主函数"""
  356. args = parse_arguments()
  357. try:
  358. # 设置配置
  359. output_dir = setup_config(args)
  360. print("开始数据处理流程")
  361. print(f"从以下位置加载配置: {args.config}")
  362. # 根据数据类型选择处理流程
  363. if args.data_type == 'lst':
  364. final_csv_path = process_lst_data(
  365. zip_data_path=args.zip_path,
  366. output_base_dir=output_dir,
  367. trafficlight_json_path=args.trafficlight_json,
  368. utm_zone=args.utm_zone,
  369. x_offset=args.x_offset,
  370. y_offset=args.y_offset
  371. )
  372. elif args.data_type == 'pgvil':
  373. final_csv_path = process_pgvil_data(
  374. zip_data_path=args.zip_path,
  375. output_base_dir=output_dir,
  376. utm_zone=args.utm_zone,
  377. x_offset=args.x_offset,
  378. y_offset=args.y_offset
  379. )
  380. else:
  381. print(f"不支持的数据类型: {args.data_type}")
  382. sys.exit(1)
  383. if not final_csv_path:
  384. print(f"{args.data_type}内置数据处理失败")
  385. sys.exit(1)
  386. print(f"\n{args.data_type}内置处理流程成功完成!")
  387. # 处理插件数据
  388. process_plugins(args, output_dir, final_csv_path)
  389. print("LST数据处理成功完成")
  390. print(f"所有处理结果已保存到: {output_dir}")
  391. sys.exit(0)
  392. except Exception as e:
  393. print(f"\n处理过程中出现错误: {e}")
  394. traceback.print_exc()
  395. sys.exit(1)
  396. if __name__ == "__main__":
  397. main()