Skip to content

Commit

Permalink
Use common CASE_FILENAMES for bks-report and app
Browse files Browse the repository at this point in the history
  • Loading branch information
mangoozt committed Oct 20, 2020
1 parent 6c9f923 commit f225393
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 21 deletions.
24 changes: 12 additions & 12 deletions bks-report.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from matplotlib import pyplot as plt

from plot import plot_from_files
from plot import plot_from_files, Case


def fix_returncode(code):
Expand All @@ -35,7 +35,7 @@ def run_case(self, datadir, usv, rvo=None):
os.chdir(datadir)

# Get a list of old results
file_list = glob.glob('maneuver*.json') + glob.glob('nav-report.json')
file_list = glob.glob(Case.CASE_FILENAMES['maneuvers']) + glob.glob(Case.CASE_FILENAMES['analyse'])
for filePath in file_list:
try:
os.remove(filePath)
Expand All @@ -44,16 +44,16 @@ def run_case(self, datadir, usv, rvo=None):

# Print the exit code.
exec_time = time.time()
completedProc = subprocess.run([usv, "--target-settings", "target-settings.json",
"--targets", "target-data.json",
"--settings", "settings.json",
"--nav-data", "nav-data.json",
"--hydrometeo", "hmi-data.json",
"--constraints", "constraints.json",
"--route", "route-data.json",
"--maneuver", "maneuver.json",
"--analyse", "analyse.json",
"--predict","target-maneuvers.json",
completedProc = subprocess.run([usv, "--target-settings", Case.CASE_FILENAMES['target_settings'],
"--targets", Case.CASE_FILENAMES['targets_data'],
"--settings", Case.CASE_FILENAMES['settings'],
"--nav-data", Case.CASE_FILENAMES['nav_data'],
"--hydrometeo", Case.CASE_FILENAMES['hydrometeo'],
"--constraints", Case.CASE_FILENAMES['constraints'],
"--route", Case.CASE_FILENAMES['route'],
"--maneuver", Case.CASE_FILENAMES['maneuvers'],
"--analyse", Case.CASE_FILENAMES['analyse'],
"--predict", Case.CASE_FILENAMES['targets_maneuvers'],
("--rvo" if rvo is True else "--no-rvo" if rvo is False else "")],
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
exec_time = time.time() - exec_time
Expand Down
33 changes: 24 additions & 9 deletions plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,37 @@ def load_json(filename):


def load_case_from_directory(dir_path):
return Case(nav_data=load_json(os.path.join(dir_path, 'nav-data.json')),
maneuvers=load_json(os.path.join(dir_path, 'maneuver.json')),
targets_data=load_json(os.path.join(dir_path, 'target-data.json')),
targets_maneuvers=load_json(os.path.join(dir_path, 'target-maneuvers.json')),
targets_real=load_json(os.path.join(dir_path, 'real-target-maneuvers.json')),
analyse=load_json(os.path.join(dir_path, 'analyse.json')),
constraints=load_json(os.path.join(dir_path, 'constraints.json')),
route=load_json(os.path.join(dir_path, 'route-data.json')),
settings=load_json(os.path.join(dir_path, 'settings.json')))
def load_file(dataname):
return load_json(os.path.join(dir_path, Case.CASE_FILENAMES[dataname]))

return Case(nav_data=load_file('nav_data'),
maneuvers=load_file('maneuvers'),
targets_data=load_file('targets_data'),
targets_maneuvers=load_file('targets_maneuvers'),
targets_real=load_file('targets_real'),
analyse=load_file('analyse'),
constraints=load_file('constraints'),
route=load_file('route'),
settings=load_file('settings'))


def path_time(path):
return sum([x['duration'] for x in path['items']])


class Case:
CASE_FILENAMES = {'nav_data': 'nav-data.json',
'maneuvers': 'maneuver.json',
'targets_data': 'target-data.json',
'target_settings': 'target-settings.json',
'targets_maneuvers': 'target-maneuvers.json',
'targets_real': 'real-target-maneuvers.json',
'analyse': 'nav-report.json',
'constraints': 'constraints.json',
'route': 'route-data.json',
'settings': 'settings.json',
'hydrometeo': 'hmi-data.json'}

def __init__(self, nav_data=None, maneuvers=None, targets_data=None, targets_maneuvers=None, targets_real=None,
analyse=None, constraints=None, route=None, settings=None):
self.nav_data = nav_data
Expand Down

0 comments on commit f225393

Please sign in to comment.