From a16430ee15d75dd850fd2723640e81c11a64cd9b Mon Sep 17 00:00:00 2001 From: dahbar Date: Wed, 20 Sep 2023 14:31:27 +0200 Subject: [PATCH] fix(notebooks): Temporary fix of PA Notebook --- ...2 Intro to Physical Architecture API.ipynb | 112 +++++++++++++----- 1 file changed, 82 insertions(+), 30 deletions(-) diff --git a/docs/source/examples/02 Intro to Physical Architecture API.ipynb b/docs/source/examples/02 Intro to Physical Architecture API.ipynb index 15564710c..505565c14 100644 --- a/docs/source/examples/02 Intro to Physical Architecture API.ipynb +++ b/docs/source/examples/02 Intro to Physical Architecture API.ipynb @@ -12,7 +12,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": null, "id": "4c181cfb", "metadata": {}, "outputs": [ @@ -43,7 +43,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 2, "id": "1386d2f7", "metadata": { "scrolled": true @@ -78,7 +78,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 3, "id": "8b555976", "metadata": { "scrolled": false @@ -113,7 +113,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 4, "id": "711574aa", "metadata": { "scrolled": true @@ -163,7 +163,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 5, "id": "21ef5c4d", "metadata": {}, "outputs": [ @@ -197,7 +197,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 6, "id": "63ff286c", "metadata": {}, "outputs": [], @@ -221,7 +221,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 7, "id": "6d8ff25c", "metadata": {}, "outputs": [ @@ -434,38 +434,54 @@ "\n", "Now lets assume that components of node nature are hardware things and behavior corresponds to software components. Assuming that lets identify leaf hardware components (lowest replaceable units) and for each of those indicate which software components they have.\n", "\n", - "To get there lets first filter out the list of components of Node nature that have at least on subcomponent of Behavior nature. To get to the end result quicker we'll use the `._filter` method of our object list. To use that method we'll need to provide a function that selects attribute of interest and a value (or list of values) that this attribute should have to be selected. To shorten the expression we'll use `lambda` functions - a way to define new function in place." + "To get there lets first filter out the list of components of Node nature that have at least on subcomponent of Behavior nature. To get to the end result quicker we'll use the `._filter` method of our object list (using python built-in filter method for now). To use that method we'll need to provide a function that selects attribute of interest and a value (or list of values) that this attribute should have to be selected. To shorten the expression we'll use `lambda` functions - a way to define new function in place." ] }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 63, "id": "01644c9d", "metadata": {}, "outputs": [ { "data": { "text/html": [ - "
  1. PhysicalComponent "Sub PC" (793e6da2-d019-4716-a5c5-af8ad550ca5e)
  2. PhysicalComponent "Deploy Sub PC" (8a6c6ec9-095d-4d8b-9728-69bc79af5f27)
  3. PhysicalComponent "Compute Card 1" (63be604e-883e-41ea-9023-fc74f29906fe)
  4. PhysicalComponent "Compute Card 2" (3a982128-3281-4d37-8838-a6058b7a25d9)
  5. PhysicalComponent "Network Switch" (b51ccc6f-5f96-4e28-b90e-72463a3b50cf)
  6. PhysicalComponent "Camera Assembly" (5bfc516b-c20d-4007-9a38-5ba0e889d0a4)
" + "
  1. PhysicalComponent "Sub PC" (793e6da2-d019-4716-a5c5-af8ad550ca5e)
  2. PhysicalComponent "Deploy Sub PC" (8a6c6ec9-095d-4d8b-9728-69bc79af5f27)
  3. PhysicalComponent "Compute Card 1" (63be604e-883e-41ea-9023-fc74f29906fe)
  4. PhysicalComponent "Compute Card 2" (3a982128-3281-4d37-8838-a6058b7a25d9)
  5. PhysicalComponent "Network Switch" (b51ccc6f-5f96-4e28-b90e-72463a3b50cf)
  6. PhysicalComponent "Camera Assembly" (5bfc516b-c20d-4007-9a38-5ba0e889d0a4)
  7. PhysicalComponent "Computer" (b14ff190-9198-4d05-95db-b121c11e9f17)
  8. PhysicalComponent "ISP Network" (221cef9f-0582-419c-b67e-96ddb678dd4c)
" ], "text/plain": [ - ", , , , , ]>" + "[0] \n", + "[1] \n", + "[2] \n", + "[3] \n", + "[4] \n", + "[5] \n", + "[6] \n", + "[7] " ] }, - "execution_count": 19, + "execution_count": 63, "metadata": {}, "output_type": "execute_result" } ], "source": [ + "from capellambse.model.common import ElementList\n", + "\n", "def select_nature(component):\n", " return component.nature\n", "\n", + "#cmps_with_sw = cmps._filter(lambda x: any(x.components._filter(select_nature, \"BEHAVIOR\")), True)\n", "\n", - "cmps = model.pa.all_components[1:]._filter(select_nature, \"NODE\")\n", + "cmps = model.pa.all_components[1:].by_nature(\"NODE\")\n", "# Note: the above [1:] assumes that 0th component is the root component and is not of interest (+ see issue #41)\n", - "cmps_with_sw = cmps._filter(lambda x: any(x.components._filter(select_nature, \"BEHAVIOR\")), True)\n", - "cmps_with_sw" + "\n", + "l_cmps = list(cmps)\n", + "l_cmps_with_sw = list(filter(lambda x: any(x.components.by_nature(\"BEHAVIOR\")), l_cmps))\n", + "cmps_with_sw = ElementList(model, [])\n", + "for elem in l_cmps_with_sw:\n", + " cmps_with_sw.append(elem)\n", + "cmps_with_sw\n", + "\n" ] }, { @@ -480,7 +496,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 64, "id": "70abf6f9", "metadata": {}, "outputs": [ @@ -490,17 +506,17 @@ "
  1. PhysicalComponent "PC 16" (8bc4b7a6-1f90-4f5f-a6b4-08fd300fc927)
