{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "endless-short", "metadata": {}, "outputs": [], "source": [ "# -*- coding: utf-8 -*-\n", "# vim: tabstop=4 shiftwidth=4 softtabstop=4\n", "#\n", "# BITE - A Basic/IoT/Example\n", "# Copyright (C) 2020-2021 Daniele ViganĂ² \n", "#\n", "# BITE is free software: you can redistribute it and/or modify\n", "# it under the terms of the GNU Affero General Public License as published by\n", "# the Free Software Foundation, either version 3 of the License, or\n", "# (at your option) any later version.\n", "#\n", "# BITE is distributed in the hope that it will be useful,\n", "# but WITHOUT ANY WARRANTY; without even the implied warranty of\n", "# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n", "# GNU Affero General Public License for more details.\n", "#\n", "# You should have received a copy of the GNU Affero General Public License\n", "# along with this program. If not, see .\n", "\n", "import requests\n", "import pandas as pd\n", "import ipywidgets as widgets\n", "import plotly.graph_objects as go\n", "\n", "from datetime import date, datetime\n", "from IPython.display import display" ] }, { "cell_type": "code", "execution_count": null, "id": "running-darwin", "metadata": {}, "outputs": [], "source": [ "serial = widgets.Text(\n", " value='esp32_1',\n", " placeholder='Type something',\n", " description='Serial:',\n", " disabled=False\n", ")\n", "date_from = widgets.DatePicker(\n", " description='From Date',\n", " disabled=False,\n", " value=date.today()\n", ")\n", "date_to = widgets.DatePicker(\n", " description='To Date',\n", " disabled=False,\n", " value=date.today()\n", ")\n", "display(serial)\n", "display(date_from)\n", "display(date_to)" ] }, { "cell_type": "code", "execution_count": null, "id": "designing-milwaukee", "metadata": {}, "outputs": [], "source": [ "date_from = datetime.combine(date_from.value, datetime.min.time())\n", "date_to = datetime.combine(date_to.value, datetime.max.time())\n", "\n", "try:\n", " r = requests.get(\"http://localhost/telemetry/{serial}/{date_from}/{date_to}/\".format(\n", " serial=serial.value,\n", " date_from=date_from,\n", " date_to=date_to\n", " ))\n", " \n", "except requests.exceptions.RequestException as e:\n", " raise SystemExit(e)\n", "\n", "r.raise_for_status()\n", "\n", "df = pd.json_normalize(r.json())\n", "if 'time' in df:\n", " index = pd.to_datetime(df['time'])\n", " df = df.set_index(index)\n", " df = df.resample('5min').agg(['min', 'max', 'mean'])\n", "else:\n", " print('No data to compute')" ] }, { "cell_type": "code", "execution_count": null, "id": "related-place", "metadata": {}, "outputs": [], "source": [ "fig = go.Figure([go.Scatter(x=df.index, y=df['payload.wifi-rssi']['max'], showlegend=False),\n", " go.Scatter(x=df.index, y=df['payload.wifi-rssi']['mean'], name=\"WiFI RSSI\"),\n", " go.Scatter(x=df.index, y=df['payload.wifi-rssi']['min'], showlegend=False),\n", " go.Scatter(x=df.index, y=df['payload.hall']['max'], showlegend=False),\n", " go.Scatter(x=df.index, y=df['payload.hall']['mean'], name=\"Hall effect\"),\n", " go.Scatter(x=df.index, y=df['payload.hall']['min'], showlegend=False)])\n", "fig.show()" ] }, { "cell_type": "code", "execution_count": null, "id": "interested-silence", "metadata": {}, "outputs": [], "source": [] } ], "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.9.2" }, "widgets": { "application/vnd.jupyter.widget-state+json": { "state": { "012db04e6f6143409f22b63f147e4e2c": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DatePickerModel", "state": { "description": "From Date", "disabled": false, "layout": "IPY_MODEL_0e7d139b30d840439d6e7b5e1b424a37", "style": "IPY_MODEL_73e5b69afa3a4bfda9ebba619d36f926", "value": { "date": 24, "month": 2, "year": 2021 } } }, "05f9de03e2354005acb4b505e0806e8d": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "07cc459eceac47dcb8b6199479039f69": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DescriptionStyleModel", "state": { "description_width": "" } }, "0e7d139b30d840439d6e7b5e1b424a37": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "10de1b7c78e54dd98c5a6a43c75e44e8": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DatePickerModel", "state": { "description": "To Date", "disabled": false, "layout": "IPY_MODEL_f45d49360f3b4026a5b14087ea1f9469", "style": "IPY_MODEL_ccca0316a69845e3830548986969b296", "value": { "date": 25, "month": 2, "year": 2021 } } }, "14937ad3e04a456f838521bba3bfd72e": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DescriptionStyleModel", "state": { "description_width": "" } }, "19a47aab423c45c994100a24e7f55b73": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "TextModel", "state": { "description": "Serial:", "layout": "IPY_MODEL_23ae3f01b8e54360a2c515e52013500f", "placeholder": "Type something", "style": "IPY_MODEL_14937ad3e04a456f838521bba3bfd72e", "value": "esp32_1" } }, "1ca6e711a3954797bd8c0fa76255509c": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DescriptionStyleModel", "state": { "description_width": "" } }, "1edc09258c11486ab4a2069aa7258f45": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "2231042a87594bf28113cd8072e1f220": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "23ae3f01b8e54360a2c515e52013500f": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "27ddcc76d0954ca8bb786e18f6add137": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "2830c0db32394a31900947bab8b2dd35": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DescriptionStyleModel", "state": { "description_width": "" } }, "291f93e47e9b49ef8f8eb420f3f4a47c": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DatePickerModel", "state": { "description": "From Date", "disabled": false, "layout": "IPY_MODEL_fdcc9a1e68c34653abff829b95bdf6ff", "style": "IPY_MODEL_d89b526fd3124032b7dabbc10ee599f0", "value": { "date": 24, "month": 2, "year": 2021 } } }, "340e5e36dbba42d5b60d13e85bedf3a4": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DescriptionStyleModel", "state": { "description_width": "" } }, "35ffe994f0de4f948e5d9f9c16c68ada": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "TextModel", "state": { "description": "Serial:", "layout": "IPY_MODEL_c2defc40ac02405393c4db522a3ff8a3", "placeholder": "Type something", "style": "IPY_MODEL_bd2bdbb620984299acfbe96a4e6f9a6e", "value": "esp32_1" } }, "3f6b191dc1d647ebb4d5ba83ee07548c": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DescriptionStyleModel", "state": { "description_width": "" } }, "41974684122d4b40be5bc0a8db64ff9e": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DatePickerModel", "state": { "description": "From Date", "disabled": false, "layout": "IPY_MODEL_fc6a1763ccf040b9b12e3e6384d9a5d2", "style": "IPY_MODEL_2830c0db32394a31900947bab8b2dd35", "value": { "date": 24, "month": 2, "year": 2021 } } }, "48166986d3f94f78b1b41bb8e45f905f": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DescriptionStyleModel", "state": { "description_width": "" } }, "547f5bcad26f43afa93b827e89803237": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "57c8140445e94f0686197d04f5b37a05": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DatePickerModel", "state": { "description": "To Date", "disabled": false, "layout": "IPY_MODEL_a5cadb7e8bb747b5879b6fda525c0211", "style": "IPY_MODEL_07cc459eceac47dcb8b6199479039f69", "value": { "date": 25, "month": 2, "year": 2021 } } }, "5bd7fed916b946b1a5da6d2d7cd3229e": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "TextModel", "state": { "description": "Serial:", "layout": "IPY_MODEL_d872e99186584085b5a052778c14eabf", "placeholder": "Type something", "style": "IPY_MODEL_340e5e36dbba42d5b60d13e85bedf3a4", "value": "esp32_1" } }, "5fe18cd07fb244b7a18f9c6a6e9cbd47": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DatePickerModel", "state": { "description": "From Date", "disabled": false, "layout": "IPY_MODEL_be1a12eef0d64b37b9612320694d96f0", "style": "IPY_MODEL_48166986d3f94f78b1b41bb8e45f905f", "value": { "date": 24, "month": 2, "year": 2021 } } }, "6ccb0bd041e047d59b1ca9a26b867d53": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "TextModel", "state": { "description": "Serial:", "layout": "IPY_MODEL_b4d7d72ddeb2440a98898417e787c1b4", "placeholder": "Type something", "style": "IPY_MODEL_818fd7e0fd414036ad7025a79d0481fa", "value": "esp32_1" } }, "6f1673f654b14011aa8b7aaf315b77e8": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DescriptionStyleModel", "state": { "description_width": "" } }, "73e5b69afa3a4bfda9ebba619d36f926": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DescriptionStyleModel", "state": { "description_width": "" } }, "796774d19b9843178e87ea97c1efd69f": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DescriptionStyleModel", "state": { "description_width": "" } }, "798e515187274617bc65df9fc4905065": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "7f0bed81c5914082886e91ee4d1cb19e": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DescriptionStyleModel", "state": { "description_width": "" } }, "810137e6614b4e94a008e270fbac3df3": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DatePickerModel", "state": { "description": "To Date", "disabled": false, "layout": "IPY_MODEL_be930797fbab4501865a8d753fc82881", "style": "IPY_MODEL_9f84286df9b54fd98a4ad9d1c373b1b2", "value": { "date": 25, "month": 2, "year": 2021 } } }, "8125ad074c344e2a858ffb86f08e7078": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "818fd7e0fd414036ad7025a79d0481fa": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DescriptionStyleModel", "state": { "description_width": "" } }, "957186e22f244091a89a12f460a1bfb6": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DatePickerModel", "state": { "description": "To Date", "disabled": false, "layout": "IPY_MODEL_27ddcc76d0954ca8bb786e18f6add137", "style": "IPY_MODEL_ea3710cdbac84d95a5698eed13342149", "value": { "date": 25, "month": 2, "year": 2021 } } }, "97e421f821cc4432a90040b07a2e3695": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DatePickerModel", "state": { "description": "To Date", "disabled": false, "layout": "IPY_MODEL_1edc09258c11486ab4a2069aa7258f45", "style": "IPY_MODEL_6f1673f654b14011aa8b7aaf315b77e8", "value": { "date": 25, "month": 2, "year": 2021 } } }, "9f84286df9b54fd98a4ad9d1c373b1b2": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DescriptionStyleModel", "state": { "description_width": "" } }, "a5cadb7e8bb747b5879b6fda525c0211": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "af53446e2d6c40799a006b23836160f0": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DatePickerModel", "state": { "description": "From Date", "disabled": false, "layout": "IPY_MODEL_2231042a87594bf28113cd8072e1f220", "style": "IPY_MODEL_1ca6e711a3954797bd8c0fa76255509c", "value": { "date": 24, "month": 2, "year": 2021 } } }, "b4d7d72ddeb2440a98898417e787c1b4": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "b81224cb976f4b20a769c9bdd191db75": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DatePickerModel", "state": { "description": "From Date", "disabled": false, "layout": "IPY_MODEL_05f9de03e2354005acb4b505e0806e8d", "style": "IPY_MODEL_3f6b191dc1d647ebb4d5ba83ee07548c", "value": { "date": 24, "month": 2, "year": 2021 } } }, "bd2bdbb620984299acfbe96a4e6f9a6e": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DescriptionStyleModel", "state": { "description_width": "" } }, "be1a12eef0d64b37b9612320694d96f0": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "be930797fbab4501865a8d753fc82881": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "c2defc40ac02405393c4db522a3ff8a3": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "c33fb64e62804915a92531a42e02ab6b": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "TextModel", "state": { "description": "Serial:", "layout": "IPY_MODEL_f0c4e8f4dd704cc1915c148293953e2e", "placeholder": "Type something", "style": "IPY_MODEL_c3fb12046c5748a1a4416805e2a2e316", "value": "esp32_1" } }, "c3fb12046c5748a1a4416805e2a2e316": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DescriptionStyleModel", "state": { "description_width": "" } }, "ca386f6b0c3b4599bf7a3258a3dd1aff": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DescriptionStyleModel", "state": { "description_width": "" } }, "ccca0316a69845e3830548986969b296": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DescriptionStyleModel", "state": { "description_width": "" } }, "d1d6e852a7dd4fb3b12c266b755bf111": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "d32b6b4bb576460484d567b610f76c44": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DatePickerModel", "state": { "description": "To Date", "disabled": false, "layout": "IPY_MODEL_d1d6e852a7dd4fb3b12c266b755bf111", "style": "IPY_MODEL_7f0bed81c5914082886e91ee4d1cb19e", "value": { "date": 25, "month": 2, "year": 2021 } } }, "d872e99186584085b5a052778c14eabf": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "d89b526fd3124032b7dabbc10ee599f0": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DescriptionStyleModel", "state": { "description_width": "" } }, "dc4dffcc7ea94b85b77f140461468811": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DescriptionStyleModel", "state": { "description_width": "" } }, "dc520429d99d49c18fa060ce1e95263c": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "dfce0d9a690546e19c7b354d4e13f4f1": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DescriptionStyleModel", "state": { "description_width": "" } }, "ea3710cdbac84d95a5698eed13342149": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DescriptionStyleModel", "state": { "description_width": "" } }, "f0c4e8f4dd704cc1915c148293953e2e": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "f45d49360f3b4026a5b14087ea1f9469": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "fbbf425e2b204570a64e24eb47f7055f": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "TextModel", "state": { "description": "Serial:", "layout": "IPY_MODEL_547f5bcad26f43afa93b827e89803237", "placeholder": "Type something", "style": "IPY_MODEL_dfce0d9a690546e19c7b354d4e13f4f1", "value": "esp32_1" } }, "fc6a1763ccf040b9b12e3e6384d9a5d2": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "fc9c348988ec4ce0874decc937da8078": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "TextModel", "state": { "description": "Serial:", "layout": "IPY_MODEL_8125ad074c344e2a858ffb86f08e7078", "placeholder": "Type something", "style": "IPY_MODEL_796774d19b9843178e87ea97c1efd69f", "value": "esp32_1" } }, "fcc822c898014962804e2fa52d397b5e": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DatePickerModel", "state": { "description": "From Date", "disabled": false, "layout": "IPY_MODEL_dc520429d99d49c18fa060ce1e95263c", "style": "IPY_MODEL_dc4dffcc7ea94b85b77f140461468811", "value": { "date": 24, "month": 2, "year": 2021 } } }, "fdcc9a1e68c34653abff829b95bdf6ff": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "fe9cfdeb23104476a3bbc9afaeaf9838": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DatePickerModel", "state": { "description": "To Date", "disabled": false, "layout": "IPY_MODEL_798e515187274617bc65df9fc4905065", "style": "IPY_MODEL_ca386f6b0c3b4599bf7a3258a3dd1aff", "value": { "date": 25, "month": 2, "year": 2021 } } } }, "version_major": 2, "version_minor": 0 } } }, "nbformat": 4, "nbformat_minor": 5 }