diff --git a/README.md b/README.md index 960c3406a3caf51c57df8ffc19924b0618599993..f28ce29d0f19bad1f539a04073c7827bb21b821a 100644 --- a/README.md +++ b/README.md @@ -7,9 +7,18 @@ python main.py (Windows users may replace `python` with `python.exe`) -## The Database +The required packages are : -### Creating a Database +``` +PySimpleGUI +numpy +pandas +sqlite3 +seaborn +scikit-learn +PyWavelets +openpyxl +``` -### Editing a database +Examples to use the tools in this repository are found in the `examples` folder. diff --git a/examples/Plot-HealthIndex.ipynb b/examples/Plot-HealthIndex.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..7d89142ad0c87abba7dd9fc27df7d7e7e9855891 --- /dev/null +++ b/examples/Plot-HealthIndex.ipynb @@ -0,0 +1,241 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Plotting the health index\n", + "\n", + "The Health index is computed using the database creation tool GUI.\n", + "This example relies on the `Robot3.sqlite` database." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Include Dependencies\n", + "\n", + "# Disable seaborn warnings\n", + "import warnings\n", + "warnings.simplefilter(action='ignore', category=FutureWarning)\n", + "\n", + "import numpy as np\n", + "import pandas as pd\n", + "import matplotlib.pyplot as plt\n", + "from sklearn.decomposition import PCA\n", + "\n", + "from typing import List, Dict, Tuple, Any\n", + "import re\n", + "\n", + "# Setup path to import tools.*\n", + "import sys\n", + "sys.path.append(\"../\")\n", + "# ---------------------\n", + "from tools.database import Database\n", + "from tools.processing import *\n", + "from tools.plots import *\n", + "from tools.predictive_indicators import *" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Getting the indicators from the Database\n", + "\n", + "This step has not been abstracted by the Database class." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "DB = Database(fr\"..\\db\\Robot3.sqlite\") # Change the path to the database if neeeded\n", + "data = pd.read_sql(QUERY_INDICATORS(3), DB.db).sort_values([ \"Date\", \"Axis\" ]) # Sort values \n", + "\n", + "# Focus on running @ 30% speed\n", + "focus = data[data[\"Speed\"] == 30]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Plotting a single day\n", + "\n", + "This example plots the health index with the time scale in seconds.\n", + "The sample time of the index is the timestamp at which the run was started." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "day_data = focus[focus[\"Date\"] == \"2024-7-29\"]\n", + "\n", + "plt.figure()\n", + "sns.scatterplot(day_data, x=\"Time\", y=\"Health\", hue=\"Axis\")\n", + "plt.grid()\n", + "plt.tight_layout()\n", + "plt.show()\n", + "\n", + "plt.figure()\n", + "sns.scatterplot(day_data, y=\"Health\", x=\"MeanTemperature\", hue=\"Axis\")\n", + "plt.grid()\n", + "plt.tight_layout()\n", + "plt.show()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We can see on the plot the impact of the motor heat on the health index." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "for a in day_data[\"Axis\"].unique():\n", + " d = day_data[day_data[\"Axis\"] == a]\n", + " print(a, np.corrcoef(d[\"Health\"], d[\"MeanTemperature\"])[0,1])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We can also see that there is a correlation between the Health index and the motor temperature." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Plotting multiple days\n", + "\n", + "To better take into account the temperature, we can look at a larger time scale.\n", + "\n", + "### Plotting according to the timestamp" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "plt.figure()\n", + "sns.scatterplot(focus, x=\"RunTime\", y=\"Health\", hue=\"Axis\")\n", + "plt.grid()\n", + "plt.tight_layout()\n", + "plt.show()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The visualisation here is hard to read, we can try to plot a line instead." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "plt.figure()\n", + "sns.lineplot(focus, x=\"RunTime\", y=\"Health\", hue=\"Axis\")\n", + "plt.grid()\n", + "plt.tight_layout()\n", + "plt.show()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "It is again hard to determine a trend in the data with this graph. \n", + "\n", + "### Plotting according to the Date\n", + "\n", + "We can group the experiment per Date of sampling. We must keep in mind that \n", + "although the time scale will appear linear, there will be variable time gaps \n", + "between the points. " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "plt.figure()\n", + "sns.scatterplot(focus, x=\"Date\", y=\"Health\", hue=\"Axis\")\n", + "plt.grid()\n", + "plt.tight_layout()\n", + "plt.show()\n", + "\n", + "plt.figure()\n", + "sns.lineplot(focus, x=\"Date\", y=\"Health\", hue=\"Axis\")\n", + "plt.grid()\n", + "plt.tight_layout()\n", + "plt.show()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Here since multiple data point exists for each date, seaborn drew the standard deviation of the data on top of each axis line.\n", + "\n", + "We can also use a boxplot to see the evolution per axis." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "plt.figure()\n", + "sns.boxplot(focus, x=\"Axis\", y=\"Health\", hue=\"Date\")\n", + "plt.grid()\n", + "plt.tight_layout()\n", + "plt.show()" + ] + } + ], + "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.10.7" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}