diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a580852 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.ipynb_checkpoints +.DS_Store \ No newline at end of file diff --git a/.ipynb_checkpoints/Element_Create_Update_Delete-checkpoint.ipynb b/.ipynb_checkpoints/Element_Create_Update_Delete-checkpoint.ipynb deleted file mode 100644 index 2687891..0000000 --- a/.ipynb_checkpoints/Element_Create_Update_Delete-checkpoint.ipynb +++ /dev/null @@ -1,763 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "3ee4834f", - "metadata": { - "tags": [] - }, - "source": [ - "# Initializing the SysML v2 API" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "id": "6b5fef59", - "metadata": {}, - "outputs": [], - "source": [ - "from __future__ import print_function\n", - "\n", - "import time\n", - "import requests\n", - "from pprint import pprint\n", - "import pandas as pd\n", - "import json\n", - "from datetime import datetime\n", - "\n", - "#host = \"\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
Project NameProject ID
Spacecraft project with Element CRUD - 2022-09-12 12:08:48.8158500659c128-afd5-42a1-912b-962068f1f053
17b-Sequence-Modeling Fri Sep 09 17:37:26 EDT 20220f7045bd-9a1c-4b54-90d9-775c0f642e1b
3a-Function-based Behavior-2 Fri Sep 09 17:26:30 EDT 2022128710cd-978f-4c6f-93ac-8afbbd194185
10c-Fuel Economy Analysis Fri Sep 09 17:30:43 EDT 20222909d482-a659-4307-9803-bdfcbe0a7989
PartTest Fri Sep 09 17:22:13 EDT 20222a2a4d7d-cd9e-41ec-bec0-2bf6fcea6767
15_05-Unification of Expression and Constraint Definition Fri Sep 09 17:35:59 EDT 202239dcf070-668c-4711-a231-c2640b9f7f88
15_19-Materials with Properties Fri Sep 09 17:36:44 EDT 20223bd937e0-ab2e-47a6-8f66-0458df9f29de
14b-Language Extensions Fri Sep 09 17:35:06 EDT 2022431cd401-010c-401f-9101-115240312d24
13b-Safety and Security Features Element Group-1 Fri Sep 09 17:33:37 EDT 202246b226ce-8519-42de-96b4-07ff1045d0dd
Spacecraft project with Element CRUD - 2022-09-12 13:03:26.5685654853c38b-85c5-40e5-9e83-b69c2e73415a
3a-Function-based Behavior-3 Fri Sep 09 17:26:52 EDT 202248f9a623-2451-4150-8b98-58e3b3c515cd
12a-Dependency Fri Sep 09 17:32:29 EDT 202249a60e69-b509-4191-b1c3-240de628110b
7b-Variant Configurations Fri Sep 09 17:28:59 EDT 202259c86238-ef81-434e-a389-5393312ba0d7
17a-Sequence-Modeling Fri Sep 09 17:37:07 EDT 2022653c5173-770d-4ea6-90dc-c173d049258c
13a-Model Containment Fri Sep 09 17:33:03 EDT 20226699f5e0-403b-414a-87c9-46671e702fab
11b-Safety and Security Feature Views Fri Sep 09 17:32:05 EDT 202284f30a8f-f839-4a71-aee9-dff2a2d28dbf
1c-Parts Tree Redefinition Fri Sep 09 17:25:05 EDT 202285d874ae-1f68-4949-9b16-378f1cbc477e
14a-Language Extensions Fri Sep 09 17:34:49 EDT 20228f0bc3b3-a580-40fd-b99b-0e8865984c4f
6-Individual and Snapshots Fri Sep 09 17:28:35 EDT 2022913dab3f-4d5d-482d-9238-7491aead3e1a
PartTest Fri Sep 09 17:21:50 EDT 202291b2be09-16de-4d35-87a4-589f3274ce55
11a-View-Viewpoint Fri Sep 09 17:31:42 EDT 202291fd6db5-4cfa-4970-b115-05010053ec72
13b-Safety and Security Features Element Group Fri Sep 09 17:33:20 EDT 202295bfcea3-8ed7-4bd4-9e98-3d6ed311091e
Spacecraft project with branches and tags - 2022-09-09 17:04:20.838366978d0199-4e44-4090-8cb6-4253fd79e315
3a-Function-based Behavior-1 Fri Sep 09 17:26:05 EDT 20229da34b47-38d0-4630-bcb4-c387d5fac1da
9-Verification-simplified Fri Sep 09 17:29:54 EDT 2022a9a02019-b810-4fcb-9a9c-5cad061db29f
10b-Trade-off Among Alternative Configurations Fri Sep 09 17:30:18 EDT 2022ada6b9b6-3534-43b3-a567-f97092ac26f1
12b-Allocation Fri Sep 09 17:32:45 EDT 2022b4c01f6d-8173-4d43-abd1-596bdb89d6d4
Spacecraft project with Element CRUD - 2022-09-12 12:08:28.268425b67ebee6-b55e-4088-b059-c2f102989ac2
8-Requirements Fri Sep 09 17:29:27 EDT 2022b6a3450b-8624-45c2-8dd9-68d301a439fe
15_10-Primitive Data Types Fri Sep 09 17:36:20 EDT 2022bb65a453-67bc-4e6c-92c7-29734c80bab1
2a-Parts Interconnection Fri Sep 09 17:23:32 EDT 2022c64923aa-79f4-419c-b983-6244fee741d6
5-State-based Behavior-1 Fri Sep 09 17:27:37 EDT 2022c6b1d4d6-a66e-4097-8752-5307ecd9ebaf
2a-Parts Interconnection Fri Sep 09 17:25:35 EDT 2022cb4e467e-772b-4054-849e-26e4b0e1e0c0
10d-Dynamics Analysis Fri Sep 09 17:31:13 EDT 2022cceed28a-64fb-4401-81da-afcadd96d1d6
13b-Safety and Security Features Element Group-2 Fri Sep 09 17:34:08 EDT 2022d4c21bc8-6778-4a97-b389-48b1e7b23260
5-State-based Behavior-1a Fri Sep 09 17:28:06 EDT 2022d63b8882-f41e-40ef-a4a2-cf74fa47f6dc
14c-Language Extensions Fri Sep 09 17:35:25 EDT 2022da4e65b6-460d-447b-8cf9-56a3ad44e514
4a-Functional Allocation Fri Sep 09 17:27:13 EDT 2022e7090e9d-74f0-4b63-a4a6-6dd8647b5bdd
Spacecraft project with Element CRUD - 2022-09-12 12:57:59.306887f8161e56-586e-44ae-ab12-53ad1fc972de
18-Use Case Fri Sep 09 17:37:44 EDT 2022ff0dfcc3-cf11-4d4f-961a-ae42326f6b12
\n" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "projects_url = f\"{host}/projects\" \n", - "projects_response = requests.get(projects_url)\n", - "\n", - "if projects_response.status_code == 200:\n", - " projects = projects_response.json()\n", - " projects_data = list(map(lambda b: {'Project Name':b['name'], 'Project ID':b['@id']}, projects))\n", - " df = pd.DataFrame.from_records(projects_data).style.hide(axis='index')\n", - " # if len(projects_data) > 0:\n", - " # df = df.style.sort_values(by='Project Name')\n", - " display(df)\n", - "else:\n", - " pprint(\"Problem in fetching projects\")" - ] - }, - { - "cell_type": "markdown", - "id": "77345839-9d8f-409f-9131-440d1b30cbea", - "metadata": {}, - "source": [ - "# Create a new project" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "id": "6d2ba2fc-157a-4ac8-b8f3-876bbd3a21ea", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'@id': 'f0594c9c-55ef-49f6-9591-d27d12cc0afb',\n", - " '@type': 'Project',\n", - " 'defaultBranch': {'@id': 'd84e4540-56c8-485a-bace-f91b3620ada5'},\n", - " 'description': 'Spacecraft project demonstrating Element Create, Update, '\n", - " 'Delete steps',\n", - " 'name': 'Spacecraft project with Element CRUD - 2022-09-12 13:16:03.708730'}\n" - ] - } - ], - "source": [ - "timestamp = datetime.now()\n", - "project_name = f\"Spacecraft project with Element CRUD - {timestamp}\"\n", - "project_data = {\n", - " \"@type\":\"Project\",\n", - " \"name\": project_name,\n", - " \"description\": \"Spacecraft project demonstrating Element Create, Update, Delete steps\"\n", - "}\n", - "\n", - "project_post_url = f\"{host}/projects\" \n", - "\n", - "project_post_response = requests.post(project_post_url, \n", - " headers={\"Content-Type\": \"application/json\"}, \n", - " data=json.dumps(project_data))\n", - "\n", - "project_id = \"\"\n", - "\n", - "if project_post_response.status_code == 200:\n", - " project_response_json = project_post_response.json()\n", - " pprint(project_response_json)\n", - " project_id = project_response_json['@id']\n", - " project_name = project_response_json['name']\n", - "else:\n", - " pprint(f\"Problem in creating a new Spacecraft project at {timestamp}\")\n", - " pprint(project_post_response)" - ] - }, - { - "cell_type": "markdown", - "id": "921efbfd-04a1-4c5c-8e66-b31f0390aa45", - "metadata": {}, - "source": [ - "# Get branches" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "id": "df3e1039-ba51-4653-8897-e98be111078e", - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
Branch NameBranch IDRef Commit (head)
maind84e4540-56c8-485a-bace-f91b3620ada5None
\n" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "branches_url = f\"{host}/projects/{project_id}/branches\" \n", - "branches_response = requests.get(branches_url)\n", - "\n", - "if branches_response.status_code == 200:\n", - " branches = branches_response.json()\n", - " branches_data = list(map(lambda b: {'Branch Name':b['name'], 'Branch ID':b['@id'], 'Ref Commit (head)':b['head']}, branches))\n", - "\n", - " df = pd.DataFrame.from_records(branches_data).sort_values(by='Branch Name').style.hide(axis='index')\n", - " display(df)\n", - "else:\n", - " pprint(f\"Problem in fetching branches of Spacecraft project {project_id}\")\n", - " pprint(branches_response)" - ] - }, - { - "cell_type": "markdown", - "id": "569ca8f1-ebf1-41d2-93f3-8795a2439eea", - "metadata": {}, - "source": [ - "# Create 1st Commit on the main (default) branch that creates 2 elements" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "id": "3eed91b9-903b-441f-b1f2-10dbcfafa342", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'@id': '25853b78-df3e-44d3-9a63-c3221743d82d',\n", - " '@type': 'Commit',\n", - " 'owningProject': {'@id': 'f0594c9c-55ef-49f6-9591-d27d12cc0afb'},\n", - " 'previousCommit': None,\n", - " 'timestamp': '2022-09-12T13:16:13.843497-04:00'}\n" - ] - } - ], - "source": [ - "commit_body = {\n", - " \"@type\": \"Commit\",\n", - " \"change\": [\n", - " {\n", - " \"@type\": \"DataVersion\",\n", - " \"payload\": {\n", - " \"@type\": \"PartDefinition\",\n", - " \"name\":\"Spacecraft System\"\n", - " }\n", - " },\n", - " {\n", - " \"@type\": \"DataVersion\",\n", - " \"payload\": {\n", - " \"@type\": \"PartDefinition\",\n", - " \"name\":\"Payload System\"\n", - " }\n", - " }\n", - " ]\n", - "}\n", - "\n", - "commit_post_url = f\"{host}/projects/{project_id}/commits\" \n", - "\n", - "commit_post_response = requests.post(commit_post_url, \n", - " headers={\"Content-Type\": \"application/json\"}, \n", - " data=json.dumps(commit_body))\n", - "\n", - "commit1_id = \"\"\n", - "\n", - "if commit_post_response.status_code == 200:\n", - " commit_response_json = commit_post_response.json()\n", - " pprint(commit_response_json)\n", - " commit1_id = commit_response_json['@id']\n", - "else:\n", - " pprint(f\"Problem in creating a new commit in Spacecraft project {project_id}\")\n", - " pprint(commit_post_response)" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "id": "65537f5c-f521-469e-92e4-9a2568afed05", - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
Element NameElement ID
Payload System1093a5fd-5a5e-47d7-8bfd-b870ede05648
Spacecraft System07a9a21c-2070-4d6b-8818-bb3bca62dfd8
\n" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "element_get_url = f\"{host}/projects/{project_id}/commits/{commit1_id}/elements\" \n", - "\n", - "element_get_response = requests.get(element_get_url)\n", - "payload_system_element_id = \"\"\n", - "spacecraft_system_element_id = \"\"\n", - "\n", - "if element_get_response.status_code == 200:\n", - " elements = element_get_response.json()\n", - " \n", - " # Gather the id of the Payload System that is created\n", - " payload_system_element = list(filter(lambda e: e['name'] == \"Payload System\", elements))\n", - " if payload_system_element:\n", - " payload_system_element_id = payload_system_element[0]['@id']\n", - " \n", - " # Gather the id of the Spacecraft System that is created\n", - " spacecraft_system_element = list(filter(lambda e: e['name'] == \"Spacecraft System\", elements))\n", - " if spacecraft_system_element:\n", - " spacecraft_system_element_id = spacecraft_system_element[0]['@id']\n", - " \n", - " elements_data = list(map(lambda b: {'Element Name':b['name'], 'Element ID':b['@id']}, elements))\n", - " df = pd.DataFrame.from_records(elements_data).sort_values(by='Element Name').style.hide(axis='index')\n", - " display(df)\n", - "else:\n", - " pprint(f\"Problem in fetching elements in the Spacecraft project {project_id} at commit {commit1_id}.\")\n", - " pprint(element_get_response)" - ] - }, - { - "cell_type": "markdown", - "id": "8e38b288-6517-4a7b-90e5-ae73c5f89df3", - "metadata": {}, - "source": [ - "# Create the 2nd Commit that updates the name of one of the elements" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "id": "76d80cb1-40c8-4f24-aeb5-51e509f4e159", - "metadata": { - "tags": [] - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'@id': 'da8991ce-1124-493b-8f34-a4bb2d0800e1',\n", - " '@type': 'Commit',\n", - " 'owningProject': {'@id': 'f0594c9c-55ef-49f6-9591-d27d12cc0afb'},\n", - " 'previousCommit': {'@id': '25853b78-df3e-44d3-9a63-c3221743d82d'},\n", - " 'timestamp': '2022-09-12T13:16:21.941689-04:00'}\n" - ] - } - ], - "source": [ - "commit_body = {\n", - " \"@type\": \"Commit\",\n", - " \"change\": [\n", - " {\n", - " \"@type\": \"DataVersion\",\n", - " \"payload\": {\n", - " \"@type\": \"PartDefinition\",\n", - " \"name\":\"New Payload System\",\n", - " \"identifier\":payload_system_element_id\n", - " },\n", - " \"identity\": {\n", - " \"@id\": payload_system_element_id\n", - " }\n", - " }\n", - " ],\n", - " \"previousCommit\": {\n", - " \"@id\": commit1_id\n", - " }\n", - "}\n", - "\n", - "commit_post_url = f\"{host}/projects/{project_id}/commits\" \n", - "\n", - "commit_post_response = requests.post(commit_post_url, \n", - " headers={\"Content-Type\": \"application/json\"}, \n", - " data=json.dumps(commit_body))\n", - "\n", - "commit2_id = \"\"\n", - "\n", - "if commit_post_response.status_code == 200:\n", - " commit_response_json = commit_post_response.json()\n", - " pprint(commit_response_json)\n", - " commit2_id = commit_response_json['@id']\n", - "else:\n", - " pprint(f\"Problem in creating a new commit in Spacecraft project {project_id}\")\n", - " pprint(commit_post_response)" - ] - }, - { - "cell_type": "markdown", - "id": "d815e4fe", - "metadata": {}, - "source": [ - "# Get all elements after the 2nd commit (should show 1 element updated)" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "id": "eac0a387-e4cf-4fc8-8b47-c64ed2ebff62", - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
Element NameElement ID
New Payload System1093a5fd-5a5e-47d7-8bfd-b870ede05648
Spacecraft System07a9a21c-2070-4d6b-8818-bb3bca62dfd8
\n" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "element_get_url = f\"{host}/projects/{project_id}/commits/{commit2_id}/elements\" \n", - "\n", - "element_get_response = requests.get(element_get_url)\n", - "\n", - "if element_get_response.status_code == 200:\n", - " elements = element_get_response.json()\n", - " elements_data = list(map(lambda b: {'Element Name':b['name'], 'Element ID':b['@id']}, elements))\n", - " df = pd.DataFrame.from_records(elements_data).sort_values(by='Element Name').style.hide(axis='index')\n", - " display(df)\n", - "else:\n", - " pprint(f\"Problem in fetching elements in the Spacecraft project {project_id} at commit {commit2_id}.\")\n", - " pprint(element_get_response)" - ] - }, - { - "cell_type": "markdown", - "id": "8dbea034-4180-415f-9604-8e1afb149fdc", - "metadata": {}, - "source": [ - "# Create the 3rd commit that deletes an element (same one whose name was updated)" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "id": "055f42b3-18de-4f94-ae53-43660948493b", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'@id': '00f0b229-7e70-4688-80e8-ae2eafc0ce8e',\n", - " '@type': 'Commit',\n", - " 'owningProject': {'@id': 'f0594c9c-55ef-49f6-9591-d27d12cc0afb'},\n", - " 'previousCommit': {'@id': 'da8991ce-1124-493b-8f34-a4bb2d0800e1'},\n", - " 'timestamp': '2022-09-12T13:16:45.992847-04:00'}\n" - ] - } - ], - "source": [ - "commit_body = {\n", - " \"@type\": \"Commit\",\n", - " \"change\": [\n", - " {\n", - " \"@type\": \"DataVersion\",\n", - " \"payload\":None,\n", - " \"identity\": {\n", - " \"@id\": payload_system_element_id\n", - " }\n", - " }\n", - " ],\n", - " \"previousCommit\": {\n", - " \"@id\": commit2_id\n", - " }\n", - "}\n", - "\n", - "commit_post_url = f\"{host}/projects/{project_id}/commits\" \n", - "\n", - "commit_post_response = requests.post(commit_post_url, \n", - " headers={\"Content-Type\": \"application/json\"}, \n", - " data=json.dumps(commit_body))\n", - "\n", - "commit3_id = \"\"\n", - "\n", - "if commit_post_response.status_code == 200:\n", - " commit_response_json = commit_post_response.json()\n", - " pprint(commit_response_json)\n", - " commit3_id = commit_response_json['@id']\n", - "else:\n", - " pprint(f\"Problem in creating a new commit in Spacecraft project {project_id}\")\n", - " pprint(commit_post_response)" - ] - }, - { - "cell_type": "markdown", - "id": "61cdaecd-44db-4e27-85dd-de5d002648cc", - "metadata": {}, - "source": [ - "# Get all elements after the 3rd commit (should only 1 element)" - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "id": "86008838-368a-4e58-9d5b-70e9c57442f4", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "'Fetching elements at commit da8991ce-1124-493b-8f34-a4bb2d0800e1'\n" - ] - }, - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
Element NameElement ID
Spacecraft System07a9a21c-2070-4d6b-8818-bb3bca62dfd8
\n" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "pprint(f\"Fetching elements at commit {commit2_id}\")\n", - "element_get_url = f\"{host}/projects/{project_id}/commits/{commit3_id}/elements\" \n", - "\n", - "element_get_response = requests.get(element_get_url)\n", - "\n", - "if element_get_response.status_code == 200:\n", - " elements = element_get_response.json()\n", - " elements_data = list(map(lambda b: {'Element Name':b['name'], 'Element ID':b['@id']}, elements))\n", - " df = pd.DataFrame.from_records(elements_data).sort_values(by='Element Name').style.hide(axis='index')\n", - " display(df)\n", - "else:\n", - " pprint(f\"Problem in fetching elements in the Spacecraft project {project_id} at commit {commit2_id}\")\n", - " pprint(element_get_response)" - ] - } - ], - "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.8.13" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/.ipynb_checkpoints/Project_Commit_Branch_Tag_Recipe-checkpoint.ipynb b/.ipynb_checkpoints/Project_Commit_Branch_Tag_Recipe-checkpoint.ipynb deleted file mode 100644 index f6672ed..0000000 --- a/.ipynb_checkpoints/Project_Commit_Branch_Tag_Recipe-checkpoint.ipynb +++ /dev/null @@ -1,1478 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "3ee4834f", - "metadata": { - "tags": [] - }, - "source": [ - "# Initializing the SysML v2 API" - ] - }, - { - "cell_type": "code", - "execution_count": 138, - "id": "6b5fef59", - "metadata": {}, - "outputs": [], - "source": [ - "from __future__ import print_function\n", - "\n", - "import time\n", - "import requests\n", - "from pprint import pprint\n", - "import pandas as pd\n", - "import json\n", - "from datetime import datetime\n", - "\n", - "#host = \"\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
Project NameProject ID
12b-Allocation Fri Nov 04 19:01:21 EDT 2022001c5431-b990-4e30-8c54-92f9a864ec97
13a-Model Containment Fri Nov 04 19:01:50 EDT 202202c58637-1259-4f3c-8239-93ceadc093a8
15_05-Unification of Expression and Constraint Definition Fri Nov 04 19:05:41 EDT 20220464d784-a8a9-4b83-b791-ea987f1d314f
15_10-Primitive Data Types Fri Nov 04 16:26:37 EDT 20220846c1fc-908a-4f31-b0a0-92b697ef9cbc
3a-Function-based Behavior-2 Fri Nov 04 16:10:36 EDT 20220ed6d350-8b64-430d-b51d-485f8593fc53
17b-Sequence-Modeling Fri Nov 04 19:07:56 EDT 2022122c3e3d-f91b-47a6-80ad-88d4b9e80716
12b-Allocation Fri Nov 04 16:21:29 EDT 202213fb75cb-89f8-42b6-9f4e-b6d5bc28edf6
7b-Variant Configurations Fri Nov 04 16:15:18 EDT 2022165b93d8-ba8f-4c1e-b2f1-440613ae81fe
2a-Parts Interconnection Fri Nov 04 16:09:04 EDT 20221b07b57e-7632-4da3-8d59-dc32442496f3
Spacecraft project with branches and tags - 2022-11-05 21:02:55.7291801cb23e7a-4d70-487e-89ad-1cd8a22efb9e
3a-Function-based Behavior-3 Fri Nov 04 16:11:12 EDT 202221c076b8-078a-4fdc-9e95-551210840042
Spacecraft project with branches and tags - 2022-11-05 20:47:28.85887124503a6b-8b0e-47c3-8a75-28f68d1610a8
10b-Trade-off Among Alternative Configurations Fri Nov 04 18:57:31 EDT 202226225070-5b08-42a6-911e-0f8e9a2c42fa
14c-Language Extensions Fri Nov 04 16:25:03 EDT 202237c1510f-670a-45b9-a702-1a8c0faf5449
11b-Safety and Security Feature Views Fri Nov 04 19:00:14 EDT 202237e56e5e-28d7-44c1-b852-a336f4cfc28e
13b-Safety and Security Features Element Group Fri Nov 04 16:22:25 EDT 2022384f296b-0600-4dad-9847-bfcfed4099a3
14c-Language Extensions Fri Nov 04 19:04:51 EDT 202239c9d18f-8135-45b3-892d-ef4768499c12
18-Use Case Fri Nov 04 19:08:26 EDT 20223facdbcd-7687-441f-98e2-082e539a7a50
12a-Dependency Fri Nov 04 16:21:03 EDT 20224f3041a7-f526-4e1c-ad48-8c58e0d25c7b
13b-Safety and Security Features Element Group Fri Nov 04 19:02:16 EDT 202250b49316-9890-47c8-8e16-1ffd76f0baa6
5-State-based Behavior-1a Fri Nov 04 18:53:45 EDT 20225149bf16-3904-49f4-89a6-9a3a0ccfd167
17b-Sequence-Modeling Fri Nov 04 16:28:20 EDT 202254f2da76-1c3b-4e3f-a6e3-64882bac71f4
4a-Functional Allocation Fri Nov 04 16:12:20 EDT 202257403ab6-ebe0-4790-8c97-37e64ec40efe
13b-Safety and Security Features Element Group-2 Fri Nov 04 16:23:28 EDT 202258a058e4-860e-4ff2-b00b-b37bab0e6d1d
5-State-based Behavior-1a Fri Nov 04 16:13:48 EDT 20226301fa4a-ff17-4a23-8804-901cd8d6edec
17a-Sequence-Modeling Fri Nov 04 16:27:49 EDT 202269becd54-6e04-4609-8859-5e4f3dffbf3a
11a-View-Viewpoint Fri Nov 04 16:19:46 EDT 20226b37b7e5-22ff-4c00-a7ff-24e6d2b8aa24
6-Individual and Snapshots Fri Nov 04 16:14:38 EDT 202273a3e7fc-86a4-47e7-8b53-9620a2348e74
14b-Language Extensions Fri Nov 04 19:04:22 EDT 202279065a85-a007-48ba-ad2e-4de5985d17d8
10c-Fuel Economy Analysis Fri Nov 04 18:58:07 EDT 202279f27bb9-964d-4e16-8a8e-28405fe3d434
9-Verification-simplified Fri Nov 04 16:16:53 EDT 202281a85b86-67f5-42c1-812a-a08346861392
10c-Fuel Economy Analysis Fri Nov 04 16:18:12 EDT 2022822d6391-0392-48b0-8e5d-d0eafb23c1a8
13b-Safety and Security Features Element Group-1 Fri Nov 04 19:02:42 EDT 202285d78565-1e4e-4da4-94c2-e459c0b7b9fe
7b-Variant Configurations Fri Nov 04 18:55:14 EDT 20228b54f0cb-e38f-400f-939b-88234de899bd
17a-Sequence-Modeling Fri Nov 04 19:07:26 EDT 20228b9f2620-4bc9-4342-a9fd-320109d0e83f
8-Requirements Fri Nov 04 18:56:05 EDT 2022933249c0-2d0b-44ef-8ece-9a12a36e5879
8-Requirements Fri Nov 04 16:16:08 EDT 20229548cafc-7b0e-4a74-89eb-e11f106cf8aa
3a-Function-based Behavior-3 Fri Nov 04 18:51:07 EDT 202296d558d1-74fb-4875-aca7-71a9cf63d110
9-Verification-simplified Fri Nov 04 18:56:53 EDT 20229be5911d-fff8-41d0-8927-1be306edf2ee
15_05-Unification of Expression and Constraint Definition Fri Nov 04 16:25:58 EDT 20229c80741b-98c1-4521-b458-7de76fc98e51
12a-Dependency Fri Nov 04 19:00:54 EDT 20229e4796a3-7387-4176-8175-a30fef0fa0f1
13b-Safety and Security Features Element Group-2 Fri Nov 04 19:03:17 EDT 2022a49e0b2a-8e89-4cea-b6d8-b564483ae945
10d-Dynamics Analysis Fri Nov 04 18:58:53 EDT 2022a7cca448-e3aa-476b-baf9-2628d8fce70b
3d-Function-based Behavior-item Fri Nov 04 18:51:40 EDT 2022a8b2dab5-1e5b-4884-bbcf-6d8cd5f593b5
5-State-based Behavior-1 Fri Nov 04 18:52:54 EDT 2022af7ad505-9c13-4043-9e22-28b88082d165
3a-Function-based Behavior-1 Fri Nov 04 16:09:57 EDT 2022b156694a-bf43-4b6e-b6f8-b825a5b748e5
6-Individual and Snapshots Fri Nov 04 18:54:36 EDT 2022b293b000-1a48-4ef2-8080-b35e9d9e6d16
3d-Function-based Behavior-item Fri Nov 04 16:11:44 EDT 2022b402c413-67e5-45b7-b4a7-decb4f88f1ec
14a-Language Extensions Fri Nov 04 16:24:05 EDT 2022bde47251-8494-443f-b82c-10f2333514e9
13b-Safety and Security Features Element Group-1 Fri Nov 04 16:22:53 EDT 2022bed09632-6252-4945-b24a-f16def2b4160
14b-Language Extensions Fri Nov 04 16:24:33 EDT 2022c1a44499-39fc-4fbd-aebf-34747b6286f0
18-Use Case Fri Nov 04 16:28:51 EDT 2022c48aef95-2ce1-4db0-812d-6174af61def6
13a-Model Containment Fri Nov 04 16:21:57 EDT 2022c9a9c7c8-3859-4758-8852-7f36365c142c
3a-Function-based Behavior-1 Fri Nov 04 18:49:56 EDT 2022cb4e32f2-556f-46dc-989c-4298d0ce0b47
15_19-Materials with Properties Fri Nov 04 19:06:44 EDT 2022cb65e8f6-2b62-44f2-ac1d-a729365c9ba2
3a-Function-based Behavior-2 Fri Nov 04 18:50:31 EDT 2022cdebea2c-f2f2-4931-9163-250d6e79e376
10b-Trade-off Among Alternative Configurations Fri Nov 04 16:17:35 EDT 2022d053582a-8e01-4ea9-a801-828c641eb303
10d-Dynamics Analysis Fri Nov 04 16:19:01 EDT 2022d362b373-2ada-4fb3-9b6d-4700485d7781
11b-Safety and Security Feature Views Fri Nov 04 16:20:23 EDT 2022d831cb7f-46d6-4fb6-860e-cbc616b3f006
4a-Functional Allocation Fri Nov 04 18:52:16 EDT 2022da6d8a97-f334-4d44-bfd1-5dc947272e50
1c-Parts Tree Redefinition Fri Nov 04 18:48:23 EDT 2022daf07ca6-a861-4a7a-a8d3-1167b3de80a0
14a-Language Extensions Fri Nov 04 19:03:56 EDT 2022ddd43252-33e9-4998-a351-6bfccaec32c6
11a-View-Viewpoint Fri Nov 04 18:59:39 EDT 2022de89c221-40f6-43ea-9325-64c59b269e99
15_19-Materials with Properties Fri Nov 04 16:27:09 EDT 2022eb8083f7-c109-48fb-bb6b-e4add07025de
15_10-Primitive Data Types Fri Nov 04 19:06:16 EDT 2022ed767842-8f7d-404a-b80e-75b46fc6ba27
1c-Parts Tree Redefinition Fri Nov 04 16:08:10 EDT 2022ed996c79-9e4b-4a73-bf9e-75fa21529c1d
2a-Parts Interconnection Fri Nov 04 18:49:09 EDT 2022efa66033-3120-47c4-8315-1f6c3e0c2038
Spacecraft project with branches and tags - 2022-11-05 20:48:22.447068f7667382-4bba-4fcb-93d6-cc84df8811d2
5-State-based Behavior-1 Fri Nov 04 16:12:59 EDT 2022f77f806b-d4e7-48ae-93aa-85bff59bd55a
\n" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "projects_url = f\"{host}/projects\" \n", - "projects_response = requests.get(projects_url)\n", - "\n", - "if projects_response.status_code == 200:\n", - " projects = projects_response.json()\n", - " projects_data = list(map(lambda b: {'Project Name':b['name'], 'Project ID':b['@id']}, projects))\n", - " df = pd.DataFrame.from_records(projects_data).style.hide(axis='index')\n", - " # if len(projects_data) > 0:\n", - " # df = df.style.sort_values(by='Project Name')\n", - " display(df)\n", - "else:\n", - " pprint(\"Problem in fetching projects\")" - ] - }, - { - "cell_type": "markdown", - "id": "77345839-9d8f-409f-9131-440d1b30cbea", - "metadata": {}, - "source": [ - "# Create a new project" - ] - }, - { - "cell_type": "code", - "execution_count": 121, - "id": "6d2ba2fc-157a-4ac8-b8f3-876bbd3a21ea", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'@id': '1cb23e7a-4d70-487e-89ad-1cd8a22efb9e',\n", - " '@type': 'Project',\n", - " 'created': '2022-11-05T21:02:55.930924-04:00',\n", - " 'defaultBranch': {'@id': 'b20df3d4-bb46-489f-b312-858952c21d89'},\n", - " 'description': 'Spacecraft project with multiple commits, branches, and tags',\n", - " 'name': 'Spacecraft project with branches and tags - 2022-11-05 '\n", - " '21:02:55.729180'}\n" - ] - } - ], - "source": [ - "timestamp = datetime.now()\n", - "project_name = f\"Spacecraft project with branches and tags - {timestamp}\"\n", - "project_data = {\n", - " \"@type\":\"Project\",\n", - " \"name\": project_name,\n", - " \"description\": \"Spacecraft project with multiple commits, branches, and tags\"\n", - "}\n", - "\n", - "project_post_url = f\"{host}/projects\" \n", - "\n", - "project_post_response = requests.post(project_post_url, \n", - " headers={\"Content-Type\": \"application/json\"}, \n", - " data=json.dumps(project_data))\n", - "\n", - "project_id = \"\"\n", - "\n", - "if project_post_response.status_code == 200:\n", - " project_response_json = project_post_response.json()\n", - " pprint(project_response_json)\n", - " project_id = project_response_json['@id']\n", - " project_name = project_response_json['name']\n", - "else:\n", - " pprint(f\"Problem in creating a new Spacecraft project at {timestamp}\")\n", - " pprint(project_post_response)" - ] - }, - { - "cell_type": "markdown", - "id": "921efbfd-04a1-4c5c-8e66-b31f0390aa45", - "metadata": {}, - "source": [ - "# Get branches" - ] - }, - { - "cell_type": "code", - "execution_count": 122, - "id": "df3e1039-ba51-4653-8897-e98be111078e", - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
Branch NameBranch IDRef Commit (head)
mainb20df3d4-bb46-489f-b312-858952c21d89None
\n" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "branches_url = f\"{host}/projects/{project_id}/branches\" \n", - "branches_response = requests.get(branches_url)\n", - "\n", - "if branches_response.status_code == 200:\n", - " branches = branches_response.json()\n", - " branches_data = list(map(lambda b: {'Branch Name':b['name'], 'Branch ID':b['@id'], 'Ref Commit (head)':b['head']}, branches))\n", - "\n", - " df = pd.DataFrame.from_records(branches_data).sort_values(by='Branch Name').style.hide(axis='index')\n", - " display(df)\n", - "else:\n", - " pprint(f\"Problem in fetching branches of Spacecraft project {project_id}\")\n", - " pprint(branches_response)" - ] - }, - { - "cell_type": "markdown", - "id": "5f761af7-0b40-4708-8c8e-217c9b2b6e8a", - "metadata": {}, - "source": [ - "# Get tags" - ] - }, - { - "cell_type": "code", - "execution_count": 123, - "id": "65deeb6c-ce34-43c5-ad62-bf145e946f1d", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[]\n" - ] - }, - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - "
\n" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "tags_url = f\"{host}/projects/{project_id}/tags\" \n", - "tags_response = requests.get(tags_url)\n", - "\n", - "if tags_response.status_code == 200:\n", - " tags = tags_response.json()\n", - " pprint(tags)\n", - " tags_data = list(map(lambda b: {'Tag Name':b['name'], 'Tag ID':b['@id'], 'Tagged Commit':b['taggedCommit']}, tags))\n", - "\n", - " df = pd.DataFrame.from_records(tags_data).style.hide(axis='index')\n", - " display(df)\n", - "else:\n", - " pprint(f\"Problem in fetching tags of Spacecraft project {project_id}\")\n", - " pprint(tags_response)" - ] - }, - { - "cell_type": "markdown", - "id": "569ca8f1-ebf1-41d2-93f3-8795a2439eea", - "metadata": {}, - "source": [ - "# Create 1st Commit" - ] - }, - { - "cell_type": "code", - "execution_count": 124, - "id": "3eed91b9-903b-441f-b1f2-10dbcfafa342", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'@id': '68654706-7146-48f0-8ed9-ec0ffa94feea',\n", - " '@type': 'Commit',\n", - " 'created': '2022-11-05T21:02:56.305306-04:00',\n", - " 'description': None,\n", - " 'owningProject': {'@id': '1cb23e7a-4d70-487e-89ad-1cd8a22efb9e'},\n", - " 'previousCommit': None}\n" - ] - } - ], - "source": [ - "commit_body = {\n", - " \"@type\": \"Commit\",\n", - " \"change\": [\n", - " {\n", - " \"@type\": \"DataVersion\",\n", - " \"payload\": {\n", - " \"@type\": \"PartDefinition\",\n", - " \"name\":\"Spacecraft System\"\n", - " }\n", - " },\n", - " {\n", - " \"@type\": \"DataVersion\",\n", - " \"payload\": {\n", - " \"@type\": \"PartDefinition\",\n", - " \"name\":\"Payload System\"\n", - " }\n", - " },\n", - " {\n", - " \"@type\": \"DataVersion\",\n", - " \"payload\": {\n", - " \"@type\": \"PartDefinition\",\n", - " \"name\":\"Propulsion System\"\n", - " }\n", - " }\n", - " ]\n", - "}\n", - "\n", - "commit_post_url = f\"{host}/projects/{project_id}/commits\" \n", - "\n", - "commit_post_response = requests.post(commit_post_url, \n", - " headers={\"Content-Type\": \"application/json\"}, \n", - " data=json.dumps(commit_body))\n", - "\n", - "commit1_id = \"\"\n", - "\n", - "if commit_post_response.status_code == 200:\n", - " commit_response_json = commit_post_response.json()\n", - " pprint(commit_response_json)\n", - " commit1_id = commit_response_json['@id']\n", - "else:\n", - " pprint(f\"Problem in creating a new commit in Spacecraft project {project_id}\")\n", - " pprint(commit_post_response)" - ] - }, - { - "cell_type": "code", - "execution_count": 125, - "id": "65537f5c-f521-469e-92e4-9a2568afed05", - "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", - "
Element NameElement ID
Payload Systemaa45735a-6001-4f00-a7f2-ecad5d442d27
Propulsion System27e4f855-aa8a-4343-b25c-0c452cfb22ab
Spacecraft System00734e2e-565f-4411-8b06-b5c8eab5e178
\n" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "element_get_url = f\"{host}/projects/{project_id}/commits/{commit1_id}/elements\" \n", - "\n", - "element_get_response = requests.get(element_get_url)\n", - "\n", - "if element_get_response.status_code == 200:\n", - " elements = element_get_response.json()\n", - " elements_data = list(map(lambda b: {'Element Name':b['name'], 'Element ID':b['@id']}, elements))\n", - " df = pd.DataFrame.from_records(elements_data).sort_values(by='Element Name').style.hide(axis='index')\n", - " display(df)\n", - "else:\n", - " pprint(f\"Problem in fetching elements in the Spacecraft project {project_id} at commit {commit1_id}.\")\n", - " pprint(element_get_response)" - ] - }, - { - "cell_type": "markdown", - "id": "8e38b288-6517-4a7b-90e5-ae73c5f89df3", - "metadata": {}, - "source": [ - "# Create 2nd Commit" - ] - }, - { - "cell_type": "code", - "execution_count": 126, - "id": "76d80cb1-40c8-4f24-aeb5-51e509f4e159", - "metadata": { - "tags": [] - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'@id': '118e6f99-cde1-41fb-8f93-928fe6fa4be0',\n", - " '@type': 'Commit',\n", - " 'created': '2022-11-05T21:02:56.7703-04:00',\n", - " 'description': None,\n", - " 'owningProject': {'@id': '1cb23e7a-4d70-487e-89ad-1cd8a22efb9e'},\n", - " 'previousCommit': {'@id': '68654706-7146-48f0-8ed9-ec0ffa94feea'}}\n" - ] - } - ], - "source": [ - "commit_body = {\n", - " \"@type\": \"Commit\",\n", - " \"change\": [\n", - " {\n", - " \"@type\": \"DataVersion\",\n", - " \"payload\": {\n", - " \"@type\": \"PartDefinition\",\n", - " \"name\":\"Avionics System\"\n", - " }\n", - " },\n", - " {\n", - " \"@type\": \"DataVersion\",\n", - " \"payload\": {\n", - " \"@type\": \"PartDefinition\",\n", - " \"name\":\"Power System\"\n", - " }\n", - " }\n", - " ],\n", - " \"previousCommit\": {\n", - " \"@id\": commit1_id\n", - " }\n", - "}\n", - "\n", - "commit_post_url = f\"{host}/projects/{project_id}/commits\" \n", - "\n", - "commit_post_response = requests.post(commit_post_url, \n", - " headers={\"Content-Type\": \"application/json\"}, \n", - " data=json.dumps(commit_body))\n", - "\n", - "commit2_id = \"\"\n", - "\n", - "if commit_post_response.status_code == 200:\n", - " commit_response_json = commit_post_response.json()\n", - " pprint(commit_response_json)\n", - " commit2_id = commit_response_json['@id']\n", - "else:\n", - " pprint(f\"Problem in creating a new commit in Spacecraft project {project_id}\")\n", - " pprint(commit_post_response)" - ] - }, - { - "cell_type": "markdown", - "id": "d815e4fe", - "metadata": {}, - "source": [ - "# Get all elements after the 2nd commit" - ] - }, - { - "cell_type": "code", - "execution_count": 127, - "id": "eac0a387-e4cf-4fc8-8b47-c64ed2ebff62", - "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", - "
Element NameElement ID
Avionics Systemd4a362f9-7a85-4887-9936-4df002c5fcae
Payload Systemaa45735a-6001-4f00-a7f2-ecad5d442d27
Power System8ac6138b-e00c-4908-8383-b25ef5dce6b0
Propulsion System27e4f855-aa8a-4343-b25c-0c452cfb22ab
Spacecraft System00734e2e-565f-4411-8b06-b5c8eab5e178
\n" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "element_get_url = f\"{host}/projects/{project_id}/commits/{commit2_id}/elements\" \n", - "\n", - "element_get_response = requests.get(element_get_url)\n", - "\n", - "if element_get_response.status_code == 200:\n", - " elements = element_get_response.json()\n", - " elements_data = list(map(lambda b: {'Element Name':b['name'], 'Element ID':b['@id']}, elements))\n", - " df = pd.DataFrame.from_records(elements_data).sort_values(by='Element Name').style.hide(axis='index')\n", - " display(df)\n", - "else:\n", - " pprint(f\"Problem in fetching elements in the Spacecraft project {project_id} at commit {commit2_id}.\")\n", - " pprint(element_get_response)" - ] - }, - { - "cell_type": "markdown", - "id": "4b841d77-eb20-4f3c-bc64-fe08031d01bc", - "metadata": {}, - "source": [ - "# Create a tag" - ] - }, - { - "cell_type": "code", - "execution_count": 128, - "id": "886842cc-c983-424f-9af9-083257a5732c", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'@id': '65b1977d-bc03-4a94-be41-2ed85eda65ed',\n", - " '@type': 'Tag',\n", - " 'created': '2022-11-05T21:02:57.096895-04:00',\n", - " 'name': 'Spacecraft Internal Release 0.1',\n", - " 'owningProject': {'@id': '1cb23e7a-4d70-487e-89ad-1cd8a22efb9e'},\n", - " 'referencedCommit': {'@id': '118e6f99-cde1-41fb-8f93-928fe6fa4be0'},\n", - " 'taggedCommit': {'@id': '118e6f99-cde1-41fb-8f93-928fe6fa4be0'}}\n" - ] - } - ], - "source": [ - "tag_body = {\n", - " \"@type\": \"Tag\",\n", - " \"name\": \"Spacecraft Internal Release 0.1\",\n", - " \"taggedCommit\": {\n", - " \"@id\": commit2_id\n", - " }\n", - "}\n", - "\n", - "tag_post_url = f\"{host}/projects/{project_id}/tags\" \n", - "\n", - "tag_post_response = requests.post(tag_post_url, \n", - " headers={\"Content-Type\": \"application/json\"}, \n", - " data=json.dumps(tag_body))\n", - "\n", - "tag1_id = \"\"\n", - "\n", - "if tag_post_response.status_code == 200:\n", - " tag_response_json = tag_post_response.json()\n", - " pprint(tag_response_json)\n", - " tag1_id = tag_response_json['@id']\n", - "else:\n", - " pprint(f\"Problem in creating a new tag in Spacecraft project {project_id}.\")\n", - " pprint(tag_post_response)" - ] - }, - { - "cell_type": "markdown", - "id": "ec239663-ce0d-4ae6-acd7-5910299dedda", - "metadata": {}, - "source": [ - "# Get Tags" - ] - }, - { - "cell_type": "code", - "execution_count": 129, - "id": "bf1ce47b-079d-429f-b43b-491c3aa156c8", - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
Tag NameTag IDTagged Commit
Spacecraft Internal Release 0.165b1977d-bc03-4a94-be41-2ed85eda65ed{'@id': '118e6f99-cde1-41fb-8f93-928fe6fa4be0'}
\n" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "tags_url = f\"{host}/projects/{project_id}/tags\" \n", - "tags_response = requests.get(tags_url)\n", - "\n", - "if tags_response.status_code == 200:\n", - " tags = tags_response.json()\n", - " tags_data = list(map(lambda b: {'Tag Name':b['name'], 'Tag ID':b['@id'], 'Tagged Commit':b['taggedCommit']}, tags))\n", - "\n", - " df = pd.DataFrame.from_records(tags_data).style.hide(axis='index')\n", - " display(df)\n", - "else:\n", - " pprint(f\"Problem in fetching tags in Spacecraft project {project_id}.\")\n", - " pprint(tag_post_response)" - ] - }, - { - "cell_type": "markdown", - "id": "5a0ec0fa-af50-4944-8401-183f2cb165af", - "metadata": {}, - "source": [ - "# Create a new branch at the second commit (also tagged as 0.1)" - ] - }, - { - "cell_type": "code", - "execution_count": 130, - "id": "cc9620df-e407-4a25-8ae4-bd803d1cde32", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'@id': 'adb35786-0381-4f86-814e-deff94481ca5',\n", - " '@type': 'Branch',\n", - " 'created': '2022-11-05T21:02:57.268637-04:00',\n", - " 'head': {'@id': '118e6f99-cde1-41fb-8f93-928fe6fa4be0'},\n", - " 'name': 'develop',\n", - " 'owningProject': {'@id': '1cb23e7a-4d70-487e-89ad-1cd8a22efb9e'},\n", - " 'referencedCommit': {'@id': '118e6f99-cde1-41fb-8f93-928fe6fa4be0'}}\n" - ] - } - ], - "source": [ - "branch_body = {\n", - " \"@type\": \"Branch\",\n", - " \"name\": \"develop\",\n", - " \"head\": {\n", - " \"@id\": commit2_id\n", - " }\n", - "}\n", - "\n", - "branch_post_url = f\"{host}/projects/{project_id}/branches\" \n", - "\n", - "branch_post_response = requests.post(branch_post_url, \n", - " headers={\"Content-Type\": \"application/json\"}, \n", - " data=json.dumps(branch_body))\n", - "\n", - "branch_develop_id = \"\"\n", - "\n", - "if branch_post_response.status_code == 200:\n", - " branch_response_json = branch_post_response.json()\n", - " pprint(branch_response_json)\n", - " branch_develop_id = branch_response_json['@id']\n", - "else:\n", - " pprint(f\"Problem in creating a new branch in Spacecraft project {project_id}\")\n", - " pprint(branch_post_response)" - ] - }, - { - "cell_type": "markdown", - "id": "19ba5702-85d2-40ec-b01c-de6f112e8bfa", - "metadata": { - "tags": [] - }, - "source": [ - "# Get branches" - ] - }, - { - "cell_type": "code", - "execution_count": 131, - "id": "61faab74-218a-4bf4-832d-2e3a3d70578d", - "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", - "
Branch NameBranch IDRef Commit (head)
developadb35786-0381-4f86-814e-deff94481ca5{'@id': '118e6f99-cde1-41fb-8f93-928fe6fa4be0'}
mainb20df3d4-bb46-489f-b312-858952c21d89{'@id': '118e6f99-cde1-41fb-8f93-928fe6fa4be0'}
\n" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "branches_url = f\"{host}/projects/{project_id}/branches\" \n", - "branches_response = requests.get(branches_url)\n", - "\n", - "if branches_response.status_code == 200:\n", - " branches = branches_response.json()\n", - " branches_data = list(map(lambda b: {'Branch Name':b['name'], 'Branch ID':b['@id'], 'Ref Commit (head)':b['head']}, branches))\n", - "\n", - " df = pd.DataFrame.from_records(branches_data).sort_values(by='Branch Name').style.hide(axis='index')\n", - " display(df)\n", - "else:\n", - " pprint(f\"Problem in fetching branches in Spacecraft project {project_id}\")\n", - " pprint(branches_response)" - ] - }, - { - "cell_type": "markdown", - "id": "8dbea034-4180-415f-9604-8e1afb149fdc", - "metadata": {}, - "source": [ - "# Create a new commit in the develop branch" - ] - }, - { - "cell_type": "code", - "execution_count": 132, - "id": "055f42b3-18de-4f94-ae53-43660948493b", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'@id': '5665c584-4474-4599-8b74-46c3c647a2cf',\n", - " '@type': 'Commit',\n", - " 'created': '2022-11-05T21:02:57.444978-04:00',\n", - " 'description': None,\n", - " 'owningProject': {'@id': '1cb23e7a-4d70-487e-89ad-1cd8a22efb9e'},\n", - " 'previousCommit': {'@id': '118e6f99-cde1-41fb-8f93-928fe6fa4be0'}}\n" - ] - } - ], - "source": [ - "commit_body = {\n", - " \"@type\": \"Commit\",\n", - " \"change\": [\n", - " {\n", - " \"@type\": \"DataVersion\",\n", - " \"payload\": {\n", - " \"@type\": \"PartDefinition\",\n", - " \"name\":\"GN & C System\"\n", - " }\n", - " }\n", - " ],\n", - " \"previousCommit\": {\n", - " \"@id\": commit2_id\n", - " }\n", - "}\n", - "\n", - "commit_post_url = f\"{host}/projects/{project_id}/commits\" \n", - "\n", - "commit_post_response = requests.post(commit_post_url, \n", - " headers={\"Content-Type\": \"application/json\"}, \n", - " data=json.dumps(commit_body),\n", - " params={\"branchId\":branch_develop_id})\n", - "\n", - "commit3_id = \"\"\n", - "\n", - "if commit_post_response.status_code == 200:\n", - " commit_response_json = commit_post_response.json()\n", - " pprint(commit_response_json)\n", - " commit3_id = commit_response_json['@id']\n", - "else:\n", - " pprint(f\"Problem in creating a new commit in Spacecraft project {project_id}\")\n", - " pprint(commit_post_response)" - ] - }, - { - "cell_type": "markdown", - "id": "e2ba3c85-db23-460d-b6d4-6afbd6461e7d", - "metadata": {}, - "source": [ - "# Get Branches" - ] - }, - { - "cell_type": "code", - "execution_count": 133, - "id": "ead42406-7536-4f47-b0d8-d34a48e9054e", - "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", - "
Branch NameBranch IDRef Commit (head)
developadb35786-0381-4f86-814e-deff94481ca5{'@id': '5665c584-4474-4599-8b74-46c3c647a2cf'}
mainb20df3d4-bb46-489f-b312-858952c21d89{'@id': '118e6f99-cde1-41fb-8f93-928fe6fa4be0'}
\n" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "branches_url = f\"{host}/projects/{project_id}/branches\" \n", - "branches_response = requests.get(branches_url)\n", - "\n", - "if branches_response.status_code == 200:\n", - " branches = branches_response.json()\n", - " branches_data = list(map(lambda b: {'Branch Name':b['name'], 'Branch ID':b['@id'], 'Ref Commit (head)':b['head']}, branches))\n", - "\n", - " df = pd.DataFrame.from_records(branches_data).sort_values(by='Branch Name').style.hide(axis='index')\n", - " display(df)\n", - "else:\n", - " pprint(f\"Problem in fetching branches in Spacecraft project {project_id}\")\n", - " pprint(commit_post_response)" - ] - }, - { - "cell_type": "markdown", - "id": "61cdaecd-44db-4e27-85dd-de5d002648cc", - "metadata": {}, - "source": [ - "# Get all elements as of the latest commit on main branch" - ] - }, - { - "cell_type": "code", - "execution_count": 134, - "id": "86008838-368a-4e58-9d5b-70e9c57442f4", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "'Fetching elements at commit 118e6f99-cde1-41fb-8f93-928fe6fa4be0'\n" - ] - }, - { - "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", - "
Element NameElement ID
Avionics Systemd4a362f9-7a85-4887-9936-4df002c5fcae
Payload Systemaa45735a-6001-4f00-a7f2-ecad5d442d27
Power System8ac6138b-e00c-4908-8383-b25ef5dce6b0
Propulsion System27e4f855-aa8a-4343-b25c-0c452cfb22ab
Spacecraft System00734e2e-565f-4411-8b06-b5c8eab5e178
\n" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "pprint(f\"Fetching elements at commit {commit2_id}\")\n", - "element_get_url = f\"{host}/projects/{project_id}/commits/{commit2_id}/elements\" \n", - "\n", - "element_get_response = requests.get(element_get_url)\n", - "\n", - "if element_get_response.status_code == 200:\n", - " elements = element_get_response.json()\n", - " elements_data = list(map(lambda b: {'Element Name':b['name'], 'Element ID':b['@id']}, elements))\n", - " df = pd.DataFrame.from_records(elements_data).sort_values(by='Element Name').style.hide(axis='index')\n", - " display(df)\n", - "else:\n", - " pprint(f\"Problem in fetching elements in the Spacecraft project {project_id} at commit {commit2_id}\")\n", - " pprint(element_get_response)" - ] - }, - { - "cell_type": "markdown", - "id": "24a94903-9a4e-4f2b-b1bf-be21b7e22e48", - "metadata": {}, - "source": [ - "# Get all elements as of the latest commit on develop branch" - ] - }, - { - "cell_type": "code", - "execution_count": 135, - "id": "60bf125d-5258-4546-99da-3680de66dd1b", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "'Fetching elements at commit 5665c584-4474-4599-8b74-46c3c647a2cf'\n" - ] - }, - { - "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", - "
Element NameElement ID
Avionics Systemd4a362f9-7a85-4887-9936-4df002c5fcae
GN & C System27d2c686-7c67-4cc5-99f1-cadc06cd4347
Payload Systemaa45735a-6001-4f00-a7f2-ecad5d442d27
Power System8ac6138b-e00c-4908-8383-b25ef5dce6b0
Propulsion System27e4f855-aa8a-4343-b25c-0c452cfb22ab
Spacecraft System00734e2e-565f-4411-8b06-b5c8eab5e178
\n" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "pprint(f\"Fetching elements at commit {commit3_id}\")\n", - "element_get_url = f\"{host}/projects/{project_id}/commits/{commit3_id}/elements\" \n", - "\n", - "element_get_response = requests.get(element_get_url)\n", - "\n", - "if element_get_response.status_code == 200:\n", - " elements = element_get_response.json()\n", - " elements_data = list(map(lambda b: {'Element Name':b['name'], 'Element ID':b['@id']}, elements))\n", - " df = pd.DataFrame.from_records(elements_data).sort_values(by='Element Name').style.hide(axis='index')\n", - " display(df)\n", - "else:\n", - " pprint(f\"Problem in fetching elements in the Spacecraft project {project_id} at commit {commit3_id}\")\n", - " pprint(element_get_response)" - ] - }, - { - "cell_type": "markdown", - "id": "f162ef4e-3e68-4a66-b8fa-2abde70e867d", - "metadata": {}, - "source": [ - "# Create a tag at the last commit on develop branch" - ] - }, - { - "cell_type": "code", - "execution_count": 136, - "id": "b3e26544-b2e4-4370-bb85-9d23aabcc0b5", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'@id': '040ddf64-13a9-4bf8-b533-ad831f7862db',\n", - " '@type': 'Tag',\n", - " 'created': '2022-11-05T21:02:58.049038-04:00',\n", - " 'name': 'Spacecraft Internal Release 0.2 build 1',\n", - " 'owningProject': {'@id': '1cb23e7a-4d70-487e-89ad-1cd8a22efb9e'},\n", - " 'referencedCommit': {'@id': '5665c584-4474-4599-8b74-46c3c647a2cf'},\n", - " 'taggedCommit': {'@id': '5665c584-4474-4599-8b74-46c3c647a2cf'}}\n" - ] - } - ], - "source": [ - "tag_body = {\n", - " \"@type\": \"Tag\",\n", - " \"name\": \"Spacecraft Internal Release 0.2 build 1\",\n", - " \"taggedCommit\": {\n", - " \"@id\": commit3_id\n", - " }\n", - "}\n", - "\n", - "tag_post_url = f\"{host}/projects/{project_id}/tags\" \n", - "\n", - "tag_post_response = requests.post(tag_post_url, \n", - " headers={\"Content-Type\": \"application/json\"}, \n", - " data=json.dumps(tag_body))\n", - "\n", - "tag1_id = \"\"\n", - "\n", - "if tag_post_response.status_code == 200:\n", - " tag_response_json = tag_post_response.json()\n", - " pprint(tag_response_json)\n", - " tag1_id = tag_response_json['@id']\n", - "else:\n", - " pprint(f\"Problem in creating a new tag in Spacecraft project {project_id}.\")\n", - " pprint(tag_post_response)" - ] - }, - { - "cell_type": "markdown", - "id": "20dfd748-3149-4442-a7e8-fbef247377a7", - "metadata": {}, - "source": [ - "# Get all tags" - ] - }, - { - "cell_type": "code", - "execution_count": 137, - "id": "aee7a152-8b4c-476a-8691-4766fc94c240", - "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", - "
Tag NameTag IDTagged Commit
Spacecraft Internal Release 0.2 build 1040ddf64-13a9-4bf8-b533-ad831f7862db{'@id': '5665c584-4474-4599-8b74-46c3c647a2cf'}
Spacecraft Internal Release 0.165b1977d-bc03-4a94-be41-2ed85eda65ed{'@id': '118e6f99-cde1-41fb-8f93-928fe6fa4be0'}
\n" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "tags_url = f\"{host}/projects/{project_id}/tags\" \n", - "tags_response = requests.get(tags_url)\n", - "\n", - "if tags_response.status_code == 200:\n", - " tags = tags_response.json()\n", - " tags_data = list(map(lambda b: {'Tag Name':b['name'], 'Tag ID':b['@id'], 'Tagged Commit':b['taggedCommit']}, tags))\n", - "\n", - " df = pd.DataFrame.from_records(tags_data).style.hide(axis='index')\n", - " display(df)\n", - "else:\n", - " pprint(f\"Problem in fetching tags in Spacecraft project {project_id}.\")\n", - " pprint(tag_post_response)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "59690f32-5000-44e3-b6f7-853be468c57c", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "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.8.13" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/.ipynb_checkpoints/Queries-checkpoint.ipynb b/.ipynb_checkpoints/Queries-checkpoint.ipynb deleted file mode 100644 index fcb2f0f..0000000 --- a/.ipynb_checkpoints/Queries-checkpoint.ipynb +++ /dev/null @@ -1,632 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "3ee4834f", - "metadata": {}, - "source": [ - "# Initializing the SysML v2 API" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "id": "6b5fef59", - "metadata": {}, - "outputs": [], - "source": [ - "from __future__ import print_function\n", - "\n", - "import time\n", - "import requests\n", - "from pprint import pprint\n", - "import pandas as pd\n", - "import json\n", - "\n", - "#host = \"\"\n", - "host = \"Specify the URL of the SysML v2 API and Service Repository\"" - ] - }, - { - "cell_type": "markdown", - "id": "04c1ff93", - "metadata": {}, - "source": [ - "# Get projects" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "id": "78788ed9", - "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", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
Project NameProject ID
0Spacecraft project with branches and tags - 20...00a50f21-3329-4871-97d5-d9988f8bda4f
117a-Sequence-Modeling Thu Jul 21 12:43:51 EDT ...048a0c99-ca99-4012-929d-f4797d395de1
212b-Allocation Thu Jul 21 12:40:33 EDT 202206a5e118-34e0-4ac3-b499-0a11773bc0f6
314a-Language Extensions Thu Jul 21 12:42:05 ED...0d9d4124-1413-428f-866d-f9b58bf23c95
49-Verification-simplified Thu Jul 21 12:38:15 ...17ffc369-e231-49dd-9f56-4330856a0fda
5Geometry Thu Jul 21 13:01:13 EDT 2022228c1a01-b8be-4d63-a87c-0ebbd9d88ff8
611a-View-Viewpoint Thu Jul 21 12:39:43 EDT 20222e65960e-5dca-4d69-bb31-0c56537b4b70
714b-Language Extensions Thu Jul 21 12:42:19 ED...2f671f67-cb65-4365-a221-c403e7b87c51
85-State-based Behavior-1a Thu Jul 21 12:36:44 ...3694e3f8-b2eb-45a7-bddd-f41cca5b36c6
911b-Safety and Security Feature Views Thu Jul ...3703933c-5a07-4555-9352-3414f345553b
1018-Use Case Thu Jul 21 12:44:19 EDT 20224223e1a2-beb7-483b-852e-3913c7a94c9c
113a-Function-based Behavior-2 Thu Jul 21 12:35:...462e55f9-2def-4b0f-abf6-e46f1cd50979
12Spacecraft project with branches and tags - 20...51cbfbec-1e60-4f6f-9956-e38594dcb33d
1310d-Dynamics Analysis Thu Jul 21 12:39:20 EDT ...6ec5dbe4-2b39-4b56-b222-ff506f15dba9
1412a-Dependency Thu Jul 21 12:40:21 EDT 2022703ade3d-7929-4d40-9806-19b7f3c002df
1515_10-Primitive Data Types Thu Jul 21 12:43:17...70cc6261-6b37-4463-a0d6-f63b01301b32
1613b-Safety and Security Features Element Group...7c91c09e-2973-46b9-ad82-275ba2124322
1713b-Safety and Security Features Element Group...7da362eb-8768-4417-8985-c705c17ee1f2
188-Requirements Thu Jul 21 12:37:52 EDT 2022827ca776-1199-4fda-84b7-f81b3dd46fae
1913a-Model Containment Thu Jul 21 12:40:47 EDT ...8d16ef4d-8b68-4661-a5f6-131ad06251d8
20Spacecraft project with branches and tags - 20...8fe6a1a1-e722-4342-bc71-961f848a7799
2117b-Sequence-Modeling Thu Jul 21 12:44:05 EDT ...96fe8de3-8af0-4d4a-96b0-354f4cceb184
2215_05-Unification of Expression and Constraint...98fa34a4-5069-4dc3-9a97-f57122adebc6
235-State-based Behavior-1 Thu Jul 21 12:36:19 E...9ea87a3e-9f70-4e13-acf4-0932d28d4362
244a-Functional Allocation Thu Jul 21 12:35:59 E...aa64678d-87ce-442f-a88e-866ae492f75b
251c-Parts Tree Redefinition Thu Jul 21 12:34:06...b1b4e96a-035e-441f-83c4-2d55fb568877
267b-Variant Configurations Thu Jul 21 12:37:28 ...b25ed4fa-5737-40dc-b69b-bfde55ca39b7
272a-Parts Interconnection Thu Jul 21 12:34:36 E...bb68bed7-3f04-4617-998f-2669d7488236
2810c-Fuel Economy Analysis Thu Jul 21 12:38:54 ...c1fae04f-f879-4fae-acec-1d7281a0124d
2913b-Safety and Security Features Element Group...cd1ba8c5-4992-4585-bf9b-9c3be3e9e033
3015_19-Materials with Properties Thu Jul 21 12:...ce489c07-79d9-4022-9dc1-1bd413bce2d8
3110b-Trade-off Among Alternative Configurations...cfddd9c9-a2c9-4446-8056-74c7552a4d63
326-Individual and Snapshots Thu Jul 21 12:37:08...db7fd713-98bc-4932-9b40-438040e85854
3314c-Language Extensions Thu Jul 21 12:42:33 ED...e6b46779-d037-4391-af1f-6fb5253f1ea2
343a-Function-based Behavior-1 Thu Jul 21 12:35:...f00664c2-ff28-4e1c-aee7-d948e9fa292d
353a-Function-based Behavior-5 Thu Jul 21 12:35:...ff54a0e3-3adb-4c8d-93a4-8e6f5e11af66
\n", - "
" - ], - "text/plain": [ - " Project Name \\\n", - "0 Spacecraft project with branches and tags - 20... \n", - "1 17a-Sequence-Modeling Thu Jul 21 12:43:51 EDT ... \n", - "2 12b-Allocation Thu Jul 21 12:40:33 EDT 2022 \n", - "3 14a-Language Extensions Thu Jul 21 12:42:05 ED... \n", - "4 9-Verification-simplified Thu Jul 21 12:38:15 ... \n", - "5 Geometry Thu Jul 21 13:01:13 EDT 2022 \n", - "6 11a-View-Viewpoint Thu Jul 21 12:39:43 EDT 2022 \n", - "7 14b-Language Extensions Thu Jul 21 12:42:19 ED... \n", - "8 5-State-based Behavior-1a Thu Jul 21 12:36:44 ... \n", - "9 11b-Safety and Security Feature Views Thu Jul ... \n", - "10 18-Use Case Thu Jul 21 12:44:19 EDT 2022 \n", - "11 3a-Function-based Behavior-2 Thu Jul 21 12:35:... \n", - "12 Spacecraft project with branches and tags - 20... \n", - "13 10d-Dynamics Analysis Thu Jul 21 12:39:20 EDT ... \n", - "14 12a-Dependency Thu Jul 21 12:40:21 EDT 2022 \n", - "15 15_10-Primitive Data Types Thu Jul 21 12:43:17... \n", - "16 13b-Safety and Security Features Element Group... \n", - "17 13b-Safety and Security Features Element Group... \n", - "18 8-Requirements Thu Jul 21 12:37:52 EDT 2022 \n", - "19 13a-Model Containment Thu Jul 21 12:40:47 EDT ... \n", - "20 Spacecraft project with branches and tags - 20... \n", - "21 17b-Sequence-Modeling Thu Jul 21 12:44:05 EDT ... \n", - "22 15_05-Unification of Expression and Constraint... \n", - "23 5-State-based Behavior-1 Thu Jul 21 12:36:19 E... \n", - "24 4a-Functional Allocation Thu Jul 21 12:35:59 E... \n", - "25 1c-Parts Tree Redefinition Thu Jul 21 12:34:06... \n", - "26 7b-Variant Configurations Thu Jul 21 12:37:28 ... \n", - "27 2a-Parts Interconnection Thu Jul 21 12:34:36 E... \n", - "28 10c-Fuel Economy Analysis Thu Jul 21 12:38:54 ... \n", - "29 13b-Safety and Security Features Element Group... \n", - "30 15_19-Materials with Properties Thu Jul 21 12:... \n", - "31 10b-Trade-off Among Alternative Configurations... \n", - "32 6-Individual and Snapshots Thu Jul 21 12:37:08... \n", - "33 14c-Language Extensions Thu Jul 21 12:42:33 ED... \n", - "34 3a-Function-based Behavior-1 Thu Jul 21 12:35:... \n", - "35 3a-Function-based Behavior-5 Thu Jul 21 12:35:... \n", - "\n", - " Project ID \n", - "0 00a50f21-3329-4871-97d5-d9988f8bda4f \n", - "1 048a0c99-ca99-4012-929d-f4797d395de1 \n", - "2 06a5e118-34e0-4ac3-b499-0a11773bc0f6 \n", - "3 0d9d4124-1413-428f-866d-f9b58bf23c95 \n", - "4 17ffc369-e231-49dd-9f56-4330856a0fda \n", - "5 228c1a01-b8be-4d63-a87c-0ebbd9d88ff8 \n", - "6 2e65960e-5dca-4d69-bb31-0c56537b4b70 \n", - "7 2f671f67-cb65-4365-a221-c403e7b87c51 \n", - "8 3694e3f8-b2eb-45a7-bddd-f41cca5b36c6 \n", - "9 3703933c-5a07-4555-9352-3414f345553b \n", - "10 4223e1a2-beb7-483b-852e-3913c7a94c9c \n", - "11 462e55f9-2def-4b0f-abf6-e46f1cd50979 \n", - "12 51cbfbec-1e60-4f6f-9956-e38594dcb33d \n", - "13 6ec5dbe4-2b39-4b56-b222-ff506f15dba9 \n", - "14 703ade3d-7929-4d40-9806-19b7f3c002df \n", - "15 70cc6261-6b37-4463-a0d6-f63b01301b32 \n", - "16 7c91c09e-2973-46b9-ad82-275ba2124322 \n", - "17 7da362eb-8768-4417-8985-c705c17ee1f2 \n", - "18 827ca776-1199-4fda-84b7-f81b3dd46fae \n", - "19 8d16ef4d-8b68-4661-a5f6-131ad06251d8 \n", - "20 8fe6a1a1-e722-4342-bc71-961f848a7799 \n", - "21 96fe8de3-8af0-4d4a-96b0-354f4cceb184 \n", - "22 98fa34a4-5069-4dc3-9a97-f57122adebc6 \n", - "23 9ea87a3e-9f70-4e13-acf4-0932d28d4362 \n", - "24 aa64678d-87ce-442f-a88e-866ae492f75b \n", - "25 b1b4e96a-035e-441f-83c4-2d55fb568877 \n", - "26 b25ed4fa-5737-40dc-b69b-bfde55ca39b7 \n", - "27 bb68bed7-3f04-4617-998f-2669d7488236 \n", - "28 c1fae04f-f879-4fae-acec-1d7281a0124d \n", - "29 cd1ba8c5-4992-4585-bf9b-9c3be3e9e033 \n", - "30 ce489c07-79d9-4022-9dc1-1bd413bce2d8 \n", - "31 cfddd9c9-a2c9-4446-8056-74c7552a4d63 \n", - "32 db7fd713-98bc-4932-9b40-438040e85854 \n", - "33 e6b46779-d037-4391-af1f-6fb5253f1ea2 \n", - "34 f00664c2-ff28-4e1c-aee7-d948e9fa292d \n", - "35 ff54a0e3-3adb-4c8d-93a4-8e6f5e11af66 " - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "projects_url = f\"{host}/projects\" \n", - "projects_response = requests.get(projects_url)\n", - "parts_tree_project_id = \"\"\n", - "\n", - "if projects_response.status_code == 200:\n", - " projects = projects_response.json()\n", - " \n", - " df = pd.DataFrame({'Project Name':[], 'Project ID':[]})\n", - " for p in projects:\n", - " df = pd.concat([df, pd.DataFrame({'Project Name':[p['name']], 'Project ID':[p['@id']]})], ignore_index=True)\n", - " display(df)\n", - " \n", - " parts_tree_project = list(filter(lambda p: 'Parts Tree' in p['name'], projects))[0] \n", - " parts_tree_project_id = parts_tree_project['@id']" - ] - }, - { - "cell_type": "markdown", - "id": "487c0624", - "metadata": {}, - "source": [ - "## Query to find all part usages" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "id": "e1e315c9-7484-4424-a3b7-2b1455dbbe91", - "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", - "
Part Usage NamePart Usage ID
0rearAxleAssembly_c102fecf3d-69f7-4f16-a2c9-90c0df53dae5
1frontAxle_c16184d9c5-57ae-4e29-906e-d042f7b7e2bb
2frontWheel005c0064-c3c2-4ecd-aec8-59483179e7e5
3vehicle1_c1dd0cba88-59dd-4b2e-9664-7608d22186ce
4rearAxle8ed3d0f9-1bb4-4207-80db-e39c5cfb1e5f
5frontAxleb53912c9-213d-4d61-b737-270969d20d65
6vehicle1149effb8-9cfb-4f55-80db-a984830eec55
7rearAxle_c1b4d0d0e0-8b79-4bea-a071-2af8315c492c
8frontAxleAssembly2b723540-a1cc-44e3-8f54-8b29cbb2962a
9frontWheel_1a88fb146-b2cb-4ef9-b2b8-d14bea29d3e1
10rearWheel_1f8bb2e98-a0e8-468f-9e78-0a391dfb927f
11frontWheel_2ba3e13d6-bb9f-4ec3-851a-7699e9839d38
12rearWheel5af0fa89-4f22-4b69-a022-9a342f0089b2
13rearAxleAssembly8435855c-96a1-489b-afc8-ba2e01b9deab
14rearWheel_2c15818e7-2edf-48f8-a04e-6900f3c13958
15frontAxleAssembly_c10e27013b-240d-44e5-bee9-d2bc949651ea
\n", - "
" - ], - "text/plain": [ - " Part Usage Name Part Usage ID\n", - "0 rearAxleAssembly_c1 02fecf3d-69f7-4f16-a2c9-90c0df53dae5\n", - "1 frontAxle_c1 6184d9c5-57ae-4e29-906e-d042f7b7e2bb\n", - "2 frontWheel 005c0064-c3c2-4ecd-aec8-59483179e7e5\n", - "3 vehicle1_c1 dd0cba88-59dd-4b2e-9664-7608d22186ce\n", - "4 rearAxle 8ed3d0f9-1bb4-4207-80db-e39c5cfb1e5f\n", - "5 frontAxle b53912c9-213d-4d61-b737-270969d20d65\n", - "6 vehicle1 149effb8-9cfb-4f55-80db-a984830eec55\n", - "7 rearAxle_c1 b4d0d0e0-8b79-4bea-a071-2af8315c492c\n", - "8 frontAxleAssembly 2b723540-a1cc-44e3-8f54-8b29cbb2962a\n", - "9 frontWheel_1 a88fb146-b2cb-4ef9-b2b8-d14bea29d3e1\n", - "10 rearWheel_1 f8bb2e98-a0e8-468f-9e78-0a391dfb927f\n", - "11 frontWheel_2 ba3e13d6-bb9f-4ec3-851a-7699e9839d38\n", - "12 rearWheel 5af0fa89-4f22-4b69-a022-9a342f0089b2\n", - "13 rearAxleAssembly 8435855c-96a1-489b-afc8-ba2e01b9deab\n", - "14 rearWheel_2 c15818e7-2edf-48f8-a04e-6900f3c13958\n", - "15 frontAxleAssembly_c1 0e27013b-240d-44e5-bee9-d2bc949651ea" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "# Query vehicle1 (PartUsage) in the \n", - "query_input = {\n", - " '@type':'Query',\n", - " 'select': ['name','@id','@type','owner'],\n", - " 'where': {\n", - " '@type': 'CompositeConstraint',\n", - " 'operator': 'and',\n", - " 'constraint': [\n", - " {\n", - " '@type': 'PrimitiveConstraint',\n", - " 'inverse': False,\n", - " 'operator': '=',\n", - " 'property': '@type',\n", - " 'value': 'PartUsage'\n", - " }\n", - " ]\n", - " }\n", - "}\n", - "\n", - "payload = json.dumps(query_input)\n", - "\n", - "vehicle1_id = ''\n", - "query_url = f\"{host}/projects/{parts_tree_project_id}/query-results\" \n", - "\n", - "query_response = requests.post(query_url, json=query_input)\n", - "\n", - "if query_response.status_code == 200:\n", - " query_response_json = query_response.json()\n", - " \n", - " df = pd.DataFrame({'Part Usage Name':[], 'Part Usage ID':[]})\n", - " for p in query_response_json:\n", - " df = pd.concat([df, pd.DataFrame({'Part Usage Name':[p['name']], 'Part Usage ID':[p['@id']]})], ignore_index=True)\n", - " display(df)" - ] - }, - { - "cell_type": "markdown", - "id": "004deca6-4832-4352-a682-dddbb2f92127", - "metadata": {}, - "source": [ - "## Query to find Part Usage with name vehicle1" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "id": "3d724e27", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[{'@id': '149effb8-9cfb-4f55-80db-a984830eec55',\n", - " '@type': 'PartUsage',\n", - " 'name': 'vehicle1',\n", - " 'owner': {'@id': 'ccc70fb3-8bba-40c1-aa18-b9c2ed15b041'}}]\n" - ] - } - ], - "source": [ - "# Query vehicle1 (PartUsage) in the \n", - "data = {\n", - " '@type':'Query',\n", - " 'select': ['name','@id','@type','owner'],\n", - " 'where': {\n", - " '@type': 'CompositeConstraint',\n", - " 'operator': 'and',\n", - " 'constraint': [\n", - " {\n", - " '@type': 'PrimitiveConstraint',\n", - " 'inverse': False,\n", - " 'operator': '=',\n", - " 'property': 'name',\n", - " 'value': 'vehicle1'\n", - " },\n", - " {\n", - " '@type': 'PrimitiveConstraint',\n", - " 'inverse': False,\n", - " 'operator': '=',\n", - " 'property': '@type',\n", - " 'value': 'PartUsage'\n", - " }\n", - " ]\n", - " }\n", - "}\n", - "\n", - "payload = json.dumps(data)\n", - "\n", - "vehicle1_id = ''\n", - "query_url = f\"{host}/projects/{parts_tree_project_id}/query-results\" \n", - "\n", - "query_response = requests.post(query_url, json=data)\n", - "\n", - "if query_response.status_code == 200:\n", - " query_response_json = query_response.json()\n", - " pprint(query_response_json)\n", - " vehicle1_id = query_response_json[0]['@id']" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "bd2276aa", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "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.8.13" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/.ipynb_checkpoints/README-checkpoint.md b/.ipynb_checkpoints/README-checkpoint.md deleted file mode 100644 index 90b65e5..0000000 --- a/.ipynb_checkpoints/README-checkpoint.md +++ /dev/null @@ -1,21 +0,0 @@ -# SysML-v2-API-Cookbook -The SysML v2 API Cookbook repository is a collection of API recipes to demonstrate patterns and examples for using the [SysML v2 API & Services](https://github.com/Systems-Modeling/SysML-v2-API-Services). - -In the current release, the cookbook contains recipes that use the SysML v2 REST/HTTP API (PSM). Each recipe is a [Jupyter notebook](https://jupyter.org/) with a sequence of API calls to the SysML v2 REST/HTTP API. - -## Description of recipes - -### Requirement, Structure, Behavior decomposition recipe -This recipe shows patterns and examples for navigating the decomposition of requirements, structure, and behavior elements using the SysML v2 API. The SysML v2 meta-model has harmonized the concepts related to element decomposition and the same concepts are used when decomposing requirements, structure, and behavior releated elements. This recipe shows the use of a common recursive function to navigate the decomposition of requirements, structure, and behavior elements. - -See the Jupyter notebook **Req_Str_Beh_Decomposition_Recipe.ipynb** for details. - -### Project, Commit, Branch, and Tag recipe -This recipe shows patterns and examples for fetching and creating commits, branches, and tags in a project. It shows an example scenario for SysML v2 project evolution over time with concurrent users working on different branches, creating new commits, and creating tags for baseline or milestone releases of the project. - -See the Jupyter notebook **Project_Commit_Branch_Tag_Recipe.ipynb** for details. - -### Queries recipe -This recipe shows patterns and examples for formulating and executing queries in a project. Examples show queries with multiple constraints. - -See the Jupyter notebook **Queries.ipynb** for details. diff --git a/.ipynb_checkpoints/Req_Str_Beh_Decomposition_Recipe-checkpoint.ipynb b/.ipynb_checkpoints/Req_Str_Beh_Decomposition_Recipe-checkpoint.ipynb deleted file mode 100644 index 1a30087..0000000 --- a/.ipynb_checkpoints/Req_Str_Beh_Decomposition_Recipe-checkpoint.ipynb +++ /dev/null @@ -1,986 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "3ee4834f", - "metadata": {}, - "source": [ - "# Initializing the SysML v2 API" - ] - }, - { - "cell_type": "code", - "execution_count": 17, - "id": "6b5fef59", - "metadata": {}, - "outputs": [], - "source": [ - "from __future__ import print_function\n", - "\n", - "import time\n", - "import requests\n", - "from pprint import pprint\n", - "import pandas as pd\n", - "import json\n", - "\n", - "#host = \"\"\n", - "host = \"Specify the URL of the SysML v2 API and Service Repository\"" - ] - }, - { - "cell_type": "markdown", - "id": "04c1ff93", - "metadata": {}, - "source": [ - "# Get projects" - ] - }, - { - "cell_type": "code", - "execution_count": 18, - "id": "78788ed9", - "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", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
Project NameProject ID
0Spacecraft project with Element CRUD - 2022-09...0659c128-afd5-42a1-912b-962068f1f053
117b-Sequence-Modeling Fri Sep 09 17:37:26 EDT ...0f7045bd-9a1c-4b54-90d9-775c0f642e1b
23a-Function-based Behavior-2 Fri Sep 09 17:26:...128710cd-978f-4c6f-93ac-8afbbd194185
310c-Fuel Economy Analysis Fri Sep 09 17:30:43 ...2909d482-a659-4307-9803-bdfcbe0a7989
4PartTest Fri Sep 09 17:22:13 EDT 20222a2a4d7d-cd9e-41ec-bec0-2bf6fcea6767
515_05-Unification of Expression and Constraint...39dcf070-668c-4711-a231-c2640b9f7f88
615_19-Materials with Properties Fri Sep 09 17:...3bd937e0-ab2e-47a6-8f66-0458df9f29de
7Spacecraft project with branches and tags - 20...3c293f80-a0aa-46a5-8cde-25a31ec697e0
83a-Function-based Behavior-1 Wed Sep 21 11:44:...413e8b6e-a4c7-483e-a212-eb25e7c47aff
914b-Language Extensions Fri Sep 09 17:35:06 ED...431cd401-010c-401f-9101-115240312d24
1013b-Safety and Security Features Element Group...46b226ce-8519-42de-96b4-07ff1045d0dd
11Spacecraft project with Element CRUD - 2022-09...4853c38b-85c5-40e5-9e83-b69c2e73415a
123a-Function-based Behavior-3 Fri Sep 09 17:26:...48f9a623-2451-4150-8b98-58e3b3c515cd
1312a-Dependency Fri Sep 09 17:32:29 EDT 202249a60e69-b509-4191-b1c3-240de628110b
144a-Functional Allocation Wed Sep 21 11:45:43 E...4f6c6172-ab0c-4572-b549-6b7da7e9e5fb
157b-Variant Configurations Fri Sep 09 17:28:59 ...59c86238-ef81-434e-a389-5393312ba0d7
161c-Parts Tree Redefinition Wed Sep 21 11:43:30...5b5474b6-68b8-43bf-b0f6-7d455bffa63d
1717a-Sequence-Modeling Fri Sep 09 17:37:07 EDT ...653c5173-770d-4ea6-90dc-c173d049258c
1813a-Model Containment Fri Sep 09 17:33:03 EDT ...6699f5e0-403b-414a-87c9-46671e702fab
19Spacecraft project with Element CRUD - 2022-09...77dd61e8-456a-425b-ac05-385bf6c20161
2011b-Safety and Security Feature Views Fri Sep ...84f30a8f-f839-4a71-aee9-dff2a2d28dbf
211c-Parts Tree Redefinition Fri Sep 09 17:25:05...85d874ae-1f68-4949-9b16-378f1cbc477e
222a-Parts Interconnection Wed Sep 21 11:43:57 E...887e0281-066f-4667-a67b-d50e886d031c
2314a-Language Extensions Fri Sep 09 17:34:49 ED...8f0bc3b3-a580-40fd-b99b-0e8865984c4f
246-Individual and Snapshots Fri Sep 09 17:28:35...913dab3f-4d5d-482d-9238-7491aead3e1a
25PartTest Fri Sep 09 17:21:50 EDT 202291b2be09-16de-4d35-87a4-589f3274ce55
2611a-View-Viewpoint Fri Sep 09 17:31:42 EDT 202291fd6db5-4cfa-4970-b115-05010053ec72
2713b-Safety and Security Features Element Group...95bfcea3-8ed7-4bd4-9e98-3d6ed311091e
28Spacecraft project with branches and tags - 20...978d0199-4e44-4090-8cb6-4253fd79e315
293a-Function-based Behavior-1 Fri Sep 09 17:26:...9da34b47-38d0-4630-bcb4-c387d5fac1da
30sysml Fri Sep 16 14:36:21 EDT 20229f7efdc8-e6d1-4cf4-a132-532e2f136e7f
319-Verification-simplified Fri Sep 09 17:29:54 ...a9a02019-b810-4fcb-9a9c-5cad061db29f
3210b-Trade-off Among Alternative Configurations...ada6b9b6-3534-43b3-a567-f97092ac26f1
3312b-Allocation Fri Sep 09 17:32:45 EDT 2022b4c01f6d-8173-4d43-abd1-596bdb89d6d4
34Spacecraft project with Element CRUD - 2022-09...b67ebee6-b55e-4088-b059-c2f102989ac2
358-Requirements Fri Sep 09 17:29:27 EDT 2022b6a3450b-8624-45c2-8dd9-68d301a439fe
3615_10-Primitive Data Types Fri Sep 09 17:36:20...bb65a453-67bc-4e6c-92c7-29734c80bab1
37sysml Fri Sep 16 14:49:18 EDT 2022c60d5b4d-5f36-4083-ae1a-e61ed2be0e78
382a-Parts Interconnection Fri Sep 09 17:23:32 E...c64923aa-79f4-419c-b983-6244fee741d6
395-State-based Behavior-1 Fri Sep 09 17:27:37 E...c6b1d4d6-a66e-4097-8752-5307ecd9ebaf
402a-Parts Interconnection Fri Sep 09 17:25:35 E...cb4e467e-772b-4054-849e-26e4b0e1e0c0
4110d-Dynamics Analysis Fri Sep 09 17:31:13 EDT ...cceed28a-64fb-4401-81da-afcadd96d1d6
4213b-Safety and Security Features Element Group...d4c21bc8-6778-4a97-b389-48b1e7b23260
435-State-based Behavior-1a Fri Sep 09 17:28:06 ...d63b8882-f41e-40ef-a4a2-cf74fa47f6dc
4414c-Language Extensions Fri Sep 09 17:35:25 ED...da4e65b6-460d-447b-8cf9-56a3ad44e514
453a-Function-based Behavior-2 Wed Sep 21 11:44:...e27d992a-91e6-450a-b6f6-b79196ebeeb9
463a-Function-based Behavior-3 Wed Sep 21 11:45:...e4966bc8-bd9f-4c63-a43d-2c21fe512d31
474a-Functional Allocation Fri Sep 09 17:27:13 E...e7090e9d-74f0-4b63-a4a6-6dd8647b5bdd
48Spacecraft project with Element CRUD - 2022-09...f0594c9c-55ef-49f6-9591-d27d12cc0afb
49Spacecraft project with Element CRUD - 2022-09...f8161e56-586e-44ae-ab12-53ad1fc972de
5018-Use Case Fri Sep 09 17:37:44 EDT 2022ff0dfcc3-cf11-4d4f-961a-ae42326f6b12
\n", - "
" - ], - "text/plain": [ - " Project Name \\\n", - "0 Spacecraft project with Element CRUD - 2022-09... \n", - "1 17b-Sequence-Modeling Fri Sep 09 17:37:26 EDT ... \n", - "2 3a-Function-based Behavior-2 Fri Sep 09 17:26:... \n", - "3 10c-Fuel Economy Analysis Fri Sep 09 17:30:43 ... \n", - "4 PartTest Fri Sep 09 17:22:13 EDT 2022 \n", - "5 15_05-Unification of Expression and Constraint... \n", - "6 15_19-Materials with Properties Fri Sep 09 17:... \n", - "7 Spacecraft project with branches and tags - 20... \n", - "8 3a-Function-based Behavior-1 Wed Sep 21 11:44:... \n", - "9 14b-Language Extensions Fri Sep 09 17:35:06 ED... \n", - "10 13b-Safety and Security Features Element Group... \n", - "11 Spacecraft project with Element CRUD - 2022-09... \n", - "12 3a-Function-based Behavior-3 Fri Sep 09 17:26:... \n", - "13 12a-Dependency Fri Sep 09 17:32:29 EDT 2022 \n", - "14 4a-Functional Allocation Wed Sep 21 11:45:43 E... \n", - "15 7b-Variant Configurations Fri Sep 09 17:28:59 ... \n", - "16 1c-Parts Tree Redefinition Wed Sep 21 11:43:30... \n", - "17 17a-Sequence-Modeling Fri Sep 09 17:37:07 EDT ... \n", - "18 13a-Model Containment Fri Sep 09 17:33:03 EDT ... \n", - "19 Spacecraft project with Element CRUD - 2022-09... \n", - "20 11b-Safety and Security Feature Views Fri Sep ... \n", - "21 1c-Parts Tree Redefinition Fri Sep 09 17:25:05... \n", - "22 2a-Parts Interconnection Wed Sep 21 11:43:57 E... \n", - "23 14a-Language Extensions Fri Sep 09 17:34:49 ED... \n", - "24 6-Individual and Snapshots Fri Sep 09 17:28:35... \n", - "25 PartTest Fri Sep 09 17:21:50 EDT 2022 \n", - "26 11a-View-Viewpoint Fri Sep 09 17:31:42 EDT 2022 \n", - "27 13b-Safety and Security Features Element Group... \n", - "28 Spacecraft project with branches and tags - 20... \n", - "29 3a-Function-based Behavior-1 Fri Sep 09 17:26:... \n", - "30 sysml Fri Sep 16 14:36:21 EDT 2022 \n", - "31 9-Verification-simplified Fri Sep 09 17:29:54 ... \n", - "32 10b-Trade-off Among Alternative Configurations... \n", - "33 12b-Allocation Fri Sep 09 17:32:45 EDT 2022 \n", - "34 Spacecraft project with Element CRUD - 2022-09... \n", - "35 8-Requirements Fri Sep 09 17:29:27 EDT 2022 \n", - "36 15_10-Primitive Data Types Fri Sep 09 17:36:20... \n", - "37 sysml Fri Sep 16 14:49:18 EDT 2022 \n", - "38 2a-Parts Interconnection Fri Sep 09 17:23:32 E... \n", - "39 5-State-based Behavior-1 Fri Sep 09 17:27:37 E... \n", - "40 2a-Parts Interconnection Fri Sep 09 17:25:35 E... \n", - "41 10d-Dynamics Analysis Fri Sep 09 17:31:13 EDT ... \n", - "42 13b-Safety and Security Features Element Group... \n", - "43 5-State-based Behavior-1a Fri Sep 09 17:28:06 ... \n", - "44 14c-Language Extensions Fri Sep 09 17:35:25 ED... \n", - "45 3a-Function-based Behavior-2 Wed Sep 21 11:44:... \n", - "46 3a-Function-based Behavior-3 Wed Sep 21 11:45:... \n", - "47 4a-Functional Allocation Fri Sep 09 17:27:13 E... \n", - "48 Spacecraft project with Element CRUD - 2022-09... \n", - "49 Spacecraft project with Element CRUD - 2022-09... \n", - "50 18-Use Case Fri Sep 09 17:37:44 EDT 2022 \n", - "\n", - " Project ID \n", - "0 0659c128-afd5-42a1-912b-962068f1f053 \n", - "1 0f7045bd-9a1c-4b54-90d9-775c0f642e1b \n", - "2 128710cd-978f-4c6f-93ac-8afbbd194185 \n", - "3 2909d482-a659-4307-9803-bdfcbe0a7989 \n", - "4 2a2a4d7d-cd9e-41ec-bec0-2bf6fcea6767 \n", - "5 39dcf070-668c-4711-a231-c2640b9f7f88 \n", - "6 3bd937e0-ab2e-47a6-8f66-0458df9f29de \n", - "7 3c293f80-a0aa-46a5-8cde-25a31ec697e0 \n", - "8 413e8b6e-a4c7-483e-a212-eb25e7c47aff \n", - "9 431cd401-010c-401f-9101-115240312d24 \n", - "10 46b226ce-8519-42de-96b4-07ff1045d0dd \n", - "11 4853c38b-85c5-40e5-9e83-b69c2e73415a \n", - "12 48f9a623-2451-4150-8b98-58e3b3c515cd \n", - "13 49a60e69-b509-4191-b1c3-240de628110b \n", - "14 4f6c6172-ab0c-4572-b549-6b7da7e9e5fb \n", - "15 59c86238-ef81-434e-a389-5393312ba0d7 \n", - "16 5b5474b6-68b8-43bf-b0f6-7d455bffa63d \n", - "17 653c5173-770d-4ea6-90dc-c173d049258c \n", - "18 6699f5e0-403b-414a-87c9-46671e702fab \n", - "19 77dd61e8-456a-425b-ac05-385bf6c20161 \n", - "20 84f30a8f-f839-4a71-aee9-dff2a2d28dbf \n", - "21 85d874ae-1f68-4949-9b16-378f1cbc477e \n", - "22 887e0281-066f-4667-a67b-d50e886d031c \n", - "23 8f0bc3b3-a580-40fd-b99b-0e8865984c4f \n", - "24 913dab3f-4d5d-482d-9238-7491aead3e1a \n", - "25 91b2be09-16de-4d35-87a4-589f3274ce55 \n", - "26 91fd6db5-4cfa-4970-b115-05010053ec72 \n", - "27 95bfcea3-8ed7-4bd4-9e98-3d6ed311091e \n", - "28 978d0199-4e44-4090-8cb6-4253fd79e315 \n", - "29 9da34b47-38d0-4630-bcb4-c387d5fac1da \n", - "30 9f7efdc8-e6d1-4cf4-a132-532e2f136e7f \n", - "31 a9a02019-b810-4fcb-9a9c-5cad061db29f \n", - "32 ada6b9b6-3534-43b3-a567-f97092ac26f1 \n", - "33 b4c01f6d-8173-4d43-abd1-596bdb89d6d4 \n", - "34 b67ebee6-b55e-4088-b059-c2f102989ac2 \n", - "35 b6a3450b-8624-45c2-8dd9-68d301a439fe \n", - "36 bb65a453-67bc-4e6c-92c7-29734c80bab1 \n", - "37 c60d5b4d-5f36-4083-ae1a-e61ed2be0e78 \n", - "38 c64923aa-79f4-419c-b983-6244fee741d6 \n", - "39 c6b1d4d6-a66e-4097-8752-5307ecd9ebaf \n", - "40 cb4e467e-772b-4054-849e-26e4b0e1e0c0 \n", - "41 cceed28a-64fb-4401-81da-afcadd96d1d6 \n", - "42 d4c21bc8-6778-4a97-b389-48b1e7b23260 \n", - "43 d63b8882-f41e-40ef-a4a2-cf74fa47f6dc \n", - "44 da4e65b6-460d-447b-8cf9-56a3ad44e514 \n", - "45 e27d992a-91e6-450a-b6f6-b79196ebeeb9 \n", - "46 e4966bc8-bd9f-4c63-a43d-2c21fe512d31 \n", - "47 e7090e9d-74f0-4b63-a4a6-6dd8647b5bdd \n", - "48 f0594c9c-55ef-49f6-9591-d27d12cc0afb \n", - "49 f8161e56-586e-44ae-ab12-53ad1fc972de \n", - "50 ff0dfcc3-cf11-4d4f-961a-ae42326f6b12 " - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "projects_url = f\"{host}/projects\" \n", - "projects_response = requests.get(projects_url)\n", - "\n", - "if projects_response.status_code == 200:\n", - " projects = projects_response.json()\n", - " \n", - " df = pd.DataFrame({'Project Name':[], 'Project ID':[]})\n", - " for p in projects:\n", - " df = pd.concat([df, pd.DataFrame({'Project Name':[p['name']], 'Project ID':[p['@id']]})], ignore_index=True)\n", - " display(df)" - ] - }, - { - "cell_type": "markdown", - "id": "d815e4fe", - "metadata": {}, - "source": [ - "# Define a function to recursively iterate over feature members \n", - "## Recursive graph traversal using FeatureMembership relations" - ] - }, - { - "cell_type": "code", - "execution_count": 19, - "id": "24ec6146", - "metadata": {}, - "outputs": [], - "source": [ - "def get_member_features(project_id, commit_id, element_id, member_type, indent):\n", - " \n", - " # Fetch the element\n", - " element_url = f\"{host}/projects/{project_id}/commits/{commit_id}/elements/{element_id}\" \n", - " response = requests.get(element_url)\n", - " \n", - " element_data = response.json()\n", - " element_name = element_data['name']\n", - " element_id = element_data['@id']\n", - " element_type = element_data ['@type']\n", - " \n", - " if element_type == member_type:\n", - " print(f\"{indent} - {element_name} (id = {element_id}, type = {element_type})\")\n", - " # Feature memberships\n", - " element_features = element_data['feature']\n", - " if len(element_features) > 0:\n", - " for feature in element_features:\n", - " get_member_features(project_id, commit_id, feature['@id'], member_type, indent + \" \")\n" - ] - }, - { - "cell_type": "markdown", - "id": "2aff54c2", - "metadata": {}, - "source": [ - "# Parts tree navigation" - ] - }, - { - "cell_type": "code", - "execution_count": 20, - "id": "482ddfe4", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[{'@id': '3fed527b-cd9f-4e7c-a0f3-360b8f02085d',\n", - " '@type': 'Commit',\n", - " 'owningProject': {'@id': '85d874ae-1f68-4949-9b16-378f1cbc477e'},\n", - " 'previousCommit': None,\n", - " 'timestamp': '2022-09-09T17:24:55.229447-04:00'}]\n" - ] - } - ], - "source": [ - "parts_tree_project_id = '85d874ae-1f68-4949-9b16-378f1cbc477e'\n", - "parts_tree_commit_id = ''\n", - "\n", - "commits_url = f\"{host}/projects/{parts_tree_project_id}/commits\" \n", - "commits_response = requests.get(commits_url)\n", - "if commits_response.status_code == 200:\n", - " commits = commits_response.json()\n", - " pprint(commits)\n", - " parts_tree_commit_id = commits[0]['@id']\n" - ] - }, - { - "cell_type": "markdown", - "id": "487c0624", - "metadata": {}, - "source": [ - "## Query to find vehicle1" - ] - }, - { - "cell_type": "code", - "execution_count": 21, - "id": "3d724e27", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[{'@id': 'b4f3d464-1319-45ee-a779-82d1b2252c3a',\n", - " '@type': 'PartUsage',\n", - " 'name': 'vehicle1',\n", - " 'owner': {'@id': 'ff4e8415-ed73-491d-8b7a-797caadcdf54'}}]\n" - ] - } - ], - "source": [ - "# Query vehicle1 (PartUsage) in the \n", - "data = {\n", - " '@type':'Query',\n", - " 'select': ['name','@id','@type','owner'],\n", - " 'where': {\n", - " '@type': 'CompositeConstraint',\n", - " 'operator': 'and',\n", - " 'constraint': [\n", - " {\n", - " '@type': 'PrimitiveConstraint',\n", - " 'inverse': False,\n", - " 'operator': '=',\n", - " 'property': 'name',\n", - " 'value': 'vehicle1'\n", - " },\n", - " {\n", - " '@type': 'PrimitiveConstraint',\n", - " 'inverse': False,\n", - " 'operator': '=',\n", - " 'property': '@type',\n", - " 'value': 'PartUsage'\n", - " }\n", - " ]\n", - " }\n", - "}\n", - "\n", - "payload = json.dumps(data)\n", - "\n", - "vehicle1_id = ''\n", - "query_url = f\"{host}/projects/{parts_tree_project_id}/query-results\" \n", - "\n", - "query_response = requests.post(query_url, json=data)\n", - "\n", - "if query_response.status_code == 200:\n", - " query_response_json = query_response.json()\n", - " pprint(query_response_json)\n", - " vehicle1_id = query_response_json[0]['@id']" - ] - }, - { - "cell_type": "markdown", - "id": "0092a660", - "metadata": {}, - "source": [ - "## Parts tree for vehicle1 (recursive FeatureMembership relation navigation)" - ] - }, - { - "cell_type": "code", - "execution_count": 22, - "id": "406504bf", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - " - vehicle1 (id = b4f3d464-1319-45ee-a779-82d1b2252c3a, type = PartUsage)\n", - " - frontAxleAssembly (id = b7011eae-20bd-4cb6-b3e4-ead27a509f47, type = PartUsage)\n", - " - frontAxle (id = 0974ffce-137c-443b-a187-c6a049d2f2b3, type = PartUsage)\n", - " - frontWheel (id = 08e6ee25-0118-4b14-b4f6-7e728401fad3, type = PartUsage)\n", - " - rearAxleAssembly (id = 62e9d93a-aa5a-4a3c-ac22-22cea9f2db3a, type = PartUsage)\n", - " - rearAxle (id = b72abb4c-11a3-428a-85ea-a9457f429989, type = PartUsage)\n", - " - rearWheel (id = 9d35829f-eb02-46b1-a284-cab4c77ad529, type = PartUsage)\n" - ] - } - ], - "source": [ - "get_member_features(parts_tree_project_id,parts_tree_commit_id,vehicle1_id,'PartUsage',\" \")" - ] - }, - { - "cell_type": "markdown", - "id": "eba630b9", - "metadata": {}, - "source": [ - "## Query to find vehicle1_c1" - ] - }, - { - "cell_type": "code", - "execution_count": 23, - "id": "5c13178f", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[{'@id': 'c0b96198-597c-489f-a026-bdac2c13444b',\n", - " '@type': 'PartUsage',\n", - " 'name': 'vehicle1_c1',\n", - " 'owner': {'@id': 'ff4e8415-ed73-491d-8b7a-797caadcdf54'}}]\n" - ] - } - ], - "source": [ - "\n", - "data = {\n", - " '@type':'Query',\n", - " 'select': ['name','@id','@type','owner'],\n", - " 'where': {\n", - " '@type': 'CompositeConstraint',\n", - " 'operator': 'and',\n", - " 'constraint': [\n", - " {\n", - " '@type': 'PrimitiveConstraint',\n", - " 'inverse': False,\n", - " 'operator': '=',\n", - " 'property': 'name',\n", - " 'value': 'vehicle1_c1'\n", - " },\n", - " {\n", - " '@type': 'PrimitiveConstraint',\n", - " 'inverse': False,\n", - " 'operator': '=',\n", - " 'property': '@type',\n", - " 'value': 'PartUsage'\n", - " }\n", - " ]\n", - " }\n", - "}\n", - "payload = json.dumps(data)\n", - "\n", - "vehicle1_c1_id = ''\n", - "query_url = f\"{host}/projects/{parts_tree_project_id}/query-results\" \n", - "\n", - "query_response = requests.post(query_url, json=data)\n", - "\n", - "if query_response.status_code == 200:\n", - " query_response_json = query_response.json()\n", - " pprint(query_response_json)\n", - " vehicle1_c1_id = query_response_json[0]['@id']" - ] - }, - { - "cell_type": "markdown", - "id": "10b45dd4", - "metadata": {}, - "source": [ - "## Parts tree for vehicle1_c1 (recursive FeatureMembership relation navigation)" - ] - }, - { - "cell_type": "code", - "execution_count": 24, - "id": "1dbfe8f6", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - " - vehicle1_c1 (id = c0b96198-597c-489f-a026-bdac2c13444b, type = PartUsage)\n", - " - frontAxleAssembly_c1 (id = c85cf569-e305-4c9d-8503-f65aaa11e56c, type = PartUsage)\n", - " - frontAxle_c1 (id = 6ae2d0f5-3ad5-4413-8939-e1488d520644, type = PartUsage)\n", - " - frontWheel_1 (id = 6da39a5b-74f4-4bb4-b56a-3ec60a455e69, type = PartUsage)\n", - " - frontWheel_2 (id = d151d807-fe16-40e7-833b-d0985470aa88, type = PartUsage)\n", - " - frontWheel (id = 08e6ee25-0118-4b14-b4f6-7e728401fad3, type = PartUsage)\n", - " - rearAxleAssembly_c1 (id = 8f4829e8-49af-4802-9435-44145e61b533, type = PartUsage)\n", - " - rearAxle_c1 (id = 92a3c5e6-1652-4365-8383-28b79958c974, type = PartUsage)\n", - " - rearWheel_1 (id = 21c018fe-a614-4089-9ee8-348af9f550c0, type = PartUsage)\n", - " - rearWheel_2 (id = 090eafcd-7970-404f-8c81-d36403d558ca, type = PartUsage)\n", - " - rearWheel (id = 9d35829f-eb02-46b1-a284-cab4c77ad529, type = PartUsage)\n" - ] - } - ], - "source": [ - "get_member_features(parts_tree_project_id,parts_tree_commit_id,vehicle1_c1_id,'PartUsage',\" \")" - ] - }, - { - "cell_type": "markdown", - "id": "b7319e39", - "metadata": {}, - "source": [ - "# Behavior Tree Navigation" - ] - }, - { - "cell_type": "code", - "execution_count": 25, - "id": "c9c96cbe", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[{'@id': 'f934f9e3-8686-4e81-9918-66ab72394e8f',\n", - " '@type': 'Commit',\n", - " 'owningProject': {'@id': '128710cd-978f-4c6f-93ac-8afbbd194185'},\n", - " 'previousCommit': None,\n", - " 'timestamp': '2022-09-09T17:26:11.688211-04:00'}]\n" - ] - } - ], - "source": [ - "behavior_project_id = '128710cd-978f-4c6f-93ac-8afbbd194185'\n", - "behavior_project_commit_id = ''\n", - "\n", - "commits_url = f\"{host}/projects/{behavior_project_id}/commits\" \n", - "commits_response = requests.get(commits_url)\n", - "if commits_response.status_code == 200:\n", - " commits = commits_response.json()\n", - " pprint(commits)\n", - " behavior_project_commit_id = commits[0]['@id']" - ] - }, - { - "cell_type": "markdown", - "id": "5d7c309e", - "metadata": {}, - "source": [ - "## Query to find Provide Power behavior (ActionUsage)" - ] - }, - { - "cell_type": "code", - "execution_count": 26, - "id": "d5a63113", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[{'@id': '2619c029-185a-456f-9ea9-12b94171e1b1',\n", - " '@type': 'ActionUsage',\n", - " 'name': 'provide power',\n", - " 'owner': {'@id': '9a44fd3f-9173-418a-8f61-f01ec86a2fd7'}}]\n" - ] - } - ], - "source": [ - "data = {\n", - " '@type':'Query',\n", - " 'select': ['name','@id','@type','owner'],\n", - " 'where': {\n", - " '@type': 'CompositeConstraint',\n", - " 'operator': 'and',\n", - " 'constraint': [\n", - " {\n", - " '@type': 'PrimitiveConstraint',\n", - " 'inverse': False,\n", - " 'operator': '=',\n", - " 'property': 'name',\n", - " 'value': 'provide power'\n", - " },\n", - " {\n", - " '@type': 'PrimitiveConstraint',\n", - " 'inverse': False,\n", - " 'operator': '=',\n", - " 'property': '@type',\n", - " 'value': 'ActionUsage'\n", - " }\n", - " ]\n", - " }\n", - "}\n", - "\n", - "payload = json.dumps(data)\n", - "\n", - "provide_power_id = ''\n", - "query_url = f\"{host}/projects/{behavior_project_id}/query-results\" \n", - "\n", - "query_response = requests.post(query_url, json=data)\n", - "\n", - "if query_response.status_code == 200:\n", - " query_response_json = query_response.json()\n", - " pprint(query_response_json)\n", - " provide_power_id = query_response_json[0]['@id']" - ] - }, - { - "cell_type": "markdown", - "id": "10018cd0", - "metadata": {}, - "source": [ - "## Behavior tree for vehicle1 (recursive FeatureMembership relation navigation)" - ] - }, - { - "cell_type": "code", - "execution_count": 27, - "id": "91193b07", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - " - provide power (id = 2619c029-185a-456f-9ea9-12b94171e1b1, type = ActionUsage)\n", - " - generate torque (id = 5a353b3d-6b09-40b4-b86c-24a2eb5bbccc, type = ActionUsage)\n", - " - amplify torque (id = aa7783bb-641c-4860-9f5e-399b693bc918, type = ActionUsage)\n", - " - transfer torque (id = 4abcd2c6-a7a6-4b3e-9e07-19faea837303, type = ActionUsage)\n", - " - distribute torque (id = 72cf307d-af84-477a-8cb5-34f58b3d1952, type = ActionUsage)\n", - " - start (id = ac7a1de9-82ed-4e08-bcc5-361ec1aa5365, type = ActionUsage)\n" - ] - } - ], - "source": [ - "get_member_features(behavior_project_id, behavior_project_commit_id, provide_power_id,\"ActionUsage\",\" \")" - ] - }, - { - "cell_type": "markdown", - "id": "a07cc348", - "metadata": {}, - "source": [ - "# Requirement tree for vehicle" - ] - }, - { - "cell_type": "code", - "execution_count": 28, - "id": "89840b26", - "metadata": {}, - "outputs": [], - "source": [ - "simple_vehicle_model_project = '8b377f03-9f29-4ae9-b60b-d266dc4a8180'\n", - "vehicle_commit = '10f84681-3d17-43be-b59a-89c480d1abeb'\n", - "host = \"http://sysml2-sst.intercax.com:9000\"" - ] - }, - { - "cell_type": "code", - "execution_count": 29, - "id": "5fa94a05-c45e-4d93-a145-7e5967a87cd9", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[{'@id': 'e397abe0-85b1-46df-87b8-69128a583c7c',\n", - " '@type': 'RequirementUsage',\n", - " 'name': 'vehicleSpecification',\n", - " 'owner': None}]\n" - ] - } - ], - "source": [ - "data = {\n", - " '@type':'Query',\n", - " 'select': ['name','@id','@type','owner'],\n", - " 'where': {\n", - " '@type': 'CompositeConstraint',\n", - " 'operator': 'and',\n", - " 'constraint': [\n", - " {\n", - " '@type': 'PrimitiveConstraint',\n", - " 'inverse': False,\n", - " 'operator': '=',\n", - " 'property': 'name',\n", - " 'value': 'vehicleSpecification'\n", - " },\n", - " {\n", - " '@type': 'PrimitiveConstraint',\n", - " 'inverse': False,\n", - " 'operator': '=',\n", - " 'property': '@type',\n", - " 'value': 'RequirementUsage'\n", - " }\n", - " ]\n", - " }\n", - "}\n", - "\n", - "payload = json.dumps(data)\n", - "\n", - "vehicle_specification_id = ''\n", - "query_url = f\"{host}/projects/{simple_vehicle_model_project}/query-results\" \n", - "\n", - "query_response = requests.post(query_url, json=data)\n", - "\n", - "if query_response.status_code == 200:\n", - " query_response_json = query_response.json()\n", - " pprint(query_response_json)\n", - " vehicle_specification_id = query_response_json[0]['@id']" - ] - }, - { - "cell_type": "code", - "execution_count": 30, - "id": "bd2276aa", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - " - vehicleSpecification (id = e397abe0-85b1-46df-87b8-69128a583c7c, type = RequirementUsage)\n", - " - vehicleMassRequirement (id = 9e144d15-af6c-4113-861f-29376923ee94, type = RequirementUsage)\n", - " - vehicleFuelEconomyRequirements (id = 11aa2bdc-43f9-4576-aae5-7f8d679a0d8f, type = RequirementUsage)\n", - " - cityFuelEconomyRequirement (id = 0e37be64-b3bd-4f24-b5c5-156b17eb0c90, type = RequirementUsage)\n", - " - highwayFuelEconomyRequirement (id = 8163dc3d-7145-470d-80f4-64dd67317a43, type = RequirementUsage)\n" - ] - } - ], - "source": [ - "get_member_features(simple_vehicle_model_project, vehicle_commit, vehicle_specification_id,\"RequirementUsage\",\" \")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "ee934c22-4fb4-4409-804d-91010d3cebab", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "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.8.13" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -}