Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of Metrics Framework #579

Open
wants to merge 45 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
487c9bc
Incorporate adding of a metric column.
gkahiu Oct 15, 2024
193f63c
Add column management.
gkahiu Oct 17, 2024
74fb9c9
Add icons.
gkahiu Oct 17, 2024
1464dff
Enable in-memory persistence of column properties.
gkahiu Oct 19, 2024
d944895
Validate columns page.
gkahiu Oct 20, 2024
7a1d5cc
Add columns in the activity metric table.
gkahiu Oct 22, 2024
296fe05
Fix moving columns in activity metrics table.
gkahiu Oct 22, 2024
adaf71c
Add activity column.
gkahiu Oct 24, 2024
0fd3256
Incorporate addition of activities.
gkahiu Oct 26, 2024
bc93f2b
Fix column metrics.
gkahiu Oct 26, 2024
55cbf33
Enable expression builder in activity columns.
gkahiu Oct 29, 2024
f8b0a4d
Fix crash due to column metric delegate.
gkahiu Oct 30, 2024
4d9ca13
Incorporate summary page.
gkahiu Oct 30, 2024
40f7825
Remap column delegates on move column.
gkahiu Oct 31, 2024
2722ecd
Add util for creating expression help in HTML.
gkahiu Nov 2, 2024
b85b69f
Enable loading of metric configuration.
gkahiu Nov 4, 2024
06007b2
Use activation to show expression builder for cell metrics.
gkahiu Nov 4, 2024
95a606d
Fix metric column positioning on moving columns.
gkahiu Nov 4, 2024
55cfdc3
Incorporate save/load of metric configurations in settings.
gkahiu Nov 6, 2024
3a5bccd
Validate metric configuration before running scenario.
gkahiu Nov 6, 2024
0064d4c
Incorporate custom metrics in report framework.
gkahiu Nov 6, 2024
4a16c62
Incorporate custom metrics report template.
gkahiu Nov 11, 2024
58035f4
Remove inapplicable report variable values.
gkahiu Nov 11, 2024
7ec98c2
Initial implementation of metrics in report generator.
gkahiu Nov 12, 2024
167f592
Update metric evaluation in report generator.
gkahiu Nov 13, 2024
0dde24b
Update report metric template.
gkahiu Nov 13, 2024
38a6810
Incorporate automatic page orientation in metrics page.
gkahiu Nov 15, 2024
e3d324f
Update metrics report template.
gkahiu Nov 15, 2024
5f83dd7
Fix positioning of items after page size change.
gkahiu Nov 15, 2024
5448113
Check metric columns limit.
gkahiu Nov 15, 2024
40dd7c7
Change windows-style line endings to Unix-style.
gkahiu Nov 16, 2024
323ce35
Fix activity model failing tests.
gkahiu Nov 17, 2024
108b635
Fix additional activity model failing tests.
gkahiu Nov 17, 2024
bb91ab4
Add metric model and builder unit tests.
gkahiu Nov 18, 2024
41938ad
Minor code cleanups.
gkahiu Nov 19, 2024
73c8d50
Incorporate metric expression unit tests.
gkahiu Nov 19, 2024
31aaff2
Cleanup metrics report template.
gkahiu Nov 19, 2024
599257f
Update API docs.
gkahiu Nov 19, 2024
5d3fde4
Incorporate number formatting options in metrics UI.
gkahiu Nov 21, 2024
d981d0e
Specify highlighted variables in metrics context.
gkahiu Nov 21, 2024
6c4e364
Remove activity NPV expression.
gkahiu Nov 30, 2024
85305dd
Update metrics tests.
gkahiu Nov 30, 2024
05e435d
Fix failing metrics tests.
gkahiu Nov 30, 2024
c56042d
Fix metric references in tests.
gkahiu Nov 30, 2024
240fcac
Fix metric configuration in tests.
gkahiu Nov 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading