├── .gitignore ├── README.md ├── Req_Str_Beh_Decomposition_Recipe.ipynb ├── Element_Owned_Elements.ipynb ├── Req_Str_Beh_Decomposition_Recipe_Spacecraft_Example.ipynb ├── Queries.ipynb ├── Element_Create_Update_Delete.ipynb └── Project_Commit_Branch_Tag_Recipe.ipynb /.gitignore: -------------------------------------------------------------------------------- 1 | .ipynb_checkpoints 2 | .DS_Store -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SysML-v2-API-Cookbook 2 | 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). 3 | 4 | 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. 5 | 6 | ## Description of recipes 7 | 8 | ### Requirement, Structure, Behavior decomposition recipe 9 | 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. 10 | 11 | See the Jupyter notebook **Req_Str_Beh_Decomposition_Recipe.ipynb** for details. 12 | 13 | ### Requirement, Structure, Behavior decomposition recipe for Spacecraft example 14 | This notebook shows the use of the Requirement, Structure, Behavior decomposition recipe (above) for a Spacecraft example. 15 | 16 | See the Jupyter notebook **Req_Str_Beh_Decomposition_Recipe_Spacecraft_Example.ipynb** for details. 17 | 18 | ### Project, Commit, Branch, and Tag recipe 19 | 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. 20 | 21 | See the Jupyter notebook **Project_Commit_Branch_Tag_Recipe.ipynb** for details. 22 | 23 | ### Element Create, Update, Delete recipe 24 | This recipe shows patterns and examples for creating, updating, and deleting elements in project commits. 25 | 26 | See the Jupyter notebook **Element_Create_Update_Delete.ipynb** for details. 27 | 28 | ### Element Owned Elements recipe 29 | This recipe shows patterns and examples to fetch the owned elements (immediate and recursive) for a given element in a given commit of a project. 30 | 31 | See the Jupyter notebook **Element_Owned_Elements.ipynb** for details. 32 | 33 | ### Queries recipe 34 | This recipe shows patterns and examples for formulating and executing queries in a project. Examples show queries with multiple constraints. 35 | 36 | See the Jupyter notebook **Queries.ipynb** for details. 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /Req_Str_Beh_Decomposition_Recipe.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "3ee4834f", 6 | "metadata": {}, 7 | "source": [ 8 | "# Initializing the SysML v2 API" 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": null, 14 | "id": "6b5fef59", 15 | "metadata": {}, 16 | "outputs": [], 17 | "source": [ 18 | "from __future__ import print_function\n", 19 | "\n", 20 | "import time\n", 21 | "import requests\n", 22 | "from pprint import pprint\n", 23 | "import pandas as pd\n", 24 | "import json\n", 25 | "\n", 26 | "#host = \"\"\n", 27 | "host = \"Specify the URL of the SysML v2 API and Service Repository\"" 28 | ] 29 | }, 30 | { 31 | "cell_type": "markdown", 32 | "id": "04c1ff93", 33 | "metadata": {}, 34 | "source": [ 35 | "# Get projects" 36 | ] 37 | }, 38 | { 39 | "cell_type": "code", 40 | "execution_count": null, 41 | "id": "78788ed9", 42 | "metadata": {}, 43 | "outputs": [], 44 | "source": [ 45 | "projects_url = f\"{host}/projects\" \n", 46 | "projects_response = requests.get(projects_url)\n", 47 | "\n", 48 | "if projects_response.status_code == 200:\n", 49 | " projects = projects_response.json()\n", 50 | " \n", 51 | " df = pd.DataFrame({'Project Name':[], 'Project ID':[]})\n", 52 | " for p in projects:\n", 53 | " df = pd.concat([df, pd.DataFrame({'Project Name':[p['name']], 'Project ID':[p['@id']]})], ignore_index=True)\n", 54 | " display(df)" 55 | ] 56 | }, 57 | { 58 | "cell_type": "markdown", 59 | "id": "d815e4fe", 60 | "metadata": {}, 61 | "source": [ 62 | "# Define a function to recursively iterate over feature members \n", 63 | "## Recursive graph traversal using FeatureMembership relations" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": null, 69 | "id": "24ec6146", 70 | "metadata": {}, 71 | "outputs": [], 72 | "source": [ 73 | "def get_member_features(project_id, commit_id, element_id, member_type, indent):\n", 74 | " \n", 75 | " # Fetch the element\n", 76 | " element_url = f\"{host}/projects/{project_id}/commits/{commit_id}/elements/{element_id}\" \n", 77 | " response = requests.get(element_url)\n", 78 | " \n", 79 | " element_data = response.json()\n", 80 | " element_name = element_data['name']\n", 81 | " element_id = element_data['@id']\n", 82 | " element_type = element_data ['@type']\n", 83 | " \n", 84 | " if element_type == member_type:\n", 85 | " print(f\"{indent} - {element_name} (id = {element_id}, type = {element_type})\")\n", 86 | " # Feature memberships\n", 87 | " element_features = element_data['feature']\n", 88 | " if len(element_features) > 0:\n", 89 | " for feature in element_features:\n", 90 | " get_member_features(project_id, commit_id, feature['@id'], member_type, indent + \" \")\n" 91 | ] 92 | }, 93 | { 94 | "cell_type": "markdown", 95 | "id": "2aff54c2", 96 | "metadata": {}, 97 | "source": [ 98 | "# Parts tree navigation" 99 | ] 100 | }, 101 | { 102 | "cell_type": "code", 103 | "execution_count": null, 104 | "id": "482ddfe4", 105 | "metadata": {}, 106 | "outputs": [], 107 | "source": [ 108 | "parts_tree_project_id = '85d874ae-1f68-4949-9b16-378f1cbc477e'\n", 109 | "parts_tree_commit_id = ''\n", 110 | "\n", 111 | "commits_url = f\"{host}/projects/{parts_tree_project_id}/commits\" \n", 112 | "commits_response = requests.get(commits_url)\n", 113 | "if commits_response.status_code == 200:\n", 114 | " commits = commits_response.json()\n", 115 | " pprint(commits)\n", 116 | " parts_tree_commit_id = commits[0]['@id']\n" 117 | ] 118 | }, 119 | { 120 | "cell_type": "markdown", 121 | "id": "487c0624", 122 | "metadata": {}, 123 | "source": [ 124 | "## Query to find vehicle1" 125 | ] 126 | }, 127 | { 128 | "cell_type": "code", 129 | "execution_count": null, 130 | "id": "3d724e27", 131 | "metadata": {}, 132 | "outputs": [], 133 | "source": [ 134 | "# Query vehicle1 (PartUsage) in the \n", 135 | "data = {\n", 136 | " '@type':'Query',\n", 137 | " 'select': ['name','@id','@type','owner'],\n", 138 | " 'where': {\n", 139 | " '@type': 'CompositeConstraint',\n", 140 | " 'operator': 'and',\n", 141 | " 'constraint': [\n", 142 | " {\n", 143 | " '@type': 'PrimitiveConstraint',\n", 144 | " 'inverse': False,\n", 145 | " 'operator': '=',\n", 146 | " 'property': 'name',\n", 147 | " 'value': 'vehicle1'\n", 148 | " },\n", 149 | " {\n", 150 | " '@type': 'PrimitiveConstraint',\n", 151 | " 'inverse': False,\n", 152 | " 'operator': '=',\n", 153 | " 'property': '@type',\n", 154 | " 'value': 'PartUsage'\n", 155 | " }\n", 156 | " ]\n", 157 | " }\n", 158 | "}\n", 159 | "\n", 160 | "payload = json.dumps(data)\n", 161 | "\n", 162 | "vehicle1_id = ''\n", 163 | "query_url = f\"{host}/projects/{parts_tree_project_id}/query-results\" \n", 164 | "\n", 165 | "query_response = requests.post(query_url, json=data)\n", 166 | "\n", 167 | "if query_response.status_code == 200:\n", 168 | " query_response_json = query_response.json()\n", 169 | " pprint(query_response_json)\n", 170 | " vehicle1_id = query_response_json[0]['@id']" 171 | ] 172 | }, 173 | { 174 | "cell_type": "markdown", 175 | "id": "0092a660", 176 | "metadata": {}, 177 | "source": [ 178 | "## Parts tree for vehicle1 (recursive FeatureMembership relation navigation)" 179 | ] 180 | }, 181 | { 182 | "cell_type": "code", 183 | "execution_count": null, 184 | "id": "406504bf", 185 | "metadata": {}, 186 | "outputs": [], 187 | "source": [ 188 | "get_member_features(parts_tree_project_id,parts_tree_commit_id,vehicle1_id,'PartUsage',\" \")" 189 | ] 190 | }, 191 | { 192 | "cell_type": "markdown", 193 | "id": "eba630b9", 194 | "metadata": {}, 195 | "source": [ 196 | "## Query to find vehicle1_c1" 197 | ] 198 | }, 199 | { 200 | "cell_type": "code", 201 | "execution_count": null, 202 | "id": "5c13178f", 203 | "metadata": {}, 204 | "outputs": [], 205 | "source": [ 206 | "\n", 207 | "data = {\n", 208 | " '@type':'Query',\n", 209 | " 'select': ['name','@id','@type','owner'],\n", 210 | " 'where': {\n", 211 | " '@type': 'CompositeConstraint',\n", 212 | " 'operator': 'and',\n", 213 | " 'constraint': [\n", 214 | " {\n", 215 | " '@type': 'PrimitiveConstraint',\n", 216 | " 'inverse': False,\n", 217 | " 'operator': '=',\n", 218 | " 'property': 'name',\n", 219 | " 'value': 'vehicle1_c1'\n", 220 | " },\n", 221 | " {\n", 222 | " '@type': 'PrimitiveConstraint',\n", 223 | " 'inverse': False,\n", 224 | " 'operator': '=',\n", 225 | " 'property': '@type',\n", 226 | " 'value': 'PartUsage'\n", 227 | " }\n", 228 | " ]\n", 229 | " }\n", 230 | "}\n", 231 | "payload = json.dumps(data)\n", 232 | "\n", 233 | "vehicle1_c1_id = ''\n", 234 | "query_url = f\"{host}/projects/{parts_tree_project_id}/query-results\" \n", 235 | "\n", 236 | "query_response = requests.post(query_url, json=data)\n", 237 | "\n", 238 | "if query_response.status_code == 200:\n", 239 | " query_response_json = query_response.json()\n", 240 | " pprint(query_response_json)\n", 241 | " vehicle1_c1_id = query_response_json[0]['@id']" 242 | ] 243 | }, 244 | { 245 | "cell_type": "markdown", 246 | "id": "10b45dd4", 247 | "metadata": {}, 248 | "source": [ 249 | "## Parts tree for vehicle1_c1 (recursive FeatureMembership relation navigation)" 250 | ] 251 | }, 252 | { 253 | "cell_type": "code", 254 | "execution_count": null, 255 | "id": "1dbfe8f6", 256 | "metadata": {}, 257 | "outputs": [], 258 | "source": [ 259 | "get_member_features(parts_tree_project_id,parts_tree_commit_id,vehicle1_c1_id,'PartUsage',\" \")" 260 | ] 261 | }, 262 | { 263 | "cell_type": "markdown", 264 | "id": "b7319e39", 265 | "metadata": {}, 266 | "source": [ 267 | "# Behavior Tree Navigation" 268 | ] 269 | }, 270 | { 271 | "cell_type": "code", 272 | "execution_count": null, 273 | "id": "c9c96cbe", 274 | "metadata": {}, 275 | "outputs": [], 276 | "source": [ 277 | "behavior_project_id = '128710cd-978f-4c6f-93ac-8afbbd194185'\n", 278 | "behavior_project_commit_id = ''\n", 279 | "\n", 280 | "commits_url = f\"{host}/projects/{behavior_project_id}/commits\" \n", 281 | "commits_response = requests.get(commits_url)\n", 282 | "if commits_response.status_code == 200:\n", 283 | " commits = commits_response.json()\n", 284 | " pprint(commits)\n", 285 | " behavior_project_commit_id = commits[0]['@id']" 286 | ] 287 | }, 288 | { 289 | "cell_type": "markdown", 290 | "id": "5d7c309e", 291 | "metadata": {}, 292 | "source": [ 293 | "## Query to find Provide Power behavior (ActionUsage)" 294 | ] 295 | }, 296 | { 297 | "cell_type": "code", 298 | "execution_count": null, 299 | "id": "d5a63113", 300 | "metadata": {}, 301 | "outputs": [], 302 | "source": [ 303 | "data = {\n", 304 | " '@type':'Query',\n", 305 | " 'select': ['name','@id','@type','owner'],\n", 306 | " 'where': {\n", 307 | " '@type': 'CompositeConstraint',\n", 308 | " 'operator': 'and',\n", 309 | " 'constraint': [\n", 310 | " {\n", 311 | " '@type': 'PrimitiveConstraint',\n", 312 | " 'inverse': False,\n", 313 | " 'operator': '=',\n", 314 | " 'property': 'name',\n", 315 | " 'value': 'provide power'\n", 316 | " },\n", 317 | " {\n", 318 | " '@type': 'PrimitiveConstraint',\n", 319 | " 'inverse': False,\n", 320 | " 'operator': '=',\n", 321 | " 'property': '@type',\n", 322 | " 'value': 'ActionUsage'\n", 323 | " }\n", 324 | " ]\n", 325 | " }\n", 326 | "}\n", 327 | "\n", 328 | "payload = json.dumps(data)\n", 329 | "\n", 330 | "provide_power_id = ''\n", 331 | "query_url = f\"{host}/projects/{behavior_project_id}/query-results\" \n", 332 | "\n", 333 | "query_response = requests.post(query_url, json=data)\n", 334 | "\n", 335 | "if query_response.status_code == 200:\n", 336 | " query_response_json = query_response.json()\n", 337 | " pprint(query_response_json)\n", 338 | " provide_power_id = query_response_json[0]['@id']" 339 | ] 340 | }, 341 | { 342 | "cell_type": "markdown", 343 | "id": "10018cd0", 344 | "metadata": {}, 345 | "source": [ 346 | "## Behavior tree for vehicle1 (recursive FeatureMembership relation navigation)" 347 | ] 348 | }, 349 | { 350 | "cell_type": "code", 351 | "execution_count": null, 352 | "id": "91193b07", 353 | "metadata": {}, 354 | "outputs": [], 355 | "source": [ 356 | "get_member_features(behavior_project_id, behavior_project_commit_id, provide_power_id,\"ActionUsage\",\" \")" 357 | ] 358 | }, 359 | { 360 | "cell_type": "markdown", 361 | "id": "a07cc348", 362 | "metadata": {}, 363 | "source": [ 364 | "# Requirement tree for vehicle" 365 | ] 366 | }, 367 | { 368 | "cell_type": "code", 369 | "execution_count": null, 370 | "id": "89840b26", 371 | "metadata": {}, 372 | "outputs": [], 373 | "source": [ 374 | "simple_vehicle_model_project = '8b377f03-9f29-4ae9-b60b-d266dc4a8180'\n", 375 | "vehicle_commit = '10f84681-3d17-43be-b59a-89c480d1abeb'" 376 | ] 377 | }, 378 | { 379 | "cell_type": "code", 380 | "execution_count": null, 381 | "id": "5fa94a05-c45e-4d93-a145-7e5967a87cd9", 382 | "metadata": {}, 383 | "outputs": [], 384 | "source": [ 385 | "data = {\n", 386 | " '@type':'Query',\n", 387 | " 'select': ['name','@id','@type','owner'],\n", 388 | " 'where': {\n", 389 | " '@type': 'CompositeConstraint',\n", 390 | " 'operator': 'and',\n", 391 | " 'constraint': [\n", 392 | " {\n", 393 | " '@type': 'PrimitiveConstraint',\n", 394 | " 'inverse': False,\n", 395 | " 'operator': '=',\n", 396 | " 'property': 'name',\n", 397 | " 'value': 'vehicleSpecification'\n", 398 | " },\n", 399 | " {\n", 400 | " '@type': 'PrimitiveConstraint',\n", 401 | " 'inverse': False,\n", 402 | " 'operator': '=',\n", 403 | " 'property': '@type',\n", 404 | " 'value': 'RequirementUsage'\n", 405 | " }\n", 406 | " ]\n", 407 | " }\n", 408 | "}\n", 409 | "\n", 410 | "payload = json.dumps(data)\n", 411 | "\n", 412 | "vehicle_specification_id = ''\n", 413 | "query_url = f\"{host}/projects/{simple_vehicle_model_project}/query-results\" \n", 414 | "\n", 415 | "query_response = requests.post(query_url, json=data)\n", 416 | "\n", 417 | "if query_response.status_code == 200:\n", 418 | " query_response_json = query_response.json()\n", 419 | " pprint(query_response_json)\n", 420 | " vehicle_specification_id = query_response_json[0]['@id']" 421 | ] 422 | }, 423 | { 424 | "cell_type": "code", 425 | "execution_count": null, 426 | "id": "bd2276aa", 427 | "metadata": {}, 428 | "outputs": [], 429 | "source": [ 430 | "get_member_features(simple_vehicle_model_project, vehicle_commit, vehicle_specification_id,\"RequirementUsage\",\" \")" 431 | ] 432 | } 433 | ], 434 | "metadata": { 435 | "kernelspec": { 436 | "display_name": "Python 3 (ipykernel)", 437 | "language": "python", 438 | "name": "python3" 439 | }, 440 | "language_info": { 441 | "codemirror_mode": { 442 | "name": "ipython", 443 | "version": 3 444 | }, 445 | "file_extension": ".py", 446 | "mimetype": "text/x-python", 447 | "name": "python", 448 | "nbconvert_exporter": "python", 449 | "pygments_lexer": "ipython3", 450 | "version": "3.8.16" 451 | } 452 | }, 453 | "nbformat": 4, 454 | "nbformat_minor": 5 455 | } 456 | -------------------------------------------------------------------------------- /Element_Owned_Elements.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "3ee4834f", 6 | "metadata": {}, 7 | "source": [ 8 | "# Initializing the SysML v2 API" 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 12, 14 | "id": "6b5fef59", 15 | "metadata": {}, 16 | "outputs": [], 17 | "source": [ 18 | "from __future__ import print_function\n", 19 | "\n", 20 | "import time\n", 21 | "import requests\n", 22 | "from pprint import pprint\n", 23 | "import pandas as pd\n", 24 | "import json\n", 25 | "\n", 26 | "#host = \"\n", 48 | "\n", 61 | "\n", 62 | " \n", 63 | " \n", 64 | " \n", 65 | " \n", 66 | " \n", 67 | " \n", 68 | " \n", 69 | " \n", 70 | " \n", 71 | " \n", 72 | " \n", 73 | " \n", 74 | " \n", 75 | " \n", 76 | " \n", 77 | " \n", 78 | " \n", 79 | " \n", 80 | " \n", 81 | " \n", 82 | " \n", 83 | " \n", 84 | " \n", 85 | " \n", 86 | " \n", 87 | " \n", 88 | " \n", 89 | " \n", 90 | " \n", 91 | " \n", 92 | " \n", 93 | " \n", 94 | " \n", 95 | " \n", 96 | " \n", 97 | " \n", 98 | " \n", 99 | " \n", 100 | " \n", 101 | " \n", 102 | " \n", 103 | " \n", 104 | " \n", 105 | " \n", 106 | " \n", 107 | " \n", 108 | " \n", 109 | " \n", 110 | " \n", 111 | " \n", 112 | " \n", 113 | " \n", 114 | " \n", 115 | " \n", 116 | " \n", 117 | " \n", 118 | " \n", 119 | " \n", 120 | " \n", 121 | " \n", 122 | " \n", 123 | " \n", 124 | " \n", 125 | " \n", 126 | "
Project NameProject ID
05-State-based Behavior-1a Fri Mar 10 17:37:14 ...024b1aa6-7489-4106-bf2d-498f441f3d56
113a-Model Containment Fri Mar 10 16:52:40 EST ...083a7c88-757c-41ff-89db-bc34a12b7794
2SimpleQuadcopter Fri Mar 10 17:54:58 EST 2023092dd68d-887f-4553-8ed2-05d405fb3a47
315_05-Unification of Expression and Constraint...098d5715-5dee-46d1-bdf8-ab96f1cc9fc6
47b-Variant Configurations Fri Mar 10 17:38:53 ...0b773e83-226e-4e20-ad89-5cbf1381b401
.........
8914b-Language Extensions Fri Mar 10 17:49:37 ES...f97580aa-646c-4895-a8cb-006cd7538bb6
9018-Use Case Fri Mar 10 17:00:37 EST 2023fa2bae57-4b5e-46e0-a0ef-ede2f121ea1f
91AnalysisAnnotation2 Wed Aug 30 04:36:12 UTC 2023fb6d4f79-04e0-4a73-b11a-09263b79d7c3
9211b-Safety and Security Feature Views Fri Mar ...fc58c0ac-58ea-4a19-90d7-c9e2f1c6da84
935-State-based Behavior-1 Fri Mar 10 17:36:13 E...fd341050-37b5-419e-be67-987ab836f668
\n", 127 | "

