{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# ASAM ODS Playground\n", "\n", "This notebook provides a simple query and mass data example you can change and extend to your needs.\n", "\n", "Use VSCode Data Wrangler or Google Colab to experiment with the data. [![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg \"Open in Colab\")](https://colab.research.google.com/github/peak-solution/data_management_learning_path/blob/main/data_management_learning_path/ods/playground.ipynb)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Initialize and connect" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The [ASAM ODSBox](https://pypi.org/project/odsbox/) contain some functionality that wraps the ODS HTTP API making using Python easier ;-)\n", "\n", "It contains:\n", "- http wrapper implemented using protobuf and requests\n", "- utility that converts ODS DataMatrices into pandas.DataFrame\n", "\n", "The ODS HTTP API is a session based API. The session ID is called conI in the ODS documentation. The ASAM ODSBox uses con_i as API object representing the session. Close this session to release the connection license. Otherwise the session will be auto closed after 30 minutes of inactivity." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Exception ignored in: \n", "Traceback (most recent call last):\n", " File \"c:\\Peak\\github\\data_management_learning_path\\.venv\\Lib\\site-packages\\odsbox\\con_i.py\", line 136, in __del__\n", " self.logout()\n", " File \"c:\\Peak\\github\\data_management_learning_path\\.venv\\Lib\\site-packages\\odsbox\\con_i.py\", line 168, in logout\n", " self.__check_result(response)\n", " File \"c:\\Peak\\github\\data_management_learning_path\\.venv\\Lib\\site-packages\\odsbox\\con_i.py\", line 510, in __check_result\n", " raise requests.HTTPError(\n", "requests.exceptions.HTTPError: {\n", " \"minorCode\": 3,\n", " \"reason\": \"Cannot find session for connection identifier 9315ec67-7879-4e8c-b768-2f6feeabd582!\"\n", "}\n" ] } ], "source": [ "try: \n", " import odsbox\n", "except:\n", " !pip install -U odsbox\n", "\n", "from odsbox.con_i import ConI\n", "from odsbox.submatrix_to_pandas import submatrix_to_pandas\n", "\n", "con_i = ConI(url='http://79.140.180.128:10032/api', auth=('Demo','mdm'))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Simple query for some data\n", "\n", "First we query for a submatrix containing the bulk data structure of a certain measurement. \n", "We use this submatrix to query for bulk data in the next step - directly converted to a Dataframe ...\n", "\n", "Try different query options (there must be more than an asterix (*) 😉) ... " ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
U_qCoolantStator_windingU_dStator_toothMotor_speedI_dI_qPmStator_yokeAmbientTorque
Time
0.0-1.87044678.80492853.3933230.62702755.5886122.761764-2.0013881.09431749.69574060.42650625.3215853.138413e-13
0.53.74769978.85914153.460695-2.55079855.659321102.164216-6.58881221.26687049.68994060.49082225.3084111.465798e+01
1.013.77133778.90088653.480459-9.70484655.698835314.802839-11.96928841.99228749.67522960.54248225.2958982.993536e+01
1.526.85116078.93978853.451930-19.58373655.723997608.984106-16.06797857.52661249.68636560.57828525.2754024.141312e+01
2.042.08846778.96630253.467553-31.88556255.743452961.552082-19.42869869.95240549.69220660.60502825.2635755.064337e+01
\n", "
" ], "text/plain": [ " U_q Coolant Stator_winding U_d Stator_tooth \\\n", "Time \n", "0.0 -1.870446 78.804928 53.393323 0.627027 55.588612 \n", "0.5 3.747699 78.859141 53.460695 -2.550798 55.659321 \n", "1.0 13.771337 78.900886 53.480459 -9.704846 55.698835 \n", "1.5 26.851160 78.939788 53.451930 -19.583736 55.723997 \n", "2.0 42.088467 78.966302 53.467553 -31.885562 55.743452 \n", "\n", " Motor_speed I_d I_q Pm Stator_yoke Ambient \\\n", "Time \n", "0.0 2.761764 -2.001388 1.094317 49.695740 60.426506 25.321585 \n", "0.5 102.164216 -6.588812 21.266870 49.689940 60.490822 25.308411 \n", "1.0 314.802839 -11.969288 41.992287 49.675229 60.542482 25.295898 \n", "1.5 608.984106 -16.067978 57.526612 49.686365 60.578285 25.275402 \n", "2.0 961.552082 -19.428698 69.952405 49.692206 60.605028 25.263575 \n", "\n", " Torque \n", "Time \n", "0.0 3.138413e-13 \n", "0.5 1.465798e+01 \n", "1.0 2.993536e+01 \n", "1.5 4.141312e+01 \n", "2.0 5.064337e+01 " ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# find submatrix (bulk root) of a certain measurement\n", "submatrices = con_i.query_data(\n", " {\n", " \"AoSubmatrix\": {\"measurement.name\": {\"$like\": \"*\"}},\n", " \"$attributes\": {\"name\": 1, \"id\": 1},\n", " \"$options\": {\"$rowlimit\": 50},\n", " }\n", ")\n", "\n", "# get the bulk data of first submatrix\n", "df = submatrix_to_pandas(con_i, submatrices.iloc[0,1])\n", "\n", "if \"Time\" in df.columns:\n", " df.set_index(\"Time\", inplace=True)\n", "elif \"time\" in df.columns:\n", " df.set_index(\"time\", inplace=True)\n", "\n", "df.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## License\n", "\n", "Copyright © 2024 [Peak Solution GmbH](https://peak-solution.de)\n", "\n", "The training material in this repository is licensed under a Creative Commons BY-NC-SA 4.0 license. See [LICENSE](../LICENSE) file for more information." ] } ], "metadata": { "kernelspec": { "display_name": ".venv", "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.11.6" } }, "nbformat": 4, "nbformat_minor": 2 }