{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "provenance": [], "authorship_tag": "ABX9TyM28NZ4aJk6pyCy9SgR04sk", "include_colab_link": true }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" } }, "cells": [ { "cell_type": "markdown", "metadata": { "id": "view-in-github", "colab_type": "text" }, "source": [ "\"Open" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 1000 }, "id": "G2vIOdeGG43G", "outputId": "801cc6d4-f269-4384-a7ba-f0398b656213" }, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Requirement already satisfied: pandas in /usr/local/lib/python3.11/dist-packages (2.2.2)\n", "Collecting dash\n", " Downloading dash-2.18.2-py3-none-any.whl.metadata (10 kB)\n", "Requirement already satisfied: numpy>=1.23.2 in /usr/local/lib/python3.11/dist-packages (from pandas) (1.26.4)\n", "Requirement already satisfied: python-dateutil>=2.8.2 in /usr/local/lib/python3.11/dist-packages (from pandas) (2.8.2)\n", "Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.11/dist-packages (from pandas) (2024.2)\n", "Requirement already satisfied: tzdata>=2022.7 in /usr/local/lib/python3.11/dist-packages (from pandas) (2025.1)\n", "Collecting Flask<3.1,>=1.0.4 (from dash)\n", " Downloading flask-3.0.3-py3-none-any.whl.metadata (3.2 kB)\n", "Collecting Werkzeug<3.1 (from dash)\n", " Downloading werkzeug-3.0.6-py3-none-any.whl.metadata (3.7 kB)\n", "Requirement already satisfied: plotly>=5.0.0 in /usr/local/lib/python3.11/dist-packages (from dash) (5.24.1)\n", "Collecting dash-html-components==2.0.0 (from dash)\n", " Downloading dash_html_components-2.0.0-py3-none-any.whl.metadata (3.8 kB)\n", "Collecting dash-core-components==2.0.0 (from dash)\n", " Downloading dash_core_components-2.0.0-py3-none-any.whl.metadata (2.9 kB)\n", "Collecting dash-table==5.0.0 (from dash)\n", " Downloading dash_table-5.0.0-py3-none-any.whl.metadata (2.4 kB)\n", "Requirement already satisfied: importlib-metadata in /usr/local/lib/python3.11/dist-packages (from dash) (8.6.1)\n", "Requirement already satisfied: typing-extensions>=4.1.1 in /usr/local/lib/python3.11/dist-packages (from dash) (4.12.2)\n", "Requirement already satisfied: requests in /usr/local/lib/python3.11/dist-packages (from dash) (2.32.3)\n", "Collecting retrying (from dash)\n", " Downloading retrying-1.3.4-py3-none-any.whl.metadata (6.9 kB)\n", "Requirement already satisfied: nest-asyncio in /usr/local/lib/python3.11/dist-packages (from dash) (1.6.0)\n", "Requirement already satisfied: setuptools in /usr/local/lib/python3.11/dist-packages (from dash) (75.1.0)\n", "Requirement already satisfied: Jinja2>=3.1.2 in /usr/local/lib/python3.11/dist-packages (from Flask<3.1,>=1.0.4->dash) (3.1.5)\n", "Requirement already satisfied: itsdangerous>=2.1.2 in /usr/local/lib/python3.11/dist-packages (from Flask<3.1,>=1.0.4->dash) (2.2.0)\n", "Requirement already satisfied: click>=8.1.3 in /usr/local/lib/python3.11/dist-packages (from Flask<3.1,>=1.0.4->dash) (8.1.8)\n", "Requirement already satisfied: blinker>=1.6.2 in /usr/local/lib/python3.11/dist-packages (from Flask<3.1,>=1.0.4->dash) (1.9.0)\n", "Requirement already satisfied: tenacity>=6.2.0 in /usr/local/lib/python3.11/dist-packages (from plotly>=5.0.0->dash) (9.0.0)\n", "Requirement already satisfied: packaging in /usr/local/lib/python3.11/dist-packages (from plotly>=5.0.0->dash) (24.2)\n", "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.11/dist-packages (from python-dateutil>=2.8.2->pandas) (1.17.0)\n", "Requirement already satisfied: MarkupSafe>=2.1.1 in /usr/local/lib/python3.11/dist-packages (from Werkzeug<3.1->dash) (3.0.2)\n", "Requirement already satisfied: zipp>=3.20 in /usr/local/lib/python3.11/dist-packages (from importlib-metadata->dash) (3.21.0)\n", "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.11/dist-packages (from requests->dash) (3.4.1)\n", "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.11/dist-packages (from requests->dash) (3.10)\n", "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.11/dist-packages (from requests->dash) (2.3.0)\n", "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.11/dist-packages (from requests->dash) (2024.12.14)\n", "Downloading dash-2.18.2-py3-none-any.whl (7.8 MB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m7.8/7.8 MB\u001b[0m \u001b[31m61.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hDownloading dash_core_components-2.0.0-py3-none-any.whl (3.8 kB)\n", "Downloading dash_html_components-2.0.0-py3-none-any.whl (4.1 kB)\n", "Downloading dash_table-5.0.0-py3-none-any.whl (3.9 kB)\n", "Downloading flask-3.0.3-py3-none-any.whl (101 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m101.7/101.7 kB\u001b[0m \u001b[31m8.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hDownloading werkzeug-3.0.6-py3-none-any.whl (227 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m228.0/228.0 kB\u001b[0m \u001b[31m17.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hDownloading retrying-1.3.4-py3-none-any.whl (11 kB)\n", "Installing collected packages: dash-table, dash-html-components, dash-core-components, Werkzeug, retrying, Flask, dash\n", " Attempting uninstall: Werkzeug\n", " Found existing installation: Werkzeug 3.1.3\n", " Uninstalling Werkzeug-3.1.3:\n", " Successfully uninstalled Werkzeug-3.1.3\n", " Attempting uninstall: Flask\n", " Found existing installation: Flask 3.1.0\n", " Uninstalling Flask-3.1.0:\n", " Successfully uninstalled Flask-3.1.0\n", "Successfully installed Flask-3.0.3 Werkzeug-3.0.6 dash-2.18.2 dash-core-components-2.0.0 dash-html-components-2.0.0 dash-table-5.0.0 retrying-1.3.4\n" ] }, { "output_type": "display_data", "data": { "text/plain": [ "" ], "application/javascript": [ "(async (port, path, width, height, cache, element) => {\n", " if (!google.colab.kernel.accessAllowed && !cache) {\n", " return;\n", " }\n", " element.appendChild(document.createTextNode(''));\n", " const url = await google.colab.kernel.proxyPort(port, {cache});\n", " const iframe = document.createElement('iframe');\n", " iframe.src = new URL(path, url).toString();\n", " iframe.height = height;\n", " iframe.width = width;\n", " iframe.style.border = 0;\n", " iframe.allow = [\n", " 'accelerometer',\n", " 'autoplay',\n", " 'camera',\n", " 'clipboard-read',\n", " 'clipboard-write',\n", " 'gyroscope',\n", " 'magnetometer',\n", " 'microphone',\n", " 'serial',\n", " 'usb',\n", " 'xr-spatial-tracking',\n", " ].join('; ');\n", " element.appendChild(iframe);\n", " })(8050, \"/\", \"100%\", 650, false, window.element)" ] }, "metadata": {} } ], "source": [ "# prompt: create visual dashboarch for speed analysis using rpm for atheletes speed analysis device where we calculate athelets speed through revolution per minute through absolute encoder sensor live\n", "\n", "# Install necessary libraries\n", "!pip install pandas dash\n", "\n", "import pandas as pd\n", "import dash\n", "from dash import dcc, html, Input, Output\n", "import plotly.graph_objs as go\n", "import time\n", "import random\n", "\n", "# Simulate live data from the RPM sensor (replace with actual data source)\n", "def get_rpm_data():\n", " \"\"\"Simulates reading RPM data from a sensor.\n", "\n", " Returns:\n", " float: A random RPM value between 0 and 100.\n", " \"\"\"\n", " return random.uniform(0, 100)\n", "\n", "def calculate_speed(rpm, wheel_radius_meters=0.3):\n", " \"\"\"Calculates speed based on RPM and wheel radius.\n", "\n", " Args:\n", " rpm (float): Revolutions per minute.\n", " wheel_radius_meters (float): Radius of the wheel in meters.\n", "\n", " Returns:\n", " float: Speed in meters per second.\n", " \"\"\"\n", " circumference = 2 * 3.14159 * wheel_radius_meters\n", " speed_mps = (rpm * circumference) / 60\n", " return speed_mps\n", "\n", "# Initialize the Dash app\n", "app = dash.Dash(__name__)\n", "\n", "# Layout of the dashboard\n", "app.layout = html.Div([\n", " html.H1(\"Athlete Speed Analysis Dashboard\"),\n", "\n", " html.Div([\n", " html.Div([\n", " html.H3(\"Real-time RPM\"),\n", " html.Div(id=\"rpm-value\", style={'fontSize': 24}),\n", " ], style={'width': '30%', 'display': 'inline-block'}),\n", " html.Div([\n", " html.H3(\"Real-time Speed (m/s)\"),\n", " html.Div(id=\"speed-value\", style={'fontSize': 24}),\n", " ], style={'width': '30%', 'display': 'inline-block'}),\n", " html.Div([\n", " html.H3(\"Live Graph\"),\n", " dcc.Graph(id=\"live-graph\"),\n", " ], style={'width': '100%', 'display': 'inline-block'}),\n", "\n", " ]),\n", " dcc.Interval(\n", " id='interval-component',\n", " interval=1000, # in milliseconds\n", " n_intervals=0\n", " )\n", "])\n", "\n", "# Callback to update the live data and graph\n", "@app.callback(\n", " [Output(\"rpm-value\", \"children\"),\n", " Output(\"speed-value\", \"children\"),\n", " Output(\"live-graph\", \"figure\")],\n", " Input(\"interval-component\", \"n_intervals\")\n", ")\n", "def update_data(n):\n", " # Simulate live data\n", " rpm = get_rpm_data()\n", " speed = calculate_speed(rpm)\n", "\n", " # Data for the graph\n", " global data_points\n", " if 'data_points' not in globals():\n", " data_points = []\n", " data_points.append({'rpm':rpm,'speed':speed})\n", " else:\n", " data_points.append({'rpm':rpm,'speed':speed})\n", "\n", " if len(data_points) > 50:\n", " data_points.pop(0)\n", "\n", " df = pd.DataFrame(data_points)\n", "\n", " # Create the graph\n", " graph = go.Figure()\n", " graph.add_trace(go.Scatter(x=df.index, y=df['rpm'], mode='lines+markers', name='RPM'))\n", " graph.add_trace(go.Scatter(x=df.index, y=df['speed'], mode='lines+markers', name='Speed (m/s)'))\n", "\n", " graph.update_layout(title='RPM and Speed over Time',\n", " xaxis_title='Time',\n", " yaxis_title='Value')\n", "\n", " return f\"{rpm:.2f}\", f\"{speed:.2f}\", graph\n", "\n", "# Run the app\n", "if __name__ == '__main__':\n", " app.run_server(debug=True, use_reloader=False) # use_reloader = false to avoid running twice in colab\n" ] } ] }