94 rows × 2 columns

\n", 128 | "" 129 | ], 130 | "text/plain": [ 131 | " Project Name \\\n", 132 | "0 5-State-based Behavior-1a Fri Mar 10 17:37:14 ... \n", 133 | "1 13a-Model Containment Fri Mar 10 16:52:40 EST ... \n", 134 | "2 SimpleQuadcopter Fri Mar 10 17:54:58 EST 2023 \n", 135 | "3 15_05-Unification of Expression and Constraint... \n", 136 | "4 7b-Variant Configurations Fri Mar 10 17:38:53 ... \n", 137 | ".. ... \n", 138 | "89 14b-Language Extensions Fri Mar 10 17:49:37 ES... \n", 139 | "90 18-Use Case Fri Mar 10 17:00:37 EST 2023 \n", 140 | "91 AnalysisAnnotation2 Wed Aug 30 04:36:12 UTC 2023 \n", 141 | "92 11b-Safety and Security Feature Views Fri Mar ... \n", 142 | "93 5-State-based Behavior-1 Fri Mar 10 17:36:13 E... \n", 143 | "\n", 144 | " Project ID \n", 145 | "0 024b1aa6-7489-4106-bf2d-498f441f3d56 \n", 146 | "1 083a7c88-757c-41ff-89db-bc34a12b7794 \n", 147 | "2 092dd68d-887f-4553-8ed2-05d405fb3a47 \n", 148 | "3 098d5715-5dee-46d1-bdf8-ab96f1cc9fc6 \n", 149 | "4 0b773e83-226e-4e20-ad89-5cbf1381b401 \n", 150 | ".. ... \n", 151 | "89 f97580aa-646c-4895-a8cb-006cd7538bb6 \n", 152 | "90 fa2bae57-4b5e-46e0-a0ef-ede2f121ea1f \n", 153 | "91 fb6d4f79-04e0-4a73-b11a-09263b79d7c3 \n", 154 | "92 fc58c0ac-58ea-4a19-90d7-c9e2f1c6da84 \n", 155 | "93 fd341050-37b5-419e-be67-987ab836f668 \n", 156 | "\n", 157 | "[94 rows x 2 columns]" 158 | ] 159 | }, 160 | "metadata": {}, 161 | "output_type": "display_data" 162 | } 163 | ], 164 | "source": [ 165 | "projects_url = f\"{host}/projects\" \n", 166 | "projects_response = requests.get(projects_url)\n", 167 | "\n", 168 | "if projects_response.status_code == 200:\n", 169 | " projects = projects_response.json()\n", 170 | " \n", 171 | " df = pd.DataFrame({'Project Name':[], 'Project ID':[]})\n", 172 | " for p in projects:\n", 173 | " df = pd.concat([df, pd.DataFrame({'Project Name':[p['name']], 'Project ID':[p['@id']]})], ignore_index=True)\n", 174 | " display(df)" 175 | ] 176 | }, 177 | { 178 | "cell_type": "markdown", 179 | "id": "d815e4fe", 180 | "metadata": {}, 181 | "source": [ 182 | "# Define functions to get owned elements - immediate and recursive\n", 183 | "## Define a function to get an element and print its name and type" 184 | ] 185 | }, 186 | { 187 | "cell_type": "code", 188 | "execution_count": 14, 189 | "id": "24e17d21-71ce-4573-960f-7533aca63337", 190 | "metadata": {}, 191 | "outputs": [], 192 | "source": [ 193 | "def get_element(project_id, commit_id, element_id, indent):\n", 194 | " # Fetch the element in the given commit of the given project\n", 195 | " element_url = f\"{host}/projects/{project_id}/commits/{commit_id}/elements/{element_id}\" \n", 196 | " response = requests.get(element_url)\n", 197 | " \n", 198 | " if response.status_code == 200:\n", 199 | " element_data = response.json()\n", 200 | " element_name_to_print = element_data['name'] if element_data['name'] else 'N/A'\n", 201 | " element_type = element_data ['@type']\n", 202 | " print(f\"{indent} - {element_name_to_print} ({element_type})\")\n", 203 | " return element_data\n", 204 | " else:\n", 205 | " return None" 206 | ] 207 | }, 208 | { 209 | "cell_type": "markdown", 210 | "id": "6a004c71-9feb-4b7b-926c-c9378efd8587", 211 | "metadata": {}, 212 | "source": [ 213 | "## Define a function to get owned elements (immediate) for a given element" 214 | ] 215 | }, 216 | { 217 | "cell_type": "code", 218 | "execution_count": 15, 219 | "id": "07216712-9c1c-4729-b940-cfa220bd8291", 220 | "metadata": {}, 221 | "outputs": [], 222 | "source": [ 223 | "# Returns direct / immediate owned elements for a given element in a given commit of a given project\n", 224 | "def get_owned_elements_immediate(project_id, commit_id, element_id, indent):\n", 225 | " \n", 226 | " # Fetch the element in the given commit of the given project\n", 227 | " element_data = get_element(project_id, commit_id, element_id, indent)\n", 228 | " \n", 229 | " if element_data:\n", 230 | " owned_elements = element_data['ownedElement']\n", 231 | " if len(owned_elements) > 0:\n", 232 | " for owned_element in owned_elements:\n", 233 | " get_element(project_id, commit_id, owned_element['@id'], indent + ' ')\n", 234 | " else:\n", 235 | " print(f\"Unable to fetch element with id '{element_id}' in commit '{commit_id}' of project '{project_id}'\")" 236 | ] 237 | }, 238 | { 239 | "cell_type": "markdown", 240 | "id": "65b74b05-7037-4382-b799-4df2cc6b0e03", 241 | "metadata": {}, 242 | "source": [ 243 | "## Define a function to get owned elements (recursive) for a given element" 244 | ] 245 | }, 246 | { 247 | "cell_type": "code", 248 | "execution_count": 16, 249 | "id": "f55e9cb8-f693-461a-aeaa-6416d40d7858", 250 | "metadata": {}, 251 | "outputs": [], 252 | "source": [ 253 | "# Returns directly / immediate owned elements for a given element in a given commit of a given project\n", 254 | "def get_owned_elements(project_id, commit_id, element_id, indent):\n", 255 | " \n", 256 | " # Fetch the element in the given commit of the given project\n", 257 | " element_data = get_element(project_id, commit_id, element_id, indent)\n", 258 | " \n", 259 | " if element_data:\n", 260 | " owned_elements = element_data['ownedElement']\n", 261 | " if len(owned_elements) > 0:\n", 262 | " for owned_element in owned_elements:\n", 263 | " get_owned_elements(project_id, commit_id, owned_element['@id'], indent+' ')\n", 264 | " else:\n", 265 | " print(f\"Unable to fetch element with id '{element_id}' in commit '{commit_id}' of project '{project_id}'\")" 266 | ] 267 | }, 268 | { 269 | "cell_type": "markdown", 270 | "id": "f020a542-14fe-4f12-9680-0faa51819cce", 271 | "metadata": {}, 272 | "source": [ 273 | "# Test for an example element in a given commit of a project" 274 | ] 275 | }, 276 | { 277 | "cell_type": "markdown", 278 | "id": "d718111e-1804-4a3c-b4cd-2719c8c78356", 279 | "metadata": {}, 280 | "source": [ 281 | "## Specify test project, commit, and element" 282 | ] 283 | }, 284 | { 285 | "cell_type": "code", 286 | "execution_count": 17, 287 | "id": "3c378cb5-e7bb-48c4-ac27-67fd893aebc5", 288 | "metadata": {}, 289 | "outputs": [], 290 | "source": [ 291 | "# Specify a project id\n", 292 | "test_project_id = 'b0c4aec0-8fce-4d82-af3d-f9abdd25af19' # 1c-Parts Tree Redifinition project\n", 293 | "\n", 294 | "# Specify a commit id in the project\n", 295 | "test_commit_id = 'caa160a2-e964-4545-bb3c-c7686d5d2979' # Latest commit in the main branch of the project\n", 296 | "\n", 297 | "# Specify an element id in the commit of that project\n", 298 | "test_element_id = '2a361c0a-a332-4910-a288-c8b4b35bd2ab' #1c-Parts Tree Redifinition package" 299 | ] 300 | }, 301 | { 302 | "cell_type": "markdown", 303 | "id": "27033be6-564c-4588-8404-0176b6d5f5df", 304 | "metadata": {}, 305 | "source": [ 306 | "## Get owned elements (immediate) for the given element in the given commit of the given project" 307 | ] 308 | }, 309 | { 310 | "cell_type": "code", 311 | "execution_count": 18, 312 | "id": "1ae44ade-1147-4057-b253-84d564e432b2", 313 | "metadata": {}, 314 | "outputs": [ 315 | { 316 | "name": "stdout", 317 | "output_type": "stream", 318 | "text": [ 319 | " - 1c-Parts Tree Redefinition (Package)\n", 320 | " - Definitions (Package)\n", 321 | " - Usages (Package)\n" 322 | ] 323 | } 324 | ], 325 | "source": [ 326 | "get_owned_elements_immediate(test_project_id, test_commit_id, test_element_id, '')" 327 | ] 328 | }, 329 | { 330 | "cell_type": "markdown", 331 | "id": "8adca507-c239-43c9-843a-ae77ff715c98", 332 | "metadata": {}, 333 | "source": [ 334 | "## Get owned elements (recursive) for the given element in the given commit of the given project" 335 | ] 336 | }, 337 | { 338 | "cell_type": "code", 339 | "execution_count": 19, 340 | "id": "0288f81f-7513-42e0-a0c7-a7e873d92e91", 341 | "metadata": {}, 342 | "outputs": [ 343 | { 344 | "name": "stdout", 345 | "output_type": "stream", 346 | "text": [ 347 | " - 1c-Parts Tree Redefinition (Package)\n", 348 | " - Definitions (Package)\n", 349 | " - Vehicle (PartDefinition)\n", 350 | " - mass (AttributeUsage)\n", 351 | " - N/A (Multiplicity)\n", 352 | " - AxleAssembly (PartDefinition)\n", 353 | " - Axle (PartDefinition)\n", 354 | " - mass (AttributeUsage)\n", 355 | " - N/A (Multiplicity)\n", 356 | " - FrontAxle (PartDefinition)\n", 357 | " - steeringAngle (AttributeUsage)\n", 358 | " - N/A (Multiplicity)\n", 359 | " - Wheel (PartDefinition)\n", 360 | " - Usages (Package)\n", 361 | " - vehicle1 (PartUsage)\n", 362 | " - mass (AttributeUsage)\n", 363 | " - N/A (OperatorExpression)\n", 364 | " - x (Feature)\n", 365 | " - N/A (LiteralInteger)\n", 366 | " - result (Feature)\n", 367 | " - y (Feature)\n", 368 | " - N/A (FeatureReferenceExpression)\n", 369 | " - result (Feature)\n", 370 | " - result (Feature)\n", 371 | " - N/A (Documentation)\n", 372 | " - frontAxleAssembly (PartUsage)\n", 373 | " - frontAxle (PartUsage)\n", 374 | " - N/A (Multiplicity)\n", 375 | " - frontWheel (PartUsage)\n", 376 | " - N/A (MultiplicityRange)\n", 377 | " - N/A (LiteralInteger)\n", 378 | " - result (Feature)\n", 379 | " - N/A (Multiplicity)\n", 380 | " - rearAxleAssembly (PartUsage)\n", 381 | " - rearAxle (PartUsage)\n", 382 | " - N/A (Multiplicity)\n", 383 | " - rearWheel (PartUsage)\n", 384 | " - N/A (MultiplicityRange)\n", 385 | " - N/A (LiteralInteger)\n", 386 | " - result (Feature)\n", 387 | " - N/A (Multiplicity)\n", 388 | " - vehicle1_c1 (PartUsage)\n", 389 | " - N/A (Comment)\n", 390 | " - mass (AttributeUsage)\n", 391 | " - N/A (OperatorExpression)\n", 392 | " - x (Feature)\n", 393 | " - N/A (LiteralInteger)\n", 394 | " - result (Feature)\n", 395 | " - y (Feature)\n", 396 | " - N/A (FeatureReferenceExpression)\n", 397 | " - result (Feature)\n", 398 | " - result (Feature)\n", 399 | " - N/A (Comment)\n", 400 | " - frontAxleAssembly_c1 (PartUsage)\n", 401 | " - frontAxle_c1 (PartUsage)\n", 402 | " - N/A (Comment)\n", 403 | " - N/A (Comment)\n", 404 | " - frontWheel_1 (PartUsage)\n", 405 | " - N/A (OperatorExpression)\n", 406 | " - seq (Feature)\n", 407 | " - N/A (FeatureReferenceExpression)\n", 408 | " - result (Feature)\n", 409 | " - index (Feature)\n", 410 | " - N/A (LiteralInteger)\n", 411 | " - result (Feature)\n", 412 | " - result (Feature)\n", 413 | " - frontWheel_2 (PartUsage)\n", 414 | " - N/A (OperatorExpression)\n", 415 | " - seq (Feature)\n", 416 | " - N/A (FeatureReferenceExpression)\n", 417 | " - result (Feature)\n", 418 | " - index (Feature)\n", 419 | " - N/A (LiteralInteger)\n", 420 | " - result (Feature)\n", 421 | " - result (Feature)\n", 422 | " - rearAxleAssembly_c1 (PartUsage)\n", 423 | " - rearAxle_c1 (PartUsage)\n", 424 | " - N/A (Comment)\n", 425 | " - rearWheel_1 (PartUsage)\n", 426 | " - N/A (OperatorExpression)\n", 427 | " - seq (Feature)\n", 428 | " - N/A (FeatureReferenceExpression)\n", 429 | " - result (Feature)\n", 430 | " - index (Feature)\n", 431 | " - N/A (LiteralInteger)\n", 432 | " - result (Feature)\n", 433 | " - result (Feature)\n", 434 | " - rearWheel_2 (PartUsage)\n", 435 | " - N/A (OperatorExpression)\n", 436 | " - seq (Feature)\n", 437 | " - N/A (FeatureReferenceExpression)\n", 438 | " - result (Feature)\n", 439 | " - index (Feature)\n", 440 | " - N/A (LiteralInteger)\n", 441 | " - result (Feature)\n", 442 | " - result (Feature)\n" 443 | ] 444 | } 445 | ], 446 | "source": [ 447 | "get_owned_elements(test_project_id, test_commit_id, test_element_id, '')" 448 | ] 449 | }, 450 | { 451 | "cell_type": "code", 452 | "execution_count": null, 453 | "id": "3aca7044-3063-47b6-8916-f4a2ef8e3105", 454 | "metadata": {}, 455 | "outputs": [], 456 | "source": [] 457 | } 458 | ], 459 | "metadata": { 460 | "kernelspec": { 461 | "display_name": "Python 3 (ipykernel)", 462 | "language": "python", 463 | "name": "python3" 464 | }, 465 | "language_info": { 466 | "codemirror_mode": { 467 | "name": "ipython", 468 | "version": 3 469 | }, 470 | "file_extension": ".py", 471 | "mimetype": "text/x-python", 472 | "name": "python", 473 | "nbconvert_exporter": "python", 474 | "pygments_lexer": "ipython3", 475 | "version": "3.8.16" 476 | } 477 | }, 478 | "nbformat": 4, 479 | "nbformat_minor": 5 480 | } 481 | -------------------------------------------------------------------------------- /Req_Str_Beh_Decomposition_Recipe_Spacecraft_Example.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "3ee4834f", 6 | "metadata": {}, 7 | "source": [ 8 | "# Initializing the SysML v2 API" 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 2, 14 | "id": "6b5fef59", 15 | "metadata": {}, 16 | "outputs": [], 17 | "source": [ 18 | "from __future__ import print_function\n", 19 | "\n", 20 | "import time\n", 21 | "import requests\n", 22 | "from pprint import pprint\n", 23 | "import pandas as pd\n", 24 | "import json\n", 25 | "\n", 26 | "#host = \"\"\n", 27 | "host = \"Specify the URL of the SysML v2 API and Service Repository\"" 28 | ] 29 | }, 30 | { 31 | "cell_type": "markdown", 32 | "id": "04c1ff93", 33 | "metadata": {}, 34 | "source": [ 35 | "# Get projects" 36 | ] 37 | }, 38 | { 39 | "cell_type": "code", 40 | "execution_count": 3, 41 | "id": "f7d5de82-fd62-4178-b1ef-5666393fa51f", 42 | "metadata": {}, 43 | "outputs": [ 44 | { 45 | "data": { 46 | "text/html": [ 47 | "
\n", 48 | "\n", 61 | "\n", 62 | " \n", 63 | " \n", 64 | " \n", 65 | " \n", 66 | " \n", 67 | " \n", 68 | " \n", 69 | " \n", 70 | " \n", 71 | " \n", 72 | " \n", 73 | " \n", 74 | " \n", 75 | " \n", 76 | " \n", 77 | " \n", 78 | " \n", 79 | " \n", 80 | " \n", 81 | " \n", 82 | " \n", 83 | " \n", 84 | " \n", 85 | " \n", 86 | " \n", 87 | " \n", 88 | " \n", 89 | " \n", 90 | " \n", 91 | " \n", 92 | " \n", 93 | " \n", 94 | " \n", 95 | " \n", 96 | " \n", 97 | " \n", 98 | " \n", 99 | " \n", 100 | " \n", 101 | " \n", 102 | " \n", 103 | " \n", 104 | " \n", 105 | " \n", 106 | " \n", 107 | " \n", 108 | " \n", 109 | " \n", 110 | " \n", 111 | " \n", 112 | " \n", 113 | " \n", 114 | " \n", 115 | " \n", 116 | " \n", 117 | " \n", 118 | " \n", 119 | " \n", 120 | " \n", 121 | " \n", 122 | " \n", 123 | " \n", 124 | " \n", 125 | " \n", 126 | "
Project NameProject ID
07b-Variant Configurations Mon Mar 13 17:54:29 ...000e9890-6935-43e6-a5d7-5d7cac601f4c
16-Individual and Snapshots Mon Mar 13 17:53:49...00bbbdc9-ea5e-4ab6-8198-94b4708639c4
211a-View-Viewpoint Mon Mar 13 17:59:02 EDT 2023021b60e9-1d9d-4c0e-af6b-8478b5928ccf
3VehiclePackage Fri May 05 12:28:40 UTC 20230768a0aa-9be9-457d-b693-12d45c68343c
4sleon_filtering_test Sat Jun 10 03:30:40 UTC 20230a8f97fe-a4c8-4806-bfa9-0d95e377761a
.........
71updated-test-project-19/05/2023 13:36:25f5d672c5-8a36-4a5a-8fcc-4eb7bfb703ff
7213b-Safety and Security Features Element Group...f9079904-26cf-437e-ab74-e1bd6b6013fb
73ts-usage-views Fri Jun 09 06:35:30 UTC 2023fcf4f295-8813-4737-ad97-f21267e3738b
74VehicleMasses_MapleConnector Mon Jan 22 20:32:...fee1b365-a84d-4de1-ba56-1d364f10478c
75BasicAJMExampleIF1 Fri Sep 22 14:00:29 UTC 2023ff444e8e-0bb0-430d-ad75-c6e3de10af30
\n", 127 | "

76 rows × 2 columns

\n", 128 | "
" 129 | ], 130 | "text/plain": [ 131 | " Project Name \\\n", 132 | "0 7b-Variant Configurations Mon Mar 13 17:54:29 ... \n", 133 | "1 6-Individual and Snapshots Mon Mar 13 17:53:49... \n", 134 | "2 11a-View-Viewpoint Mon Mar 13 17:59:02 EDT 2023 \n", 135 | "3 VehiclePackage Fri May 05 12:28:40 UTC 2023 \n", 136 | "4 sleon_filtering_test Sat Jun 10 03:30:40 UTC 2023 \n", 137 | ".. ... \n", 138 | "71 updated-test-project-19/05/2023 13:36:25 \n", 139 | "72 13b-Safety and Security Features Element Group... \n", 140 | "73 ts-usage-views Fri Jun 09 06:35:30 UTC 2023 \n", 141 | "74 VehicleMasses_MapleConnector Mon Jan 22 20:32:... \n", 142 | "75 BasicAJMExampleIF1 Fri Sep 22 14:00:29 UTC 2023 \n", 143 | "\n", 144 | " Project ID \n", 145 | "0 000e9890-6935-43e6-a5d7-5d7cac601f4c \n", 146 | "1 00bbbdc9-ea5e-4ab6-8198-94b4708639c4 \n", 147 | "2 021b60e9-1d9d-4c0e-af6b-8478b5928ccf \n", 148 | "3 0768a0aa-9be9-457d-b693-12d45c68343c \n", 149 | "4 0a8f97fe-a4c8-4806-bfa9-0d95e377761a \n", 150 | ".. ... \n", 151 | "71 f5d672c5-8a36-4a5a-8fcc-4eb7bfb703ff \n", 152 | "72 f9079904-26cf-437e-ab74-e1bd6b6013fb \n", 153 | "73 fcf4f295-8813-4737-ad97-f21267e3738b \n", 154 | "74 fee1b365-a84d-4de1-ba56-1d364f10478c \n", 155 | "75 ff444e8e-0bb0-430d-ad75-c6e3de10af30 \n", 156 | "\n", 157 | "[76 rows x 2 columns]" 158 | ] 159 | }, 160 | "metadata": {}, 161 | "output_type": "display_data" 162 | } 163 | ], 164 | "source": [ 165 | "projects_url = f\"{host}/projects\" \n", 166 | "projects_response = requests.get(projects_url)\n", 167 | "\n", 168 | "if projects_response.status_code == 200:\n", 169 | " projects = projects_response.json()\n", 170 | " \n", 171 | " df = pd.DataFrame({'Project Name':[], 'Project ID':[]})\n", 172 | " for p in projects:\n", 173 | " df = pd.concat([df, pd.DataFrame({'Project Name':[p['name']], 'Project ID':[p['@id']]})], ignore_index=True)\n", 174 | " display(df)" 175 | ] 176 | }, 177 | { 178 | "cell_type": "markdown", 179 | "id": "d815e4fe", 180 | "metadata": {}, 181 | "source": [ 182 | "# Define a function to recursively iterate over feature members \n", 183 | "## Recursive graph traversal using FeatureMembership relations" 184 | ] 185 | }, 186 | { 187 | "cell_type": "code", 188 | "execution_count": 34, 189 | "id": "24ec6146", 190 | "metadata": {}, 191 | "outputs": [], 192 | "source": [ 193 | "def get_member_features(project_id, commit_id, element_id, member_type, indent):\n", 194 | " \n", 195 | " # Fetch the element\n", 196 | " element_url = f\"{host}/projects/{project_id}/commits/{commit_id}/elements/{element_id}\" \n", 197 | " response = requests.get(element_url)\n", 198 | " \n", 199 | " element_data = response.json()\n", 200 | " element_name = element_data['name']\n", 201 | " element_id = element_data['@id']\n", 202 | " element_type = element_data ['@type']\n", 203 | " \n", 204 | " if element_type == member_type:\n", 205 | " print(f\"{indent} - {element_name} (id = {element_id}, type = {element_type})\")\n", 206 | " # Feature memberships\n", 207 | " element_features = element_data['feature']\n", 208 | " if len(element_features) > 0:\n", 209 | " for feature in element_features:\n", 210 | " get_member_features(project_id, commit_id, feature['@id'], member_type, indent + \" \")\n" 211 | ] 212 | }, 213 | { 214 | "cell_type": "markdown", 215 | "id": "a47d1b56-9176-4c97-b0f8-443e159a1f20", 216 | "metadata": {}, 217 | "source": [ 218 | "## Project" 219 | ] 220 | }, 221 | { 222 | "cell_type": "code", 223 | "execution_count": 35, 224 | "id": "a8cb5b5b-f182-49cd-bc83-a82dc94c422a", 225 | "metadata": {}, 226 | "outputs": [], 227 | "source": [ 228 | "spacecraft_project_id = 'a24a3f81-db33-4514-8cee-11b8db59d3e8'" 229 | ] 230 | }, 231 | { 232 | "cell_type": "code", 233 | "execution_count": 36, 234 | "id": "482ddfe4", 235 | "metadata": {}, 236 | "outputs": [ 237 | { 238 | "name": "stdout", 239 | "output_type": "stream", 240 | "text": [ 241 | "[{'@id': '40666fb1-cab2-415e-8764-75121b14ec87',\n", 242 | " '@type': 'Commit',\n", 243 | " 'created': '2023-06-13T18:54:44.606759-04:00',\n", 244 | " 'description': None,\n", 245 | " 'owningProject': {'@id': 'a24a3f81-db33-4514-8cee-11b8db59d3e8'},\n", 246 | " 'previousCommit': None}]\n" 247 | ] 248 | } 249 | ], 250 | "source": [ 251 | "spacecraft_project_commit_id = ''\n", 252 | "\n", 253 | "commits_url = f\"{host}/projects/{spacecraft_project_id}/commits\" \n", 254 | "commits_response = requests.get(commits_url)\n", 255 | "if commits_response.status_code == 200:\n", 256 | " commits = commits_response.json()\n", 257 | " pprint(commits)\n", 258 | " spacecraft_project_commit_id = commits[0]['@id']\n" 259 | ] 260 | }, 261 | { 262 | "cell_type": "markdown", 263 | "id": "487c0624", 264 | "metadata": {}, 265 | "source": [ 266 | "## Query to find Spacecraft part" 267 | ] 268 | }, 269 | { 270 | "cell_type": "code", 271 | "execution_count": 37, 272 | "id": "3d724e27", 273 | "metadata": {}, 274 | "outputs": [ 275 | { 276 | "name": "stdout", 277 | "output_type": "stream", 278 | "text": [ 279 | "[{'@id': '6a262fe1-6958-4c05-8ff1-c19d4cd68c41',\n", 280 | " '@type': 'PartUsage',\n", 281 | " 'name': 'Spacecraft',\n", 282 | " 'owner': {'@id': 'e51d38d7-3459-4c19-b760-1d6a257641b1'}}]\n" 283 | ] 284 | } 285 | ], 286 | "source": [ 287 | " \n", 288 | "data = {\n", 289 | " '@type':'Query',\n", 290 | " 'select': ['name','@id','@type','owner'],\n", 291 | " 'where': {\n", 292 | " '@type': 'CompositeConstraint',\n", 293 | " 'operator': 'and',\n", 294 | " 'constraint': [\n", 295 | " {\n", 296 | " '@type': 'PrimitiveConstraint',\n", 297 | " 'inverse': False,\n", 298 | " 'operator': '=',\n", 299 | " 'property': 'name',\n", 300 | " 'value': 'Spacecraft'\n", 301 | " },\n", 302 | " {\n", 303 | " '@type': 'PrimitiveConstraint',\n", 304 | " 'inverse': False,\n", 305 | " 'operator': '=',\n", 306 | " 'property': '@type',\n", 307 | " 'value': 'PartUsage'\n", 308 | " }\n", 309 | " ]\n", 310 | " }\n", 311 | "}\n", 312 | "\n", 313 | "payload = json.dumps(data)\n", 314 | "\n", 315 | "vehicle1_id = ''\n", 316 | "query_url = f\"{host}/projects/{spacecraft_project_id}/query-results\" \n", 317 | "\n", 318 | "query_response = requests.post(query_url, json=data)\n", 319 | "\n", 320 | "if query_response.status_code == 200:\n", 321 | " query_response_json = query_response.json()\n", 322 | " pprint(query_response_json)\n", 323 | " spacecraft_part_id = query_response_json[0]['@id']" 324 | ] 325 | }, 326 | { 327 | "cell_type": "markdown", 328 | "id": "0092a660", 329 | "metadata": {}, 330 | "source": [ 331 | "## Parts tree for Spacecraft (recursive FeatureMembership relation navigation)" 332 | ] 333 | }, 334 | { 335 | "cell_type": "code", 336 | "execution_count": 38, 337 | "id": "406504bf", 338 | "metadata": {}, 339 | "outputs": [ 340 | { 341 | "name": "stdout", 342 | "output_type": "stream", 343 | "text": [ 344 | " - Spacecraft (id = 6a262fe1-6958-4c05-8ff1-c19d4cd68c41, type = PartUsage)\n", 345 | " - Payload_Subsystem (id = 091aada9-3687-4bfc-a683-7d8b92972935, type = PartUsage)\n", 346 | " - Payload_sensor (id = 9a2721e1-410c-49f9-9551-9c8721ef589e, type = PartUsage)\n", 347 | " - Payload_software (id = 31fc0cdb-4ac4-4da3-bee8-713b41e5781c, type = PartUsage)\n", 348 | " - Power_Subsystem (id = 32ab132f-9db6-4ea0-9c77-d399fdf41faa, type = PartUsage)\n", 349 | " - Solar_Array (id = 97713133-38b4-42a3-929f-6a1f024ba37d, type = PartUsage)\n", 350 | " - Battery (id = 4518e4c0-a6a5-441e-b007-38b66a4fc589, type = PartUsage)\n", 351 | " - Communications_Subsystem (id = be62763d-fdff-425a-a993-d81cdf5fcf93, type = PartUsage)\n", 352 | " - Communication_Software (id = f88566d8-65cd-4a9e-91df-44eda6faf7db, type = PartUsage)\n", 353 | " - High_Rate_Antenna (id = cf7f9c85-f994-4496-a80e-2517d2bc75c7, type = PartUsage)\n", 354 | " - Thermal_Subsystem (id = 0411b359-503e-43ef-af18-1b904f6b35b2, type = PartUsage)\n", 355 | " - Radiator (id = 87963be9-6564-4e5b-b890-ab195f2faeb4, type = PartUsage)\n", 356 | " - Heat_Pipe (id = b37ae9c9-68d1-4e36-894b-fe2dbbfaadb0, type = PartUsage)\n", 357 | " - Structure_and_Mechanisms_Subsystem (id = 777e9209-3e37-4b85-9105-4229199f1405, type = PartUsage)\n", 358 | " - Antenna_Gimbal (id = d3b285e5-3e73-4b0a-a7b9-1cd80c562f5d, type = PartUsage)\n", 359 | " - Solar_Array_Gimbal (id = 4971b596-e0b0-4d4c-b41b-1e115b14295d, type = PartUsage)\n", 360 | " - Avionics_Subsystem (id = c71bee28-2fda-49c1-8b8b-46ee864ba1c1, type = PartUsage)\n", 361 | " - Onboard_Controller (id = 672471b6-6395-4900-a48c-66e37589b679, type = PartUsage)\n", 362 | " - System_Controller (id = ef4e6b6a-7da6-4029-8ff8-5545d32e4e48, type = PartUsage)\n", 363 | " - Onboard_Computer (id = a0142360-ed07-4411-92ad-bc6a30b87f58, type = PartUsage)\n", 364 | " - Mission_Software (id = 8ab1b5d8-8675-4e54-8573-9df7389a75c2, type = PartUsage)\n", 365 | " - Flight_Software (id = c1706220-0a73-434b-a6bd-3d5184346bf3, type = PartUsage)\n", 366 | " - GNC_Subsystem (id = d5ec8534-e7ed-4c4f-ae12-663f8df74f9c, type = PartUsage)\n", 367 | " - Reaction_Wheel (id = 31c8c58d-48ef-4d27-8fbd-c98a5b461f68, type = PartUsage)\n", 368 | " - GNC_Software (id = d8866c3b-f07a-4583-9bdb-a8ec2266cbc3, type = PartUsage)\n", 369 | " - Propulsion_Subsystem (id = dc94ce90-5390-415e-be7d-5f10e6b8867a, type = PartUsage)\n", 370 | " - Propellant_Line (id = 5c34b5b1-b7b0-4844-948e-a0046f14c0d4, type = PartUsage)\n", 371 | " - Propulsion_Software (id = d2544b57-2b06-42cf-92e3-414630bcd7ac, type = PartUsage)\n", 372 | " - Harness_Subsystem (id = 789d0600-10de-4d09-9632-49d80cf9d386, type = PartUsage)\n", 373 | " - Power_Harness (id = cfcdbe53-3075-416a-8200-5226fc9c5267, type = PartUsage)\n", 374 | " - Data_Harness (id = 206d7021-5396-4fbe-a8a6-7e1704d2c5d3, type = PartUsage)\n" 375 | ] 376 | } 377 | ], 378 | "source": [ 379 | "get_member_features(spacecraft_project_id,spacecraft_project_commit_id, spacecraft_part_id,'PartUsage',\" \")" 380 | ] 381 | }, 382 | { 383 | "cell_type": "code", 384 | "execution_count": 39, 385 | "id": "5fa94a05-c45e-4d93-a145-7e5967a87cd9", 386 | "metadata": {}, 387 | "outputs": [ 388 | { 389 | "name": "stdout", 390 | "output_type": "stream", 391 | "text": [ 392 | "[{'@id': '459f5ec9-dc82-45c0-87e3-d013ed6773e5',\n", 393 | " '@type': 'RequirementUsage',\n", 394 | " 'name': 'Spacecraft_Specification',\n", 395 | " 'owner': {'@id': '26bc955e-5ea4-4a51-8099-db42169e7436'}}]\n" 396 | ] 397 | } 398 | ], 399 | "source": [ 400 | "data = {\n", 401 | " '@type':'Query',\n", 402 | " 'select': ['name','@id','@type','owner'],\n", 403 | " 'where': {\n", 404 | " '@type': 'CompositeConstraint',\n", 405 | " 'operator': 'and',\n", 406 | " 'constraint': [\n", 407 | " {\n", 408 | " '@type': 'PrimitiveConstraint',\n", 409 | " 'inverse': False,\n", 410 | " 'operator': '=',\n", 411 | " 'property': 'name',\n", 412 | " 'value': 'Spacecraft_Specification'\n", 413 | " },\n", 414 | " {\n", 415 | " '@type': 'PrimitiveConstraint',\n", 416 | " 'inverse': False,\n", 417 | " 'operator': '=',\n", 418 | " 'property': '@type',\n", 419 | " 'value': 'RequirementUsage'\n", 420 | " }\n", 421 | " ]\n", 422 | " }\n", 423 | "}\n", 424 | "\n", 425 | "payload = json.dumps(data)\n", 426 | "\n", 427 | "vehicle_specification_id = ''\n", 428 | "query_url = f\"{host}/projects/{spacecraft_project_id}/query-results\" \n", 429 | "\n", 430 | "query_response = requests.post(query_url, json=data)\n", 431 | "\n", 432 | "if query_response.status_code == 200:\n", 433 | " query_response_json = query_response.json()\n", 434 | " pprint(query_response_json)\n", 435 | " spacecraft_specification_id = query_response_json[0]['@id']" 436 | ] 437 | }, 438 | { 439 | "cell_type": "code", 440 | "execution_count": 40, 441 | "id": "bd2276aa", 442 | "metadata": {}, 443 | "outputs": [ 444 | { 445 | "name": "stdout", 446 | "output_type": "stream", 447 | "text": [ 448 | " - Spacecraft_Specification (id = 459f5ec9-dc82-45c0-87e3-d013ed6773e5, type = RequirementUsage)\n", 449 | " - Launch_Vehicle_Interface (id = 9df26fa1-e5c6-4679-8c45-4c482b544497, type = RequirementUsage)\n", 450 | " - Launch_Vehicle_Mechanical_Interface (id = 6a262fdd-1964-490b-ad2b-b8f444aa60d7, type = RequirementUsage)\n", 451 | " - Launch_Vehicle_Electrics_Interface (id = 0674630a-ee6e-4e03-8ada-3d24cc82f700, type = RequirementUsage)\n", 452 | " - Functional_and_Performance (id = b2a2a88e-d6c8-4277-a43c-ce9c7e74bf95, type = RequirementUsage)\n", 453 | " - Probability_of_Detection (id = b896853b-cdc3-4776-b28e-b11dba0701f7, type = RequirementUsage)\n", 454 | " - Probability_of_False_Alarm (id = d1941cc0-fd36-4a74-933c-cc444e105d5d, type = RequirementUsage)\n", 455 | " - Pointing_Accuracy (id = 24f75812-2686-4445-9c48-dd842b0a0b17, type = RequirementUsage)\n", 456 | " - Downlink_Capacity (id = 71d84b57-0033-4a20-a598-781d547d5c51, type = RequirementUsage)\n", 457 | " - Data_Storage (id = 9d9bcba4-4d1c-421a-b947-ebd1d19fc931, type = RequirementUsage)\n", 458 | " - Fault_Management (id = ac07ab51-7583-4ef3-89c9-661e974ffae9, type = RequirementUsage)\n", 459 | " - Physical (id = a9f208ca-a42e-4a49-9da5-4e7422d1e1da, type = RequirementUsage)\n", 460 | " - Mass (id = 9b9737fa-96bd-460f-8d05-d76917f1c90b, type = RequirementUsage)\n", 461 | " - Electrical_Power (id = 83a0bea4-ef39-49ee-af64-ea2e205c880f, type = RequirementUsage)\n", 462 | " - Orbit_Constraints (id = f2e61320-d428-4f91-93aa-af2ac87154ea, type = RequirementUsage)\n", 463 | " - Thermal_Protection (id = 14796f3e-6d17-479b-8d3c-ef29ed9166a2, type = RequirementUsage)\n", 464 | " - Payload_Accomodation (id = 79ed4e4b-d99e-45f9-9a0a-cdd7cbbc41ae, type = RequirementUsage)\n", 465 | " - Structural_Integrity (id = 9bbef78f-ed8c-47f3-b76a-4c203b07046d, type = RequirementUsage)\n", 466 | " - Quality_Characteristics (id = 0a412f71-01f4-481b-a616-371f3263435a, type = RequirementUsage)\n", 467 | " - Reliability (id = a465415d-c243-46a6-8148-4a42cbe0acd2, type = RequirementUsage)\n", 468 | " - Lifetime (id = 59e08f8f-3e3e-4316-8b9a-0fe5db46b7fb, type = RequirementUsage)\n", 469 | " - Unit_Cost (id = 1b9e87f8-4acd-4a32-9570-6e19a7f7caf0, type = RequirementUsage)\n" 470 | ] 471 | } 472 | ], 473 | "source": [ 474 | "get_member_features(spacecraft_project_id, spacecraft_project_commit_id, spacecraft_specification_id,\"RequirementUsage\",\" \")" 475 | ] 476 | }, 477 | { 478 | "cell_type": "code", 479 | "execution_count": null, 480 | "id": "c9d67e6b-d814-42d0-b180-41458eb34eb6", 481 | "metadata": {}, 482 | "outputs": [], 483 | "source": [] 484 | } 485 | ], 486 | "metadata": { 487 | "kernelspec": { 488 | "display_name": "Python 3 (ipykernel)", 489 | "language": "python", 490 | "name": "python3" 491 | }, 492 | "language_info": { 493 | "codemirror_mode": { 494 | "name": "ipython", 495 | "version": 3 496 | }, 497 | "file_extension": ".py", 498 | "mimetype": "text/x-python", 499 | "name": "python", 500 | "nbconvert_exporter": "python", 501 | "pygments_lexer": "ipython3", 502 | "version": "3.8.16" 503 | } 504 | }, 505 | "nbformat": 4, 506 | "nbformat_minor": 5 507 | } 508 | -------------------------------------------------------------------------------- /Queries.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "3ee4834f", 6 | "metadata": {}, 7 | "source": [ 8 | "# Initializing the SysML v2 API" 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 8, 14 | "id": "6b5fef59", 15 | "metadata": {}, 16 | "outputs": [], 17 | "source": [ 18 | "from __future__ import print_function\n", 19 | "\n", 20 | "import time\n", 21 | "import requests\n", 22 | "from pprint import pprint\n", 23 | "import pandas as pd\n", 24 | "import json\n", 25 | "\n", 26 | "#host = \"\"\n", 27 | "host = \"Specify the URL of the SysML v2 API and Service Repository\"" 28 | ] 29 | }, 30 | { 31 | "cell_type": "markdown", 32 | "id": "04c1ff93", 33 | "metadata": {}, 34 | "source": [ 35 | "# Get projects" 36 | ] 37 | }, 38 | { 39 | "cell_type": "code", 40 | "execution_count": 9, 41 | "id": "78788ed9", 42 | "metadata": {}, 43 | "outputs": [ 44 | { 45 | "data": { 46 | "text/html": [ 47 | "
\n", 48 | "\n", 61 | "\n", 62 | " \n", 63 | " \n", 64 | " \n", 65 | " \n", 66 | " \n", 67 | " \n", 68 | " \n", 69 | " \n", 70 | " \n", 71 | " \n", 72 | " \n", 73 | " \n", 74 | " \n", 75 | " \n", 76 | " \n", 77 | " \n", 78 | " \n", 79 | " \n", 80 | " \n", 81 | " \n", 82 | " \n", 83 | " \n", 84 | " \n", 85 | " \n", 86 | " \n", 87 | " \n", 88 | " \n", 89 | " \n", 90 | " \n", 91 | " \n", 92 | " \n", 93 | " \n", 94 | " \n", 95 | " \n", 96 | " \n", 97 | " \n", 98 | " \n", 99 | " \n", 100 | " \n", 101 | " \n", 102 | " \n", 103 | " \n", 104 | " \n", 105 | " \n", 106 | " \n", 107 | " \n", 108 | " \n", 109 | " \n", 110 | " \n", 111 | " \n", 112 | " \n", 113 | " \n", 114 | " \n", 115 | " \n", 116 | " \n", 117 | " \n", 118 | " \n", 119 | " \n", 120 | " \n", 121 | " \n", 122 | " \n", 123 | " \n", 124 | " \n", 125 | " \n", 126 | " \n", 127 | " \n", 128 | " \n", 129 | " \n", 130 | " \n", 131 | " \n", 132 | " \n", 133 | " \n", 134 | " \n", 135 | " \n", 136 | " \n", 137 | " \n", 138 | " \n", 139 | " \n", 140 | " \n", 141 | " \n", 142 | " \n", 143 | " \n", 144 | " \n", 145 | " \n", 146 | " \n", 147 | " \n", 148 | " \n", 149 | " \n", 150 | " \n", 151 | " \n", 152 | " \n", 153 | " \n", 154 | " \n", 155 | " \n", 156 | " \n", 157 | " \n", 158 | " \n", 159 | " \n", 160 | " \n", 161 | " \n", 162 | " \n", 163 | " \n", 164 | " \n", 165 | " \n", 166 | " \n", 167 | " \n", 168 | " \n", 169 | " \n", 170 | " \n", 171 | " \n", 172 | " \n", 173 | " \n", 174 | " \n", 175 | " \n", 176 | " \n", 177 | " \n", 178 | " \n", 179 | " \n", 180 | " \n", 181 | " \n", 182 | " \n", 183 | " \n", 184 | " \n", 185 | " \n", 186 | " \n", 187 | " \n", 188 | " \n", 189 | " \n", 190 | " \n", 191 | " \n", 192 | " \n", 193 | " \n", 194 | " \n", 195 | " \n", 196 | " \n", 197 | " \n", 198 | " \n", 199 | " \n", 200 | " \n", 201 | " \n", 202 | " \n", 203 | " \n", 204 | " \n", 205 | " \n", 206 | " \n", 207 | " \n", 208 | " \n", 209 | " \n", 210 | " \n", 211 | " \n", 212 | " \n", 213 | " \n", 214 | " \n", 215 | " \n", 216 | " \n", 217 | " \n", 218 | " \n", 219 | " \n", 220 | " \n", 221 | " \n", 222 | " \n", 223 | " \n", 224 | " \n", 225 | " \n", 226 | " \n", 227 | " \n", 228 | " \n", 229 | " \n", 230 | " \n", 231 | " \n", 232 | " \n", 233 | " \n", 234 | " \n", 235 | " \n", 236 | " \n", 237 | " \n", 238 | " \n", 239 | " \n", 240 | " \n", 241 | " \n", 242 | " \n", 243 | " \n", 244 | " \n", 245 | " \n", 246 | " \n", 247 | " \n", 248 | " \n", 249 | " \n", 250 | " \n", 251 | "
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", 252 | "
" 253 | ], 254 | "text/plain": [ 255 | " Project Name \\\n", 256 | "0 Spacecraft project with branches and tags - 20... \n", 257 | "1 17a-Sequence-Modeling Thu Jul 21 12:43:51 EDT ... \n", 258 | "2 12b-Allocation Thu Jul 21 12:40:33 EDT 2022 \n", 259 | "3 14a-Language Extensions Thu Jul 21 12:42:05 ED... \n", 260 | "4 9-Verification-simplified Thu Jul 21 12:38:15 ... \n", 261 | "5 Geometry Thu Jul 21 13:01:13 EDT 2022 \n", 262 | "6 11a-View-Viewpoint Thu Jul 21 12:39:43 EDT 2022 \n", 263 | "7 14b-Language Extensions Thu Jul 21 12:42:19 ED... \n", 264 | "8 5-State-based Behavior-1a Thu Jul 21 12:36:44 ... \n", 265 | "9 11b-Safety and Security Feature Views Thu Jul ... \n", 266 | "10 18-Use Case Thu Jul 21 12:44:19 EDT 2022 \n", 267 | "11 3a-Function-based Behavior-2 Thu Jul 21 12:35:... \n", 268 | "12 Spacecraft project with branches and tags - 20... \n", 269 | "13 10d-Dynamics Analysis Thu Jul 21 12:39:20 EDT ... \n", 270 | "14 12a-Dependency Thu Jul 21 12:40:21 EDT 2022 \n", 271 | "15 15_10-Primitive Data Types Thu Jul 21 12:43:17... \n", 272 | "16 13b-Safety and Security Features Element Group... \n", 273 | "17 13b-Safety and Security Features Element Group... \n", 274 | "18 8-Requirements Thu Jul 21 12:37:52 EDT 2022 \n", 275 | "19 13a-Model Containment Thu Jul 21 12:40:47 EDT ... \n", 276 | "20 Spacecraft project with branches and tags - 20... \n", 277 | "21 17b-Sequence-Modeling Thu Jul 21 12:44:05 EDT ... \n", 278 | "22 15_05-Unification of Expression and Constraint... \n", 279 | "23 5-State-based Behavior-1 Thu Jul 21 12:36:19 E... \n", 280 | "24 4a-Functional Allocation Thu Jul 21 12:35:59 E... \n", 281 | "25 1c-Parts Tree Redefinition Thu Jul 21 12:34:06... \n", 282 | "26 7b-Variant Configurations Thu Jul 21 12:37:28 ... \n", 283 | "27 2a-Parts Interconnection Thu Jul 21 12:34:36 E... \n", 284 | "28 10c-Fuel Economy Analysis Thu Jul 21 12:38:54 ... \n", 285 | "29 13b-Safety and Security Features Element Group... \n", 286 | "30 15_19-Materials with Properties Thu Jul 21 12:... \n", 287 | "31 10b-Trade-off Among Alternative Configurations... \n", 288 | "32 6-Individual and Snapshots Thu Jul 21 12:37:08... \n", 289 | "33 14c-Language Extensions Thu Jul 21 12:42:33 ED... \n", 290 | "34 3a-Function-based Behavior-1 Thu Jul 21 12:35:... \n", 291 | "35 3a-Function-based Behavior-5 Thu Jul 21 12:35:... \n", 292 | "\n", 293 | " Project ID \n", 294 | "0 00a50f21-3329-4871-97d5-d9988f8bda4f \n", 295 | "1 048a0c99-ca99-4012-929d-f4797d395de1 \n", 296 | "2 06a5e118-34e0-4ac3-b499-0a11773bc0f6 \n", 297 | "3 0d9d4124-1413-428f-866d-f9b58bf23c95 \n", 298 | "4 17ffc369-e231-49dd-9f56-4330856a0fda \n", 299 | "5 228c1a01-b8be-4d63-a87c-0ebbd9d88ff8 \n", 300 | "6 2e65960e-5dca-4d69-bb31-0c56537b4b70 \n", 301 | "7 2f671f67-cb65-4365-a221-c403e7b87c51 \n", 302 | "8 3694e3f8-b2eb-45a7-bddd-f41cca5b36c6 \n", 303 | "9 3703933c-5a07-4555-9352-3414f345553b \n", 304 | "10 4223e1a2-beb7-483b-852e-3913c7a94c9c \n", 305 | "11 462e55f9-2def-4b0f-abf6-e46f1cd50979 \n", 306 | "12 51cbfbec-1e60-4f6f-9956-e38594dcb33d \n", 307 | "13 6ec5dbe4-2b39-4b56-b222-ff506f15dba9 \n", 308 | "14 703ade3d-7929-4d40-9806-19b7f3c002df \n", 309 | "15 70cc6261-6b37-4463-a0d6-f63b01301b32 \n", 310 | "16 7c91c09e-2973-46b9-ad82-275ba2124322 \n", 311 | "17 7da362eb-8768-4417-8985-c705c17ee1f2 \n", 312 | "18 827ca776-1199-4fda-84b7-f81b3dd46fae \n", 313 | "19 8d16ef4d-8b68-4661-a5f6-131ad06251d8 \n", 314 | "20 8fe6a1a1-e722-4342-bc71-961f848a7799 \n", 315 | "21 96fe8de3-8af0-4d4a-96b0-354f4cceb184 \n", 316 | "22 98fa34a4-5069-4dc3-9a97-f57122adebc6 \n", 317 | "23 9ea87a3e-9f70-4e13-acf4-0932d28d4362 \n", 318 | "24 aa64678d-87ce-442f-a88e-866ae492f75b \n", 319 | "25 b1b4e96a-035e-441f-83c4-2d55fb568877 \n", 320 | "26 b25ed4fa-5737-40dc-b69b-bfde55ca39b7 \n", 321 | "27 bb68bed7-3f04-4617-998f-2669d7488236 \n", 322 | "28 c1fae04f-f879-4fae-acec-1d7281a0124d \n", 323 | "29 cd1ba8c5-4992-4585-bf9b-9c3be3e9e033 \n", 324 | "30 ce489c07-79d9-4022-9dc1-1bd413bce2d8 \n", 325 | "31 cfddd9c9-a2c9-4446-8056-74c7552a4d63 \n", 326 | "32 db7fd713-98bc-4932-9b40-438040e85854 \n", 327 | "33 e6b46779-d037-4391-af1f-6fb5253f1ea2 \n", 328 | "34 f00664c2-ff28-4e1c-aee7-d948e9fa292d \n", 329 | "35 ff54a0e3-3adb-4c8d-93a4-8e6f5e11af66 " 330 | ] 331 | }, 332 | "metadata": {}, 333 | "output_type": "display_data" 334 | } 335 | ], 336 | "source": [ 337 | "projects_url = f\"{host}/projects\" \n", 338 | "projects_response = requests.get(projects_url)\n", 339 | "parts_tree_project_id = \"\"\n", 340 | "\n", 341 | "if projects_response.status_code == 200:\n", 342 | " projects = projects_response.json()\n", 343 | " \n", 344 | " df = pd.DataFrame({'Project Name':[], 'Project ID':[]})\n", 345 | " for p in projects:\n", 346 | " df = pd.concat([df, pd.DataFrame({'Project Name':[p['name']], 'Project ID':[p['@id']]})], ignore_index=True)\n", 347 | " display(df)\n", 348 | " \n", 349 | " parts_tree_project = list(filter(lambda p: 'Parts Tree' in p['name'], projects))[0] \n", 350 | " parts_tree_project_id = parts_tree_project['@id']" 351 | ] 352 | }, 353 | { 354 | "cell_type": "markdown", 355 | "id": "487c0624", 356 | "metadata": {}, 357 | "source": [ 358 | "## Query to find all part usages" 359 | ] 360 | }, 361 | { 362 | "cell_type": "code", 363 | "execution_count": 10, 364 | "id": "e1e315c9-7484-4424-a3b7-2b1455dbbe91", 365 | "metadata": {}, 366 | "outputs": [ 367 | { 368 | "data": { 369 | "text/html": [ 370 | "
\n", 371 | "\n", 384 | "\n", 385 | " \n", 386 | " \n", 387 | " \n", 388 | " \n", 389 | " \n", 390 | " \n", 391 | " \n", 392 | " \n", 393 | " \n", 394 | " \n", 395 | " \n", 396 | " \n", 397 | " \n", 398 | " \n", 399 | " \n", 400 | " \n", 401 | " \n", 402 | " \n", 403 | " \n", 404 | " \n", 405 | " \n", 406 | " \n", 407 | " \n", 408 | " \n", 409 | " \n", 410 | " \n", 411 | " \n", 412 | " \n", 413 | " \n", 414 | " \n", 415 | " \n", 416 | " \n", 417 | " \n", 418 | " \n", 419 | " \n", 420 | " \n", 421 | " \n", 422 | " \n", 423 | " \n", 424 | " \n", 425 | " \n", 426 | " \n", 427 | " \n", 428 | " \n", 429 | " \n", 430 | " \n", 431 | " \n", 432 | " \n", 433 | " \n", 434 | " \n", 435 | " \n", 436 | " \n", 437 | " \n", 438 | " \n", 439 | " \n", 440 | " \n", 441 | " \n", 442 | " \n", 443 | " \n", 444 | " \n", 445 | " \n", 446 | " \n", 447 | " \n", 448 | " \n", 449 | " \n", 450 | " \n", 451 | " \n", 452 | " \n", 453 | " \n", 454 | " \n", 455 | " \n", 456 | " \n", 457 | " \n", 458 | " \n", 459 | " \n", 460 | " \n", 461 | " \n", 462 | " \n", 463 | " \n", 464 | " \n", 465 | " \n", 466 | " \n", 467 | " \n", 468 | " \n", 469 | " \n", 470 | " \n", 471 | " \n", 472 | " \n", 473 | " \n", 474 | "
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", 475 | "
" 476 | ], 477 | "text/plain": [ 478 | " Part Usage Name Part Usage ID\n", 479 | "0 rearAxleAssembly_c1 02fecf3d-69f7-4f16-a2c9-90c0df53dae5\n", 480 | "1 frontAxle_c1 6184d9c5-57ae-4e29-906e-d042f7b7e2bb\n", 481 | "2 frontWheel 005c0064-c3c2-4ecd-aec8-59483179e7e5\n", 482 | "3 vehicle1_c1 dd0cba88-59dd-4b2e-9664-7608d22186ce\n", 483 | "4 rearAxle 8ed3d0f9-1bb4-4207-80db-e39c5cfb1e5f\n", 484 | "5 frontAxle b53912c9-213d-4d61-b737-270969d20d65\n", 485 | "6 vehicle1 149effb8-9cfb-4f55-80db-a984830eec55\n", 486 | "7 rearAxle_c1 b4d0d0e0-8b79-4bea-a071-2af8315c492c\n", 487 | "8 frontAxleAssembly 2b723540-a1cc-44e3-8f54-8b29cbb2962a\n", 488 | "9 frontWheel_1 a88fb146-b2cb-4ef9-b2b8-d14bea29d3e1\n", 489 | "10 rearWheel_1 f8bb2e98-a0e8-468f-9e78-0a391dfb927f\n", 490 | "11 frontWheel_2 ba3e13d6-bb9f-4ec3-851a-7699e9839d38\n", 491 | "12 rearWheel 5af0fa89-4f22-4b69-a022-9a342f0089b2\n", 492 | "13 rearAxleAssembly 8435855c-96a1-489b-afc8-ba2e01b9deab\n", 493 | "14 rearWheel_2 c15818e7-2edf-48f8-a04e-6900f3c13958\n", 494 | "15 frontAxleAssembly_c1 0e27013b-240d-44e5-bee9-d2bc949651ea" 495 | ] 496 | }, 497 | "metadata": {}, 498 | "output_type": "display_data" 499 | } 500 | ], 501 | "source": [ 502 | "# Query vehicle1 (PartUsage) in the \n", 503 | "query_input = {\n", 504 | " '@type':'Query',\n", 505 | " 'select': ['name','@id','@type','owner'],\n", 506 | " 'where': {\n", 507 | " '@type': 'CompositeConstraint',\n", 508 | " 'operator': 'and',\n", 509 | " 'constraint': [\n", 510 | " {\n", 511 | " '@type': 'PrimitiveConstraint',\n", 512 | " 'inverse': False,\n", 513 | " 'operator': '=',\n", 514 | " 'property': '@type',\n", 515 | " 'value': 'PartUsage'\n", 516 | " }\n", 517 | " ]\n", 518 | " }\n", 519 | "}\n", 520 | "\n", 521 | "payload = json.dumps(query_input)\n", 522 | "\n", 523 | "vehicle1_id = ''\n", 524 | "query_url = f\"{host}/projects/{parts_tree_project_id}/query-results\" \n", 525 | "\n", 526 | "query_response = requests.post(query_url, json=query_input)\n", 527 | "\n", 528 | "if query_response.status_code == 200:\n", 529 | " query_response_json = query_response.json()\n", 530 | " \n", 531 | " df = pd.DataFrame({'Part Usage Name':[], 'Part Usage ID':[]})\n", 532 | " for p in query_response_json:\n", 533 | " df = pd.concat([df, pd.DataFrame({'Part Usage Name':[p['name']], 'Part Usage ID':[p['@id']]})], ignore_index=True)\n", 534 | " display(df)" 535 | ] 536 | }, 537 | { 538 | "cell_type": "markdown", 539 | "id": "004deca6-4832-4352-a682-dddbb2f92127", 540 | "metadata": {}, 541 | "source": [ 542 | "## Query to find Part Usage with name vehicle1" 543 | ] 544 | }, 545 | { 546 | "cell_type": "code", 547 | "execution_count": 11, 548 | "id": "3d724e27", 549 | "metadata": {}, 550 | "outputs": [ 551 | { 552 | "name": "stdout", 553 | "output_type": "stream", 554 | "text": [ 555 | "[{'@id': '149effb8-9cfb-4f55-80db-a984830eec55',\n", 556 | " '@type': 'PartUsage',\n", 557 | " 'name': 'vehicle1',\n", 558 | " 'owner': {'@id': 'ccc70fb3-8bba-40c1-aa18-b9c2ed15b041'}}]\n" 559 | ] 560 | } 561 | ], 562 | "source": [ 563 | "# Query vehicle1 (PartUsage) in the \n", 564 | "data = {\n", 565 | " '@type':'Query',\n", 566 | " 'select': ['name','@id','@type','owner'],\n", 567 | " 'where': {\n", 568 | " '@type': 'CompositeConstraint',\n", 569 | " 'operator': 'and',\n", 570 | " 'constraint': [\n", 571 | " {\n", 572 | " '@type': 'PrimitiveConstraint',\n", 573 | " 'inverse': False,\n", 574 | " 'operator': '=',\n", 575 | " 'property': 'name',\n", 576 | " 'value': 'vehicle1'\n", 577 | " },\n", 578 | " {\n", 579 | " '@type': 'PrimitiveConstraint',\n", 580 | " 'inverse': False,\n", 581 | " 'operator': '=',\n", 582 | " 'property': '@type',\n", 583 | " 'value': 'PartUsage'\n", 584 | " }\n", 585 | " ]\n", 586 | " }\n", 587 | "}\n", 588 | "\n", 589 | "payload = json.dumps(data)\n", 590 | "\n", 591 | "vehicle1_id = ''\n", 592 | "query_url = f\"{host}/projects/{parts_tree_project_id}/query-results\" \n", 593 | "\n", 594 | "query_response = requests.post(query_url, json=data)\n", 595 | "\n", 596 | "if query_response.status_code == 200:\n", 597 | " query_response_json = query_response.json()\n", 598 | " pprint(query_response_json)\n", 599 | " vehicle1_id = query_response_json[0]['@id']" 600 | ] 601 | }, 602 | { 603 | "cell_type": "code", 604 | "execution_count": null, 605 | "id": "bd2276aa", 606 | "metadata": {}, 607 | "outputs": [], 608 | "source": [] 609 | } 610 | ], 611 | "metadata": { 612 | "kernelspec": { 613 | "display_name": "Python 3 (ipykernel)", 614 | "language": "python", 615 | "name": "python3" 616 | }, 617 | "language_info": { 618 | "codemirror_mode": { 619 | "name": "ipython", 620 | "version": 3 621 | }, 622 | "file_extension": ".py", 623 | "mimetype": "text/x-python", 624 | "name": "python", 625 | "nbconvert_exporter": "python", 626 | "pygments_lexer": "ipython3", 627 | "version": "3.8.13" 628 | } 629 | }, 630 | "nbformat": 4, 631 | "nbformat_minor": 5 632 | } 633 | -------------------------------------------------------------------------------- /Element_Create_Update_Delete.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "3ee4834f", 6 | "metadata": { 7 | "tags": [] 8 | }, 9 | "source": [ 10 | "# Initializing the SysML v2 API" 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": 1, 16 | "id": "6b5fef59", 17 | "metadata": {}, 18 | "outputs": [], 19 | "source": [ 20 | "from __future__ import print_function\n", 21 | "\n", 22 | "import time\n", 23 | "import requests\n", 24 | "from pprint import pprint\n", 25 | "import pandas as pd\n", 26 | "import json\n", 27 | "from datetime import datetime\n", 28 | "\n", 29 | "#host = \"\n", 51 | "\n", 52 | "\n", 53 | " \n", 54 | " \n", 55 | " \n", 56 | " \n", 57 | " \n", 58 | " \n", 59 | " \n", 60 | " \n", 61 | " \n", 62 | " \n", 63 | " \n", 64 | " \n", 65 | " \n", 66 | " \n", 67 | " \n", 68 | " \n", 69 | " \n", 70 | " \n", 71 | " \n", 72 | " \n", 73 | " \n", 74 | " \n", 75 | " \n", 76 | " \n", 77 | " \n", 78 | " \n", 79 | " \n", 80 | " \n", 81 | " \n", 82 | " \n", 83 | " \n", 84 | " \n", 85 | " \n", 86 | " \n", 87 | " \n", 88 | " \n", 89 | " \n", 90 | " \n", 91 | " \n", 92 | " \n", 93 | " \n", 94 | " \n", 95 | " \n", 96 | " \n", 97 | " \n", 98 | " \n", 99 | " \n", 100 | " \n", 101 | " \n", 102 | " \n", 103 | " \n", 104 | " \n", 105 | " \n", 106 | " \n", 107 | " \n", 108 | " \n", 109 | " \n", 110 | " \n", 111 | " \n", 112 | " \n", 113 | " \n", 114 | " \n", 115 | " \n", 116 | " \n", 117 | " \n", 118 | " \n", 119 | " \n", 120 | " \n", 121 | " \n", 122 | " \n", 123 | " \n", 124 | " \n", 125 | " \n", 126 | " \n", 127 | " \n", 128 | " \n", 129 | " \n", 130 | " \n", 131 | " \n", 132 | " \n", 133 | " \n", 134 | " \n", 135 | " \n", 136 | " \n", 137 | " \n", 138 | " \n", 139 | " \n", 140 | " \n", 141 | " \n", 142 | " \n", 143 | " \n", 144 | " \n", 145 | " \n", 146 | " \n", 147 | " \n", 148 | " \n", 149 | " \n", 150 | " \n", 151 | " \n", 152 | " \n", 153 | " \n", 154 | " \n", 155 | " \n", 156 | " \n", 157 | " \n", 158 | " \n", 159 | " \n", 160 | " \n", 161 | " \n", 162 | " \n", 163 | " \n", 164 | " \n", 165 | " \n", 166 | " \n", 167 | " \n", 168 | " \n", 169 | " \n", 170 | " \n", 171 | " \n", 172 | " \n", 173 | " \n", 174 | " \n", 175 | " \n", 176 | " \n", 177 | " \n", 178 | " \n", 179 | " \n", 180 | " \n", 181 | " \n", 182 | " \n", 183 | " \n", 184 | " \n", 185 | " \n", 186 | " \n", 187 | " \n", 188 | " \n", 189 | " \n", 190 | " \n", 191 | " \n", 192 | " \n", 193 | " \n", 194 | " \n", 195 | " \n", 196 | " \n", 197 | " \n", 198 | " \n", 199 | " \n", 200 | " \n", 201 | " \n", 202 | " \n", 203 | " \n", 204 | " \n", 205 | " \n", 206 | " \n", 207 | " \n", 208 | " \n", 209 | " \n", 210 | " \n", 211 | " \n", 212 | " \n", 213 | " \n", 214 | " \n", 215 | " \n", 216 | " \n", 217 | " \n", 218 | " \n", 219 | " \n", 220 | " \n", 221 | "
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" 222 | ], 223 | "text/plain": [ 224 | "" 225 | ] 226 | }, 227 | "metadata": {}, 228 | "output_type": "display_data" 229 | } 230 | ], 231 | "source": [ 232 | "projects_url = f\"{host}/projects\" \n", 233 | "projects_response = requests.get(projects_url)\n", 234 | "\n", 235 | "if projects_response.status_code == 200:\n", 236 | " projects = projects_response.json()\n", 237 | " projects_data = list(map(lambda b: {'Project Name':b['name'], 'Project ID':b['@id']}, projects))\n", 238 | " df = pd.DataFrame.from_records(projects_data).style.hide(axis='index')\n", 239 | " # if len(projects_data) > 0:\n", 240 | " # df = df.style.sort_values(by='Project Name')\n", 241 | " display(df)\n", 242 | "else:\n", 243 | " pprint(\"Problem in fetching projects\")" 244 | ] 245 | }, 246 | { 247 | "cell_type": "markdown", 248 | "id": "77345839-9d8f-409f-9131-440d1b30cbea", 249 | "metadata": {}, 250 | "source": [ 251 | "# Create a new project" 252 | ] 253 | }, 254 | { 255 | "cell_type": "code", 256 | "execution_count": 5, 257 | "id": "6d2ba2fc-157a-4ac8-b8f3-876bbd3a21ea", 258 | "metadata": {}, 259 | "outputs": [ 260 | { 261 | "name": "stdout", 262 | "output_type": "stream", 263 | "text": [ 264 | "{'@id': 'f0594c9c-55ef-49f6-9591-d27d12cc0afb',\n", 265 | " '@type': 'Project',\n", 266 | " 'defaultBranch': {'@id': 'd84e4540-56c8-485a-bace-f91b3620ada5'},\n", 267 | " 'description': 'Spacecraft project demonstrating Element Create, Update, '\n", 268 | " 'Delete steps',\n", 269 | " 'name': 'Spacecraft project with Element CRUD - 2022-09-12 13:16:03.708730'}\n" 270 | ] 271 | } 272 | ], 273 | "source": [ 274 | "timestamp = datetime.now()\n", 275 | "project_name = f\"Spacecraft project with Element CRUD - {timestamp}\"\n", 276 | "project_data = {\n", 277 | " \"@type\":\"Project\",\n", 278 | " \"name\": project_name,\n", 279 | " \"description\": \"Spacecraft project demonstrating Element Create, Update, Delete steps\"\n", 280 | "}\n", 281 | "\n", 282 | "project_post_url = f\"{host}/projects\" \n", 283 | "\n", 284 | "project_post_response = requests.post(project_post_url, \n", 285 | " headers={\"Content-Type\": \"application/json\"}, \n", 286 | " data=json.dumps(project_data))\n", 287 | "\n", 288 | "project_id = \"\"\n", 289 | "\n", 290 | "if project_post_response.status_code == 200:\n", 291 | " project_response_json = project_post_response.json()\n", 292 | " pprint(project_response_json)\n", 293 | " project_id = project_response_json['@id']\n", 294 | " project_name = project_response_json['name']\n", 295 | "else:\n", 296 | " pprint(f\"Problem in creating a new Spacecraft project at {timestamp}\")\n", 297 | " pprint(project_post_response)" 298 | ] 299 | }, 300 | { 301 | "cell_type": "markdown", 302 | "id": "921efbfd-04a1-4c5c-8e66-b31f0390aa45", 303 | "metadata": {}, 304 | "source": [ 305 | "# Get branches" 306 | ] 307 | }, 308 | { 309 | "cell_type": "code", 310 | "execution_count": 6, 311 | "id": "df3e1039-ba51-4653-8897-e98be111078e", 312 | "metadata": {}, 313 | "outputs": [ 314 | { 315 | "data": { 316 | "text/html": [ 317 | "\n", 319 | "\n", 320 | " \n", 321 | " \n", 322 | " \n", 323 | " \n", 324 | " \n", 325 | " \n", 326 | " \n", 327 | " \n", 328 | " \n", 329 | " \n", 330 | " \n", 331 | " \n", 332 | " \n", 333 | " \n", 334 | "
Branch NameBranch IDRef Commit (head)
maind84e4540-56c8-485a-bace-f91b3620ada5None
\n" 335 | ], 336 | "text/plain": [ 337 | "" 338 | ] 339 | }, 340 | "metadata": {}, 341 | "output_type": "display_data" 342 | } 343 | ], 344 | "source": [ 345 | "branches_url = f\"{host}/projects/{project_id}/branches\" \n", 346 | "branches_response = requests.get(branches_url)\n", 347 | "\n", 348 | "if branches_response.status_code == 200:\n", 349 | " branches = branches_response.json()\n", 350 | " branches_data = list(map(lambda b: {'Branch Name':b['name'], 'Branch ID':b['@id'], 'Ref Commit (head)':b['head']}, branches))\n", 351 | "\n", 352 | " df = pd.DataFrame.from_records(branches_data).sort_values(by='Branch Name').style.hide(axis='index')\n", 353 | " display(df)\n", 354 | "else:\n", 355 | " pprint(f\"Problem in fetching branches of Spacecraft project {project_id}\")\n", 356 | " pprint(branches_response)" 357 | ] 358 | }, 359 | { 360 | "cell_type": "markdown", 361 | "id": "569ca8f1-ebf1-41d2-93f3-8795a2439eea", 362 | "metadata": {}, 363 | "source": [ 364 | "# Create 1st Commit on the main (default) branch that creates 2 elements" 365 | ] 366 | }, 367 | { 368 | "cell_type": "code", 369 | "execution_count": 7, 370 | "id": "3eed91b9-903b-441f-b1f2-10dbcfafa342", 371 | "metadata": {}, 372 | "outputs": [ 373 | { 374 | "name": "stdout", 375 | "output_type": "stream", 376 | "text": [ 377 | "{'@id': '25853b78-df3e-44d3-9a63-c3221743d82d',\n", 378 | " '@type': 'Commit',\n", 379 | " 'owningProject': {'@id': 'f0594c9c-55ef-49f6-9591-d27d12cc0afb'},\n", 380 | " 'previousCommit': None,\n", 381 | " 'timestamp': '2022-09-12T13:16:13.843497-04:00'}\n" 382 | ] 383 | } 384 | ], 385 | "source": [ 386 | "commit_body = {\n", 387 | " \"@type\": \"Commit\",\n", 388 | " \"change\": [\n", 389 | " {\n", 390 | " \"@type\": \"DataVersion\",\n", 391 | " \"payload\": {\n", 392 | " \"@type\": \"PartDefinition\",\n", 393 | " \"name\":\"Spacecraft System\"\n", 394 | " }\n", 395 | " },\n", 396 | " {\n", 397 | " \"@type\": \"DataVersion\",\n", 398 | " \"payload\": {\n", 399 | " \"@type\": \"PartDefinition\",\n", 400 | " \"name\":\"Payload System\"\n", 401 | " }\n", 402 | " }\n", 403 | " ]\n", 404 | "}\n", 405 | "\n", 406 | "commit_post_url = f\"{host}/projects/{project_id}/commits\" \n", 407 | "\n", 408 | "commit_post_response = requests.post(commit_post_url, \n", 409 | " headers={\"Content-Type\": \"application/json\"}, \n", 410 | " data=json.dumps(commit_body))\n", 411 | "\n", 412 | "commit1_id = \"\"\n", 413 | "\n", 414 | "if commit_post_response.status_code == 200:\n", 415 | " commit_response_json = commit_post_response.json()\n", 416 | " pprint(commit_response_json)\n", 417 | " commit1_id = commit_response_json['@id']\n", 418 | "else:\n", 419 | " pprint(f\"Problem in creating a new commit in Spacecraft project {project_id}\")\n", 420 | " pprint(commit_post_response)" 421 | ] 422 | }, 423 | { 424 | "cell_type": "code", 425 | "execution_count": 8, 426 | "id": "65537f5c-f521-469e-92e4-9a2568afed05", 427 | "metadata": {}, 428 | "outputs": [ 429 | { 430 | "data": { 431 | "text/html": [ 432 | "\n", 434 | "\n", 435 | " \n", 436 | " \n", 437 | " \n", 438 | " \n", 439 | " \n", 440 | " \n", 441 | " \n", 442 | " \n", 443 | " \n", 444 | " \n", 445 | " \n", 446 | " \n", 447 | " \n", 448 | " \n", 449 | " \n", 450 | " \n", 451 | "
Element NameElement ID
Payload System1093a5fd-5a5e-47d7-8bfd-b870ede05648
Spacecraft System07a9a21c-2070-4d6b-8818-bb3bca62dfd8
\n" 452 | ], 453 | "text/plain": [ 454 | "" 455 | ] 456 | }, 457 | "metadata": {}, 458 | "output_type": "display_data" 459 | } 460 | ], 461 | "source": [ 462 | "element_get_url = f\"{host}/projects/{project_id}/commits/{commit1_id}/elements\" \n", 463 | "\n", 464 | "element_get_response = requests.get(element_get_url)\n", 465 | "payload_system_element_id = \"\"\n", 466 | "spacecraft_system_element_id = \"\"\n", 467 | "\n", 468 | "if element_get_response.status_code == 200:\n", 469 | " elements = element_get_response.json()\n", 470 | " \n", 471 | " # Gather the id of the Payload System that is created\n", 472 | " payload_system_element = list(filter(lambda e: e['name'] == \"Payload System\", elements))\n", 473 | " if payload_system_element:\n", 474 | " payload_system_element_id = payload_system_element[0]['@id']\n", 475 | " \n", 476 | " # Gather the id of the Spacecraft System that is created\n", 477 | " spacecraft_system_element = list(filter(lambda e: e['name'] == \"Spacecraft System\", elements))\n", 478 | " if spacecraft_system_element:\n", 479 | " spacecraft_system_element_id = spacecraft_system_element[0]['@id']\n", 480 | " \n", 481 | " elements_data = list(map(lambda b: {'Element Name':b['name'], 'Element ID':b['@id']}, elements))\n", 482 | " df = pd.DataFrame.from_records(elements_data).sort_values(by='Element Name').style.hide(axis='index')\n", 483 | " display(df)\n", 484 | "else:\n", 485 | " pprint(f\"Problem in fetching elements in the Spacecraft project {project_id} at commit {commit1_id}.\")\n", 486 | " pprint(element_get_response)" 487 | ] 488 | }, 489 | { 490 | "cell_type": "markdown", 491 | "id": "8e38b288-6517-4a7b-90e5-ae73c5f89df3", 492 | "metadata": {}, 493 | "source": [ 494 | "# Create the 2nd Commit that updates the name of one of the elements" 495 | ] 496 | }, 497 | { 498 | "cell_type": "code", 499 | "execution_count": 9, 500 | "id": "76d80cb1-40c8-4f24-aeb5-51e509f4e159", 501 | "metadata": { 502 | "tags": [] 503 | }, 504 | "outputs": [ 505 | { 506 | "name": "stdout", 507 | "output_type": "stream", 508 | "text": [ 509 | "{'@id': 'da8991ce-1124-493b-8f34-a4bb2d0800e1',\n", 510 | " '@type': 'Commit',\n", 511 | " 'owningProject': {'@id': 'f0594c9c-55ef-49f6-9591-d27d12cc0afb'},\n", 512 | " 'previousCommit': {'@id': '25853b78-df3e-44d3-9a63-c3221743d82d'},\n", 513 | " 'timestamp': '2022-09-12T13:16:21.941689-04:00'}\n" 514 | ] 515 | } 516 | ], 517 | "source": [ 518 | "commit_body = {\n", 519 | " \"@type\": \"Commit\",\n", 520 | " \"change\": [\n", 521 | " {\n", 522 | " \"@type\": \"DataVersion\",\n", 523 | " \"payload\": {\n", 524 | " \"@type\": \"PartDefinition\",\n", 525 | " \"name\":\"New Payload System\",\n", 526 | " \"identifier\":payload_system_element_id\n", 527 | " },\n", 528 | " \"identity\": {\n", 529 | " \"@id\": payload_system_element_id\n", 530 | " }\n", 531 | " }\n", 532 | " ],\n", 533 | " \"previousCommit\": {\n", 534 | " \"@id\": commit1_id\n", 535 | " }\n", 536 | "}\n", 537 | "\n", 538 | "commit_post_url = f\"{host}/projects/{project_id}/commits\" \n", 539 | "\n", 540 | "commit_post_response = requests.post(commit_post_url, \n", 541 | " headers={\"Content-Type\": \"application/json\"}, \n", 542 | " data=json.dumps(commit_body))\n", 543 | "\n", 544 | "commit2_id = \"\"\n", 545 | "\n", 546 | "if commit_post_response.status_code == 200:\n", 547 | " commit_response_json = commit_post_response.json()\n", 548 | " pprint(commit_response_json)\n", 549 | " commit2_id = commit_response_json['@id']\n", 550 | "else:\n", 551 | " pprint(f\"Problem in creating a new commit in Spacecraft project {project_id}\")\n", 552 | " pprint(commit_post_response)" 553 | ] 554 | }, 555 | { 556 | "cell_type": "markdown", 557 | "id": "d815e4fe", 558 | "metadata": {}, 559 | "source": [ 560 | "# Get all elements after the 2nd commit (should show 1 element updated)" 561 | ] 562 | }, 563 | { 564 | "cell_type": "code", 565 | "execution_count": 10, 566 | "id": "eac0a387-e4cf-4fc8-8b47-c64ed2ebff62", 567 | "metadata": {}, 568 | "outputs": [ 569 | { 570 | "data": { 571 | "text/html": [ 572 | "\n", 574 | "\n", 575 | " \n", 576 | " \n", 577 | " \n", 578 | " \n", 579 | " \n", 580 | " \n", 581 | " \n", 582 | " \n", 583 | " \n", 584 | " \n", 585 | " \n", 586 | " \n", 587 | " \n", 588 | " \n", 589 | " \n", 590 | " \n", 591 | "
Element NameElement ID
New Payload System1093a5fd-5a5e-47d7-8bfd-b870ede05648
Spacecraft System07a9a21c-2070-4d6b-8818-bb3bca62dfd8
\n" 592 | ], 593 | "text/plain": [ 594 | "" 595 | ] 596 | }, 597 | "metadata": {}, 598 | "output_type": "display_data" 599 | } 600 | ], 601 | "source": [ 602 | "element_get_url = f\"{host}/projects/{project_id}/commits/{commit2_id}/elements\" \n", 603 | "\n", 604 | "element_get_response = requests.get(element_get_url)\n", 605 | "\n", 606 | "if element_get_response.status_code == 200:\n", 607 | " elements = element_get_response.json()\n", 608 | " elements_data = list(map(lambda b: {'Element Name':b['name'], 'Element ID':b['@id']}, elements))\n", 609 | " df = pd.DataFrame.from_records(elements_data).sort_values(by='Element Name').style.hide(axis='index')\n", 610 | " display(df)\n", 611 | "else:\n", 612 | " pprint(f\"Problem in fetching elements in the Spacecraft project {project_id} at commit {commit2_id}.\")\n", 613 | " pprint(element_get_response)" 614 | ] 615 | }, 616 | { 617 | "cell_type": "markdown", 618 | "id": "8dbea034-4180-415f-9604-8e1afb149fdc", 619 | "metadata": {}, 620 | "source": [ 621 | "# Create the 3rd commit that deletes an element (same one whose name was updated)" 622 | ] 623 | }, 624 | { 625 | "cell_type": "code", 626 | "execution_count": 11, 627 | "id": "055f42b3-18de-4f94-ae53-43660948493b", 628 | "metadata": {}, 629 | "outputs": [ 630 | { 631 | "name": "stdout", 632 | "output_type": "stream", 633 | "text": [ 634 | "{'@id': '00f0b229-7e70-4688-80e8-ae2eafc0ce8e',\n", 635 | " '@type': 'Commit',\n", 636 | " 'owningProject': {'@id': 'f0594c9c-55ef-49f6-9591-d27d12cc0afb'},\n", 637 | " 'previousCommit': {'@id': 'da8991ce-1124-493b-8f34-a4bb2d0800e1'},\n", 638 | " 'timestamp': '2022-09-12T13:16:45.992847-04:00'}\n" 639 | ] 640 | } 641 | ], 642 | "source": [ 643 | "commit_body = {\n", 644 | " \"@type\": \"Commit\",\n", 645 | " \"change\": [\n", 646 | " {\n", 647 | " \"@type\": \"DataVersion\",\n", 648 | " \"payload\":None,\n", 649 | " \"identity\": {\n", 650 | " \"@id\": payload_system_element_id\n", 651 | " }\n", 652 | " }\n", 653 | " ],\n", 654 | " \"previousCommit\": {\n", 655 | " \"@id\": commit2_id\n", 656 | " }\n", 657 | "}\n", 658 | "\n", 659 | "commit_post_url = f\"{host}/projects/{project_id}/commits\" \n", 660 | "\n", 661 | "commit_post_response = requests.post(commit_post_url, \n", 662 | " headers={\"Content-Type\": \"application/json\"}, \n", 663 | " data=json.dumps(commit_body))\n", 664 | "\n", 665 | "commit3_id = \"\"\n", 666 | "\n", 667 | "if commit_post_response.status_code == 200:\n", 668 | " commit_response_json = commit_post_response.json()\n", 669 | " pprint(commit_response_json)\n", 670 | " commit3_id = commit_response_json['@id']\n", 671 | "else:\n", 672 | " pprint(f\"Problem in creating a new commit in Spacecraft project {project_id}\")\n", 673 | " pprint(commit_post_response)" 674 | ] 675 | }, 676 | { 677 | "cell_type": "markdown", 678 | "id": "61cdaecd-44db-4e27-85dd-de5d002648cc", 679 | "metadata": {}, 680 | "source": [ 681 | "# Get all elements after the 3rd commit (should only 1 element)" 682 | ] 683 | }, 684 | { 685 | "cell_type": "code", 686 | "execution_count": 12, 687 | "id": "86008838-368a-4e58-9d5b-70e9c57442f4", 688 | "metadata": {}, 689 | "outputs": [ 690 | { 691 | "name": "stdout", 692 | "output_type": "stream", 693 | "text": [ 694 | "'Fetching elements at commit da8991ce-1124-493b-8f34-a4bb2d0800e1'\n" 695 | ] 696 | }, 697 | { 698 | "data": { 699 | "text/html": [ 700 | "\n", 702 | "\n", 703 | " \n", 704 | " \n", 705 | " \n", 706 | " \n", 707 | " \n", 708 | " \n", 709 | " \n", 710 | " \n", 711 | " \n", 712 | " \n", 713 | " \n", 714 | " \n", 715 | "
Element NameElement ID
Spacecraft System07a9a21c-2070-4d6b-8818-bb3bca62dfd8
\n" 716 | ], 717 | "text/plain": [ 718 | "" 719 | ] 720 | }, 721 | "metadata": {}, 722 | "output_type": "display_data" 723 | } 724 | ], 725 | "source": [ 726 | "pprint(f\"Fetching elements at commit {commit2_id}\")\n", 727 | "element_get_url = f\"{host}/projects/{project_id}/commits/{commit3_id}/elements\" \n", 728 | "\n", 729 | "element_get_response = requests.get(element_get_url)\n", 730 | "\n", 731 | "if element_get_response.status_code == 200:\n", 732 | " elements = element_get_response.json()\n", 733 | " elements_data = list(map(lambda b: {'Element Name':b['name'], 'Element ID':b['@id']}, elements))\n", 734 | " df = pd.DataFrame.from_records(elements_data).sort_values(by='Element Name').style.hide(axis='index')\n", 735 | " display(df)\n", 736 | "else:\n", 737 | " pprint(f\"Problem in fetching elements in the Spacecraft project {project_id} at commit {commit2_id}\")\n", 738 | " pprint(element_get_response)" 739 | ] 740 | } 741 | ], 742 | "metadata": { 743 | "kernelspec": { 744 | "display_name": "Python 3 (ipykernel)", 745 | "language": "python", 746 | "name": "python3" 747 | }, 748 | "language_info": { 749 | "codemirror_mode": { 750 | "name": "ipython", 751 | "version": 3 752 | }, 753 | "file_extension": ".py", 754 | "mimetype": "text/x-python", 755 | "name": "python", 756 | "nbconvert_exporter": "python", 757 | "pygments_lexer": "ipython3", 758 | "version": "3.8.13" 759 | } 760 | }, 761 | "nbformat": 4, 762 | "nbformat_minor": 5 763 | } 764 | -------------------------------------------------------------------------------- /Project_Commit_Branch_Tag_Recipe.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "3ee4834f", 6 | "metadata": { 7 | "tags": [] 8 | }, 9 | "source": [ 10 | "# Initializing the SysML v2 API" 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": 138, 16 | "id": "6b5fef59", 17 | "metadata": {}, 18 | "outputs": [], 19 | "source": [ 20 | "from __future__ import print_function\n", 21 | "\n", 22 | "import time\n", 23 | "import requests\n", 24 | "from pprint import pprint\n", 25 | "import pandas as pd\n", 26 | "import json\n", 27 | "from datetime import datetime\n", 28 | "\n", 29 | "#host = \"\n", 51 | "\n", 52 | "\n", 53 | " \n", 54 | " \n", 55 | " \n", 56 | " \n", 57 | " \n", 58 | " \n", 59 | " \n", 60 | " \n", 61 | " \n", 62 | " \n", 63 | " \n", 64 | " \n", 65 | " \n", 66 | " \n", 67 | " \n", 68 | " \n", 69 | " \n", 70 | " \n", 71 | " \n", 72 | " \n", 73 | " \n", 74 | " \n", 75 | " \n", 76 | " \n", 77 | " \n", 78 | " \n", 79 | " \n", 80 | " \n", 81 | " \n", 82 | " \n", 83 | " \n", 84 | " \n", 85 | " \n", 86 | " \n", 87 | " \n", 88 | " \n", 89 | " \n", 90 | " \n", 91 | " \n", 92 | " \n", 93 | " \n", 94 | " \n", 95 | " \n", 96 | " \n", 97 | " \n", 98 | " \n", 99 | " \n", 100 | " \n", 101 | " \n", 102 | " \n", 103 | " \n", 104 | " \n", 105 | " \n", 106 | " \n", 107 | " \n", 108 | " \n", 109 | " \n", 110 | " \n", 111 | " \n", 112 | " \n", 113 | " \n", 114 | " \n", 115 | " \n", 116 | " \n", 117 | " \n", 118 | " \n", 119 | " \n", 120 | " \n", 121 | " \n", 122 | " \n", 123 | " \n", 124 | " \n", 125 | " \n", 126 | " \n", 127 | " \n", 128 | " \n", 129 | " \n", 130 | " \n", 131 | " \n", 132 | " \n", 133 | " \n", 134 | " \n", 135 | " \n", 136 | " \n", 137 | " \n", 138 | " \n", 139 | " \n", 140 | " \n", 141 | " \n", 142 | " \n", 143 | " \n", 144 | " \n", 145 | " \n", 146 | " \n", 147 | " \n", 148 | " \n", 149 | " \n", 150 | " \n", 151 | " \n", 152 | " \n", 153 | " \n", 154 | " \n", 155 | " \n", 156 | " \n", 157 | " \n", 158 | " \n", 159 | " \n", 160 | " \n", 161 | " \n", 162 | " \n", 163 | " \n", 164 | " \n", 165 | " \n", 166 | " \n", 167 | " \n", 168 | " \n", 169 | " \n", 170 | " \n", 171 | " \n", 172 | " \n", 173 | " \n", 174 | " \n", 175 | " \n", 176 | " \n", 177 | " \n", 178 | " \n", 179 | " \n", 180 | " \n", 181 | " \n", 182 | " \n", 183 | " \n", 184 | " \n", 185 | " \n", 186 | " \n", 187 | " \n", 188 | " \n", 189 | " \n", 190 | " \n", 191 | " \n", 192 | " \n", 193 | " \n", 194 | " \n", 195 | " \n", 196 | " \n", 197 | " \n", 198 | " \n", 199 | " \n", 200 | " \n", 201 | " \n", 202 | " \n", 203 | " \n", 204 | " \n", 205 | " \n", 206 | " \n", 207 | " \n", 208 | " \n", 209 | " \n", 210 | " \n", 211 | " \n", 212 | " \n", 213 | " \n", 214 | " \n", 215 | " \n", 216 | " \n", 217 | " \n", 218 | " \n", 219 | " \n", 220 | " \n", 221 | " \n", 222 | " \n", 223 | " \n", 224 | " \n", 225 | " \n", 226 | " \n", 227 | " \n", 228 | " \n", 229 | " \n", 230 | " \n", 231 | " \n", 232 | " \n", 233 | " \n", 234 | " \n", 235 | " \n", 236 | " \n", 237 | " \n", 238 | " \n", 239 | " \n", 240 | " \n", 241 | " \n", 242 | " \n", 243 | " \n", 244 | " \n", 245 | " \n", 246 | " \n", 247 | " \n", 248 | " \n", 249 | " \n", 250 | " \n", 251 | " \n", 252 | " \n", 253 | " \n", 254 | " \n", 255 | " \n", 256 | " \n", 257 | " \n", 258 | " \n", 259 | " \n", 260 | " \n", 261 | " \n", 262 | " \n", 263 | " \n", 264 | " \n", 265 | " \n", 266 | " \n", 267 | " \n", 268 | " \n", 269 | " \n", 270 | " \n", 271 | " \n", 272 | " \n", 273 | " \n", 274 | " \n", 275 | " \n", 276 | " \n", 277 | " \n", 278 | " \n", 279 | " \n", 280 | " \n", 281 | " \n", 282 | " \n", 283 | " \n", 284 | " \n", 285 | " \n", 286 | " \n", 287 | " \n", 288 | " \n", 289 | " \n", 290 | " \n", 291 | " \n", 292 | " \n", 293 | " \n", 294 | " \n", 295 | " \n", 296 | " \n", 297 | " \n", 298 | " \n", 299 | " \n", 300 | " \n", 301 | " \n", 302 | " \n", 303 | " \n", 304 | " \n", 305 | " \n", 306 | " \n", 307 | " \n", 308 | " \n", 309 | " \n", 310 | " \n", 311 | " \n", 312 | " \n", 313 | " \n", 314 | " \n", 315 | " \n", 316 | " \n", 317 | " \n", 318 | " \n", 319 | " \n", 320 | " \n", 321 | " \n", 322 | " \n", 323 | " \n", 324 | " \n", 325 | " \n", 326 | " \n", 327 | " \n", 328 | " \n", 329 | " \n", 330 | " \n", 331 | " \n", 332 | " \n", 333 | " \n", 334 | " \n", 335 | " \n", 336 | " \n", 337 | "
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" 338 | ], 339 | "text/plain": [ 340 | "" 341 | ] 342 | }, 343 | "metadata": {}, 344 | "output_type": "display_data" 345 | } 346 | ], 347 | "source": [ 348 | "projects_url = f\"{host}/projects\" \n", 349 | "projects_response = requests.get(projects_url)\n", 350 | "\n", 351 | "if projects_response.status_code == 200:\n", 352 | " projects = projects_response.json()\n", 353 | " projects_data = list(map(lambda b: {'Project Name':b['name'], 'Project ID':b['@id']}, projects))\n", 354 | " df = pd.DataFrame.from_records(projects_data).style.hide(axis='index')\n", 355 | " # if len(projects_data) > 0:\n", 356 | " # df = df.style.sort_values(by='Project Name')\n", 357 | " display(df)\n", 358 | "else:\n", 359 | " pprint(\"Problem in fetching projects\")" 360 | ] 361 | }, 362 | { 363 | "cell_type": "markdown", 364 | "id": "77345839-9d8f-409f-9131-440d1b30cbea", 365 | "metadata": {}, 366 | "source": [ 367 | "# Create a new project" 368 | ] 369 | }, 370 | { 371 | "cell_type": "code", 372 | "execution_count": 121, 373 | "id": "6d2ba2fc-157a-4ac8-b8f3-876bbd3a21ea", 374 | "metadata": {}, 375 | "outputs": [ 376 | { 377 | "name": "stdout", 378 | "output_type": "stream", 379 | "text": [ 380 | "{'@id': '1cb23e7a-4d70-487e-89ad-1cd8a22efb9e',\n", 381 | " '@type': 'Project',\n", 382 | " 'created': '2022-11-05T21:02:55.930924-04:00',\n", 383 | " 'defaultBranch': {'@id': 'b20df3d4-bb46-489f-b312-858952c21d89'},\n", 384 | " 'description': 'Spacecraft project with multiple commits, branches, and tags',\n", 385 | " 'name': 'Spacecraft project with branches and tags - 2022-11-05 '\n", 386 | " '21:02:55.729180'}\n" 387 | ] 388 | } 389 | ], 390 | "source": [ 391 | "timestamp = datetime.now()\n", 392 | "project_name = f\"Spacecraft project with branches and tags - {timestamp}\"\n", 393 | "project_data = {\n", 394 | " \"@type\":\"Project\",\n", 395 | " \"name\": project_name,\n", 396 | " \"description\": \"Spacecraft project with multiple commits, branches, and tags\"\n", 397 | "}\n", 398 | "\n", 399 | "project_post_url = f\"{host}/projects\" \n", 400 | "\n", 401 | "project_post_response = requests.post(project_post_url, \n", 402 | " headers={\"Content-Type\": \"application/json\"}, \n", 403 | " data=json.dumps(project_data))\n", 404 | "\n", 405 | "project_id = \"\"\n", 406 | "\n", 407 | "if project_post_response.status_code == 200:\n", 408 | " project_response_json = project_post_response.json()\n", 409 | " pprint(project_response_json)\n", 410 | " project_id = project_response_json['@id']\n", 411 | " project_name = project_response_json['name']\n", 412 | "else:\n", 413 | " pprint(f\"Problem in creating a new Spacecraft project at {timestamp}\")\n", 414 | " pprint(project_post_response)" 415 | ] 416 | }, 417 | { 418 | "cell_type": "markdown", 419 | "id": "921efbfd-04a1-4c5c-8e66-b31f0390aa45", 420 | "metadata": {}, 421 | "source": [ 422 | "# Get branches" 423 | ] 424 | }, 425 | { 426 | "cell_type": "code", 427 | "execution_count": 122, 428 | "id": "df3e1039-ba51-4653-8897-e98be111078e", 429 | "metadata": {}, 430 | "outputs": [ 431 | { 432 | "data": { 433 | "text/html": [ 434 | "\n", 436 | "\n", 437 | " \n", 438 | " \n", 439 | " \n", 440 | " \n", 441 | " \n", 442 | " \n", 443 | " \n", 444 | " \n", 445 | " \n", 446 | " \n", 447 | " \n", 448 | " \n", 449 | " \n", 450 | " \n", 451 | "
Branch NameBranch IDRef Commit (head)
mainb20df3d4-bb46-489f-b312-858952c21d89None
\n" 452 | ], 453 | "text/plain": [ 454 | "" 455 | ] 456 | }, 457 | "metadata": {}, 458 | "output_type": "display_data" 459 | } 460 | ], 461 | "source": [ 462 | "branches_url = f\"{host}/projects/{project_id}/branches\" \n", 463 | "branches_response = requests.get(branches_url)\n", 464 | "\n", 465 | "if branches_response.status_code == 200:\n", 466 | " branches = branches_response.json()\n", 467 | " branches_data = list(map(lambda b: {'Branch Name':b['name'], 'Branch ID':b['@id'], 'Ref Commit (head)':b['head']}, branches))\n", 468 | "\n", 469 | " df = pd.DataFrame.from_records(branches_data).sort_values(by='Branch Name').style.hide(axis='index')\n", 470 | " display(df)\n", 471 | "else:\n", 472 | " pprint(f\"Problem in fetching branches of Spacecraft project {project_id}\")\n", 473 | " pprint(branches_response)" 474 | ] 475 | }, 476 | { 477 | "cell_type": "markdown", 478 | "id": "5f761af7-0b40-4708-8c8e-217c9b2b6e8a", 479 | "metadata": {}, 480 | "source": [ 481 | "# Get tags" 482 | ] 483 | }, 484 | { 485 | "cell_type": "code", 486 | "execution_count": 123, 487 | "id": "65deeb6c-ce34-43c5-ad62-bf145e946f1d", 488 | "metadata": {}, 489 | "outputs": [ 490 | { 491 | "name": "stdout", 492 | "output_type": "stream", 493 | "text": [ 494 | "[]\n" 495 | ] 496 | }, 497 | { 498 | "data": { 499 | "text/html": [ 500 | "\n", 502 | "\n", 503 | " \n", 504 | " \n", 505 | " \n", 506 | " \n", 507 | "
\n" 508 | ], 509 | "text/plain": [ 510 | "" 511 | ] 512 | }, 513 | "metadata": {}, 514 | "output_type": "display_data" 515 | } 516 | ], 517 | "source": [ 518 | "tags_url = f\"{host}/projects/{project_id}/tags\" \n", 519 | "tags_response = requests.get(tags_url)\n", 520 | "\n", 521 | "if tags_response.status_code == 200:\n", 522 | " tags = tags_response.json()\n", 523 | " pprint(tags)\n", 524 | " tags_data = list(map(lambda b: {'Tag Name':b['name'], 'Tag ID':b['@id'], 'Tagged Commit':b['taggedCommit']}, tags))\n", 525 | "\n", 526 | " df = pd.DataFrame.from_records(tags_data).style.hide(axis='index')\n", 527 | " display(df)\n", 528 | "else:\n", 529 | " pprint(f\"Problem in fetching tags of Spacecraft project {project_id}\")\n", 530 | " pprint(tags_response)" 531 | ] 532 | }, 533 | { 534 | "cell_type": "markdown", 535 | "id": "569ca8f1-ebf1-41d2-93f3-8795a2439eea", 536 | "metadata": {}, 537 | "source": [ 538 | "# Create 1st Commit" 539 | ] 540 | }, 541 | { 542 | "cell_type": "code", 543 | "execution_count": 124, 544 | "id": "3eed91b9-903b-441f-b1f2-10dbcfafa342", 545 | "metadata": {}, 546 | "outputs": [ 547 | { 548 | "name": "stdout", 549 | "output_type": "stream", 550 | "text": [ 551 | "{'@id': '68654706-7146-48f0-8ed9-ec0ffa94feea',\n", 552 | " '@type': 'Commit',\n", 553 | " 'created': '2022-11-05T21:02:56.305306-04:00',\n", 554 | " 'description': None,\n", 555 | " 'owningProject': {'@id': '1cb23e7a-4d70-487e-89ad-1cd8a22efb9e'},\n", 556 | " 'previousCommit': None}\n" 557 | ] 558 | } 559 | ], 560 | "source": [ 561 | "commit_body = {\n", 562 | " \"@type\": \"Commit\",\n", 563 | " \"change\": [\n", 564 | " {\n", 565 | " \"@type\": \"DataVersion\",\n", 566 | " \"payload\": {\n", 567 | " \"@type\": \"PartDefinition\",\n", 568 | " \"name\":\"Spacecraft System\"\n", 569 | " }\n", 570 | " },\n", 571 | " {\n", 572 | " \"@type\": \"DataVersion\",\n", 573 | " \"payload\": {\n", 574 | " \"@type\": \"PartDefinition\",\n", 575 | " \"name\":\"Payload System\"\n", 576 | " }\n", 577 | " },\n", 578 | " {\n", 579 | " \"@type\": \"DataVersion\",\n", 580 | " \"payload\": {\n", 581 | " \"@type\": \"PartDefinition\",\n", 582 | " \"name\":\"Propulsion System\"\n", 583 | " }\n", 584 | " }\n", 585 | " ]\n", 586 | "}\n", 587 | "\n", 588 | "commit_post_url = f\"{host}/projects/{project_id}/commits\" \n", 589 | "\n", 590 | "commit_post_response = requests.post(commit_post_url, \n", 591 | " headers={\"Content-Type\": \"application/json\"}, \n", 592 | " data=json.dumps(commit_body))\n", 593 | "\n", 594 | "commit1_id = \"\"\n", 595 | "\n", 596 | "if commit_post_response.status_code == 200:\n", 597 | " commit_response_json = commit_post_response.json()\n", 598 | " pprint(commit_response_json)\n", 599 | " commit1_id = commit_response_json['@id']\n", 600 | "else:\n", 601 | " pprint(f\"Problem in creating a new commit in Spacecraft project {project_id}\")\n", 602 | " pprint(commit_post_response)" 603 | ] 604 | }, 605 | { 606 | "cell_type": "code", 607 | "execution_count": 125, 608 | "id": "65537f5c-f521-469e-92e4-9a2568afed05", 609 | "metadata": {}, 610 | "outputs": [ 611 | { 612 | "data": { 613 | "text/html": [ 614 | "\n", 616 | "\n", 617 | " \n", 618 | " \n", 619 | " \n", 620 | " \n", 621 | " \n", 622 | " \n", 623 | " \n", 624 | " \n", 625 | " \n", 626 | " \n", 627 | " \n", 628 | " \n", 629 | " \n", 630 | " \n", 631 | " \n", 632 | " \n", 633 | " \n", 634 | " \n", 635 | " \n", 636 | " \n", 637 | "
Element NameElement ID
Payload Systemaa45735a-6001-4f00-a7f2-ecad5d442d27
Propulsion System27e4f855-aa8a-4343-b25c-0c452cfb22ab
Spacecraft System00734e2e-565f-4411-8b06-b5c8eab5e178
\n" 638 | ], 639 | "text/plain": [ 640 | "" 641 | ] 642 | }, 643 | "metadata": {}, 644 | "output_type": "display_data" 645 | } 646 | ], 647 | "source": [ 648 | "element_get_url = f\"{host}/projects/{project_id}/commits/{commit1_id}/elements\" \n", 649 | "\n", 650 | "element_get_response = requests.get(element_get_url)\n", 651 | "\n", 652 | "if element_get_response.status_code == 200:\n", 653 | " elements = element_get_response.json()\n", 654 | " elements_data = list(map(lambda b: {'Element Name':b['name'], 'Element ID':b['@id']}, elements))\n", 655 | " df = pd.DataFrame.from_records(elements_data).sort_values(by='Element Name').style.hide(axis='index')\n", 656 | " display(df)\n", 657 | "else:\n", 658 | " pprint(f\"Problem in fetching elements in the Spacecraft project {project_id} at commit {commit1_id}.\")\n", 659 | " pprint(element_get_response)" 660 | ] 661 | }, 662 | { 663 | "cell_type": "markdown", 664 | "id": "8e38b288-6517-4a7b-90e5-ae73c5f89df3", 665 | "metadata": {}, 666 | "source": [ 667 | "# Create 2nd Commit" 668 | ] 669 | }, 670 | { 671 | "cell_type": "code", 672 | "execution_count": 126, 673 | "id": "76d80cb1-40c8-4f24-aeb5-51e509f4e159", 674 | "metadata": { 675 | "tags": [] 676 | }, 677 | "outputs": [ 678 | { 679 | "name": "stdout", 680 | "output_type": "stream", 681 | "text": [ 682 | "{'@id': '118e6f99-cde1-41fb-8f93-928fe6fa4be0',\n", 683 | " '@type': 'Commit',\n", 684 | " 'created': '2022-11-05T21:02:56.7703-04:00',\n", 685 | " 'description': None,\n", 686 | " 'owningProject': {'@id': '1cb23e7a-4d70-487e-89ad-1cd8a22efb9e'},\n", 687 | " 'previousCommit': {'@id': '68654706-7146-48f0-8ed9-ec0ffa94feea'}}\n" 688 | ] 689 | } 690 | ], 691 | "source": [ 692 | "commit_body = {\n", 693 | " \"@type\": \"Commit\",\n", 694 | " \"change\": [\n", 695 | " {\n", 696 | " \"@type\": \"DataVersion\",\n", 697 | " \"payload\": {\n", 698 | " \"@type\": \"PartDefinition\",\n", 699 | " \"name\":\"Avionics System\"\n", 700 | " }\n", 701 | " },\n", 702 | " {\n", 703 | " \"@type\": \"DataVersion\",\n", 704 | " \"payload\": {\n", 705 | " \"@type\": \"PartDefinition\",\n", 706 | " \"name\":\"Power System\"\n", 707 | " }\n", 708 | " }\n", 709 | " ],\n", 710 | " \"previousCommit\": {\n", 711 | " \"@id\": commit1_id\n", 712 | " }\n", 713 | "}\n", 714 | "\n", 715 | "commit_post_url = f\"{host}/projects/{project_id}/commits\" \n", 716 | "\n", 717 | "commit_post_response = requests.post(commit_post_url, \n", 718 | " headers={\"Content-Type\": \"application/json\"}, \n", 719 | " data=json.dumps(commit_body))\n", 720 | "\n", 721 | "commit2_id = \"\"\n", 722 | "\n", 723 | "if commit_post_response.status_code == 200:\n", 724 | " commit_response_json = commit_post_response.json()\n", 725 | " pprint(commit_response_json)\n", 726 | " commit2_id = commit_response_json['@id']\n", 727 | "else:\n", 728 | " pprint(f\"Problem in creating a new commit in Spacecraft project {project_id}\")\n", 729 | " pprint(commit_post_response)" 730 | ] 731 | }, 732 | { 733 | "cell_type": "markdown", 734 | "id": "d815e4fe", 735 | "metadata": {}, 736 | "source": [ 737 | "# Get all elements after the 2nd commit" 738 | ] 739 | }, 740 | { 741 | "cell_type": "code", 742 | "execution_count": 127, 743 | "id": "eac0a387-e4cf-4fc8-8b47-c64ed2ebff62", 744 | "metadata": {}, 745 | "outputs": [ 746 | { 747 | "data": { 748 | "text/html": [ 749 | "\n", 751 | "\n", 752 | " \n", 753 | " \n", 754 | " \n", 755 | " \n", 756 | " \n", 757 | " \n", 758 | " \n", 759 | " \n", 760 | " \n", 761 | " \n", 762 | " \n", 763 | " \n", 764 | " \n", 765 | " \n", 766 | " \n", 767 | " \n", 768 | " \n", 769 | " \n", 770 | " \n", 771 | " \n", 772 | " \n", 773 | " \n", 774 | " \n", 775 | " \n", 776 | " \n", 777 | " \n", 778 | " \n", 779 | " \n", 780 | "
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" 781 | ], 782 | "text/plain": [ 783 | "" 784 | ] 785 | }, 786 | "metadata": {}, 787 | "output_type": "display_data" 788 | } 789 | ], 790 | "source": [ 791 | "element_get_url = f\"{host}/projects/{project_id}/commits/{commit2_id}/elements\" \n", 792 | "\n", 793 | "element_get_response = requests.get(element_get_url)\n", 794 | "\n", 795 | "if element_get_response.status_code == 200:\n", 796 | " elements = element_get_response.json()\n", 797 | " elements_data = list(map(lambda b: {'Element Name':b['name'], 'Element ID':b['@id']}, elements))\n", 798 | " df = pd.DataFrame.from_records(elements_data).sort_values(by='Element Name').style.hide(axis='index')\n", 799 | " display(df)\n", 800 | "else:\n", 801 | " pprint(f\"Problem in fetching elements in the Spacecraft project {project_id} at commit {commit2_id}.\")\n", 802 | " pprint(element_get_response)" 803 | ] 804 | }, 805 | { 806 | "cell_type": "markdown", 807 | "id": "4b841d77-eb20-4f3c-bc64-fe08031d01bc", 808 | "metadata": {}, 809 | "source": [ 810 | "# Create a tag" 811 | ] 812 | }, 813 | { 814 | "cell_type": "code", 815 | "execution_count": 128, 816 | "id": "886842cc-c983-424f-9af9-083257a5732c", 817 | "metadata": {}, 818 | "outputs": [ 819 | { 820 | "name": "stdout", 821 | "output_type": "stream", 822 | "text": [ 823 | "{'@id': '65b1977d-bc03-4a94-be41-2ed85eda65ed',\n", 824 | " '@type': 'Tag',\n", 825 | " 'created': '2022-11-05T21:02:57.096895-04:00',\n", 826 | " 'name': 'Spacecraft Internal Release 0.1',\n", 827 | " 'owningProject': {'@id': '1cb23e7a-4d70-487e-89ad-1cd8a22efb9e'},\n", 828 | " 'referencedCommit': {'@id': '118e6f99-cde1-41fb-8f93-928fe6fa4be0'},\n", 829 | " 'taggedCommit': {'@id': '118e6f99-cde1-41fb-8f93-928fe6fa4be0'}}\n" 830 | ] 831 | } 832 | ], 833 | "source": [ 834 | "tag_body = {\n", 835 | " \"@type\": \"Tag\",\n", 836 | " \"name\": \"Spacecraft Internal Release 0.1\",\n", 837 | " \"taggedCommit\": {\n", 838 | " \"@id\": commit2_id\n", 839 | " }\n", 840 | "}\n", 841 | "\n", 842 | "tag_post_url = f\"{host}/projects/{project_id}/tags\" \n", 843 | "\n", 844 | "tag_post_response = requests.post(tag_post_url, \n", 845 | " headers={\"Content-Type\": \"application/json\"}, \n", 846 | " data=json.dumps(tag_body))\n", 847 | "\n", 848 | "tag1_id = \"\"\n", 849 | "\n", 850 | "if tag_post_response.status_code == 200:\n", 851 | " tag_response_json = tag_post_response.json()\n", 852 | " pprint(tag_response_json)\n", 853 | " tag1_id = tag_response_json['@id']\n", 854 | "else:\n", 855 | " pprint(f\"Problem in creating a new tag in Spacecraft project {project_id}.\")\n", 856 | " pprint(tag_post_response)" 857 | ] 858 | }, 859 | { 860 | "cell_type": "markdown", 861 | "id": "ec239663-ce0d-4ae6-acd7-5910299dedda", 862 | "metadata": {}, 863 | "source": [ 864 | "# Get Tags" 865 | ] 866 | }, 867 | { 868 | "cell_type": "code", 869 | "execution_count": 129, 870 | "id": "bf1ce47b-079d-429f-b43b-491c3aa156c8", 871 | "metadata": {}, 872 | "outputs": [ 873 | { 874 | "data": { 875 | "text/html": [ 876 | "\n", 878 | "\n", 879 | " \n", 880 | " \n", 881 | " \n", 882 | " \n", 883 | " \n", 884 | " \n", 885 | " \n", 886 | " \n", 887 | " \n", 888 | " \n", 889 | " \n", 890 | " \n", 891 | " \n", 892 | " \n", 893 | "
Tag NameTag IDTagged Commit
Spacecraft Internal Release 0.165b1977d-bc03-4a94-be41-2ed85eda65ed{'@id': '118e6f99-cde1-41fb-8f93-928fe6fa4be0'}
\n" 894 | ], 895 | "text/plain": [ 896 | "" 897 | ] 898 | }, 899 | "metadata": {}, 900 | "output_type": "display_data" 901 | } 902 | ], 903 | "source": [ 904 | "tags_url = f\"{host}/projects/{project_id}/tags\" \n", 905 | "tags_response = requests.get(tags_url)\n", 906 | "\n", 907 | "if tags_response.status_code == 200:\n", 908 | " tags = tags_response.json()\n", 909 | " tags_data = list(map(lambda b: {'Tag Name':b['name'], 'Tag ID':b['@id'], 'Tagged Commit':b['taggedCommit']}, tags))\n", 910 | "\n", 911 | " df = pd.DataFrame.from_records(tags_data).style.hide(axis='index')\n", 912 | " display(df)\n", 913 | "else:\n", 914 | " pprint(f\"Problem in fetching tags in Spacecraft project {project_id}.\")\n", 915 | " pprint(tag_post_response)" 916 | ] 917 | }, 918 | { 919 | "cell_type": "markdown", 920 | "id": "5a0ec0fa-af50-4944-8401-183f2cb165af", 921 | "metadata": {}, 922 | "source": [ 923 | "# Create a new branch at the second commit (also tagged as 0.1)" 924 | ] 925 | }, 926 | { 927 | "cell_type": "code", 928 | "execution_count": 130, 929 | "id": "cc9620df-e407-4a25-8ae4-bd803d1cde32", 930 | "metadata": {}, 931 | "outputs": [ 932 | { 933 | "name": "stdout", 934 | "output_type": "stream", 935 | "text": [ 936 | "{'@id': 'adb35786-0381-4f86-814e-deff94481ca5',\n", 937 | " '@type': 'Branch',\n", 938 | " 'created': '2022-11-05T21:02:57.268637-04:00',\n", 939 | " 'head': {'@id': '118e6f99-cde1-41fb-8f93-928fe6fa4be0'},\n", 940 | " 'name': 'develop',\n", 941 | " 'owningProject': {'@id': '1cb23e7a-4d70-487e-89ad-1cd8a22efb9e'},\n", 942 | " 'referencedCommit': {'@id': '118e6f99-cde1-41fb-8f93-928fe6fa4be0'}}\n" 943 | ] 944 | } 945 | ], 946 | "source": [ 947 | "branch_body = {\n", 948 | " \"@type\": \"Branch\",\n", 949 | " \"name\": \"develop\",\n", 950 | " \"head\": {\n", 951 | " \"@id\": commit2_id\n", 952 | " }\n", 953 | "}\n", 954 | "\n", 955 | "branch_post_url = f\"{host}/projects/{project_id}/branches\" \n", 956 | "\n", 957 | "branch_post_response = requests.post(branch_post_url, \n", 958 | " headers={\"Content-Type\": \"application/json\"}, \n", 959 | " data=json.dumps(branch_body))\n", 960 | "\n", 961 | "branch_develop_id = \"\"\n", 962 | "\n", 963 | "if branch_post_response.status_code == 200:\n", 964 | " branch_response_json = branch_post_response.json()\n", 965 | " pprint(branch_response_json)\n", 966 | " branch_develop_id = branch_response_json['@id']\n", 967 | "else:\n", 968 | " pprint(f\"Problem in creating a new branch in Spacecraft project {project_id}\")\n", 969 | " pprint(branch_post_response)" 970 | ] 971 | }, 972 | { 973 | "cell_type": "markdown", 974 | "id": "19ba5702-85d2-40ec-b01c-de6f112e8bfa", 975 | "metadata": { 976 | "tags": [] 977 | }, 978 | "source": [ 979 | "# Get branches" 980 | ] 981 | }, 982 | { 983 | "cell_type": "code", 984 | "execution_count": 131, 985 | "id": "61faab74-218a-4bf4-832d-2e3a3d70578d", 986 | "metadata": {}, 987 | "outputs": [ 988 | { 989 | "data": { 990 | "text/html": [ 991 | "\n", 993 | "\n", 994 | " \n", 995 | " \n", 996 | " \n", 997 | " \n", 998 | " \n", 999 | " \n", 1000 | " \n", 1001 | " \n", 1002 | " \n", 1003 | " \n", 1004 | " \n", 1005 | " \n", 1006 | " \n", 1007 | " \n", 1008 | " \n", 1009 | " \n", 1010 | " \n", 1011 | " \n", 1012 | " \n", 1013 | "
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" 1014 | ], 1015 | "text/plain": [ 1016 | "" 1017 | ] 1018 | }, 1019 | "metadata": {}, 1020 | "output_type": "display_data" 1021 | } 1022 | ], 1023 | "source": [ 1024 | "branches_url = f\"{host}/projects/{project_id}/branches\" \n", 1025 | "branches_response = requests.get(branches_url)\n", 1026 | "\n", 1027 | "if branches_response.status_code == 200:\n", 1028 | " branches = branches_response.json()\n", 1029 | " branches_data = list(map(lambda b: {'Branch Name':b['name'], 'Branch ID':b['@id'], 'Ref Commit (head)':b['head']}, branches))\n", 1030 | "\n", 1031 | " df = pd.DataFrame.from_records(branches_data).sort_values(by='Branch Name').style.hide(axis='index')\n", 1032 | " display(df)\n", 1033 | "else:\n", 1034 | " pprint(f\"Problem in fetching branches in Spacecraft project {project_id}\")\n", 1035 | " pprint(branches_response)" 1036 | ] 1037 | }, 1038 | { 1039 | "cell_type": "markdown", 1040 | "id": "8dbea034-4180-415f-9604-8e1afb149fdc", 1041 | "metadata": {}, 1042 | "source": [ 1043 | "# Create a new commit in the develop branch" 1044 | ] 1045 | }, 1046 | { 1047 | "cell_type": "code", 1048 | "execution_count": 132, 1049 | "id": "055f42b3-18de-4f94-ae53-43660948493b", 1050 | "metadata": {}, 1051 | "outputs": [ 1052 | { 1053 | "name": "stdout", 1054 | "output_type": "stream", 1055 | "text": [ 1056 | "{'@id': '5665c584-4474-4599-8b74-46c3c647a2cf',\n", 1057 | " '@type': 'Commit',\n", 1058 | " 'created': '2022-11-05T21:02:57.444978-04:00',\n", 1059 | " 'description': None,\n", 1060 | " 'owningProject': {'@id': '1cb23e7a-4d70-487e-89ad-1cd8a22efb9e'},\n", 1061 | " 'previousCommit': {'@id': '118e6f99-cde1-41fb-8f93-928fe6fa4be0'}}\n" 1062 | ] 1063 | } 1064 | ], 1065 | "source": [ 1066 | "commit_body = {\n", 1067 | " \"@type\": \"Commit\",\n", 1068 | " \"change\": [\n", 1069 | " {\n", 1070 | " \"@type\": \"DataVersion\",\n", 1071 | " \"payload\": {\n", 1072 | " \"@type\": \"PartDefinition\",\n", 1073 | " \"name\":\"GN & C System\"\n", 1074 | " }\n", 1075 | " }\n", 1076 | " ],\n", 1077 | " \"previousCommit\": {\n", 1078 | " \"@id\": commit2_id\n", 1079 | " }\n", 1080 | "}\n", 1081 | "\n", 1082 | "commit_post_url = f\"{host}/projects/{project_id}/commits\" \n", 1083 | "\n", 1084 | "commit_post_response = requests.post(commit_post_url, \n", 1085 | " headers={\"Content-Type\": \"application/json\"}, \n", 1086 | " data=json.dumps(commit_body),\n", 1087 | " params={\"branchId\":branch_develop_id})\n", 1088 | "\n", 1089 | "commit3_id = \"\"\n", 1090 | "\n", 1091 | "if commit_post_response.status_code == 200:\n", 1092 | " commit_response_json = commit_post_response.json()\n", 1093 | " pprint(commit_response_json)\n", 1094 | " commit3_id = commit_response_json['@id']\n", 1095 | "else:\n", 1096 | " pprint(f\"Problem in creating a new commit in Spacecraft project {project_id}\")\n", 1097 | " pprint(commit_post_response)" 1098 | ] 1099 | }, 1100 | { 1101 | "cell_type": "markdown", 1102 | "id": "e2ba3c85-db23-460d-b6d4-6afbd6461e7d", 1103 | "metadata": {}, 1104 | "source": [ 1105 | "# Get Branches" 1106 | ] 1107 | }, 1108 | { 1109 | "cell_type": "code", 1110 | "execution_count": 133, 1111 | "id": "ead42406-7536-4f47-b0d8-d34a48e9054e", 1112 | "metadata": {}, 1113 | "outputs": [ 1114 | { 1115 | "data": { 1116 | "text/html": [ 1117 | "\n", 1119 | "\n", 1120 | " \n", 1121 | " \n", 1122 | " \n", 1123 | " \n", 1124 | " \n", 1125 | " \n", 1126 | " \n", 1127 | " \n", 1128 | " \n", 1129 | " \n", 1130 | " \n", 1131 | " \n", 1132 | " \n", 1133 | " \n", 1134 | " \n", 1135 | " \n", 1136 | " \n", 1137 | " \n", 1138 | " \n", 1139 | "
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" 1140 | ], 1141 | "text/plain": [ 1142 | "" 1143 | ] 1144 | }, 1145 | "metadata": {}, 1146 | "output_type": "display_data" 1147 | } 1148 | ], 1149 | "source": [ 1150 | "branches_url = f\"{host}/projects/{project_id}/branches\" \n", 1151 | "branches_response = requests.get(branches_url)\n", 1152 | "\n", 1153 | "if branches_response.status_code == 200:\n", 1154 | " branches = branches_response.json()\n", 1155 | " branches_data = list(map(lambda b: {'Branch Name':b['name'], 'Branch ID':b['@id'], 'Ref Commit (head)':b['head']}, branches))\n", 1156 | "\n", 1157 | " df = pd.DataFrame.from_records(branches_data).sort_values(by='Branch Name').style.hide(axis='index')\n", 1158 | " display(df)\n", 1159 | "else:\n", 1160 | " pprint(f\"Problem in fetching branches in Spacecraft project {project_id}\")\n", 1161 | " pprint(commit_post_response)" 1162 | ] 1163 | }, 1164 | { 1165 | "cell_type": "markdown", 1166 | "id": "61cdaecd-44db-4e27-85dd-de5d002648cc", 1167 | "metadata": {}, 1168 | "source": [ 1169 | "# Get all elements as of the latest commit on main branch" 1170 | ] 1171 | }, 1172 | { 1173 | "cell_type": "code", 1174 | "execution_count": 134, 1175 | "id": "86008838-368a-4e58-9d5b-70e9c57442f4", 1176 | "metadata": {}, 1177 | "outputs": [ 1178 | { 1179 | "name": "stdout", 1180 | "output_type": "stream", 1181 | "text": [ 1182 | "'Fetching elements at commit 118e6f99-cde1-41fb-8f93-928fe6fa4be0'\n" 1183 | ] 1184 | }, 1185 | { 1186 | "data": { 1187 | "text/html": [ 1188 | "\n", 1190 | "\n", 1191 | " \n", 1192 | " \n", 1193 | " \n", 1194 | " \n", 1195 | " \n", 1196 | " \n", 1197 | " \n", 1198 | " \n", 1199 | " \n", 1200 | " \n", 1201 | " \n", 1202 | " \n", 1203 | " \n", 1204 | " \n", 1205 | " \n", 1206 | " \n", 1207 | " \n", 1208 | " \n", 1209 | " \n", 1210 | " \n", 1211 | " \n", 1212 | " \n", 1213 | " \n", 1214 | " \n", 1215 | " \n", 1216 | " \n", 1217 | " \n", 1218 | " \n", 1219 | "
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" 1220 | ], 1221 | "text/plain": [ 1222 | "" 1223 | ] 1224 | }, 1225 | "metadata": {}, 1226 | "output_type": "display_data" 1227 | } 1228 | ], 1229 | "source": [ 1230 | "pprint(f\"Fetching elements at commit {commit2_id}\")\n", 1231 | "element_get_url = f\"{host}/projects/{project_id}/commits/{commit2_id}/elements\" \n", 1232 | "\n", 1233 | "element_get_response = requests.get(element_get_url)\n", 1234 | "\n", 1235 | "if element_get_response.status_code == 200:\n", 1236 | " elements = element_get_response.json()\n", 1237 | " elements_data = list(map(lambda b: {'Element Name':b['name'], 'Element ID':b['@id']}, elements))\n", 1238 | " df = pd.DataFrame.from_records(elements_data).sort_values(by='Element Name').style.hide(axis='index')\n", 1239 | " display(df)\n", 1240 | "else:\n", 1241 | " pprint(f\"Problem in fetching elements in the Spacecraft project {project_id} at commit {commit2_id}\")\n", 1242 | " pprint(element_get_response)" 1243 | ] 1244 | }, 1245 | { 1246 | "cell_type": "markdown", 1247 | "id": "24a94903-9a4e-4f2b-b1bf-be21b7e22e48", 1248 | "metadata": {}, 1249 | "source": [ 1250 | "# Get all elements as of the latest commit on develop branch" 1251 | ] 1252 | }, 1253 | { 1254 | "cell_type": "code", 1255 | "execution_count": 135, 1256 | "id": "60bf125d-5258-4546-99da-3680de66dd1b", 1257 | "metadata": {}, 1258 | "outputs": [ 1259 | { 1260 | "name": "stdout", 1261 | "output_type": "stream", 1262 | "text": [ 1263 | "'Fetching elements at commit 5665c584-4474-4599-8b74-46c3c647a2cf'\n" 1264 | ] 1265 | }, 1266 | { 1267 | "data": { 1268 | "text/html": [ 1269 | "\n", 1271 | "\n", 1272 | " \n", 1273 | " \n", 1274 | " \n", 1275 | " \n", 1276 | " \n", 1277 | " \n", 1278 | " \n", 1279 | " \n", 1280 | " \n", 1281 | " \n", 1282 | " \n", 1283 | " \n", 1284 | " \n", 1285 | " \n", 1286 | " \n", 1287 | " \n", 1288 | " \n", 1289 | " \n", 1290 | " \n", 1291 | " \n", 1292 | " \n", 1293 | " \n", 1294 | " \n", 1295 | " \n", 1296 | " \n", 1297 | " \n", 1298 | " \n", 1299 | " \n", 1300 | " \n", 1301 | " \n", 1302 | " \n", 1303 | " \n", 1304 | "
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" 1305 | ], 1306 | "text/plain": [ 1307 | "" 1308 | ] 1309 | }, 1310 | "metadata": {}, 1311 | "output_type": "display_data" 1312 | } 1313 | ], 1314 | "source": [ 1315 | "pprint(f\"Fetching elements at commit {commit3_id}\")\n", 1316 | "element_get_url = f\"{host}/projects/{project_id}/commits/{commit3_id}/elements\" \n", 1317 | "\n", 1318 | "element_get_response = requests.get(element_get_url)\n", 1319 | "\n", 1320 | "if element_get_response.status_code == 200:\n", 1321 | " elements = element_get_response.json()\n", 1322 | " elements_data = list(map(lambda b: {'Element Name':b['name'], 'Element ID':b['@id']}, elements))\n", 1323 | " df = pd.DataFrame.from_records(elements_data).sort_values(by='Element Name').style.hide(axis='index')\n", 1324 | " display(df)\n", 1325 | "else:\n", 1326 | " pprint(f\"Problem in fetching elements in the Spacecraft project {project_id} at commit {commit3_id}\")\n", 1327 | " pprint(element_get_response)" 1328 | ] 1329 | }, 1330 | { 1331 | "cell_type": "markdown", 1332 | "id": "f162ef4e-3e68-4a66-b8fa-2abde70e867d", 1333 | "metadata": {}, 1334 | "source": [ 1335 | "# Create a tag at the last commit on develop branch" 1336 | ] 1337 | }, 1338 | { 1339 | "cell_type": "code", 1340 | "execution_count": 136, 1341 | "id": "b3e26544-b2e4-4370-bb85-9d23aabcc0b5", 1342 | "metadata": {}, 1343 | "outputs": [ 1344 | { 1345 | "name": "stdout", 1346 | "output_type": "stream", 1347 | "text": [ 1348 | "{'@id': '040ddf64-13a9-4bf8-b533-ad831f7862db',\n", 1349 | " '@type': 'Tag',\n", 1350 | " 'created': '2022-11-05T21:02:58.049038-04:00',\n", 1351 | " 'name': 'Spacecraft Internal Release 0.2 build 1',\n", 1352 | " 'owningProject': {'@id': '1cb23e7a-4d70-487e-89ad-1cd8a22efb9e'},\n", 1353 | " 'referencedCommit': {'@id': '5665c584-4474-4599-8b74-46c3c647a2cf'},\n", 1354 | " 'taggedCommit': {'@id': '5665c584-4474-4599-8b74-46c3c647a2cf'}}\n" 1355 | ] 1356 | } 1357 | ], 1358 | "source": [ 1359 | "tag_body = {\n", 1360 | " \"@type\": \"Tag\",\n", 1361 | " \"name\": \"Spacecraft Internal Release 0.2 build 1\",\n", 1362 | " \"taggedCommit\": {\n", 1363 | " \"@id\": commit3_id\n", 1364 | " }\n", 1365 | "}\n", 1366 | "\n", 1367 | "tag_post_url = f\"{host}/projects/{project_id}/tags\" \n", 1368 | "\n", 1369 | "tag_post_response = requests.post(tag_post_url, \n", 1370 | " headers={\"Content-Type\": \"application/json\"}, \n", 1371 | " data=json.dumps(tag_body))\n", 1372 | "\n", 1373 | "tag1_id = \"\"\n", 1374 | "\n", 1375 | "if tag_post_response.status_code == 200:\n", 1376 | " tag_response_json = tag_post_response.json()\n", 1377 | " pprint(tag_response_json)\n", 1378 | " tag1_id = tag_response_json['@id']\n", 1379 | "else:\n", 1380 | " pprint(f\"Problem in creating a new tag in Spacecraft project {project_id}.\")\n", 1381 | " pprint(tag_post_response)" 1382 | ] 1383 | }, 1384 | { 1385 | "cell_type": "markdown", 1386 | "id": "20dfd748-3149-4442-a7e8-fbef247377a7", 1387 | "metadata": {}, 1388 | "source": [ 1389 | "# Get all tags" 1390 | ] 1391 | }, 1392 | { 1393 | "cell_type": "code", 1394 | "execution_count": 137, 1395 | "id": "aee7a152-8b4c-476a-8691-4766fc94c240", 1396 | "metadata": {}, 1397 | "outputs": [ 1398 | { 1399 | "data": { 1400 | "text/html": [ 1401 | "\n", 1403 | "\n", 1404 | " \n", 1405 | " \n", 1406 | " \n", 1407 | " \n", 1408 | " \n", 1409 | " \n", 1410 | " \n", 1411 | " \n", 1412 | " \n", 1413 | " \n", 1414 | " \n", 1415 | " \n", 1416 | " \n", 1417 | " \n", 1418 | " \n", 1419 | " \n", 1420 | " \n", 1421 | " \n", 1422 | " \n", 1423 | "
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" 1424 | ], 1425 | "text/plain": [ 1426 | "" 1427 | ] 1428 | }, 1429 | "metadata": {}, 1430 | "output_type": "display_data" 1431 | } 1432 | ], 1433 | "source": [ 1434 | "tags_url = f\"{host}/projects/{project_id}/tags\" \n", 1435 | "tags_response = requests.get(tags_url)\n", 1436 | "\n", 1437 | "if tags_response.status_code == 200:\n", 1438 | " tags = tags_response.json()\n", 1439 | " tags_data = list(map(lambda b: {'Tag Name':b['name'], 'Tag ID':b['@id'], 'Tagged Commit':b['taggedCommit']}, tags))\n", 1440 | "\n", 1441 | " df = pd.DataFrame.from_records(tags_data).style.hide(axis='index')\n", 1442 | " display(df)\n", 1443 | "else:\n", 1444 | " pprint(f\"Problem in fetching tags in Spacecraft project {project_id}.\")\n", 1445 | " pprint(tag_post_response)" 1446 | ] 1447 | }, 1448 | { 1449 | "cell_type": "code", 1450 | "execution_count": null, 1451 | "id": "59690f32-5000-44e3-b6f7-853be468c57c", 1452 | "metadata": {}, 1453 | "outputs": [], 1454 | "source": [] 1455 | } 1456 | ], 1457 | "metadata": { 1458 | "kernelspec": { 1459 | "display_name": "Python 3 (ipykernel)", 1460 | "language": "python", 1461 | "name": "python3" 1462 | }, 1463 | "language_info": { 1464 | "codemirror_mode": { 1465 | "name": "ipython", 1466 | "version": 3 1467 | }, 1468 | "file_extension": ".py", 1469 | "mimetype": "text/x-python", 1470 | "name": "python", 1471 | "nbconvert_exporter": "python", 1472 | "pygments_lexer": "ipython3", 1473 | "version": "3.8.16" 1474 | } 1475 | }, 1476 | "nbformat": 4, 1477 | "nbformat_minor": 5 1478 | } 1479 | --------------------------------------------------------------------------------