6. Introduction to Requirement access and management¶
Welcome to the ReqIF extension Showcase notebook. This notebook will show you some basic (and not so basic) things that you can get done using this library.
The below code loads the library and one of the test models:
[1]:
import capellambse
path_to_model = "../../../tests/data/melodymodel/5_0/Melody Model Test.aird"
model = capellambse.MelodyModel(path_to_model)
model
[1]:
<capellambse.model.MelodyModel at 0x7f6c60257ca0>
You can access a lookup for all requirements defined in a specific layer.
[2]:
model.oa.all_requirements
[2]:
- Requirement "TestReq1" (3c2d312c-37c9-41b5-8c32-67578fa52dc3)
- Requirement "TypedReq2" (0a9a68b1-ba9a-4793-b2cf-4448f0b4b8cc)
- Requirement "TestReq3" (79291c33-5147-4543-9398-9077d582576d)
- Requirement "TypedReq1" (85d41db2-9e17-438b-95cf-49342452ddf3)
- Requirement "TestReq" (1092f69a-5f3a-4fe6-a8fd-b2dffde90650)
Have a look at all of the available attributes for a Requirement ModelElement:
[3]:
model.oa.all_requirements[0]
[3]:
TestReq1 (Requirements:Requirement)
applied_property_value_groups | (Empty list) |
---|---|
applied_property_values | (Empty list) |
attributes |
|
chapter_name | 2 |
constraints | (Empty list) |
description | This is a test requirement of kind 1. |
diagrams | (Empty list) |
filtering_criteria | (Empty list) |
foreign_id | 1 |
identifier | REQTYPE-1 |
long_name | 1 |
name | TestReq1 |
owner | Folder "Folder" (e16f5cc1-3299-43d0-b1a0-82d31a137111) |
parent | Folder "Folder" (e16f5cc1-3299-43d0-b1a0-82d31a137111) |
prefix | 3 |
progress_status | NOT_SET |
property_value_groups | (Empty list) |
property_values | (Empty list) |
pvmt | <capellambse.extensions.pvmt.PropertyValueProxy object at 0x7f3afe4e68d0> |
related |
|
relations |
|
requirements |
|
summary | None |
text | Test requirement 1 really l o n g text that is way too long to display here as that < > " '
|
traces | (Empty list) |
type | RequirementType "ReqType" (db47fca9-ddb6-4397-8d4b-e397e53d277e) |
uuid | 3c2d312c-37c9-41b5-8c32-67578fa52dc3 |
xtype | Requirements:Requirement |
6.1. Filtering for requirements by type¶
You probably know about typing of your Requirements. You can have a view of all requirement type folders directly on a specific layer and see the stored requirement_types:
[4]:
model.oa.requirement_types_folders[0]
[4]:
CapellaTypesFolder (CapellaRequirements:CapellaTypesFolder)
applied_property_value_groups | (Empty list) |
---|---|
applied_property_values | (Empty list) |
constraints | (Empty list) |
data_type_definitions |
|
description | None |
diagrams | (Empty list) |
filtering_criteria | (Empty list) |
identifier | None |
long_name | Types |
module_types |
|
name | None |
parent | OperationalAnalysis "Operational Analysis" (ddbef16d-ddb9-4162-934c-f1e40e6f8bed) |
prefix | None |
progress_status | NOT_SET |
property_value_groups | (Empty list) |
property_values | (Empty list) |
pvmt | <capellambse.extensions.pvmt.PropertyValueProxy object at 0x7f3ad72c8f50> |
relation_types |
|
requirement_types |
|
requirements | (Empty list) |
summary | None |
traces | (Empty list) |
type | None |
uuid | 67bba9cf-953c-4f0b-9986-41991c68d241 |
xtype | CapellaRequirements:CapellaTypesFolder |
[5]:
reqtype = model.oa.requirement_types_folders[0].requirement_types[0]
reqtype
[5]:
RequirementType (Requirements:RequirementType)
applied_property_value_groups | (Empty list) |
---|---|
applied_property_values | (Empty list) |
attribute_definitions |
|
constraints | (Empty list) |
description | None |
diagrams | (Empty list) |
filtering_criteria | (Empty list) |
identifier | None |
long_name | ReqType |
name | None |
owner | CapellaTypesFolder "Types" (67bba9cf-953c-4f0b-9986-41991c68d241) |
parent | CapellaTypesFolder "Types" (67bba9cf-953c-4f0b-9986-41991c68d241) |
prefix | None |
progress_status | NOT_SET |
property_value_groups | (Empty list) |
property_values | (Empty list) |
pvmt | <capellambse.extensions.pvmt.PropertyValueProxy object at 0x7f3ad72f7910> |
requirements | (Empty list) |
summary | None |
traces | (Empty list) |
type | None |
uuid | db47fca9-ddb6-4397-8d4b-e397e53d277e |
xtype | Requirements:RequirementType |
Now we actually want to filter the requirements by this type with name ‘ReqType’. Very original name, we know. You wouldn’t really see the filtering effect since all requirements in the oa layer are of that type. So let us create one new requirement dynamically:
[6]:
new_req = model.oa.requirement_modules[0].requirements.create(
name="New showcase req1"
)
display(new_req)
model.oa.all_requirements
New showcase req1 (Requirements:Requirement)
applied_property_value_groups | (Empty list) |
---|---|
applied_property_values | (Empty list) |
attributes | (Empty list) |
chapter_name | None |
constraints | (Empty list) |
description | None |
diagrams | (Empty list) |
filtering_criteria | (Empty list) |
foreign_id | None |
identifier | None |
long_name | None |
name | New showcase req1 |
owner | CapellaModule "Test Module" (f8e2195d-b5f5-4452-a12b-79233d943d5e) |
parent | CapellaModule "Test Module" (f8e2195d-b5f5-4452-a12b-79233d943d5e) |
prefix | None |
progress_status | NOT_SET |
property_value_groups | (Empty list) |
property_values | (Empty list) |
pvmt | <capellambse.extensions.pvmt.PropertyValueProxy object at 0x7f3afc3ddd50> |
related | (Empty list) |
relations | (Empty list) |
requirements | (Empty list) |
summary | None |
text | |
traces | (Empty list) |
type | None |
uuid | 0ce7877e-68d6-4113-8aca-be69b2e25253 |
xtype | Requirements:Requirement |
[6]:
- Requirement "TestReq1" (3c2d312c-37c9-41b5-8c32-67578fa52dc3)
- Requirement "TypedReq2" (0a9a68b1-ba9a-4793-b2cf-4448f0b4b8cc)
- Requirement "TestReq3" (79291c33-5147-4543-9398-9077d582576d)
- Requirement "TypedReq1" (85d41db2-9e17-438b-95cf-49342452ddf3)
- Requirement "New showcase req1" (0ce7877e-68d6-4113-8aca-be69b2e25253)
- Requirement "TestReq" (1092f69a-5f3a-4fe6-a8fd-b2dffde90650)
Info about creation: Whenever you have an ElementList which deals with one specified classtype, here it is Requirement, then the classtype name doesn’t need to be included.
[7]:
model.oa.all_requirements.by_type("ReqType")
[7]:
- Requirement "TestReq1" (3c2d312c-37c9-41b5-8c32-67578fa52dc3)
- Requirement "TypedReq2" (0a9a68b1-ba9a-4793-b2cf-4448f0b4b8cc)
- Requirement "TestReq3" (79291c33-5147-4543-9398-9077d582576d)
- Requirement "TypedReq1" (85d41db2-9e17-438b-95cf-49342452ddf3)
- Requirement "TestReq" (1092f69a-5f3a-4fe6-a8fd-b2dffde90650)
We see our Requirements with type ReqType
are missing the new one. Let’s change that, without using capella.
[8]:
new_req.type = reqtype
model.oa.all_requirements.by_type("ReqType")
[8]:
- Requirement "TestReq1" (3c2d312c-37c9-41b5-8c32-67578fa52dc3)
- Requirement "TypedReq2" (0a9a68b1-ba9a-4793-b2cf-4448f0b4b8cc)
- Requirement "TestReq3" (79291c33-5147-4543-9398-9077d582576d)
- Requirement "TypedReq1" (85d41db2-9e17-438b-95cf-49342452ddf3)
- Requirement "New showcase req1" (0ce7877e-68d6-4113-8aca-be69b2e25253)
- Requirement "TestReq" (1092f69a-5f3a-4fe6-a8fd-b2dffde90650)
If you are sure about attributes when creating a Requirement you can also include it during creation.
[9]:
model.oa.requirement_modules[0].requirements.create(
name="ReqType during Creation",
type=reqtype,
)
model.oa.all_requirements.by_type("ReqType")
[9]:
- Requirement "TestReq1" (3c2d312c-37c9-41b5-8c32-67578fa52dc3)
- Requirement "TypedReq2" (0a9a68b1-ba9a-4793-b2cf-4448f0b4b8cc)
- Requirement "TestReq3" (79291c33-5147-4543-9398-9077d582576d)
- Requirement "TypedReq1" (85d41db2-9e17-438b-95cf-49342452ddf3)
- Requirement "New showcase req1" (0ce7877e-68d6-4113-8aca-be69b2e25253)
- Requirement "ReqType during Creation" (ec5f6680-501c-4a6c-a2ce-3ae8fe93be00)
- Requirement "TestReq" (1092f69a-5f3a-4fe6-a8fd-b2dffde90650)
[10]:
model.oa.all_requirements[0]
[10]:
TestReq1 (Requirements:Requirement)
applied_property_value_groups | (Empty list) |
---|---|
applied_property_values | (Empty list) |
attributes |
|
chapter_name | 2 |
constraints | (Empty list) |
description | This is a test requirement of kind 1. |
diagrams | (Empty list) |
filtering_criteria | (Empty list) |
foreign_id | 1 |
identifier | REQTYPE-1 |
long_name | 1 |
name | TestReq1 |
owner | Folder "Folder" (e16f5cc1-3299-43d0-b1a0-82d31a137111) |
parent | Folder "Folder" (e16f5cc1-3299-43d0-b1a0-82d31a137111) |
prefix | 3 |
progress_status | NOT_SET |
property_value_groups | (Empty list) |
property_values | (Empty list) |
pvmt | <capellambse.extensions.pvmt.PropertyValueProxy object at 0x7f3ad72dfd90> |
related |
|
relations |
|
requirements |
|
summary | None |
text | Test requirement 1 really l o n g text that is way too long to display here as that < > " '
|
traces | (Empty list) |
type | RequirementType "ReqType" (db47fca9-ddb6-4397-8d4b-e397e53d277e) |
uuid | 3c2d312c-37c9-41b5-8c32-67578fa52dc3 |
xtype | Requirements:Requirement |
6.2. Export all requirements to excel with pandas¶
With Pandas
you are able to generate data tables and export to many file-types like .xlsx for excel. Note that this requires the xlsxwriter
module in addition to pandas
itself.
[11]:
import pandas as pd
requirements = [
{"id": f"Req_{i}", "uuid": req.uuid, "text": req.text}
for i, req in enumerate(model.oa.all_requirements)
]
data = pd.DataFrame(requirements)
data.to_excel(excel_writer="Test_requirements.xlsx")
6.3. Export a Requirements module as Requirements Interchange Format (.reqif
) file¶
capellambse
features basic export functionality for requirements modules, which allows to write .reqif
or compressed .reqifz
files. These can then be imported into other ReqIF-compliant applications, like CodeBeamer or IBM DOORS.
Let’s first take a glance at the module we’re going to export:
[12]:
req_module = model.by_uuid("f8e2195d-b5f5-4452-a12b-79233d943d5e")
req_module
[12]:
Test Module (CapellaRequirements:CapellaModule)
applied_property_value_groups | (Empty list) |
---|---|
applied_property_values | (Empty list) |
attributes |
|
constraints | (Empty list) |
description | This is a test requirement module. |
diagrams | (Empty list) |
filtering_criteria | (Empty list) |
folders |
|
identifier | 1 |
long_name | Module |
name | Test Module |
parent | OperationalAnalysis "Operational Analysis" (ddbef16d-ddb9-4162-934c-f1e40e6f8bed) |
prefix | T |
progress_status | NOT_SET |
property_value_groups | (Empty list) |
property_values | (Empty list) |
pvmt | <capellambse.extensions.pvmt.PropertyValueProxy object at 0x7f3ad4787a10> |
requirement_types_folders | (Empty list) |
requirements |
|
summary | None |
traces | (Empty list) |
type | ModuleType "ModuleType" (a67e7f43-4b49-425c-a6a7-d44e1054a488) |
uuid | f8e2195d-b5f5-4452-a12b-79233d943d5e |
xtype | CapellaRequirements:CapellaModule |
[13]:
req_module.to_reqif(req_module.name + ".reqif")
And that’s it! This code has created the file “Test Module.reqif” next to this notebook, which contains all Requirements defined in that module.