docs(notebooks): add extract_numbers docstring

This commit is contained in:
nuluh
2024-09-03 11:09:47 +07:00
parent 9da3dae709
commit 0306f28a68

View File

@@ -302,7 +302,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 4, "execution_count": 5,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -325,12 +325,25 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 5, "execution_count": 3,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"# Define a function to extract numbers from a filename that later used as labels features\n", "# Define a function to extract numbers from a filename that later used as labels features\n",
"def extract_numbers(filename):\n", "def extract_numbers(filename):\n",
" '''\n",
" Extract numbers from a filename\n",
"\n",
" Parameters\n",
" ----------\n",
" filename : str\n",
" The filename to extract numbers from\n",
"\n",
" Returns\n",
" -------\n",
" list\n",
" A list of extracted numbers: [damage_number, test_number, sensor_number]\n",
" '''\n",
" # Find all occurrences of one or more digits in the filename\n", " # Find all occurrences of one or more digits in the filename\n",
" numbers = re.findall(r'\\d+', filename)\n", " numbers = re.findall(r'\\d+', filename)\n",
" # Convert the list of number strings to integers\n", " # Convert the list of number strings to integers\n",
@@ -372,7 +385,7 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"data_dir = \"../../data/raw\"\n", "data_dir = \"../../data/QUGS/raw\"\n",
"# Extract features\n", "# Extract features\n",
"df1 = build_features(data_dir, sensor=1)\n", "df1 = build_features(data_dir, sensor=1)\n",
"df2 = build_features(data_dir, sensor=2)" "df2 = build_features(data_dir, sensor=2)"
@@ -411,145 +424,17 @@
" <thead>\n", " <thead>\n",
" <tr style=\"text-align: right;\">\n", " <tr style=\"text-align: right;\">\n",
" <th></th>\n", " <th></th>\n",
" <th>Mean</th>\n",
" <th>Max</th>\n",
" <th>Peak (Pm)</th>\n",
" <th>Peak-to-Peak (Pk)</th>\n",
" <th>RMS</th>\n",
" <th>Variance</th>\n",
" <th>Standard Deviation</th>\n",
" <th>Power</th>\n",
" <th>Crest Factor</th>\n",
" <th>Form Factor</th>\n",
" <th>Pulse Indicator</th>\n",
" <th>Margin</th>\n",
" <th>Kurtosis</th>\n",
" <th>Skewness</th>\n",
" <th>label</th>\n",
" <th>filename</th>\n",
" </tr>\n", " </tr>\n",
" </thead>\n", " </thead>\n",
" <tbody>\n", " <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>-0.075377</td>\n",
" <td>1.466510</td>\n",
" <td>2.254903</td>\n",
" <td>3.721414</td>\n",
" <td>1.037986</td>\n",
" <td>1.071734</td>\n",
" <td>1.091245</td>\n",
" <td>1.077416</td>\n",
" <td>2.172382</td>\n",
" <td>-13.770555</td>\n",
" <td>-29.914909</td>\n",
" <td>2.764892</td>\n",
" <td>2.817839</td>\n",
" <td>-0.649122</td>\n",
" <td>1</td>\n",
" <td>D1_TEST01_1.csv</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>-0.227331</td>\n",
" <td>1.307743</td>\n",
" <td>1.575323</td>\n",
" <td>2.883067</td>\n",
" <td>0.953077</td>\n",
" <td>0.856677</td>\n",
" <td>0.975635</td>\n",
" <td>0.908357</td>\n",
" <td>1.652881</td>\n",
" <td>-4.192466</td>\n",
" <td>-6.929646</td>\n",
" <td>1.821195</td>\n",
" <td>1.915737</td>\n",
" <td>0.260070</td>\n",
" <td>1</td>\n",
" <td>D1_TEST02_1.csv</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>0.009247</td>\n",
" <td>1.139160</td>\n",
" <td>1.476295</td>\n",
" <td>2.615455</td>\n",
" <td>0.906951</td>\n",
" <td>0.822475</td>\n",
" <td>0.955961</td>\n",
" <td>0.822560</td>\n",
" <td>1.627755</td>\n",
" <td>98.077724</td>\n",
" <td>159.646548</td>\n",
" <td>1.868548</td>\n",
" <td>1.763273</td>\n",
" <td>-0.503998</td>\n",
" <td>1</td>\n",
" <td>D1_TEST03_1.csv</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>0.050242</td>\n",
" <td>2.637336</td>\n",
" <td>2.637336</td>\n",
" <td>4.445498</td>\n",
" <td>1.135680</td>\n",
" <td>1.287244</td>\n",
" <td>1.195939</td>\n",
" <td>1.289768</td>\n",
" <td>2.322254</td>\n",
" <td>22.604275</td>\n",
" <td>52.492866</td>\n",
" <td>3.417678</td>\n",
" <td>3.644127</td>\n",
" <td>0.696925</td>\n",
" <td>1</td>\n",
" <td>D1_TEST04_1.csv</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>-0.063636</td>\n",
" <td>1.814052</td>\n",
" <td>1.814052</td>\n",
" <td>3.213308</td>\n",
" <td>0.919439</td>\n",
" <td>0.841319</td>\n",
" <td>0.966850</td>\n",
" <td>0.845369</td>\n",
" <td>1.972998</td>\n",
" <td>-14.448310</td>\n",
" <td>-28.506483</td>\n",
" <td>2.255246</td>\n",
" <td>2.633599</td>\n",
" <td>0.716632</td>\n",
" <td>1</td>\n",
" <td>D1_TEST05_1.csv</td>\n",
" </tr>\n",
" </tbody>\n", " </tbody>\n",
"</table>\n", "</table>\n",
"</div>" "</div>"
], ],
"text/plain": [ "text/plain": [
" Mean Max Peak (Pm) Peak-to-Peak (Pk) RMS Variance \\\n", "Empty DataFrame\n",
"0 -0.075377 1.466510 2.254903 3.721414 1.037986 1.071734 \n", "Columns: []\n",
"1 -0.227331 1.307743 1.575323 2.883067 0.953077 0.856677 \n", "Index: []"
"2 0.009247 1.139160 1.476295 2.615455 0.906951 0.822475 \n",
"3 0.050242 2.637336 2.637336 4.445498 1.135680 1.287244 \n",
"4 -0.063636 1.814052 1.814052 3.213308 0.919439 0.841319 \n",
"\n",
" Standard Deviation Power Crest Factor Form Factor Pulse Indicator \\\n",
"0 1.091245 1.077416 2.172382 -13.770555 -29.914909 \n",
"1 0.975635 0.908357 1.652881 -4.192466 -6.929646 \n",
"2 0.955961 0.822560 1.627755 98.077724 159.646548 \n",
"3 1.195939 1.289768 2.322254 22.604275 52.492866 \n",
"4 0.966850 0.845369 1.972998 -14.448310 -28.506483 \n",
"\n",
" Margin Kurtosis Skewness label filename \n",
"0 2.764892 2.817839 -0.649122 1 D1_TEST01_1.csv \n",
"1 1.821195 1.915737 0.260070 1 D1_TEST02_1.csv \n",
"2 1.868548 1.763273 -0.503998 1 D1_TEST03_1.csv \n",
"3 3.417678 3.644127 0.696925 1 D1_TEST04_1.csv \n",
"4 2.255246 2.633599 0.716632 1 D1_TEST05_1.csv "
] ]
}, },
"execution_count": 7, "execution_count": 7,