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._model.MelodyModel at 0x78f9a032d490>
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 |
layer | OperationalAnalysis "Operational Analysis" (ddbef16d-ddb9-4162-934c-f1e40e6f8bed) |
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_value_packages | (Empty list) |
property_values | (Empty list) |
pvmt | Property Value Management for Requirement "TestReq1" (3c2d312c-37c9-41b5-8c32-67578fa52dc3) |
related |
|
relations |
|
requirements |
|
sid | |
summary | |
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 |
validation | <capellambse.extensions.validation._validate.ElementValidation object at 0x78f9a98ce600> |
visible_on_diagrams |
|
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 | |
diagrams | (Empty list) |
filtering_criteria | (Empty list) |
identifier | |
layer | OperationalAnalysis "Operational Analysis" (ddbef16d-ddb9-4162-934c-f1e40e6f8bed) |
long_name | Types |
module_types |
|
name | |
parent | OperationalAnalysis "Operational Analysis" (ddbef16d-ddb9-4162-934c-f1e40e6f8bed) |
prefix | |
progress_status | NOT_SET |
property_value_groups | (Empty list) |
property_value_packages | (Empty list) |
property_values | (Empty list) |
pvmt | Property Value Management for CapellaTypesFolder "Types" (67bba9cf-953c-4f0b-9986-41991c68d241) |
relation_types |
|
requirement_types |
|
requirements | (Empty list) |
sid | |
summary | |
traces | (Empty list) |
type | None |
uuid | 67bba9cf-953c-4f0b-9986-41991c68d241 |
validation | <capellambse.extensions.validation._validate.ElementValidation object at 0x78f99a5fede0> |
visible_on_diagrams | (Empty list) |
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 | |
diagrams | (Empty list) |
filtering_criteria | (Empty list) |
identifier | |
layer | OperationalAnalysis "Operational Analysis" (ddbef16d-ddb9-4162-934c-f1e40e6f8bed) |
long_name | ReqType |
name | |
owner | CapellaTypesFolder "Types" (67bba9cf-953c-4f0b-9986-41991c68d241) |
parent | CapellaTypesFolder "Types" (67bba9cf-953c-4f0b-9986-41991c68d241) |
prefix | |
progress_status | NOT_SET |
property_value_groups | (Empty list) |
property_value_packages | (Empty list) |
property_values | (Empty list) |
pvmt | Property Value Management for RequirementType "ReqType" (db47fca9-ddb6-4397-8d4b-e397e53d277e) |
requirements | (Empty list) |
sid | |
summary | |
traces | (Empty list) |
type | None |
uuid | db47fca9-ddb6-4397-8d4b-e397e53d277e |
validation | <capellambse.extensions.validation._validate.ElementValidation object at 0x78f99a5ffd40> |
visible_on_diagrams | (Empty list) |
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 | |
constraints | (Empty list) |
description | |
diagrams | (Empty list) |
filtering_criteria | (Empty list) |
foreign_id | 0 |
identifier | |
layer | OperationalAnalysis "Operational Analysis" (ddbef16d-ddb9-4162-934c-f1e40e6f8bed) |
long_name | |
name | New showcase req1 |
owner | CapellaModule "Test Module" (f8e2195d-b5f5-4452-a12b-79233d943d5e) |
parent | CapellaModule "Test Module" (f8e2195d-b5f5-4452-a12b-79233d943d5e) |
prefix | |
progress_status | NOT_SET |
property_value_groups | (Empty list) |
property_value_packages | (Empty list) |
property_values | (Empty list) |
pvmt | Property Value Management for Requirement "New showcase req1" (3a208454-d271-49f4-8b93-20b958721300) |
related | (Empty list) |
relations | (Empty list) |
requirements | (Empty list) |
sid | |
summary | |
text | |
traces | (Empty list) |
type | None |
uuid | 3a208454-d271-49f4-8b93-20b958721300 |
validation | <capellambse.extensions.validation._validate.ElementValidation object at 0x78f99a5ff290> |
visible_on_diagrams | (Empty list) |
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" (3a208454-d271-49f4-8b93-20b958721300)
- 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" (3a208454-d271-49f4-8b93-20b958721300)
- 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" (3a208454-d271-49f4-8b93-20b958721300)
- Requirement "ReqType during Creation" (887e45f3-a6b9-487c-ab66-46535abe70ab)
- 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 |
layer | OperationalAnalysis "Operational Analysis" (ddbef16d-ddb9-4162-934c-f1e40e6f8bed) |
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_value_packages | (Empty list) |
property_values | (Empty list) |
pvmt | Property Value Management for Requirement "TestReq1" (3c2d312c-37c9-41b5-8c32-67578fa52dc3) |
related |
|
relations |
|
requirements |
|
sid | |
summary | |
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 |
validation | <capellambse.extensions.validation._validate.ElementValidation object at 0x78f99a5ffd40> |
visible_on_diagrams |
|
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 |
layer | OperationalAnalysis "Operational Analysis" (ddbef16d-ddb9-4162-934c-f1e40e6f8bed) |
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_value_packages | (Empty list) |
property_values | (Empty list) |
pvmt | Property Value Management for CapellaModule "Test Module" (f8e2195d-b5f5-4452-a12b-79233d943d5e) |
requirement_types_folders | (Empty list) |
requirements |
|
sid | |
summary | |
traces | (Empty list) |
type | ModuleType "ModuleType" (a67e7f43-4b49-425c-a6a7-d44e1054a488) |
uuid | f8e2195d-b5f5-4452-a12b-79233d943d5e |
validation | <capellambse.extensions.validation._validate.ElementValidation object at 0x78f98e93f860> |
visible_on_diagrams | (Empty list) |
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.