{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Query ASAM ODS Server" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In this example Notebook, we show you how to query (instance) data from your ASAM ODS Server.\n", "\n", "The first sections are on initializing and connecting. The fun starts with \"Query Instances\"." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Dependencies for this notebook" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The [ASAM ODSBox](https://pypi.org/project/odsbox/) contains 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", "- JAQueL implementation that converts MongoDB style JSON queries into a native ODS SelectStatement\n", "- utility that converts ODS DataMatrices into pandas.DataFrame\n", "\n", "> All examples are using the JAQueL query style to help you getting started.\n", "> Use `jaquel_to_select_statement` to convert JAQueL to a native ODS `SelectStatement`. " ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "try: \n", " import odsbox\n", "except:\n", " !pip install odsbox \n", "\n", "from odsbox.con_i import ConI" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## ASAM ODS Queries" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Establish session" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The ODS HTTP API is a session based API. The session ID is called conI in the ODS documentation. The [ASAM ODSBox](https://pypi.org/project/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": 3, "metadata": {}, "outputs": [], "source": [ "con_i = ConI(url='http://79.140.180.128:10032/api', auth=('Demo','mdm'))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Query Instances" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Query Units" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Engineering units are contained in every ASAM ODS server, so we can use them to get started:\n", "Lets search for all units in this server" ] }, { "cell_type": "code", "execution_count": 4, "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", " \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", "
Unit.IdUnit.NameUnit.MimeTypeUnit.DescriptionUnit.DateCreatedUnit.FactorUnit.OffsetUnit.dBUnit.dB_reference_factorUnit.PhysDimension
01mapplication/x-asam.aounit197001010000001.00.0False0.03
12kgapplication/x-asam.aounit197001010000001.00.0False0.02
23sapplication/x-asam.aounit197001010000001.00.0False0.01
34Aapplication/x-asam.aounit197001010000001.00.0False0.04
45Kapplication/x-asam.aounit197001010000001.00.0False0.05
.................................
9596kat/m^3application/x-asam.aounit197001010000001.00.0False0.071
9697Sv/sapplication/x-asam.aounit197001010000001.00.0False0.063
9798A*s/kgapplication/x-asam.aounit197001010000001.00.0False0.064
9899°Capplication/x-asam.aounit197001010000001.00.0False0.073
99100rpmapplication/x-asam.aounit197001010000001.00.0False0.073
\n", "

100 rows × 10 columns

\n", "
" ], "text/plain": [ " Unit.Id Unit.Name Unit.MimeType Unit.Description \\\n", "0 1 m application/x-asam.aounit \n", "1 2 kg application/x-asam.aounit \n", "2 3 s application/x-asam.aounit \n", "3 4 A application/x-asam.aounit \n", "4 5 K application/x-asam.aounit \n", ".. ... ... ... ... \n", "95 96 kat/m^3 application/x-asam.aounit \n", "96 97 Sv/s application/x-asam.aounit \n", "97 98 A*s/kg application/x-asam.aounit \n", "98 99 °C application/x-asam.aounit \n", "99 100 rpm application/x-asam.aounit \n", "\n", " Unit.DateCreated Unit.Factor Unit.Offset Unit.dB \\\n", "0 19700101000000 1.0 0.0 False \n", "1 19700101000000 1.0 0.0 False \n", "2 19700101000000 1.0 0.0 False \n", "3 19700101000000 1.0 0.0 False \n", "4 19700101000000 1.0 0.0 False \n", ".. ... ... ... ... \n", "95 19700101000000 1.0 0.0 False \n", "96 19700101000000 1.0 0.0 False \n", "97 19700101000000 1.0 0.0 False \n", "98 19700101000000 1.0 0.0 False \n", "99 19700101000000 1.0 0.0 False \n", "\n", " Unit.dB_reference_factor Unit.PhysDimension \n", "0 0.0 3 \n", "1 0.0 2 \n", "2 0.0 1 \n", "3 0.0 4 \n", "4 0.0 5 \n", ".. ... ... \n", "95 0.0 71 \n", "96 0.0 63 \n", "97 0.0 64 \n", "98 0.0 73 \n", "99 0.0 73 \n", "\n", "[100 rows x 10 columns]" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# There is always one Entity derived from AoUnit\n", "con_i.query_data({\n", " \"AoUnit\":{}\n", " })" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In our first query we've used the base name 'AoUnit' - so this query works on every ODS server. \n", "In our query result above we see that the entity derived from 'AoUnit' is called 'Unit'. So we can use this directly." ] }, { "cell_type": "code", "execution_count": 5, "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", "
Unit.IdUnit.NameUnit.MimeTypeUnit.DescriptionUnit.DateCreatedUnit.FactorUnit.OffsetUnit.dBUnit.dB_reference_factorUnit.PhysDimension
9596kat/m^3application/x-asam.aounit197001010000001.00.0False0.071
9697Sv/sapplication/x-asam.aounit197001010000001.00.0False0.063
9798A*s/kgapplication/x-asam.aounit197001010000001.00.0False0.064
9899°Capplication/x-asam.aounit197001010000001.00.0False0.073
99100rpmapplication/x-asam.aounit197001010000001.00.0False0.073
\n", "
" ], "text/plain": [ " Unit.Id Unit.Name Unit.MimeType Unit.Description \\\n", "95 96 kat/m^3 application/x-asam.aounit \n", "96 97 Sv/s application/x-asam.aounit \n", "97 98 A*s/kg application/x-asam.aounit \n", "98 99 °C application/x-asam.aounit \n", "99 100 rpm application/x-asam.aounit \n", "\n", " Unit.DateCreated Unit.Factor Unit.Offset Unit.dB \\\n", "95 19700101000000 1.0 0.0 False \n", "96 19700101000000 1.0 0.0 False \n", "97 19700101000000 1.0 0.0 False \n", "98 19700101000000 1.0 0.0 False \n", "99 19700101000000 1.0 0.0 False \n", "\n", " Unit.dB_reference_factor Unit.PhysDimension \n", "95 0.0 71 \n", "96 0.0 63 \n", "97 0.0 64 \n", "98 0.0 73 \n", "99 0.0 73 " ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "con_i.query_data({\n", " \"Unit\":{}\n", " }).tail()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now lets narrow down the list to the interesting attributes like 'name', 'factor' and 'offset'. And instead of its id we want to know the 'name' of the referenced physical dimension." ] }, { "cell_type": "code", "execution_count": 6, "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", "
Unit.NameUnit.FactorUnit.OffsetPhysDimension.Name
95kat/m^31.00.0catalytic_concentration
96Sv/s1.00.0equivalent_dose_rate
97A*s/kg1.00.0exposure_as_a_quantity
98°C1.00.0unknown
99rpm1.00.0unknown
\n", "
" ], "text/plain": [ " Unit.Name Unit.Factor Unit.Offset PhysDimension.Name\n", "95 kat/m^3 1.0 0.0 catalytic_concentration\n", "96 Sv/s 1.0 0.0 equivalent_dose_rate\n", "97 A*s/kg 1.0 0.0 exposure_as_a_quantity\n", "98 °C 1.0 0.0 unknown\n", "99 rpm 1.0 0.0 unknown" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "con_i.query_data({\n", " \"Unit\":{},\n", " \"$attributes\":{\n", " \"name\":1,\n", " \"factor\":1,\n", " \"offset\":1,\n", " \"PhysDimension.name\":1\n", " }\n", " }).tail()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In addition to the 'name' of the physical dimension, we are also interested in the lenght exponent." ] }, { "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", "
Unit.NameUnit.FactorUnit.OffsetPhysDimension.NamePhysDimension.Length
95kat/m^31.00.0catalytic_concentration-3
96Sv/s1.00.0equivalent_dose_rate2
97A*s/kg1.00.0exposure_as_a_quantity0
98°C1.00.0unknown0
99rpm1.00.0unknown0
\n", "
" ], "text/plain": [ " Unit.Name Unit.Factor Unit.Offset PhysDimension.Name \\\n", "95 kat/m^3 1.0 0.0 catalytic_concentration \n", "96 Sv/s 1.0 0.0 equivalent_dose_rate \n", "97 A*s/kg 1.0 0.0 exposure_as_a_quantity \n", "98 °C 1.0 0.0 unknown \n", "99 rpm 1.0 0.0 unknown \n", "\n", " PhysDimension.Length \n", "95 -3 \n", "96 2 \n", "97 0 \n", "98 0 \n", "99 0 " ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "con_i.query_data({\n", " \"Unit\":{},\n", " \"$attributes\":{\n", " \"name\":1,\n", " \"factor\":1,\n", " \"offset\":1,\n", " \"PhysDimension.name\":1,\n", " \"PhysDimension.length_exp\":1\n", " }\n", " }).tail()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Ok, and if I'm only interested in Units with a physical dimension with a length exponent of '1'?" ] }, { "cell_type": "code", "execution_count": 8, "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", "
Unit.NameUnit.FactorUnit.OffsetPhysDimension.NamePhysDimension.Length
4N1.00.0force1
5N/s1.00.0momentum1
6W/m*K1.00.0thermal_conductivity1
7V/m1.00.0electric_field_strength1
8H/m1.00.0permeability1
\n", "
" ], "text/plain": [ " Unit.Name Unit.Factor Unit.Offset PhysDimension.Name \\\n", "4 N 1.0 0.0 force \n", "5 N/s 1.0 0.0 momentum \n", "6 W/m*K 1.0 0.0 thermal_conductivity \n", "7 V/m 1.0 0.0 electric_field_strength \n", "8 H/m 1.0 0.0 permeability \n", "\n", " PhysDimension.Length \n", "4 1 \n", "5 1 \n", "6 1 \n", "7 1 \n", "8 1 " ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "con_i.query_data({\n", " \"Unit\":{\"PhysDimension.length_exp\":1},\n", " \"$attributes\":{\n", " \"name\":1,\n", " \"factor\":1,\n", " \"offset\":1,\n", " \"PhysDimension.name\":1,\n", " \"PhysDimension.length_exp\":1\n", " }\n", " }).tail()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ ".... or in those, where the 'name' of the physical dimension is 'length' ..." ] }, { "cell_type": "code", "execution_count": 9, "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", "
Unit.NameUnit.FactorUnit.OffsetPhysDimension.NamePhysDimension.Length
0m1.00.0length1
\n", "
" ], "text/plain": [ " Unit.Name Unit.Factor Unit.Offset PhysDimension.Name PhysDimension.Length\n", "0 m 1.0 0.0 length 1" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "con_i.query_data({\n", " \"Unit\":{\"PhysDimension.name\":\"length\"},\n", " \"$attributes\":{\n", " \"name\":1,\n", " \"factor\":1,\n", " \"offset\":1,\n", " \"PhysDimension.name\":1,\n", " \"PhysDimension.length_exp\":1\n", " }\n", " }).tail()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "... we can also make it easier getting a group of attributes of the same type in return... " ] }, { "cell_type": "code", "execution_count": 10, "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", "
Unit.NameUnit.FactorUnit.OffsetPhysDimension.NamePhysDimension.Length
0m1.00.0length1
\n", "
" ], "text/plain": [ " Unit.Name Unit.Factor Unit.Offset PhysDimension.Name PhysDimension.Length\n", "0 m 1.0 0.0 length 1" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "con_i.query_data({\n", " \"Unit\":{\"PhysDimension.name\":\"length\"},\n", " \"$attributes\":{\n", " \"name\":1,\n", " \"factor\":1,\n", " \"offset\":1,\n", " \"PhysDimension\": {\n", " \"name\":1,\n", " \"length_exp\":1\n", " }\n", " }\n", " }).tail()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "All queries have used 'equal' as implicit operator before. Now lets use 'like' instead." ] }, { "cell_type": "code", "execution_count": 11, "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", "
Unit.NameUnit.FactorUnit.OffsetPhysDimension.NamePhysDimension.Length
3kg/m^31.00.0density-3
4km/h3.60.0velocity1
5kW*h3600000.00.0energy2
6kat1.00.0catalytic_activity0
7kat/m^31.00.0catalytic_concentration-3
\n", "
" ], "text/plain": [ " Unit.Name Unit.Factor Unit.Offset PhysDimension.Name \\\n", "3 kg/m^3 1.0 0.0 density \n", "4 km/h 3.6 0.0 velocity \n", "5 kW*h 3600000.0 0.0 energy \n", "6 kat 1.0 0.0 catalytic_activity \n", "7 kat/m^3 1.0 0.0 catalytic_concentration \n", "\n", " PhysDimension.Length \n", "3 -3 \n", "4 1 \n", "5 2 \n", "6 0 \n", "7 -3 " ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "con_i.query_data({\n", " \"Unit\":{\n", " \"name\":{\"$like\":\"k*\"}\n", " },\n", " \"$attributes\":{\n", " \"name\":1,\n", " \"factor\":1,\n", " \"offset\":1,\n", " \"PhysDimension\": {\n", " \"name\":1,\n", " \"length_exp\":1\n", " }\n", " }\n", " }).tail()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Query Hierarchy elements\n", "\n", "When you think about using ASAM ODS as a tool to manage and harmonize measurement data files like CSV, XLSX, MDF4, ... you can think of the following data model:\n", "\n", "- *file* -> 'TestStep'\n", "- *group*, *sheet* -> 'MeaResult'\n", "- *channel*, *column* -> 'MeaQuantity'" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "So lets query for them and reduce the maximal amount returned to a fix number - here: 5." ] }, { "cell_type": "code", "execution_count": 12, "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", "
TestStep.IdTestStep.NameTestStep.MimeTypeTestStep.DescriptionTestStep.DateCreatedTestStep.OptionalTestStep.SortindexTestStep.MDMLinksTestStep.TestTestStep.TplTestStepTestStep.TestEquipmentTestStep.UnitUnderTestTestStep.TestSequenceTestStep.Classification
01ElectricMotorTemperatureTestapplication/x-asam.aosubtest.teststep19700101000000False0[]100000
\n", "
" ], "text/plain": [ " TestStep.Id TestStep.Name \\\n", "0 1 ElectricMotorTemperatureTest \n", "\n", " TestStep.MimeType TestStep.Description \\\n", "0 application/x-asam.aosubtest.teststep \n", "\n", " TestStep.DateCreated TestStep.Optional TestStep.Sortindex \\\n", "0 19700101000000 False 0 \n", "\n", " TestStep.MDMLinks TestStep.Test TestStep.TplTestStep \\\n", "0 [] 1 0 \n", "\n", " TestStep.TestEquipment TestStep.UnitUnderTest TestStep.TestSequence \\\n", "0 0 0 0 \n", "\n", " TestStep.Classification \n", "0 0 " ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "con_i.query_data({\n", " \"TestStep\": {},\n", " \"$options\": { \"$rowlimit\": 5 }\n", "})" ] }, { "cell_type": "code", "execution_count": 13, "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", "
MeaResult.IdMeaResult.NameMeaResult.MimeTypeMeaResult.DescriptionMeaResult.DateCreatedMeaResult.MeasurementBeginMeaResult.MeasurementEndMeaResult.MDMLinksMeaResult.TestStepMeaResult.TestEquipmentMeaResult.UnitUnderTestMeaResult.TestSequenceMeaResult.ClassificationMeaResult.TplMeaResult
01Profile_02application/x-asam.aomeasurement197001010000002024060700000020240607000000[]100000
12Profile_03application/x-asam.aomeasurement197001010000002024071300000020240713000000[]100000
23Profile_04application/x-asam.aomeasurement197001010000002024062700000020240627000000[]100000
34Profile_05application/x-asam.aomeasurement197001010000002024070900000020240709000000[]100000
45Profile_06application/x-asam.aomeasurement197001010000002024051500000020240515000000[]100000
\n", "
" ], "text/plain": [ " MeaResult.Id MeaResult.Name MeaResult.MimeType \\\n", "0 1 Profile_02 application/x-asam.aomeasurement \n", "1 2 Profile_03 application/x-asam.aomeasurement \n", "2 3 Profile_04 application/x-asam.aomeasurement \n", "3 4 Profile_05 application/x-asam.aomeasurement \n", "4 5 Profile_06 application/x-asam.aomeasurement \n", "\n", " MeaResult.Description MeaResult.DateCreated MeaResult.MeasurementBegin \\\n", "0 19700101000000 20240607000000 \n", "1 19700101000000 20240713000000 \n", "2 19700101000000 20240627000000 \n", "3 19700101000000 20240709000000 \n", "4 19700101000000 20240515000000 \n", "\n", " MeaResult.MeasurementEnd MeaResult.MDMLinks MeaResult.TestStep \\\n", "0 20240607000000 [] 1 \n", "1 20240713000000 [] 1 \n", "2 20240627000000 [] 1 \n", "3 20240709000000 [] 1 \n", "4 20240515000000 [] 1 \n", "\n", " MeaResult.TestEquipment MeaResult.UnitUnderTest MeaResult.TestSequence \\\n", "0 0 0 0 \n", "1 0 0 0 \n", "2 0 0 0 \n", "3 0 0 0 \n", "4 0 0 0 \n", "\n", " MeaResult.Classification MeaResult.TplMeaResult \n", "0 0 0 \n", "1 0 0 \n", "2 0 0 \n", "3 0 0 \n", "4 0 0 " ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "con_i.query_data({\n", " \"MeaResult\": {},\n", " \"$options\": { \"$rowlimit\": 5 }\n", "})" ] }, { "cell_type": "code", "execution_count": 14, "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", " \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", "
MeaQuantity.IdMeaQuantity.NameMeaQuantity.MimeTypeMeaQuantity.DescriptionMeaQuantity.InterpolationMeaQuantity.DataTypeMeaQuantity.RankMeaQuantity.DimensionMeaQuantity.TypeSizeMeaQuantity.MinimumMeaQuantity.MaximumMeaQuantity.AverageMeaQuantity.DeviationMeaQuantity.non_reference_channel_nameMeaQuantity.reference_channel_nameMeaQuantity.MeaResultMeaQuantity.QuantityMeaQuantity.UnitMeaQuantity.Classification
01Timeapplication/x-asam.aomeasurementquantityTime measured in 2 Hz070[]00.0000009678.5000004839.2500002794.0866311030
12U_qapplication/x-asam.aomeasurementquantityVoltage q-component measurement in dq-coordinates070[]03.9196058.7985125.8945082.23183810760
23Coolantapplication/x-asam.aomeasurementquantityCoolant temperature070[]015.59486519.77464718.5420540.32855810820
34Stator_windingapplication/x-asam.aomeasurementquantityStator winding temperature measured with therm...070[]019.428793103.28251651.11027037.97869910820
45U_dapplication/x-asam.aomeasurementquantityVoltage d-component measurement in dq-coordinates070[]0-9.8204811.701082-2.8154225.47447110760
\n", "
" ], "text/plain": [ " MeaQuantity.Id MeaQuantity.Name MeaQuantity.MimeType \\\n", "0 1 Time application/x-asam.aomeasurementquantity \n", "1 2 U_q application/x-asam.aomeasurementquantity \n", "2 3 Coolant application/x-asam.aomeasurementquantity \n", "3 4 Stator_winding application/x-asam.aomeasurementquantity \n", "4 5 U_d application/x-asam.aomeasurementquantity \n", "\n", " MeaQuantity.Description \\\n", "0 Time measured in 2 Hz \n", "1 Voltage q-component measurement in dq-coordinates \n", "2 Coolant temperature \n", "3 Stator winding temperature measured with therm... \n", "4 Voltage d-component measurement in dq-coordinates \n", "\n", " MeaQuantity.Interpolation MeaQuantity.DataType MeaQuantity.Rank \\\n", "0 0 7 0 \n", "1 0 7 0 \n", "2 0 7 0 \n", "3 0 7 0 \n", "4 0 7 0 \n", "\n", " MeaQuantity.Dimension MeaQuantity.TypeSize MeaQuantity.Minimum \\\n", "0 [] 0 0.000000 \n", "1 [] 0 3.919605 \n", "2 [] 0 15.594865 \n", "3 [] 0 19.428793 \n", "4 [] 0 -9.820481 \n", "\n", " MeaQuantity.Maximum MeaQuantity.Average MeaQuantity.Deviation \\\n", "0 9678.500000 4839.250000 2794.086631 \n", "1 8.798512 5.894508 2.231838 \n", "2 19.774647 18.542054 0.328558 \n", "3 103.282516 51.110270 37.978699 \n", "4 1.701082 -2.815422 5.474471 \n", "\n", " MeaQuantity.non_reference_channel_name MeaQuantity.reference_channel_name \\\n", "0 \n", "1 \n", "2 \n", "3 \n", "4 \n", "\n", " MeaQuantity.MeaResult MeaQuantity.Quantity MeaQuantity.Unit \\\n", "0 1 0 3 \n", "1 1 0 76 \n", "2 1 0 82 \n", "3 1 0 82 \n", "4 1 0 76 \n", "\n", " MeaQuantity.Classification \n", "0 0 \n", "1 0 \n", "2 0 \n", "3 0 \n", "4 0 " ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "con_i.query_data({\n", " \"MeaQuantity\": {},\n", " \"$options\": { \"$rowlimit\": 5 }\n", "})" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Get parent properties\n", "Consider you're looking for *columns* (MeaQuantity), but also being interested to which *sheet* (MeaResult) and *file* (TestStep) they belong, the following query will give you an idea how this works... " ] }, { "cell_type": "code", "execution_count": 15, "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", " \n", " \n", " \n", " \n", " \n", "
MeaQuantity.IdMeaQuantity.NameMeaResult.IdMeaResult.NameTestStep.IdTestStep.NameUnit.Name
01Time1Profile_021ElectricMotorTemperatureTests
12U_q1Profile_021ElectricMotorTemperatureTestV
23Coolant1Profile_021ElectricMotorTemperatureTestgradC
34Stator_winding1Profile_021ElectricMotorTemperatureTestgradC
45U_d1Profile_021ElectricMotorTemperatureTestV
56Stator_tooth1Profile_021ElectricMotorTemperatureTestgradC
67Motor_speed1Profile_021ElectricMotorTemperatureTest1/min
78I_d1Profile_021ElectricMotorTemperatureTestA
89I_q1Profile_021ElectricMotorTemperatureTestA
910Pm1Profile_021ElectricMotorTemperatureTestgradC
\n", "
" ], "text/plain": [ " MeaQuantity.Id MeaQuantity.Name MeaResult.Id MeaResult.Name TestStep.Id \\\n", "0 1 Time 1 Profile_02 1 \n", "1 2 U_q 1 Profile_02 1 \n", "2 3 Coolant 1 Profile_02 1 \n", "3 4 Stator_winding 1 Profile_02 1 \n", "4 5 U_d 1 Profile_02 1 \n", "5 6 Stator_tooth 1 Profile_02 1 \n", "6 7 Motor_speed 1 Profile_02 1 \n", "7 8 I_d 1 Profile_02 1 \n", "8 9 I_q 1 Profile_02 1 \n", "9 10 Pm 1 Profile_02 1 \n", "\n", " TestStep.Name Unit.Name \n", "0 ElectricMotorTemperatureTest s \n", "1 ElectricMotorTemperatureTest V \n", "2 ElectricMotorTemperatureTest gradC \n", "3 ElectricMotorTemperatureTest gradC \n", "4 ElectricMotorTemperatureTest V \n", "5 ElectricMotorTemperatureTest gradC \n", "6 ElectricMotorTemperatureTest 1/min \n", "7 ElectricMotorTemperatureTest A \n", "8 ElectricMotorTemperatureTest A \n", "9 ElectricMotorTemperatureTest gradC " ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "con_i.query_data({\n", " \"MeaQuantity\": {},\n", " \"$attributes\": {\n", " \"Id\": 1,\n", " \"Name\": 1,\n", " \"MeaResult\": {\n", " \"Id\": 1,\n", " \"Name\": 1,\n", " \"TestStep\": {\n", " \"Id\": 1,\n", " \"Name\": 1\n", " }\n", " },\n", " \"Unit.name\": 1\n", " },\n", " \"$options\": {\"$rowlimit\": 10}\n", "})" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Parameter and ParameterSets" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Parameters are a flexible way to carry additional information, not being strictly pre-defined by the data model. Those parameters are name value pairs with an additional data type information, being grouped in parameter sets.\n", "The following query returns the parameters belonging to certain MeaResult - including their parameter set information... " ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
ResultParameter.NameResultParameter.ValueResultParameter.DataTypeResultParameterSet.NameMeaResult.Id
\n", "
" ], "text/plain": [ "Empty DataFrame\n", "Columns: [ResultParameter.Name, ResultParameter.Value, ResultParameter.DataType, ResultParameterSet.Name, MeaResult.Id]\n", "Index: []" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "con_i.query_data({\n", " \"ResultParameter\": {\"parameter_set.MeaResult.Name\": {\"$like\": \"Pend*\"}},\n", " \"$attributes\": {\n", " \"Name\": 1,\n", " \"Value\": 1,\n", " \"DataType\": 1,\n", " \"parameter_set.Name\": 1,\n", " \"parameter_set.MeaResult.Id\": 1\n", " },\n", " \"$options\": {\"$rowlimit\": 20}\n", "})\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Given their flexible character, only minimal query capabilities can be offered for Parameters. Be aware that the conditions are combined by \"AND\" and lead to an empty result if you try to use multiple properties." ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
ResultParameter.NameResultParameter.ValueResultParameter.DataTypeResultParameterSet.NameMeaResult.Id
\n", "
" ], "text/plain": [ "Empty DataFrame\n", "Columns: [ResultParameter.Name, ResultParameter.Value, ResultParameter.DataType, ResultParameterSet.Name, MeaResult.Id]\n", "Index: []" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "con_i.query_data({\n", " \"ResultParameter\": {\n", " \"parameter_set.MeaResult.Name\": {\"$like\": \"Pend*\"},\n", " \"Name\":\"start_time\",\n", " \"DataType\":1,\n", " \"Value\": {\"$like\": \"2023*\"}\n", " },\n", " \"$attributes\": {\n", " \"Name\": 1,\n", " \"Value\": 1,\n", " \"DataType\": 1,\n", " \"parameter_set.Name\": 1,\n", " \"parameter_set.MeaResult.Id\": 1\n", " },\n", " \"$options\": {\"$rowlimit\": 20}\n", "})" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
ResultParameter.NameResultParameter.ValueResultParameter.DataTypeResultParameterSet.NameMeaResult.Id
\n", "
" ], "text/plain": [ "Empty DataFrame\n", "Columns: [ResultParameter.Name, ResultParameter.Value, ResultParameter.DataType, ResultParameterSet.Name, MeaResult.Id]\n", "Index: []" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "con_i.query_data({\n", " \"ResultParameter\": {\n", " \"parameter_set.MeaResult.Name\": {\"$like\": \"Pend*\"},\n", " \"$and\": [\n", " {\n", " \"Name\": \"start_time\",\n", " \"DataType\": 1,\n", " \"Value\": {\"$like\": \"2023*\"}\n", " }\n", " ]\n", " },\n", " \"$attributes\": {\n", " \"Name\": 1,\n", " \"Value\": 1,\n", " \"DataType\": 1,\n", " \"parameter_set.Name\": 1,\n", " \"parameter_set.MeaResult.Id\": 1\n", " },\n", " \"$options\": {\"$rowlimit\": 20}\n", "})\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Aggregates" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Distinct" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Test.Name
0First Campaign
\n", "
" ], "text/plain": [ " Test.Name\n", "0 First Campaign" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "con_i.query_data({\n", " \"Test\": {},\n", " \"$attributes\": {\n", " \"name\": {\"$distinct\": 1}\n", " }\n", "})\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Lets do it adaptive with query condition" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Test.Name
0First Campaign
\n", "
" ], "text/plain": [ " Test.Name\n", "0 First Campaign" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "con_i.query_data({\n", " \"Test\": {\"name\": {\"$like\": \"*\"}},\n", " \"$attributes\": {\n", " \"name\": {\"$distinct\": 1}\n", " }\n", "})\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Min & Max" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
TestStep.DateCreated
019700101000000
\n", "
" ], "text/plain": [ " TestStep.DateCreated\n", "0 19700101000000" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "con_i.query_data({\n", " \"TestStep\": {},\n", " \"$attributes\": {\n", " \"DateCreated\": {\"$max\": 1}\n", " }\n", "})" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
TestStep.DateCreated
019700101000000
\n", "
" ], "text/plain": [ " TestStep.DateCreated\n", "0 19700101000000" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "con_i.query_data({\n", " \"TestStep\": {},\n", " \"$attributes\": {\n", " \"DateCreated\": {\"$min\": 1}\n", " }\n", "})" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
TestStep.DateCreated
019700101000000
\n", "
" ], "text/plain": [ " TestStep.DateCreated\n", "0 19700101000000" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "con_i.query_data({\n", " \"TestStep\": {},\n", " \"$attributes\": {\n", " \"DateCreated\": {\"$max\": 1, \"$min\": 1}\n", " }\n", "})" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Lets do it adaptive with query condition" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
TestStep.DateCreated
019700101000000
\n", "
" ], "text/plain": [ " TestStep.DateCreated\n", "0 19700101000000" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "con_i.query_data({\n", " \"TestStep\": {\"Name\": {\"$like\": \"EngineNoise*\"}},\n", " \"$attributes\": {\n", " \"DateCreated\": {\"$max\": 1, \"$min\":1}\n", " }\n", "})" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Close session\n", "Don't forget to close the session to release the connection license. Otherwise the session will be auto closed after 30 minutes of inactivity." ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [], "source": [ "con_i.logout()" ] }, { "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": "Python 3 (ipykernel)", "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" }, "vscode": { "interpreter": { "hash": "369f2c481f4da34e4445cda3fffd2e751bd1c4d706f27375911949ba6bb62e1c" } } }, "nbformat": 4, "nbformat_minor": 4 }