{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# robot image table\n", "\n", "> watches all of the images from the robot tests, grouped by folder\n", "\n", "- Restart and run all, then click the _Run 🤖_ button" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from pathlib import Path\n", "from base64 import b64encode\n", "import asyncio\n", "import subprocess\n", "import ipywidgets as W\n", "import IPython, pandas as pd\n", "import time\n", "from tornado.ioloop import IOLoop\n", "HERE = Path().parent.resolve()\n", "ROOT = HERE.parent.resolve()\n", "AOUT = ROOT / \"atest\" / \"output\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "out = W.HTML()\n", "status = W.HTML(value=\"Click the button!\")\n", "btn = W.Button(description=\"🤖\", button_style=\"primary\", icon=\"play\", layout=dict(width=\"5em\"))\n", "btn.on_click(lambda *args: IOLoop.current().add_callback(run))\n", "W.VBox([W.HBox([btn, status]), out])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%%html\n", "" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def quilt():\n", " imgs = sorted([p for p in AOUT.rglob(\"*.png\") if \"pabot_results\" in str(p)])\n", " df = pd.DataFrame(imgs, columns=[\"path\"])\n", " df[\"folder\"] = df[\"path\"].apply(lambda x: str(x.parent.relative_to(AOUT)).split(\"screens\")[-1])\n", " df[\"name\"] = df[\"path\"].apply(lambda x: x.name)\n", " df[\"modified\"] = df[\"path\"].apply(lambda x: x.stat().st_mtime)\n", " df = df.sort_values([\"folder\", \"modified\"])\n", " df = df.set_index([\"folder\"])\n", " df[\"img\"] = df[\"path\"].apply(lambda x: f\"\"\"{x.name} \"\"\")\n", " by_row = pd.DataFrame(df.groupby(['folder'])['img'].transform(lambda x: f\"\"\"
{\" \".join(x[::-1])}
\"\"\"))\n", " return by_row.reset_index().set_index([\"folder\"]).drop_duplicates()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def update(start):\n", " try:\n", " df = quilt().T\n", " out.value = \"\\n\".join([\n", " df.to_html(escape=False)\n", " ])\n", " if len(df):\n", " status.value = f\"{df.size} images in {int(time.time() - start)}s\"\n", " return\n", " except:\n", " pass" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "async def run():\n", " btn.button_style = \"warning\"\n", " out.value = \"waiting to start...\"\n", " status.value = \"forgetting...\"\n", " subprocess.call([\"doit\", \"forget\", \"robot\"], cwd=ROOT)\n", " status.value = \"starting...\"\n", " proc = subprocess.Popen([\"doit\", \"robot\"], cwd=ROOT)\n", " start = time.time()\n", " proc.poll()\n", " while proc.returncode is None:\n", " await asyncio.sleep(1)\n", " proc.poll()\n", " update(start)\n", " \n", " status.value += f\" done {proc.returncode}\"\n", " \n", " for log in AOUT.rglob(\"log.html\"):\n", " status.value += f\"\"\" {log.parent.name}\"\"\"\n", " \n", " if proc.returncode == 0:\n", " btn.button_style = \"success\"\n", " else:\n", " btn.button_style = \"danger\"" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.5" } }, "nbformat": 4, "nbformat_minor": 4 }