From 41b71368eb81e002503598885eae57217de4a204 Mon Sep 17 00:00:00 2001 From: YouGuessedMyName Date: Sat, 1 Feb 2025 13:52:50 +0100 Subject: [PATCH] progress fast exploration --- docs/getting_started/01_study.ipynb | 423 ++++++++------------ docs/getting_started/layouts/pinkgreen.json | 2 +- docs/getting_started/study.html | 29 +- stormvogel/html_templates.py | 17 +- stormvogel/show.py | 1 + stormvogel/visjs.py | 58 ++- stormvogel/visualization.py | 13 +- 7 files changed, 235 insertions(+), 308 deletions(-) diff --git a/docs/getting_started/01_study.ipynb b/docs/getting_started/01_study.ipynb index b76699d..23173e4 100644 --- a/docs/getting_started/01_study.ipynb +++ b/docs/getting_started/01_study.ipynb @@ -161,263 +161,34 @@ "scrolled": true }, "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "be7c1a38bc504a67abc215743d681813", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Output()" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, { "data": { "text/html": [ - "\n", - " \n", + "function return_id_result(url, id, data) {\n", + " fetch(url, {\n", + " method: 'POST',\n", + " body: JSON.stringify({\n", + " 'id': id,\n", + " 'data': data\n", + " })\n", + " })\n", " }\n", - " },\n", - " "width": 800,\n", - " "height": 600,\n", - " "physics": true,\n", - " "results_and_rewards": {\n", - " "show_results": true,\n", - " "resultSymbol": "\\u2606",\n", - " "show_rewards": true\n", - " }\n", - "};\n", - " //js\n", - "var container = document.getElementById("mynetwork");\n", - "var data = {\n", - " nodes: nodes,\n", - " edges: edges,\n", - "};\n", - "var network = new vis.Network(container, data, options);\n", - "function makeAllNodesInvisible() {\n", - " ids = nodes.getIds();\n", - " for (let i = 0; i < ids.length; i++) {\n", - " var nodeId = ids[i];\n", - " var node = nodes.get(nodeId);\n", - " node["hidden"] = true;\n", - " nodes.update(node);\n", - " }\n", - "};\n", - "function makeNeighborsVisible(myNode) {\n", - " var ids = network.getConnectedNodes(myNode, 'to');\n", - " for (let i = 0; i < ids.length; i++) {\n", - " var nodeId = ids[i];\n", - " var node = nodes.get(nodeId);\n", - " node["hidden"] = false;\n", - " nodes.update(node);\n", - " }\n", - "};\n", - "function makeNodeVisible(nodeId) {\n", - " var node = nodes.get(nodeId);\n", - " node["hidden"] = false;\n", - " nodes.update(node);\n", - "};\n", - "network.on( 'click', function(properties) {\n", - " var nodeId = network.getNodeAt({x:properties.event.srcEvent.offsetX, y:properties.event.srcEvent.offsetY});\n", - " makeNeighborsVisible(nodeId);\n", - "});\n", - "\n", - " </script>\n", - " </body>\n", - "</html>\n", - "\"\n", - " border:none !important;\n", - " allowfullscreen webkitallowfullscreen mozallowfullscreen\n", - " >" + "" ], "text/plain": [ "" @@ -425,15 +196,84 @@ }, "metadata": {}, "output_type": "display_data" + }, + { + "data": { + "application/javascript": [ + "return_id_result('http://127.0.0.1:8889', 'zZtxQrYJanXwlIbrckDc', 'test message')" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "f073135af213448c994b303e53484519", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Output()" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "bd4476310d4241688ea7f374c549b0b5", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "HBox(children=(Output(), Output()))" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/javascript": [ + "//js\n", + "document.getElementById('studywjFNvmgEOX').contentWindow.network.on( 'click', function(properties) {\n", + " var nodeId = document.getElementById('studywjFNvmgEOX').contentWindow.network.getNodeAt({x:properties.event.srcEvent.offsetX, y:properties.event.srcEvent.offsetY});\n", + " if (! (nodeId === undefined)) {\n", + " return_id_result('http://127.0.0.1:8889', 'MoudfJVIPcWgNAgFZTZW', nodeId);\n", + " }\n", + "});" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "explore 10000000001\n", + "2\n", + "make visible 2 \n", + "document.getElementById('studywjFNvmgEOX').contentWindow.nodes.update({ id: 2, label: `didn't study\n", + "\u20ac\tR: 15`, group: \"states\", x: 57, y: -10 });\n" + ] } ], "source": [ - "vis = show(mdp, layout=Layout(\"layouts/pinkgreen.json\"), name=\"study\", show_editor=False)" + "vis = show(mdp, layout=Layout(\"layouts/pinkgreen.json\"), name=\"study\", show_editor=True)" ] }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 9, "id": "6cb412a1-52fa-4663-b7ba-371e06001f7a", "metadata": {}, "outputs": [ @@ -441,19 +281,86 @@ "name": "stdout", "output_type": "stream", "text": [ - "{0: {Edge(from_=0, to_=10000000001, label=None)}, 10000000000: set(), 10000000001: set(), 1: {Edge(from_=1, to_=4, label='1/10')}, 2: {Edge(from_=2, to_=4, label='3/5')}, 3: set(), 4: set()}\n" + "{0: {Edge(from_=0, to_=10000000000, label=None), Edge(from_=0, to_=10000000001, label=None)}, 10000000000: {Edge(from_=10000000000, to_=1, label='1')}, 10000000001: {Edge(from_=10000000001, to_=2, label='1')}, 1: {Edge(from_=1, to_=3, label='9/10'), Edge(from_=1, to_=4, label='1/10')}, 2: {Edge(from_=2, to_=4, label='3/5'), Edge(from_=2, to_=3, label='2/5')}, 3: {Edge(from_=3, to_=5, label='1')}, 4: {Edge(from_=4, to_=5, label='1')}}\n" ] } ], "source": [ - "\n", "print(vis.nt.edges)" ] }, + { + "cell_type": "code", + "execution_count": 10, + "id": "f281c503-d45e-4f36-a368-71bda9e0a898", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "make visible 10000000001 \n", + "document.getElementById('studywjFNvmgEOX').contentWindow.nodes.update({ id: 10000000001, label: `don't study\n", + "\u20ac\tR: 0`, group: \"actions\", x: 77, y: -144 });\n" + ] + }, + { + "data": { + "application/javascript": [ + "document.getElementById('studywjFNvmgEOX').contentWindow.nodes.update({ id: 10000000001, label: `don't study\n", + "\u20ac\tR: 0`, group: \"actions\", x: 77, y: -144 });" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "vis.nt.make_node_visible(10000000001, True)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "fee61f37-2e8e-48d0-9d57-e7f92c3effab", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "make visible 2 \n", + "document.getElementById('studywjFNvmgEOX').contentWindow.nodes.update({ id: 2, label: `didn't study\n", + "\u20ac\tR: 15`, group: \"states\", x: 57, y: -10 });\n" + ] + }, + { + "data": { + "application/javascript": [ + "document.getElementById('studywjFNvmgEOX').contentWindow.nodes.update({ id: 2, label: `didn't study\n", + "\u20ac\tR: 15`, group: \"states\", x: 57, y: -10 });" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "vis.nt.make_node_visible(2, True)" + ] + }, { "cell_type": "code", "execution_count": null, - "id": "f1a87851-75b5-4e49-91ab-9382f711e495", + "id": "5ffb652e-e2ca-4212-b8b3-44db33ba46f3", "metadata": {}, "outputs": [], "source": [] diff --git a/docs/getting_started/layouts/pinkgreen.json b/docs/getting_started/layouts/pinkgreen.json index 799d8a7..5b72941 100644 --- a/docs/getting_started/layouts/pinkgreen.json +++ b/docs/getting_started/layouts/pinkgreen.json @@ -103,7 +103,7 @@ "enable_physics": true, "width": 800, "height": 600, - "explore": false + "explore": true }, "saving": { "relative_path": true, diff --git a/docs/getting_started/study.html b/docs/getting_started/study.html index 2e637d8..2228f93 100644 --- a/docs/getting_started/study.html +++ b/docs/getting_started/study.html @@ -1,6 +1,6 @@