Skip to content

Commit

Permalink
Merge pull request #579 from gkahiu/feature_metrics_framework
Browse files Browse the repository at this point in the history
Implementation of Metrics Framework
  • Loading branch information
gkahiu authored Dec 12, 2024
2 parents 4637c7a + 4783804 commit 1c5e903
Show file tree
Hide file tree
Showing 35 changed files with 7,216 additions and 104 deletions.
9 changes: 9 additions & 0 deletions docs/developer/api/core/api_reports_metrics.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Helper Functions for Metric Expressions

::: src.cplus_plugin.lib.reports.metrics
handler: python
options:
docstring_style: sphinx
heading_level: 1
show_source: true
show_root_heading: false
9 changes: 9 additions & 0 deletions docs/developer/api/gui/api_metrics_builder_dialog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Metrics Builder Dialog

::: src.cplus_plugin.gui.metrics_builder_dialog
handler: python
options:
docstring_style: sphinx
heading_level: 1
show_source: true
show_root_heading: false
9 changes: 9 additions & 0 deletions docs/developer/api/gui/api_metrics_builder_model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Metrics Builder View Model

::: src.cplus_plugin.gui.metrics_builder_model
handler: python
options:
docstring_style: sphinx
heading_level: 1
show_source: true
show_root_heading: false
41 changes: 40 additions & 1 deletion src/cplus_plugin/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from qgis.core import QgsSettings

from .definitions.constants import (
STYLE_ATTRIBUTE,
METRIC_CONFIGURATION_PROPERTY,
NCS_CARBON_SEGMENT,
NCS_PATHWAY_SEGMENT,
NPV_COLLECTION_PROPERTY,
Expand All @@ -26,6 +26,7 @@
PATHWAYS_ATTRIBUTE,
PIXEL_VALUE_ATTRIBUTE,
PRIORITY_LAYERS_SEGMENT,
STYLE_ATTRIBUTE,
UUID_ATTRIBUTE,
)
from .definitions.defaults import PRIORITY_LAYERS
Expand All @@ -41,10 +42,13 @@
activity_npv_collection_to_dict,
create_activity,
create_activity_npv_collection,
create_metric_configuration,
create_ncs_pathway,
layer_component_to_dict,
metric_configuration_to_dict,
ncs_pathway_to_dict,
)
from .models.report import MetricConfiguration
from .utils import log, todict, CustomJsonEncoder


Expand Down Expand Up @@ -238,6 +242,9 @@ class Settings(enum.Enum):
# Processing option
PROCESSING_TYPE = "processing_type"

# REPORT OPTIONS
USE_CUSTOM_METRICS = "use_custom_metrics"

# DEBUG
DEBUG = "debug"
BASE_API_URL = "base_api_url"
Expand Down Expand Up @@ -1477,6 +1484,38 @@ def save_npv_collection(self, npv_collection: ActivityNpvCollection):
npv_collection_str = json.dumps(npv_collection_dict)
self.set_value(NPV_COLLECTION_PROPERTY, npv_collection_str)

def get_metric_configuration(self) -> typing.Optional[MetricConfiguration]:
"""Gets the activity metric configuration.
:returns: The activity metric configuration or None
if not defined or if an error occurred when deserializing.
:rtype: MetricConfiguration
"""
metric_configuration_str = self.get_value(METRIC_CONFIGURATION_PROPERTY, None)
if not metric_configuration_str:
return None

metric_configuration_dict = {}
try:
metric_configuration_dict = json.loads(metric_configuration_str)
except json.JSONDecodeError:
log("Metric configuration JSON is invalid.")

return create_metric_configuration(
metric_configuration_dict, self.get_all_activities()
)

def save_metric_configuration(self, metric_configuration: MetricConfiguration):
"""Serializes the metric configuration in settings as a JSON string.
:param metric_configuration: Activity NPV collection serialized to a JSON string.
:type metric_configuration: ActivityNpvCollection
"""
metric_configuration_dict = metric_configuration_to_dict(metric_configuration)
metric_configuration_str = json.dumps(metric_configuration_dict)
print(metric_configuration_dict)
self.set_value(METRIC_CONFIGURATION_PROPERTY, metric_configuration_str)

def save_online_scenario(self, scenario_uuid):
"""Save the passed scenario settings into the plugin settings as online tasl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2487,12 +2487,12 @@
<Option type="QString" value=""/>
<Option type="QString" value=""/>
<Option type="QString" value=""/>
<Option type="QString" value="C:\Users\Kahiu\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\cplus_plugin\icons\cplus_logo.svg"/>
<Option type="QString" value="C:\Users\Kahiu\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\cplus_plugin\icons\ci_logo.svg"/>
<Option type="QString" value=""/>
<Option type="QString" value=""/>
<Option type="QString" value=""/>
<Option type="QString" value="D:\Frank\Kartoza\Data\cplus\Temp"/>
<Option type="QString" value=""/>
<Option type="QString" value=""/>
<Option type="QString" value=""/>
<Option type="QString" value="Scenario name will be inserted here"/>
<Option type="QString" value="Scenario description will be inserted here"/>
<Option type="QString" value=""/>
Expand Down
Loading

0 comments on commit 1c5e903

Please sign in to comment.