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

Upgrade Group Tree module package #863

Merged
merged 11 commits into from
Feb 14, 2025
4 changes: 2 additions & 2 deletions backend_py/primary/primary/routers/flow_network/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async def get_realization_flow_network(
summary_access=summary_access,
realization=realization,
summary_frequency=summary_frequency,
node_types=unique_node_types,
selected_node_types=unique_node_types,
flow_network_mode=NetworkModeOptions.SINGLE_REAL,
)

Expand All @@ -57,7 +57,7 @@ async def get_realization_flow_network(
dated_networks,
edge_metadata,
node_metadata,
) = await network_assembler.create_dated_networks_and_metadata_lists()
) = network_assembler.create_dated_networks_and_metadata_lists()
create_data_time_ms = timer.lap_ms()

LOGGER.info(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import logging
from dataclasses import dataclass

LOGGER = logging.getLogger(__name__)


@dataclass
# Dataclass needs to save a bunch of timestamps. Many attributes is okay here, as splitting it would be more cumbersome
# pylint: disable-next=too-many-instance-attributes
class PerformanceTimes:
"""Simple utility class to store performance timer results for different internal method calls"""

init_sumo_data: int = 0
init_summary_vector_list: int = 0
fetch_grouptree_df: int = 0
init_grouptree_df_model: int = 0
create_filtered_dataframe: int = 0
init_summary_vector_data_table: int = 0
create_node_classifications: int = 0
create_network_summary_vectors_info: int = 0

# Unused for logging for now, but available if needed
build_and_verify_vectors_of_interest: int = 0
create_well_node_classifications: int = 0

def log_sumo_download_times(self) -> None:
# Log download from Sumo times
LOGGER.info(
f"Total time to fetch data from Sumo: {self.init_sumo_data + self.init_summary_vector_data_table}ms, "
f"Get summary vector list in: {self.init_summary_vector_list}ms, "
f"Get group tree table in: {self.fetch_grouptree_df}ms, "
f"Get summary vectors in: {self.init_summary_vector_data_table}ms"
)

def log_structure_init_times(self) -> None:
# Log initialization of data structures times
LOGGER.info(
f"Initialize GroupTreeModel in: {self.init_grouptree_df_model}ms, "
f"Create filtered dataframe in: {self.create_filtered_dataframe}ms, "
f"Create node classifications in: {self.create_node_classifications}ms, "
f"Create group tree summary vectors info in: {self.create_network_summary_vectors_info}ms"
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import logging
import pandas as pd
import numpy as np

from primary.services.sumo_access.group_tree_types import TreeType
from .flow_network_types import (
Expand All @@ -9,11 +11,18 @@
NodeSummaryVectorsInfo,
EdgeOrNode,
DataType,
NodeType,
)


LOGGER = logging.getLogger(__name__)

NODE_TYPE_ENUM_TO_STRING_MAPPING = {
NodeType.INJ: "Injector",
NodeType.PROD: "Producer",
NodeType.OTHER: "Other",
}


FIELD_DATATYPE_VECTOR_MAP = {
DataType.OILRATE: "FOPR",
Expand Down Expand Up @@ -255,3 +264,33 @@ def _compute_node_datatypes_for_name_and_keyword(
datatypes.append(DataType.GASINJRATE)

return datatypes


def is_valid_node_type(node_classification: NodeClassification, valid_node_types: set[NodeType]) -> bool:
"""Returns True if the node classification is a valid node type"""
if node_classification.IS_PROD and NodeType.PROD in valid_node_types:
return True
if node_classification.IS_INJ and NodeType.INJ in valid_node_types:
return True
if node_classification.IS_OTHER and NodeType.OTHER in valid_node_types:
return True
return False


def create_edge_label_list_from_vfp_table_column(vfp_table_column: pd.Series) -> list[str]:
"""
Creates an edge label list based on the column named "VFP_TABLE".

If the VFP_TABLE column is not present, the function will raise a ValueError.
"""
if vfp_table_column.empty:
raise ValueError("VFP_TABLE column is empty.")

edge_labels: list[str] = []
for vfp_nb in vfp_table_column:
if vfp_nb in [None, 9999] or np.isnan(vfp_nb):
edge_labels.append("")
else:
edge_labels.append(f"VFP {int(vfp_nb)}")

return edge_labels
Loading
Loading