" ], "text/plain": [ - "]>" + "[0] " ] }, - "execution_count": 20, + "execution_count": 64, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def get_sw_components(sw_component):\n", - " subcmp = sw_component.components._filter(select_nature, \"BEHAVIOR\")\n", + " subcmp = sw_component.components.by_nature(\"BEHAVIOR\")\n", " for cmp in subcmp:\n", " subcmp += get_sw_components(cmp)\n", " return subcmp\n", @@ -518,7 +534,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 65, "id": "faa00eb0", "metadata": {}, "outputs": [ @@ -578,6 +594,16 @@ " Camera Assembly\n", " Camera Firmware\n", " \n", + " \n", + " 6\n", + " Computer\n", + " Mail client\n", + " \n", + " \n", + " 7\n", + " ISP Network\n", + " Mail server\n", + " \n", " \n", "\n", "" @@ -589,10 +615,12 @@ "2 Compute Card 1 Card 1 OS; Camera Driver SWC; App 1 SWC\n", "3 Compute Card 2 Card 2 OS; App 2 SWC\n", "4 Network Switch Switch Firmware; Switch Configuration\n", - "5 Camera Assembly Camera Firmware" + "5 Camera Assembly Camera Firmware\n", + "6 Computer Mail client\n", + "7 ISP Network Mail server" ] }, - "execution_count": 21, + "execution_count": 65, "metadata": {}, "output_type": "execute_result" } @@ -618,35 +646,59 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 67, "id": "e48d4998", "metadata": {}, "outputs": [ { "data": { "text/html": [ - "
  1. PhysicalComponent "PC 1" (8a6d68c8-ac3d-4654-a07e-ada7adeed09f)
  2. PhysicalComponent "PC 3" (f5d7980d-e1e9-4515-8bb0-be7e80ac5839)
  3. PhysicalComponent "Vehicle" (a2c7f619-b38a-4b92-94a5-cbaa631badfc)
  4. PhysicalComponent "Vehicle" (b327d900-abd2-4138-a111-9ff0684739d8)
  5. PhysicalComponent "Equipment compartment" (3d68852d-fcc0-452c-af12-a2fbe22f81fa)
  6. PhysicalComponent "Server" (9137f463-7497-40c2-b20a-897158fdba9a)
  7. PhysicalComponent "Cooling Fan" (65e82f3f-c5b7-44c1-bfea-8e20bb0230be)
  8. PhysicalComponent "Sensor compartment" (3f416925-9d8a-4e9c-99f3-e912efb23d2f)
  9. PhysicalComponent "PA 1" (a0847e9c-8b82-407d-8143-e908e2db97a1)
" + "
  1. PhysicalComponent "PC 1" (8a6d68c8-ac3d-4654-a07e-ada7adeed09f)
  2. PhysicalComponent "PC 3" (f5d7980d-e1e9-4515-8bb0-be7e80ac5839)
  3. PhysicalComponent "Vehicle" (a2c7f619-b38a-4b92-94a5-cbaa631badfc)
  4. PhysicalComponent "Vehicle" (b327d900-abd2-4138-a111-9ff0684739d8)
  5. PhysicalComponent "Equipment compartment" (3d68852d-fcc0-452c-af12-a2fbe22f81fa)
  6. PhysicalComponent "Server" (9137f463-7497-40c2-b20a-897158fdba9a)
  7. PhysicalComponent "Cooling Fan" (65e82f3f-c5b7-44c1-bfea-8e20bb0230be)
  8. PhysicalComponent "Sensor compartment" (3f416925-9d8a-4e9c-99f3-e912efb23d2f)
  9. PhysicalComponent "Router" (69bfe48d-78f0-4b1f-89c0-917dc2339ff9)
  10. PhysicalComponent "PA 1" (a0847e9c-8b82-407d-8143-e908e2db97a1)
" ], "text/plain": [ - ", , , , , , , , ]>" + "[0] \n", + "[1] \n", + "[2] \n", + "[3] \n", + "[4] \n", + "[5] \n", + "[6] \n", + "[7] \n", + "[8] \n", + "[9] " ] }, - "execution_count": 22, + "execution_count": 67, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "cmps_without_sw = cmps._filter(lambda x: any(x.components._filter(select_nature, \"BEHAVIOR\")), False)\n", + "#cmps_without_sw = cmps._filter(lambda x: any(x.components._filter(select_nature, \"BEHAVIOR\")), False)\n", + "cmps_without_sw = ElementList(model, [])\n", + "\n", + "l_cmps_without_sw = list(filter(lambda x: not any(x.components.by_nature(\"BEHAVIOR\")), l_cmps))\n", + "\n", + "for elem in l_cmps_without_sw:\n", + " cmps_without_sw.append(elem)\n", + "\n", "cmps_without_sw" ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "86b58bc7-bbd7-4f19-8437-0c48c47c8f29", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "venv", + "display_name": "Python 3 (ipykernel)", "language": "python", - "name": "venv" + "name": "python3" }, "language_info": { "codemirror_mode": { @@ -658,7 +710,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.6" + "version": "3.10.12" } }, "nbformat": 4,