Skip to content

Commit 0943ab7

Browse files
committed
fix: cyber_record may fail unexpectedly
1 parent bdeca8e commit 0943ab7

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

framework/oracles/__init__.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from framework.oracles.impl.JunctionLaneChangeOracle import JunctionLaneChangeOracle
1515

1616
from typing import List, Tuple
17+
import time
1718

1819

1920
class RecordAnalyzer:
@@ -23,11 +24,15 @@ class RecordAnalyzer:
2324
:param str record_path: filename of the record
2425
"""
2526
record_path: str
27+
analyzed: bool
28+
MAX_RETRY = 3 # times
29+
RETRY_DELAY = 2 # seconds
2630

2731
def __init__(self, record_path: str) -> None:
2832
self.oracle_manager = OracleManager()
2933
self.record_path = record_path
3034
self.register_oracles()
35+
self.analyzed = False
3136

3237
def register_oracles(self):
3338
"""
@@ -56,10 +61,22 @@ def analyze(self) -> List[Tuple]:
5661
:returns: list of violations
5762
:rtype: List[Tuple]
5863
"""
59-
record = Record(self.record_path)
60-
for topic, message, t in record.read_messages():
61-
self.oracle_manager.on_new_message(topic, message, t)
62-
return self.get_results()
64+
trial = 1
65+
while trial <= RecordAnalyzer.MAX_RETRY:
66+
try :
67+
record = Record(self.record_path)
68+
for topic, message, t in record.read_messages():
69+
self.oracle_manager.on_new_message(topic, message, t)
70+
self.analyzed = True
71+
return self.get_results()
72+
except AttributeError:
73+
time.sleep(2)
74+
trial += 1
75+
except FileNotFoundError:
76+
time.sleep(2)
77+
trial += 1
78+
return list()
79+
6380

6481
def get_results(self) -> List[Tuple]:
6582
"""
@@ -68,4 +85,6 @@ def get_results(self) -> List[Tuple]:
6885
:returns: list of violations
6986
:rtype: List[Tuple]
7087
"""
88+
if not self.analyzed:
89+
return list()
7190
return self.oracle_manager.get_results()

test_analyzer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from hdmap.MapParser import MapParser
33

44
ma = MapParser('./data/maps/borregas_ave/base_map.bin')
5-
record_path = "/home/yuqi/ResearchWorkspace/apollo/movies/movie_yuqi/Generation_00021/Scenario_00002/apollo_dev_ROUTE_1.Scenario_00002.00000"
5+
record_path = ""
66
ra = RecordAnalyzer(record_path)
77
ra.analyze()
88
print(ra.get_results())

0 commit comments

Comments
 (0)