MCPcopy Create free account
hub / github.com/Tencent/TAD_Sim / parse

Method parse

simcore/post_script/pb_save_agent.py:304–378  ·  view source on GitHub ↗

parse .pblog file :param pblog_file: .pblog file :return: None

(self, pblog_path: str, start_ms: float, end_ms: float, simrec_path: str, frames_path: str, ext_info: str)

Source from the content-addressed store, hash-verified

302 return json.dumps(data)
303
304 def parse(self, pblog_path: str, start_ms: float, end_ms: float, simrec_path: str, frames_path: str, ext_info: str):
305 """
306 parse .pblog file
307 :param pblog_file: .pblog file
308 :return: None
309 """
310
311 # 异常处理 - pblog 文件不存在
312 if not os.path.exists(pblog_path):
313 glog.error("usage: python PostProcess.py -f <pblog file>")
314 return False
315
316 #
317 self.pb_log_file = pblog_path
318 # if simrec_file exists. remove
319 if simrec_path and os.path.exists(simrec_path):
320 os.remove(simrec_path)
321
322 if frames_path and os.path.exists(frames_path):
323 os.remove(frames_path)
324
325 # 读取 pblog 文件, 并处理异常 - 读取失败
326 if not self.pblog_reader.open(self.pb_log_file):
327 glog.error("fail to open pblog file {}".format(self.pb_log_file))
328 return False
329
330 # 正常业务处理流程
331 # protobuf msg read from .pblog file
332 event = PbEvent(0.0, "", bytes())
333
334 frames_dict = {"frameId": -1, "extInfo": "", "tfc": "", "loc": ""}
335
336 # parse protobuf msg
337 datas_frames = []
338 while self.pblog_reader.read_one(event):
339 if event.topic in self.parser_dict.keys() and start_ms <= event.timestamp <= end_ms:
340 try:
341 if self.parser_dict[event.topic].parse(event):
342 self.parser_dict[TOPIC.TrafficRecords4LogSimParser].serialize(event.topic, self.parser_dict)
343
344 frame_id = int(event.timestamp / 20 + 1)
345
346 if frames_dict["frameId"] != -1 and frame_id != frames_dict["frameId"]:
347 # print("=================================")
348 datas_frames.append(json.dumps(frames_dict))
349
350 frames_dict["frameId"] = frame_id
351 frames_dict["extInfo"] = ext_info
352 # print(event.topic, frame_id)
353
354 if self.parser_dict[TOPIC.LOCATION].parse(event):
355 frames_dict["loc"] = self.parser_dict[TOPIC.LOCATION].get_base64()
356 # print(f"{frames_dict['loc'] = }")
357
358 if self.parser_dict[TOPIC.TRAFFIC].parse(event):
359 frames_dict["tfc"] = self.parser_dict[TOPIC.TRAFFIC].get_base64()
360 # print(f"{frames_dict['tfc'] = }")
361

Callers

nothing calls this directly

Calls 14

set_data_simrecMethod · 0.95
save2fileMethod · 0.95
PbEventClass · 0.85
read_oneMethod · 0.80
appendMethod · 0.80
openFunction · 0.50
errorMethod · 0.45
removeMethod · 0.45
openMethod · 0.45
parseMethod · 0.45
serializeMethod · 0.45
get_base64Method · 0.45

Tested by

no test coverage detected