Skip to content
Snippets Groups Projects
Commit 688d2f34 authored by VulcanixFR's avatar VulcanixFR
Browse files

Add Health Index example notebook

parent 9cba6dfa
No related merge requests found
......@@ -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.
%% Cell type:markdown id: tags:
# Plotting the health index
The Health index is computed using the database creation tool GUI.
This example relies on the `Robot3.sqlite` database.
%% Cell type:code id: tags:
``` python
# Include Dependencies
# Disable seaborn warnings
import warnings
warnings.simplefilter(action='ignore', category=FutureWarning)
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.decomposition import PCA
from typing import List, Dict, Tuple, Any
import re
# Setup path to import tools.*
import sys
sys.path.append("../")
# ---------------------
from tools.database import Database
from tools.processing import *
from tools.plots import *
from tools.predictive_indicators import *
```
%% Cell type:markdown id: tags:
## Getting the indicators from the Database
This step has not been abstracted by the Database class.
%% Cell type:code id: tags:
``` python
DB = Database(fr"..\db\Robot3.sqlite") # Change the path to the database if neeeded
data = pd.read_sql(QUERY_INDICATORS(3), DB.db).sort_values([ "Date", "Axis" ]) # Sort values
# Focus on running @ 30% speed
focus = data[data["Speed"] == 30]
```
%% Cell type:markdown id: tags:
## Plotting a single day
This example plots the health index with the time scale in seconds.
The sample time of the index is the timestamp at which the run was started.
%% Cell type:code id: tags:
``` python
day_data = focus[focus["Date"] == "2024-7-29"]
plt.figure()
sns.scatterplot(day_data, x="Time", y="Health", hue="Axis")
plt.grid()
plt.tight_layout()
plt.show()
plt.figure()
sns.scatterplot(day_data, y="Health", x="MeanTemperature", hue="Axis")
plt.grid()
plt.tight_layout()
plt.show()
```
%% Cell type:markdown id: tags:
We can see on the plot the impact of the motor heat on the health index.
%% Cell type:code id: tags:
``` python
for a in day_data["Axis"].unique():
d = day_data[day_data["Axis"] == a]
print(a, np.corrcoef(d["Health"], d["MeanTemperature"])[0,1])
```
%% Cell type:markdown id: tags:
We can also see that there is a correlation between the Health index and the motor temperature.
%% Cell type:markdown id: tags:
## Plotting multiple days
To better take into account the temperature, we can look at a larger time scale.
### Plotting according to the timestamp
%% Cell type:code id: tags:
``` python
plt.figure()
sns.scatterplot(focus, x="RunTime", y="Health", hue="Axis")
plt.grid()
plt.tight_layout()
plt.show()
```
%% Cell type:markdown id: tags:
The visualisation here is hard to read, we can try to plot a line instead.
%% Cell type:code id: tags:
``` python
plt.figure()
sns.lineplot(focus, x="RunTime", y="Health", hue="Axis")
plt.grid()
plt.tight_layout()
plt.show()
```
%% Cell type:markdown id: tags:
It is again hard to determine a trend in the data with this graph.
### Plotting according to the Date
We can group the experiment per Date of sampling. We must keep in mind that
although the time scale will appear linear, there will be variable time gaps
between the points.
%% Cell type:code id: tags:
``` python
plt.figure()
sns.scatterplot(focus, x="Date", y="Health", hue="Axis")
plt.grid()
plt.tight_layout()
plt.show()
plt.figure()
sns.lineplot(focus, x="Date", y="Health", hue="Axis")
plt.grid()
plt.tight_layout()
plt.show()
```
%% Cell type:markdown id: tags:
Here since multiple data point exists for each date, seaborn drew the standard deviation of the data on top of each axis line.
We can also use a boxplot to see the evolution per axis.
%% Cell type:code id: tags:
``` python
plt.figure()
sns.boxplot(focus, x="Axis", y="Health", hue="Date")
plt.grid()
plt.tight_layout()
plt.show()
```
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment