Commit 708f3adb authored by hagrid67's avatar hagrid67
Browse files

added separate debug mouse move checkbox

added on_click debug message containing transition info at the clicked cell
parent 4e9a18df
......@@ -49,6 +49,7 @@ class JupEditor(object):
self.gRCTrans = array([[-1, 0], [0, 1], [1, 0], [0, -1]]) # NESW in RC
self.debug = False
self.debug_move = False
self.wid_output = None
self.drawMode = "Draw"
self.env_filename = "temp.npy"
......@@ -65,7 +66,11 @@ class JupEditor(object):
def setDebug(self, dEvent):
self.debug = dEvent["new"]
self.log("Debug:", self.debug)
self.log("Set Debug:", self.debug)
def setDebugMove(self, dEvent):
self.debug_move = dEvent["new"]
self.log("Set DebugMove:", self.debug)
def setOutput(self, wid_output):
self.wid_output = wid_output
......@@ -89,6 +94,13 @@ class JupEditor(object):
# self.log("agent", self.drawMode, self.iAgent, rcCell)
if self.debug:
self.log("debug:", event)
binTrans = self.env.rail.get_transitions(rcCell)
sbinTrans = format(binTrans, "#018b")[2:]
self.log("cell ", rcCell, "Transitions: ", binTrans, sbinTrans,
[sbinTrans[i:i+4] for i in range(0, len(sbinTrans), 4)])
self.redraw()
def event_handler(self, wid, event):
......@@ -102,7 +114,7 @@ class JupEditor(object):
bRedrawn = False
writableData = None
if self.debug:
if self.debug and (event["buttons"] > 0 or self.debug_move):
self.log("debug:", len(qEvents), len(rcHistory), event)
assert wid == self.wid_img, "wid not same as wid_img"
......
......@@ -94,10 +94,34 @@
%%%% Output: execute_result
10
%% Cell type:code id: tags:
``` python
import sys
sys.path
```
%%%% Output: execute_result
['/home/jeremy/projects/heating',
'/home/jeremy/projects/aicrowd/rl-trains/MAgent/python',
'/home/jeremy/ve367/lib/python36.zip',
'/home/jeremy/ve367/lib/python3.6',
'/home/jeremy/ve367/lib/python3.6/lib-dynload',
'/usr/lib/python3.6',
'',
'/home/jeremy/ve367/lib/python3.6/site-packages',
'/home/jeremy/projects/aicrowd/rl-trains/torch-rl/torch_rl',
'/home/jeremy/projects/aicrowd/rl-trains/gym-minigrid',
'/home/jeremy/projects/aicrowd/rl-trains/flatland',
'/home/jeremy/projects/aicrowd/rl-trains/Jupyter_Canvas_Widget',
'/home/jeremy/ve367/lib/python3.6/site-packages/IPython/extensions',
'/home/jeremy/.ipython']
%% Cell type:markdown id: tags:
### Clear the rails
%% Cell type:code id: tags:
......@@ -150,10 +174,13 @@
``` python
wid_drawMode = ipywidgets.RadioButtons(options=["Draw", "Erase", "Origin", "Destination"])
wid_drawMode.observe(oEditor.setDrawMode, names="value")
wid_debug = ipywidgets.Checkbox(description = "Debug")
wid_debug.observe(oEditor.setDebug, names="value")
wid_debug_move = ipywidgets.Checkbox(description = "Debug mouse move")
wid_debug_move.observe(oEditor.setDebugMove, names="value")
wid_output = ipywidgets.Output()
oEditor.setOutput(wid_output)
wid_filename = ipywidgets.Text(description = "Filename")
wid_filename.value = sfEnv
oEditor.setFilename(sfEnv)
......@@ -182,11 +209,11 @@
wid_button.on_click(dButton["method"])
lwid_buttons.append(wid_button)
#wid_debug = interact(oEditor.setDebug, debug=False)
vbox_controls = VBox([wid_filename, wid_drawMode, *lwid_buttons, wid_size, wid_debug])
vbox_controls = VBox([wid_filename, wid_drawMode, *lwid_buttons, wid_size, wid_debug, wid_debug_move])
```
%% Cell type:markdown id: tags:
......@@ -203,56 +230,33 @@
```
%%%% Output: display_data
%%%% Output: error
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
~/projects/aicrowd/rl-trains/flatland/flatland/utils/editor.py in on_click(self, wid, event)
80
81 if self.drawMode == "Origin":
---> 82 self.iAgent = self.env.add_agent(rcCell, rcCell, None)
83 self.drawMode = "Destination"
84 self.player = None # will need to start a new player
~/projects/aicrowd/rl-trains/flatland/flatland/envs/rail_env.py in add_agent(self, rcPos, rcTarget, iDir)
536 if iDir is None:
537 iDir = self.pick_agent_direction(rcPos, rcTarget)
--> 538 self.agents_direction[iAgent] = iDir
539
540 self.agents_direction.append(0)
IndexError: list assignment index out of range
%% Cell type:code id: tags:
``` python
oEditor.env.number_of_agents
```
%%%% Output: execute_result
0
%% Cell type:code id: tags:
``` python
wid_output.clear_output()
wid_output
```
%%%% Output: display_data
%% Cell type:markdown id: tags:
### Experimental
enable the thread.start below to try background stepping of the agents. It tends to make a mess.
%% Cell type:code id: tags:
``` python
import threading
def bgUpdate(editor):
for i in range(100):
editor.step_event()
time.sleep(0.2)
```
%% Cell type:code id: tags:
......@@ -261,21 +265,23 @@
```
%% Cell type:code id: tags:
``` python
#thread.start()
if False:
thread.start()
```
%% Cell type:markdown id: tags:
### Save the image (change the filename...)
%% Cell type:code id: tags:
``` python
oEnv.rail.save_transition_map("../flatland/env-data/tests/test-editor.npy")
if False:
oEnv.rail.save_transition_map("../flatland/env-data/tests/test-editor.npy")
```
%% Cell type:markdown id: tags:
## Junk below here
......@@ -390,11 +396,19 @@
%% Cell type:code id: tags:
``` python
[2,3] == (2,3)
binTrans = format(32800, "#016b")
[binTrans[i+2:i+6] for i in range(0, len(binTrans)-2, 4)]
```
%%%% Output: execute_result
False
['1000', '0000', '0010', '0000']
%% Cell type:code id: tags:
``` python
```
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment