bt_monitor_server/bt_monitor_analyze.ipynb

332 lines
209 KiB
Plaintext
Raw Normal View History

2024-03-11 20:54:28 +01:00
{
"cells": [
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import seaborn as sns\n",
"import matplotlib.pyplot as plt\n",
"data_file = \"/home/martin/code/ansible/roles/bluetooth-monitor/other/logfile_2024-03-07 20:23:13.359108.csv\"\n",
"df = pd.read_csv(data_file)\n",
"\n",
"# Cleanup\n",
"df = df.rename(columns=lambda x: x.strip())\n",
"df.applymap(lambda x: x.strip() if isinstance(x, str) else x)\n",
"rooms = set(df['real_room']).union(set(df['room']))\n",
"room_dtype = pd.CategoricalDtype(categories=list(rooms), ordered=True)\n",
"df['room'] = df['room'].astype(room_dtype)\n",
"df['real_room'] = df['real_room'].astype(room_dtype)"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [
{
"ename": "ValueError",
"evalue": "The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m/tmp/ipykernel_449868/2929942538.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mdf\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mdf\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'# device'\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m\"martins_apple_watch\"\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0mdf\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'tx_power'\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m>\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'tx_power'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0munique\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;32m/usr/lib/python3/dist-packages/pandas/core/generic.py\u001b[0m in \u001b[0;36m__nonzero__\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 1535\u001b[0m \u001b[0;34m@\u001b[0m\u001b[0mfinal\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1536\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__nonzero__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1537\u001b[0;31m raise ValueError(\n\u001b[0m\u001b[1;32m 1538\u001b[0m \u001b[0;34mf\"The truth value of a {type(self).__name__} is ambiguous. \"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1539\u001b[0m \u001b[0;34m\"Use a.empty, a.bool(), a.item(), a.any() or a.all().\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mValueError\u001b[0m: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()."
]
}
],
"source": [
"df[df['# device'] == \"martins_apple_watch\" and df['tx_power'] > 0]['tx_power'].unique()"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/tmp/ipykernel_449868/10187827.py:7: UserWarning: FixedFormatter should only be used together with FixedLocator\n",
" ax.set_xticklabels(labels, rotation=90) # set new labels\n"
]
},
{
"data": {
"text/plain": [
"<Figure size 2880x432 with 0 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAD/8AAAG4CAYAAAAZ2sVsAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAEAAElEQVR4nOzdd3hUZdrH8d/U9JBCS+gqAoJA6AKCoChFiqsormBdF1BX2dVVVmV17XUtqCiK+rruWrAr4tpoLkVBmh3pkISE9D7tef+IjEYpEyA5mcn3c11zkfOcmbnvZ2a4Mznz3GdsxhgjAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABgGbvVCQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA0NjR/A8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAgMVo/gcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwGI0/wMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAYDGa/wEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAsBjN/wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWIzmfwAAELJVq1ZpyJAhVqcBAAAAAAAAAAAAAAAAAAAAAAAAAEDEofkfR11jbQw92LxXr16tM84447Dvu1OnTtq+ffth3/5AMjIytHPnzqN+vwCAg9u1a5c6deokn89ndSoAIkxjfS9+uCorKzVt2jT17t1bV199tdXpAAhDjbXuHmrel156qd555x09+eSTuummm0K6z9mzZ+u66647WikCiHDU3/rB8Qsg8jTW+nk43njjDZ1//vkH3D9lyhTNnz8/pPvasmWLJkyYoIyMDL3wwgsHvN4777yjSy+9tNa5ArAOdfXw1dV7zb///e96/PHHj+p91odD/d4B0LBQ/+sejzEQmfi/HbraHHf4tT/84Q968803j2o+rDUGGi9qd90bM2aMVq1aZXUaABoAau7h43gzgEjltDoBoDHo06eP/vvf/1qdxm+sXbvW6hQA1DOfzyens35//VsRsyFjwTwANBwffPCB9u7dq1WrVvG7CgCOomeffdbqFAAAAIAG45lnnlG/fv301ltvHfR648aN07hx4+onKQCIULfddpvVKQAAAACWeuaZZ4I/v/HGG5o/f75eeumlI7pP1hoDQN1ZsGCB1SkAAA6A480ArGa3OgE0PFY0JdIIWTfC8XE1xigQCFidBhBRhg8frrlz52rs2LHq2bOnfD6f1q1bp0mTJqlPnz4aN25cjbNGvv766xo1apQyMjJ06qmn6uWXXz4qMT/55BONGTNGffr00ZQpU7R58+bg9Tdv3qwpU6aoT58+GjNmjD755JPgvpkzZ+rWW2/VH/7wB2VkZGjSpEnKzc3VnXfeqb59+2rkyJH65ptvjuxBCsHTTz+twYMHa/DgwZo/f746deqk7du3S5IWL16sCRMmqFevXho6dKhmz54dvN2+M8nNnz9fp5xyii666CJNnjxZktS3b19lZGQEPyB57bXXNGrUKPXt21eXXXaZdu/eHbyfTp066aWXXtLpp5+uvn376h//+IeMMXU+bwD1i/fi9SszM1Pt27en8R9oxKi7AGAN6i8AHB7qZ3jKzMxUx44drU7jsPEaQCSjrqK+8LwDDQv1HwAOD/Wz7rF+NnQ8VkBoqN04XH6/3+oUgLBDzUV94XkHGg+a/yGJxtC68MILL2j06NHKzs7WqlWrNGTIkBpznzdvnsaOHavevXtrxowZqqqqCu5/5plngg2mr732Wo379Xg8uvfee3XKKado4MCB+vvf/67KykpJCsaZO3euBg0apL/97W+aNm2aMjIygpfOnTvrjTfekKQajau1fQyHDx+uZ555Jvj83Xjjjdq7d2/w9hdffLGKioqC1z/Y62nKlCl66KGHNGnSJPXo0UM7d+48is8EAKn6zJBz587V6tWrlZeXp6lTp2r69On6/PPPdcMNN+jqq69Wfn6+JCk1NVVPPfWUvvzyS9199926++679fXXXx9RzJ07d+raa6/VjTfeqBUrVmjIkCGaNm2aPB6PvF6vpk2bpkGDBmn58uW6+eabdd1112nLli3B+1q4cKFmzJihlStXyu1267zzzlPXrl21cuVKnXHGGbr77rsPmMfYsWPVp0+f/V5uvfXWkOaydOlSPf/883ruuef00Ucf6fPPP6+xPyYmRvfee69Wr16tp556Si+99JI+/vjjGtf54osv9P7772vevHl68cUXg2Nr165VRkaGPv74Yz311FN67LHHtGLFCvXu3VvXXnttjftYvHixXnvtNb399ttauHChli1bFlL+ABo23osfufz8fE2dOlV9+vRRv3799Pvf/z74Ie+Bcn/00Uf1xBNPaOHChcrIyND8+fO1Y8cOXXjhherfv7/69++va6+9VsXFxXWaO4D6R909+n55DGTKlCmaP39+cN8bb7yh888/P7i9adMmXXLJJerXr58GDhyoJ598MrjP6/Xq+uuvV0ZGhsaMGaONGzcG9+3Zs0d/+tOfNGDAAA0fPlwvvPBC/UwOwFFD/T36alN/N2/eHKy/Z5xxht5///3gvsrKSt1zzz0aNmyYevfurfPPPz94zFmS3n33XZ1yyinq37+/5syZExwPBAKaO3euTjvtNPXv31/XXHONCgsL63bSQCNE/TxyBztukJWVpauuukoDBgxQ//79f/MNHvfee6/69u2r4cOHa8mSJfu9/4MdT7jwwgu1atUq3XbbbcrIyNAXX3xR43O7Hj16qFOnTpJ+W7s7deqkf//73zr99NOVkZGhhx9+WDt27NB5552nXr166ZprrpHH45H082eETz/9tE466SQNHjxYH3/8sZYsWaIzzjhD/fr1q/He+2A1fH8ntAUiCXX1yE2ePFn//e9/JUmrV69Wp06dgjVy+fLlGj9+vKTqWvPEE09o2LBhOumkk3T99derpKSkxn0d6L3m7Nmzdc011+z3OMH7779fo5Z269ZNU6ZMCT4+Dz30kKTa18bZs2fr6quv1nXXXaeMjAyNHTtWW7du1VNPPaWTTjpJQ4cO1WeffRa8fklJiW688UYNHjxYJ598sh566KHgwvg33nhDkyZN0l133aV+/fpp9uzZKikp0fXXX68BAwZo2LBheuKJJ2o0KxljdPvtt6t3794aOXKkVqxYEXKs888/P6TfWUBjRv0/ckVFRZo6daoGDBigvn37aurUqcrOzpak4LqHfZcTTzxRw4cPP+j9eTwe3XnnncE1cnfeeWfw/e0+Tz75pPr376/hw4frnXfeqXHbQ62fe/bZZ4P1//XXXz/KjwbQeFA/j9zB6qd04PWzO3bs0DnnnKPevXtr+vTpNY69Hmo97vz587V582bdcsstWrdunTIyMtSnTx9J0pIlSzR69GhlZGTo5JNP1rx58ySJtcZABKF2Hx2LFi3S+PHj1adPH02aNEnfffddcN/cuXN18sknKyMjQ2eccUbwb/gNGzbod7/7nXr16qWBAwcG1zbvOz6873LCCScEv2Rs+PDhWr58uaTaH5v4ZV3MyMjQtGnTVFBQoGuvvVa9evXS2WefrV27dgWvf7DPC2fOnKlbbrlFl19+uXr27FnjNQLgwKi5R47jzdVqe7wZQCNhAGPMsGHDzLhx40xmZqapqKgw2dnZpl+/fmbx4sXG7/ebzz77zPTr18/k5eUZY4xZtGiR2b59uwkEAmbVqlWme/fu5quvvjLGGLNy5Upz8skn1zrmli1bTI8ePcxnn31mPB6PmTt3rjnttNNMVVWV8Xg85rTTTjNz5swxVVVVZvny5aZnz55m8+bNxhhjbrjhBtOvXz+zceNGU1lZaaZMmWKGDRtm3nzzTePz+cw///lPM3ny5APmcuaZZ5revXvv93LLLbeE9Bj+ct6PPfaYmTBhQvDx+vVjMmzYMHP22Web7OxsU1BQYEaOHGn+85//GGOMWbJkiTnppJPM999/b8rKysxf/vIXc/zxx5tt27YZY4y54447zNSpU01BQYEpKSkxU6dONQ888EAwTpcuXcx9991nqqqqTEVFRY0clyxZYgYNGmQyMzONMabG/db
"text/plain": [
"<Figure size 4102.1x360 with 11 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"plt.rcParams[\"xtick.labelsize\"] = 5\n",
"sns.set_theme()\n",
"plt.figure(figsize=(40, 6))\n",
"g = sns.relplot(data=df, x=\"room\", y=\"rssi\", style=\"room\", hue=\"room\", col=\"real_room\")\n",
"for ax in g.axes.flat:\n",
" labels = ax.get_xticklabels() # get x labels\n",
" ax.set_xticklabels(labels, rotation=90) # set new labels"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# SVM"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"from sklearn import svm\n"
]
},
{
"cell_type": "code",
"execution_count": 38,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"CategoricalDtype(categories=[' arbeitszimmer', ' küche', ' wohnzimmer', ' kinderzimmer',\n",
" ' kueche', ' wohnzimmeroben', ' schlafzimmer', ' garten',\n",
" ' az_oben', ' esszimmer', ' sofa'],\n",
", ordered=True)"
]
},
"execution_count": 38,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th># device</th>\n",
" <th>room</th>\n",
" <th>rssi</th>\n",
" <th>tx_power</th>\n",
" <th>real_room</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>martins_iphone</td>\n",
" <td>wohnzimmeroben</td>\n",
" <td>-90</td>\n",
" <td>12</td>\n",
" <td>arbeitszimmer</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>martins_apple_watch</td>\n",
" <td>wohnzimmer</td>\n",
" <td>-97</td>\n",
" <td>2</td>\n",
" <td>arbeitszimmer</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>martins_iphone</td>\n",
" <td>garten</td>\n",
" <td>-89</td>\n",
" <td>-1</td>\n",
" <td>arbeitszimmer</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>martins_iphone</td>\n",
" <td>wohnzimmeroben</td>\n",
" <td>-89</td>\n",
" <td>12</td>\n",
" <td>arbeitszimmer</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>martins_iphone</td>\n",
" <td>garten</td>\n",
" <td>-89</td>\n",
" <td>-1</td>\n",
" <td>arbeitszimmer</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>49258</th>\n",
" <td>martins_apple_watch</td>\n",
" <td>kinderzimmer</td>\n",
" <td>-91</td>\n",
" <td>8</td>\n",
" <td>sofa</td>\n",
" </tr>\n",
" <tr>\n",
" <th>49259</th>\n",
" <td>martins_iphone</td>\n",
" <td>kueche</td>\n",
" <td>-96</td>\n",
" <td>12</td>\n",
" <td>sofa</td>\n",
" </tr>\n",
" <tr>\n",
" <th>49260</th>\n",
" <td>martins_iphone</td>\n",
" <td>wohnzimmer</td>\n",
" <td>-69</td>\n",
" <td>2</td>\n",
" <td>sofa</td>\n",
" </tr>\n",
" <tr>\n",
" <th>49261</th>\n",
" <td>martins_iphone</td>\n",
" <td>garten</td>\n",
" <td>-86</td>\n",
" <td>2</td>\n",
" <td>sofa</td>\n",
" </tr>\n",
" <tr>\n",
" <th>49262</th>\n",
" <td>martins_apple_watch</td>\n",
" <td>wohnzimmeroben</td>\n",
" <td>-86</td>\n",
" <td>8</td>\n",
" <td>sofa</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>49263 rows × 5 columns</p>\n",
"</div>"
],
"text/plain": [
" # device room rssi tx_power real_room\n",
"0 martins_iphone wohnzimmeroben -90 12 arbeitszimmer\n",
"1 martins_apple_watch wohnzimmer -97 2 arbeitszimmer\n",
"2 martins_iphone garten -89 -1 arbeitszimmer\n",
"3 martins_iphone wohnzimmeroben -89 12 arbeitszimmer\n",
"4 martins_iphone garten -89 -1 arbeitszimmer\n",
"... ... ... ... ... ...\n",
"49258 martins_apple_watch kinderzimmer -91 8 sofa\n",
"49259 martins_iphone kueche -96 12 sofa\n",
"49260 martins_iphone wohnzimmer -69 2 sofa\n",
"49261 martins_iphone garten -86 2 sofa\n",
"49262 martins_apple_watch wohnzimmeroben -86 8 sofa\n",
"\n",
"[49263 rows x 5 columns]"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def cleanup_data(df):\n",
" df['real_room']\n",
"df"
]
},
{
"cell_type": "code",
"execution_count": null,
"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.10.12"
}
},
"nbformat": 4,
"nbformat_minor": 2
}