Helpers¶
Helper functions for supporting model management.
activity_metric_to_dict ¶
Converts an activity column metric to a dictionary representation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
activity_metric |
ActivityColumnMetric
|
Activity column metric to be serialized to a dictionary. |
required |
Returns:
Type | Description |
---|---|
dict
|
A dictionary containing attribute values of an activity column metric. |
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_metric_configuration_profile ¶
Creates a deep copy version of the specified metric configuration profile.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metric_config_profile |
MetricConfigurationProfile
|
Metric configuration profile to be cloned. |
required |
referenced_activities |
List[Activity]
|
Activities which will be used to extract those referenced in the metric configuration profile. |
required |
Returns:
Type | Description |
---|---|
MetricConfigurationProfile
|
Cloned metric configuration profile or None if the input metric configuration profile was invalid. |
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_metric ¶
Creates a metric column from the equivalent dictionary representation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
activity_metric_dict |
dict
|
Dictionary containing information for deserializing the dict to a metric column. |
required |
activity |
Activity
|
Referenced activity matching the saved UUID. |
required |
metric_column |
MetricColumn
|
Referenced metric column matching the saved name. |
required |
Returns:
Type | Description |
---|---|
MetricColumn
|
Metric column object or None if the deserialization failed. |
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_metric_column ¶
Creates a metric column from the equivalent dictionary representation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metric_column_dict |
dict
|
Dictionary containing information for deserializing the dict to a metric column. |
required |
Returns:
Type | Description |
---|---|
MetricColumn
|
Metric column object or None if the deserialization failed. |
Source code in src/cplus_plugin/models/helpers.py
create_metric_configuration ¶
Creates a metric configuration from the equivalent dictionary representation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metric_configuration_dict |
dict
|
Dictionary containing information for deserializing a metric configuration object. |
required |
referenced_activities |
List[Activity]
|
Activities which will be used to extract those referenced in the metric configuration. |
required |
Returns:
Type | Description |
---|---|
MetricConfiguration
|
Metric configuration object or None if the deserialization failed. |
Source code in src/cplus_plugin/models/helpers.py
create_metric_configuration_profile ¶
Creates a metric configuration profile from the equivalent dictionary representation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metric_configuration_profile_dict |
dict
|
Dictionary containing information for deserializing a metric configuration profile. |
required |
referenced_activities |
List[Activity]
|
Activities which will be used to extract those referenced in the metric configuration profile. |
required |
Returns:
Type | Description |
---|---|
MetricConfiguration
|
Metric configuration profile object or None if the deserialization failed. |
Source code in src/cplus_plugin/models/helpers.py
create_metrics_profile_collection ¶
Deserialized a metric profile collection from the equivalent dictionary representation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metric_profile_collection_dict |
dict
|
Dictionary containing information about the profile collection. |
required |
referenced_activities |
List[Activity]
|
Activities which will be used to extract those referenced in the metric configuration objects that correspond to the respective profiles. |
required |
Returns:
Type | Description |
---|---|
MetricProfileCollection
|
Metric profile configuration object or None if the deserialization failed. |
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
create_ncs_pathway_npv ¶
Creates an NcsPathwayNpv object from the equivalent dictionary representation.
Please note that the pathway
attribute of the NcsPathwayNpv
object will be
None
hence, will have to be set manually by extracting the corresponding NcsPathway
from the activity UUID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pathway_npv_dict |
dict
|
Dictionary containing information for deserializing to the NcsPathwayNpv object. |
required |
Returns:
Type | Description |
---|---|
NcsPathwayNpv
|
NcsPathwayNpv deserialized from the dictionary representation. |
Source code in src/cplus_plugin/models/helpers.py
create_ncs_pathway_npv_collection ¶
Creates an NCS pathway NPV collection object from the corresponding dictionary representation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pathway_collection_dict |
dict
|
Dictionary representation containing information of an NCS pathway NPV collection object. |
required |
reference_pathways |
List[NcsPathway]
|
Optional list of NCS pathways that will be used to lookup when deserializing the NcsPathwayNpv objects. |
None
|
Returns:
Type | Description |
---|---|
NcsPathwayNpvCollection
|
NCS pathway NPV collection object from the dictionary representation or None if the source dictionary is invalid. |
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
|
source_crs |
QgsCoordinateReferenceSystem
|
Specify a source CRS to use for the transformation otherwise it will revert to the default which is WGS84. |
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
extent_to_url_param ¶
Converts the bounding box in a QgsRectangle object to the equivalent param for use in a URL. 'bbox' is appended as a prefix in the URL query part.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rect_extent |
QgsRectangle
|
Spatial extent that defines the AOI. |
required |
Returns:
Type | Description |
---|---|
str
|
String representing the param defining the extents of the AOI. If the extent is empty, it will return an empty string. |
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
metric_column_to_dict ¶
Converts a metric column object to a dictionary representation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metric_column |
MetricColumn
|
Metric column to be serialized to a dictionary. |
required |
Returns:
Type | Description |
---|---|
dict
|
A dictionary containing attribute values of a metric column. |
Source code in src/cplus_plugin/models/helpers.py
metric_configuration_profile_to_dict ¶
Serializes a metric configuration profile to a dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metric_config_profile |
MetricConfigurationProfile
|
Metric configuration profile to be serialized. |
required |
Returns:
Type | Description |
---|---|
dict
|
A dictionary representing a metric configuration profile. |
Source code in src/cplus_plugin/models/helpers.py
metric_configuration_to_dict ¶
Serializes a metric configuration to dict.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metric_configuration |
MetricConfiguration
|
Metric configuration to tbe serialized. |
required |
Returns:
Type | Description |
---|---|
dict
|
A dictionary representing a metric configuration. |
Source code in src/cplus_plugin/models/helpers.py
metric_profile_collection_to_dict ¶
Serializes a metric configuration profile to a dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metric_profile_collection |
MetricProfileCollection
|
Metric profile collection to be serialized. |
required |
Returns:
Type | Description |
---|---|
dict
|
A dictionary representing a metric profile collection. |
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_npv_collection_to_dict ¶
Converts the NCS pathway NPV collection object to the dictionary representation.
Returns:
Type | Description |
---|---|
dict
|
A dictionary containing the attribute name-value pairs of an NCS pathway NPV collection object |
Source code in src/cplus_plugin/models/helpers.py
ncs_pathway_npv_to_dict ¶
Converts an NcsPathwayNpv 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
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. |