Helpers
Helper functions for supporting model management.
activity_npv_collection_to_dict
Converts the activity NPV collection object to the dictionary representation.
Returns:
Type | Description |
---|---|
dict
|
A dictionary containing the attribute name-value pairs of an activity NPV collection object |
Source code in src/cplus_plugin/models/helpers.py
activity_npv_to_dict
Converts an ActivityNpv object to a dictionary representation.
Returns:
Type | Description |
---|---|
dict
|
A dictionary containing attribute name-value pairs. |
Source code in src/cplus_plugin/models/helpers.py
clone_activity
Creates a deep copy of the given activity.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
activity |
Activity
|
activity to clone. |
required |
Returns:
Type | Description |
---|---|
Activity
|
A deep copy of the original activity object. |
Source code in src/cplus_plugin/models/helpers.py
clone_layer_component
Clones a layer-based model component.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
layer_component |
LayerModelComponent
|
Layer-based model component to clone. |
required |
model_cls |
Callable[[UUID, str, str], LayerModelComponentType]
|
Callable class that will be created based on the input argument values from the dictionary. |
required |
Returns:
Type | Description |
---|---|
LayerModelComponent
|
A new instance of the cloned model component. It will return None if the input is not a layer-based model component. |
Source code in src/cplus_plugin/models/helpers.py
clone_ncs_pathway
Creates a deep copy of the given NCS pathway.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ncs |
NcsPathway
|
NCS pathway to clone. |
required |
Returns:
Type | Description |
---|---|
NcsPathway
|
A deep copy of the original NCS pathway object. |
Source code in src/cplus_plugin/models/helpers.py
copy_layer_component_attributes
Copies the attribute values of source to target. The uuid attribute value is not copied as well as the layer attribute. However, for the latter, the path is copied.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target |
LayerModelComponent
|
Target object whose attribute values will be updated. |
required |
source |
LayerModelComponent
|
Source object whose attribute values will be copied to the target. |
required |
Returns:
Type | Description |
---|---|
LayerModelComponent
|
Target object containing the updated attribute values apart for the uuid whose value will not change. |
Source code in src/cplus_plugin/models/helpers.py
create_activity
Factory method for creating an activity using attribute values defined in a dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source_dict |
dict
|
Dictionary containing property values. |
required |
Returns:
Type | Description |
---|---|
Activity
|
activity with property values set from the dictionary. |
Source code in src/cplus_plugin/models/helpers.py
create_activity_npv
Creates an ActivityNpv object from the equivalent dictionary representation.
Please note that the activity
attribute of the ActivityNpv
object will be
None
hence, will have to be set manually by extracting the corresponding Activity
from the activity UUID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
activity_npv_dict |
dict
|
Dictionary containing information for deserializing to the ActivityNpv object. |
required |
Returns:
Type | Description |
---|---|
ActivityNpv
|
ActivityNpv deserialized from the dictionary representation. |
Source code in src/cplus_plugin/models/helpers.py
create_activity_npv_collection
Creates an activity NPV collection object from the corresponding dictionary representation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
activity_collection_dict |
dict
|
Dictionary representation containing information of an activity NPV collection object. |
required |
reference_activities |
List[Activity]
|
Optional list of activities that will be used to lookup when deserializing the ActivityNpv objects. |
None
|
Returns:
Type | Description |
---|---|
ActivityNpvCollection
|
Activity NPV collection object from the dictionary representation or None if the source dictionary is invalid. |
Source code in src/cplus_plugin/models/helpers.py
create_layer_component
Factory method for creating a layer model component using attribute values defined in a dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source_dict |
dict
|
Dictionary containing property values. |
required |
model_cls |
Callable[[UUID, str, str, str, LayerType, bool], LayerModelComponentType]
|
Callable class that will be created based on the input argument values from the dictionary. |
required |
Returns:
Type | Description |
---|---|
LayerModelComponent
|
Layer model component object with property values set from the dictionary. |
Source code in src/cplus_plugin/models/helpers.py
create_model_component
Factory method for creating and setting attribute values for a base model component object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source_dict |
dict
|
Dictionary containing attribute values. |
required |
model_cls |
Callable[[UUID, str, str], BaseModelComponentType]
|
Callable class that will be created based on the input argument values from the dictionary. |
required |
Returns:
Type | Description |
---|---|
BaseModelComponent
|
Base model component object with property values derived from the dictionary. |
Source code in src/cplus_plugin/models/helpers.py
create_ncs_pathway
Factory method for creating an NcsPathway object using attribute values defined in a dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source_dict |
dict
|
Dictionary containing property values. |
required |
Returns:
Type | Description |
---|---|
NcsPathway
|
NCS pathway object with property values set from the dictionary. |
Source code in src/cplus_plugin/models/helpers.py
extent_to_project_crs_extent
Transforms SpatialExtent model to an QGIS extent based on the CRS of the given project.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
spatial_extent |
SpatialExtent
|
Spatial extent data model that defines the scenario bounds. |
required |
project |
QgsProject
|
Project whose CRS will be used to determine the values of the output extent. |
None
|
Returns:
Type | Description |
---|---|
QgsRectangle
|
Output extent in the project's CRS. If the input extent is invalid, this function will return None. |
Source code in src/cplus_plugin/models/helpers.py
extent_to_qgs_rectangle
Returns a QgsRectangle object from the SpatialExtent object.
If the SpatialExtent is invalid (i.e. less than four items) then it will return None.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
spatial_extent |
SpatialExtent
|
Spatial extent data model that defines the scenario bounds. |
required |
Returns:
Type | Description |
---|---|
QgsRectangle
|
QGIS rectangle defining the bounds for the scenario. |
Source code in src/cplus_plugin/models/helpers.py
layer_component_to_dict
Creates a dictionary containing attribute name-value pairs from a layer model component object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
layer_component |
LayerModelComponentType
|
Source layer model component object whose values are to be mapped to the corresponding attribute names. |
required |
uuid_to_str |
bool
|
Set True to convert the UUID to a string equivalent, else False. Some serialization engines such as JSON are unable to handle UUID objects hence the need to convert to string. |
True
|
Returns:
Type | Description |
---|---|
dict
|
Returns a dictionary item containing attribute name-value pairs. |
Source code in src/cplus_plugin/models/helpers.py
layer_from_scenario_result
Gets the scenario output layer from the results of the analysis.
Returns:
Type | Description |
---|---|
QgsRasterLayer
|
Raster layer corresponding to the output scenario path or None if the file does not exist or if the raster layer is invalid. |
Source code in src/cplus_plugin/models/helpers.py
model_component_to_dict
Creates a dictionary containing the base attribute name-value pairs from a model component object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_component |
BaseModelComponentType
|
Source model component object whose values are to be mapped to the corresponding attribute names. |
required |
uuid_to_str |
bool
|
Set True to convert the UUID to a string equivalent, else False. Some serialization engines such as JSON are unable to handle UUID objects hence the need to convert to string. |
True
|
Returns:
Type | Description |
---|---|
dict
|
Returns a dictionary item containing attribute name-value pairs. |
Source code in src/cplus_plugin/models/helpers.py
ncs_pathway_to_dict
Creates a dictionary containing attribute name-value pairs from an NCS pathway object.
This function has been retained for legacy support.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ncs_pathway |
NcsPathway
|
Source NCS pathway object whose values are to be mapped to the corresponding attribute names. |
required |
uuid_to_str |
bool
|
Set True to convert the UUID to a string equivalent, else False. Some serialization engines such as JSON are unable to handle UUID objects hence the need to convert to string. |
True
|
Returns:
Type | Description |
---|---|
dict
|
Returns a dictionary item containing attribute name-value pairs. |