1 # -*- coding: utf-8 -*-
2 """This scipt loads result JSON and print cost dependent on time.
5 argv[1] -- 1st file/folder with json trajectory results.
6 argv[2] -- 2nd file/folder with json trajectory results.
9 from math import cos, pi, sin
10 from matplotlib import pyplot as plt
11 from os import listdir
12 from sys import argv, exit
20 print("Exactly 2 arguments needed.")
26 def load_trajectory(fname):
27 """Load trajectory from file."""
29 raise ValueError("File name as argument needed")
30 with open(fname, "r") as f:
31 trajectory = loads(f.read())
34 def plot_nodes(nodes=[]):
35 """Return xcoords, ycoords of nodes to plot.
38 nodes -- The list of nodes to plot.
45 return (xcoords, ycoords)
47 if __name__ == "__main__":
52 # blue nodes (not parallel)
54 for f in listdir(TRAJ_FILE):
56 t = load_trajectory("{}/{}".format(TRAJ_FILE, f))
57 for p in zip(t["secs"], t[YAX]):
59 nhist.append(t["elap"])
64 t = load_trajectory(TRAJ_FILE) # fixed to trajectories
65 for p in zip(t["secs"], t[YAX]):
67 nhist.append(t["elap"])
69 print("Failed loading 1st")
71 # red nodes (parallel)
73 for f in listdir(TRAJ_FILE2):
75 t = load_trajectory("{}/{}".format(TRAJ_FILE2, f))
76 for p in zip(t["secs"], t[YAX]):
78 phist.append(t["elap"])
83 t = load_trajectory(TRAJ_FILE2) # fixed to trajectories
84 for p in zip(t["secs"], t[YAX]):
86 phist.append(t["elap"])
88 print("Failed loading 2nd")
92 ax = fig.add_subplot(111)
94 ax.set_aspect("equal")
97 ax.set_title("SCENARIO")
98 ax.set_xlabel("Time [s]")
100 ax.set_ylabel("Cost (Euclidean length) [m]")
102 ax.set_ylabel("Number of nodes [-]")
110 plt.plot(*plot_nodes(nodes), color="blue")
111 plt.plot(*plot_nodes(podes), color="red")
117 #plt.savefig("{}_{}.png".format(argv[1], argv[2]))
120 if ELAP_HIST_MAX > 0:
121 plt.hist(nhist, log=True, range=[0, ELAP_HIST_MAX], bins=100)
123 plt.hist(phist, log=True, range=[0, ELAP_HIST_MAX], bins=100)