|
|
@@ -16,16 +16,19 @@ class PoABLayer(BaseLayer):
|
|
|
"""
|
|
|
|
|
|
__colors__ = {
|
|
|
- "highlight": [255, 255, 0, 100], # yellow
|
|
|
+ "highlight": [150, 0, 250, 200], # yellow
|
|
|
"nodes": [150, 0, 250, 200], # purple
|
|
|
- "sailing": [0, 150, 250, 200], # blue
|
|
|
- "tugging": [150, 250, 0, 200] # green
|
|
|
+ "ecological": [0, 255, 0, 200] # green
|
|
|
}
|
|
|
|
|
|
def __init__(self, sim=None, streamer=None):
|
|
|
self.sim = sim
|
|
|
self.streamer = streamer
|
|
|
self.sim_active = False
|
|
|
+ self.starting = False
|
|
|
+
|
|
|
+ self.sailing = sim.model.sailer.v_sailing
|
|
|
+ self.tugging = sim.model.sailer.v_tugging
|
|
|
|
|
|
self.berths = pd.read_csv("berths.csv")
|
|
|
# Uncomment the following lines if the berths list should only look at berths used
|
|
|
@@ -104,7 +107,10 @@ class PoABLayer(BaseLayer):
|
|
|
|
|
|
|
|
|
if not self.sim_active:
|
|
|
- ui_manager.status("Press Space to Start Simulation")
|
|
|
+ if self.starting:
|
|
|
+ ui_manager.status("Starting Simulation...")
|
|
|
+ else:
|
|
|
+ ui_manager.status("Press Space to Start Simulation")
|
|
|
else:
|
|
|
# Show the simulation time in top right
|
|
|
# model = self.sim.model
|
|
|
@@ -118,9 +124,18 @@ class PoABLayer(BaseLayer):
|
|
|
for vessel in self.streamer.vessels:
|
|
|
if vessel.source is not None and vessel.target is not None:
|
|
|
if vessel.task == "sailing":
|
|
|
- self.painter.set_color(self.__colors__["sailing"])
|
|
|
+ rng = self.sailing
|
|
|
else:
|
|
|
- self.painter.set_color(self.__colors__["tugging"])
|
|
|
+ rng = self.tugging
|
|
|
+ col = self.__colors__["ecological"]
|
|
|
+ dist = 0
|
|
|
+ if vessel.velocity < rng[0]:
|
|
|
+ dist = rng[0] - vessel.velocity
|
|
|
+ elif vessel.velocity > rng[1]:
|
|
|
+ dist = vessel.velocity - rng[1]
|
|
|
+ col[0] = min(255, int(dist) * 50)
|
|
|
+ col[1] = 255 - min(255, int(dist) * 50)
|
|
|
+ self.painter.set_color(col)
|
|
|
|
|
|
# Obtain (and draw) vessel trajectory
|
|
|
if vessel.mmsi not in self.vcache or self.vcache[vessel.mmsi] != vessel.source:
|
|
|
@@ -130,6 +145,8 @@ class PoABLayer(BaseLayer):
|
|
|
|
|
|
path, dists = self.pcache[vessel.mmsi]
|
|
|
|
|
|
+ self.draw_path(path, proj)
|
|
|
+
|
|
|
# Compute distance traveled and draw a vessel there
|
|
|
tot_distance = vessel.total_distance
|
|
|
traveled_approx = tot_distance - vessel.distance_left
|
|
|
@@ -150,12 +167,11 @@ class PoABLayer(BaseLayer):
|
|
|
if euler_distance(sx + dx, sy + dy, mouse_x, mouse_y) < 10:
|
|
|
self.painter.set_color(self.__colors__["highlight"])
|
|
|
tooltips.append("%s (MMSI: %s)" % (str(vessel.name), str(vessel.mmsi)))
|
|
|
- tooltips.append("velocity: %.3f m/s" % vessel.velocity)
|
|
|
- tooltips.append("distance total: %.3f m" % vessel.total_distance)
|
|
|
- tooltips.append("distance left: %.3f m" % vessel.distance_left)
|
|
|
- tooltips.append("ETA: %s" % epoch_to_str(vessel.distance_left / vessel.velocity + ts))
|
|
|
+ tooltips.append("task: %s | ETA: %s" % (vessel.task, epoch_to_str(vessel.distance_left / vessel.velocity + ts)))
|
|
|
+ tooltips.append("velocity: %.3f m/s%s" % (vessel.velocity, "" if dist > 0 else " (ecological)"))
|
|
|
+ tooltips.append("dist left/total: %.3f/%.3f m" % (vessel.distance_left, vessel.total_distance))
|
|
|
|
|
|
- self.draw_path(path, proj)
|
|
|
+ # self.draw_path(path, proj)
|
|
|
self.draw_shape(sx + dx, sy + dy)
|
|
|
|
|
|
ui_manager.tooltip("\n".join(tooltips))
|
|
|
@@ -168,6 +184,7 @@ class PoABLayer(BaseLayer):
|
|
|
def on_key_release(self, key, modifiers):
|
|
|
if key == pyglet.window.key.SPACE:
|
|
|
if self.sim is not None:
|
|
|
+ self.starting = True
|
|
|
self.sim.simulate()
|
|
|
self.sim_active = True
|
|
|
|