|
@@ -19,10 +19,53 @@ osgb = 'thq_20230710.osgb'
|
|
|
|
|
|
vehicle_name = 'PuJin_distribution' # 配送 PuJin_distribution 巡检 PuJin_patrol_robot
|
|
vehicle_name = 'PuJin_distribution' # 配送 PuJin_distribution 巡检 PuJin_patrol_robot
|
|
xoscName = 'scenario.xosc'
|
|
xoscName = 'scenario.xosc'
|
|
-logging.basicConfig(filename=path2 + 'log/2simulation.log', level=logging.INFO,
|
|
|
|
|
|
+logging.basicConfig(filename=path2 + 'log/2simulation-pjibot_delivery.log', level=logging.INFO,
|
|
format='%(asctime)s - %(levelname)s - %(message)s')
|
|
format='%(asctime)s - %(levelname)s - %(message)s')
|
|
|
|
|
|
-sleep_time = 60 # 每多少秒扫描一次
|
|
|
|
|
|
+sleep_time = 30 # 每多少秒扫描一次
|
|
|
|
+
|
|
|
|
+error_bag_json = "/mnt/disk001/dcl_data_process/src/python2/pjisuv/2simulation-errorBag.json"
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def parse_json_to_string_array(file_path):
|
|
|
|
+ try:
|
|
|
|
+ # 打开并读取JSON文件(Python 2中不支持encoding参数,需要使用codecs模块或处理文件读取后的编码)
|
|
|
|
+ with open(file_path, 'r') as file:
|
|
|
|
+ # 读取文件内容
|
|
|
|
+ file_content = file.read()
|
|
|
|
+ # 解析JSON内容(Python 2中json.loads用于解析字符串)
|
|
|
|
+ data = json.loads(file_content.decode('utf-8')) # 假设文件是UTF-8编码,这里需要手动解码
|
|
|
|
+
|
|
|
|
+ # 检查数据是否是一个列表,并且列表中的元素是否是字符串
|
|
|
|
+ if isinstance(data, list):
|
|
|
|
+ for item in data:
|
|
|
|
+ if not isinstance(item, basestring): # Python 2中字符串类型包括str和unicode,用basestring检查
|
|
|
|
+ raise ValueError("JSON数组中的元素不是字符串")
|
|
|
|
+ return data
|
|
|
|
+ else:
|
|
|
|
+ return []
|
|
|
|
+ except Exception as e:
|
|
|
|
+ return []
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def list_to_json_file(data, file_path):
|
|
|
|
+ """
|
|
|
|
+ 将列表转换为JSON格式并写入指定的文件路径。
|
|
|
|
+ 如果文件已存在,则覆盖它。
|
|
|
|
+
|
|
|
|
+ 参数:
|
|
|
|
+ data (list): 要转换为JSON的列表。
|
|
|
|
+ file_path (str): 要写入JSON数据的文件路径。
|
|
|
|
+ """
|
|
|
|
+ # 将列表转换为JSON格式的字符串,并确保输出为UTF-8编码的字符串
|
|
|
|
+ json_data = json.dumps(data, ensure_ascii=False, indent=4)
|
|
|
|
+ json_data_utf8 = json_data.encode('utf-8') # 编码为UTF-8
|
|
|
|
+
|
|
|
|
+ # 以写入模式打开文件,如果文件已存在则覆盖
|
|
|
|
+ with open(file_path, 'w') as file:
|
|
|
|
+ # 将UTF-8编码的JSON字符串写入文件
|
|
|
|
+ file.write(json_data_utf8)
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
def move_xosc_before_simulation(root_path):
|
|
def move_xosc_before_simulation(root_path):
|
|
@@ -53,6 +96,9 @@ def upload_simulation(parse_prefix, mp41):
|
|
logging.info('上传仿真视频到 %s' % parse_prefix + 'scenario_orig.mp4')
|
|
logging.info('上传仿真视频到 %s' % parse_prefix + 'scenario_orig.mp4')
|
|
shutil.rmtree(path1) # 仿真完就删除
|
|
shutil.rmtree(path1) # 仿真完就删除
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
|
+ error_bag_list = parse_json_to_string_array(error_bag_json)
|
|
|
|
+ error_bag_list.append(parse_prefix)
|
|
|
|
+ list_to_json_file(error_bag_list, error_bag_json)
|
|
logging.exception("上传视频报错 %s" % str(e))
|
|
logging.exception("上传视频报错 %s" % str(e))
|
|
|
|
|
|
|
|
|
|
@@ -120,6 +166,9 @@ if __name__ == '__main__':
|
|
continue
|
|
continue
|
|
if mp4_done:
|
|
if mp4_done:
|
|
continue
|
|
continue
|
|
|
|
+ error_bag_list = parse_json_to_string_array(error_bag_json)
|
|
|
|
+ if str(parse_prefix_full) in error_bag_list:
|
|
|
|
+ continue
|
|
logging.info("需要生成仿真视频: %s" % str(parse_prefix_full))
|
|
logging.info("需要生成仿真视频: %s" % str(parse_prefix_full))
|
|
parse_prefix_full = str(parse_prefix_full)
|
|
parse_prefix_full = str(parse_prefix_full)
|
|
local_dir_full = path1 + parse_prefix_full
|
|
local_dir_full = path1 + parse_prefix_full
|