Helper Functions for Metric Expressions¶
Provides variables and functions for custom activity metrics.
ActivityIrrecoverableCarbonFunction ¶
Bases: QgsScopedExpressionFunction
Calculates the total irrecoverable carbon of an activity using the means-based reference carbon layer.
Source code in src/cplus_plugin/lib/reports/metrics.py
clone ¶
Gets a clone of this function.
Returns:
Type | Description |
---|---|
ActivityIrrecoverableCarbonFunction
|
A clone of this function. |
func ¶
Returns the result of evaluating the function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
values |
List[Any]
|
List of values passed to the function |
required |
context |
QgsExpressionContext
|
Context expression is being evaluated against |
required |
parent |
QgsExpression
|
Parent expression |
required |
node |
QgsExpressionNodeFunction
|
Expression node |
required |
Returns:
Type | Description |
---|---|
typing.Any
|
The result of the function. |
Source code in src/cplus_plugin/lib/reports/metrics.py
ActivityNpvFunction ¶
Bases: QgsScopedExpressionFunction
Calculates the financial NPV of an activity by extracting the individual NPV values of the pathways in the activity.
Source code in src/cplus_plugin/lib/reports/metrics.py
clone ¶
Gets a clone of this function.
Returns:
Type | Description |
---|---|
ActivityNpvFunction
|
A clone of this function. |
func ¶
Returns the result of evaluating the function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
values |
List[Any]
|
List of values passed to the function |
required |
context |
QgsExpressionContext
|
Context expression is being evaluated against |
required |
parent |
QgsExpression
|
Parent expression |
required |
node |
QgsExpressionNodeFunction
|
Expression node |
required |
Returns:
Type | Description |
---|---|
typing.Any
|
The result of the function. |
Source code in src/cplus_plugin/lib/reports/metrics.py
ActivityPwlImpactFunction ¶
Bases: QgsScopedExpressionFunction
Calculates the PWL impact an activity.
Source code in src/cplus_plugin/lib/reports/metrics.py
clone ¶
Gets a clone of this function.
Returns:
Type | Description |
---|---|
ActivityPwlImpactFunction
|
A clone of this function. |
func ¶
Returns the result of evaluating the function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
values |
List[Any]
|
List of values passed to the function |
required |
context |
QgsExpressionContext
|
Context expression is being evaluated against |
required |
parent |
QgsExpression
|
Parent expression |
required |
node |
QgsExpressionNodeFunction
|
Expression node |
required |
Returns:
Type | Description |
---|---|
typing.Any
|
The result of the function. |
Source code in src/cplus_plugin/lib/reports/metrics.py
MetricsExpressionContextGenerator ¶
Bases: QgsExpressionContextGenerator
Helper class that generates the metrics expression context for use in QGIS objects that expect an expression context generator.
createExpressionContext ¶
Returns a metrics expression context.
Returns:
Type | Description |
---|---|
QgsExpressionContext
|
Metrics expression context with CPLUS-specific functions and variables. |
Source code in src/cplus_plugin/lib/reports/metrics.py
calculate_activity_pwl_impact ¶
Calculates the PWL impact an activity.
It sums up the result of the number of jobs multiplied by the area of each NCS pathway that constitutes the activity.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
activity_id |
str
|
The ID of the specific activity. |
required |
number_jobs |
float
|
Number of jobs for the activity. |
required |
Returns:
Type | Description |
---|---|
float
|
Returns the total pwl impact of the activity, or -1.0 if the activity does not exist or if found, lacks pathways or if the area of all pathways could not be computed. |
Source code in src/cplus_plugin/lib/reports/metrics.py
create_metrics_expression_context ¶
Gets the expression context to use in the initial set up (e.g. expression builder) as well as computation stage of activity metrics.
It includes the global and project scopes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
project |
QgsProject
|
The QGIS project whose functions and variables will be included in the expression context. If not specified, the current project will be used. |
None
|
Returns:
Type | Description |
---|---|
QgsExpressionContext
|
The expression to use in the customization of activity metrics. |
Source code in src/cplus_plugin/lib/reports/metrics.py
create_metrics_expression_scope ¶
Creates the expression context scope for activity metrics.
The initial variable values will be arbitrary and will only be updated just prior to the evaluation of the expression in a separate function.
Returns:
Type | Description |
---|---|
QgsExpressionContextScope
|
The expression scope for activity metrics. |
Source code in src/cplus_plugin/lib/reports/metrics.py
evaluate_activity_metric ¶
Calculates the metrics for an activity using the information in the expression context and for an activity in the info object.
The context will first be updated with the latest activity information in the info object before the expression is evaluated.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
context |
QgsExpressionContext
|
Expression context containing the global, project and metrics scopes respectively. |
required |
activity_info |
ActivityContextInfo
|
Contains information about an activity whose attribute values will be used to evaluate the expression. |
required |
expression_str |
str
|
Expression to be evaluated. |
required |
Returns:
Type | Description |
---|---|
MetricEvalResult
|
The result of the activity's metric calculation. |
Source code in src/cplus_plugin/lib/reports/metrics.py
metric_function_by_name ¶
Gets a metric function in the library based on the name.
Returns:
Type | Description |
---|---|
QgsScopedExpressionFunction
|
Corresponding function in the metrics library or None if not found. |
Source code in src/cplus_plugin/lib/reports/metrics.py
register_metric_functions ¶
Register our custom functions with the expression engine.
Source code in src/cplus_plugin/lib/reports/metrics.py
unregister_metric_functions ¶
Unregister the custom metric functions from the expression engine.