From c6c407d213c2a6d442209950b98f28adea355ef8 Mon Sep 17 00:00:00 2001 From: jorgenherje Date: Tue, 28 Nov 2023 15:19:03 +0100 Subject: [PATCH 1/4] Adjust naming according to new property names Adjusted names of props and updated dict to have "key" instead of "name" for edges and nodes. This key corresponds to the key in edge/node data in tree data --- .../_utils/_ensemble_group_tree_data.py | 37 +++++++++++-------- .../_views/_group_tree_view/_view.py | 6 +-- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/webviz_subsurface/plugins/_group_tree/_utils/_ensemble_group_tree_data.py b/webviz_subsurface/plugins/_group_tree/_utils/_ensemble_group_tree_data.py index c06382bf6..0ecf3692f 100644 --- a/webviz_subsurface/plugins/_group_tree/_utils/_ensemble_group_tree_data.py +++ b/webviz_subsurface/plugins/_group_tree/_utils/_ensemble_group_tree_data.py @@ -84,8 +84,7 @@ def create_grouptree_dataset( grouptree data, before the filtered data is sent to the function that is actually creating the dataset. - Returns the group tree data and two lists with dropdown options for what - to display on the edges and nodes. + Returns the group tree data and two lists with metadata for edges and nodes in the tree data structure A sample data set can be found here: https://github.com/equinor/webviz-subsurface-components/blob/master/react/src/demo/example-data/group-tree.json @@ -130,13 +129,16 @@ def create_grouptree_dataset( dfs.append(gruptree_filtered[gruptree_filtered[f"IS_{tpe.value}".upper()]]) gruptree_filtered = pd.concat(dfs).drop_duplicates() + # Metadata for node: {key: str, label: str, unit: Optional[str]} + # The "key" correspond to the key for node data in the tree data set. + node_metadata_list = [ + {"key": datatype, "label": get_label(datatype)} + for datatype in [DataType.PRESSURE, DataType.BHP, DataType.WMCTL] + ] return ( create_dataset(smry, gruptree_filtered, self._sumvecs, self._terminal_node), - self.get_edge_options(node_types), - [ - {"name": datatype, "label": get_label(datatype)} - for datatype in [DataType.PRESSURE, DataType.BHP, DataType.WMCTL] - ], + self.create_edge_metadata_list(node_types), + node_metadata_list, ) @CACHE.memoize() @@ -217,32 +219,35 @@ def _check_that_sumvecs_exists(self, check_sumvecs: List[str]) -> None: ) @CACHE.memoize() - def get_edge_options(self, node_types: List[NodeType]) -> List[Dict[str, str]]: - """Returns a list with edge node options for the dropdown - menu in the GroupTree component. The output list has the format: + def create_edge_metadata_list(self, node_types: List[NodeType]) -> List[Dict[str, str]]: + """Creates a list with edge metadata for both dropdowns and tree data + in the GroupTree component. The "key" correspond to the key for edge data + in the tree data set. + + The output list has the format: [ - {"name": DataType.OILRATE, "label": "Oil Rate"}, - {"name": DataType.GasRATE, "label": "Gas Rate"}, + {"key": DataType.OILRATE, "label": "Oil Rate", "unit": "m3/d"}, + {"key": DataType.GasRATE, "label": "Gas Rate", "unit": "m3/d"}, ] """ options = [] if NodeType.PROD in node_types: for rate in [DataType.OILRATE, DataType.GASRATE, DataType.WATERRATE]: - options.append({"name": rate, "label": get_label(rate)}) + options.append({"key": rate, "label": get_label(rate)}) if NodeType.INJ in node_types and self._has_waterinj: options.append( { - "name": DataType.WATERINJRATE, + "key": DataType.WATERINJRATE, "label": get_label(DataType.WATERINJRATE), } ) if NodeType.INJ in node_types and self._has_gasinj: options.append( - {"name": DataType.GASINJRATE, "label": get_label(DataType.GASINJRATE)} + {"key": DataType.GASINJRATE, "label": get_label(DataType.GASINJRATE)} ) if options: return options - return [{"name": DataType.OILRATE, "label": get_label(DataType.OILRATE)}] + return [{"key": DataType.OILRATE, "label": get_label(DataType.OILRATE)}] def get_edge_label(row: pd.Series) -> str: diff --git a/webviz_subsurface/plugins/_group_tree/_views/_group_tree_view/_view.py b/webviz_subsurface/plugins/_group_tree/_views/_group_tree_view/_view.py index 3b5973cd0..3f04a3a2a 100644 --- a/webviz_subsurface/plugins/_group_tree/_views/_group_tree_view/_view.py +++ b/webviz_subsurface/plugins/_group_tree/_views/_group_tree_view/_view.py @@ -299,7 +299,7 @@ def _render_grouptree( ensemble_name: str, ) -> list: """This callback updates the input dataset to the Grouptree component.""" - data, edge_options, node_options = self._group_tree_data[ + data, edge_metadata_list, node_metadata_list = self._group_tree_data[ ensemble_name ].create_grouptree_dataset( tree_mode, @@ -312,8 +312,8 @@ def _render_grouptree( wsc.GroupTree( id=self._group_tree_component_id, data=data, - edge_options=edge_options, - node_options=node_options, + edge_metadata_list=edge_metadata_list, + node_metadata_list=node_metadata_list, ), ] From ae10fb36fd3eb417ab5df79f7bd6348237b369ce Mon Sep 17 00:00:00 2001 From: jorgenherje Date: Wed, 29 Nov 2023 13:35:15 +0100 Subject: [PATCH 2/4] Adjust based on black formatting --- .../_group_tree/_utils/_ensemble_group_tree_data.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/webviz_subsurface/plugins/_group_tree/_utils/_ensemble_group_tree_data.py b/webviz_subsurface/plugins/_group_tree/_utils/_ensemble_group_tree_data.py index 0ecf3692f..8ee517acc 100644 --- a/webviz_subsurface/plugins/_group_tree/_utils/_ensemble_group_tree_data.py +++ b/webviz_subsurface/plugins/_group_tree/_utils/_ensemble_group_tree_data.py @@ -132,9 +132,9 @@ def create_grouptree_dataset( # Metadata for node: {key: str, label: str, unit: Optional[str]} # The "key" correspond to the key for node data in the tree data set. node_metadata_list = [ - {"key": datatype, "label": get_label(datatype)} - for datatype in [DataType.PRESSURE, DataType.BHP, DataType.WMCTL] - ] + {"key": datatype, "label": get_label(datatype)} + for datatype in [DataType.PRESSURE, DataType.BHP, DataType.WMCTL] + ] return ( create_dataset(smry, gruptree_filtered, self._sumvecs, self._terminal_node), self.create_edge_metadata_list(node_types), @@ -219,11 +219,13 @@ def _check_that_sumvecs_exists(self, check_sumvecs: List[str]) -> None: ) @CACHE.memoize() - def create_edge_metadata_list(self, node_types: List[NodeType]) -> List[Dict[str, str]]: + def create_edge_metadata_list( + self, node_types: List[NodeType] + ) -> List[Dict[str, str]]: """Creates a list with edge metadata for both dropdowns and tree data in the GroupTree component. The "key" correspond to the key for edge data in the tree data set. - + The output list has the format: [ {"key": DataType.OILRATE, "label": "Oil Rate", "unit": "m3/d"}, From 260d78fca4a89b97488e7ebff10f4f8889583695 Mon Sep 17 00:00:00 2001 From: jorgenherje Date: Wed, 13 Dec 2023 14:42:16 +0100 Subject: [PATCH 3/4] Update wsc version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 740ee6218..bf2724812 100644 --- a/setup.py +++ b/setup.py @@ -110,7 +110,7 @@ "vtk>=9.2.2,<9.3", "webviz-config", "webviz-core-components>=0.6", - "webviz-subsurface-components==1.0.1", + "webviz-subsurface-components==1.0.2", ], extras_require={"tests": TESTS_REQUIRE}, setup_requires=["setuptools_scm~=3.2"], From 2e7ffc05e446a438328223b9409923d8bdf737b4 Mon Sep 17 00:00:00 2001 From: jorgenherje Date: Wed, 13 Dec 2023 15:12:49 +0100 Subject: [PATCH 4/4] Fix code style and lint errors --- .../plugins/_group_tree/_utils/_ensemble_group_tree_data.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/webviz_subsurface/plugins/_group_tree/_utils/_ensemble_group_tree_data.py b/webviz_subsurface/plugins/_group_tree/_utils/_ensemble_group_tree_data.py index 8ee517acc..fdf27dded 100644 --- a/webviz_subsurface/plugins/_group_tree/_utils/_ensemble_group_tree_data.py +++ b/webviz_subsurface/plugins/_group_tree/_utils/_ensemble_group_tree_data.py @@ -84,9 +84,11 @@ def create_grouptree_dataset( grouptree data, before the filtered data is sent to the function that is actually creating the dataset. - Returns the group tree data and two lists with metadata for edges and nodes in the tree data structure + Returns the group tree data and two lists with metadata for edges and nodes + in the tree data structure A sample data set can be found here: + # pylint: disable=line-too-long https://github.com/equinor/webviz-subsurface-components/blob/master/react/src/demo/example-data/group-tree.json """ # noqa