From a1e2f81f71709f3251d9347af689a6d19a0bdab8 Mon Sep 17 00:00:00 2001 From: Hans Kallekleiv <16436291+HansKallekleiv@users.noreply.github.com> Date: Tue, 3 Dec 2024 09:09:06 +0100 Subject: [PATCH] fixes --- .../smda_access/drogon/drogon_smda_access.py | 6 +++--- .../services/smda_access/smda_access.py | 18 +++++++++++++----- .../services/ssdl_access/_ssdl_get_request.py | 2 +- .../services/ssdl_access/well_access.py | 14 +++++++------- .../src/modules/Intersection/view/view.tsx | 5 +---- 5 files changed, 25 insertions(+), 20 deletions(-) diff --git a/backend_py/primary/primary/services/smda_access/drogon/drogon_smda_access.py b/backend_py/primary/primary/services/smda_access/drogon/drogon_smda_access.py index a2b82cbf3..e32f82fc4 100644 --- a/backend_py/primary/primary/services/smda_access/drogon/drogon_smda_access.py +++ b/backend_py/primary/primary/services/smda_access/drogon/drogon_smda_access.py @@ -8,10 +8,12 @@ class SmdaAccess: + """Drogon SMDA access class containing methods to get mocked Drogon data + disable-unused-argument needed to keep the same method signature as the SMDA access class""" + def __init__(self) -> None: pass - # type: ignore # pylint: disable=unused-argument async def get_stratigraphic_units(self, stratigraphic_column_identifier: str) -> List[StratigraphicUnit]: return get_drogon_strat_units() @@ -27,7 +29,6 @@ async def get_wellbore_trajectories(self, wellbore_uuids: Optional[List[str]] = return [traj for traj in all_well_trajs if traj.wellbore_uuid in wellbore_uuids] return all_well_trajs - # type: ignore # pylint: disable=unused-argument async def get_wellbore_picks_for_wellbore( self, wellbore_uuid: str, obs_no: Optional[int] = None @@ -36,7 +37,6 @@ async def get_wellbore_picks_for_wellbore( well_picks = [pick for pick in get_drogon_well_picks() if pick.wellbore_uuid == wellbore_uuid] return well_picks - # type: ignore # pylint: disable=unused-argument async def get_wellbore_picks_for_pick_identifier( self, diff --git a/backend_py/primary/primary/services/smda_access/smda_access.py b/backend_py/primary/primary/services/smda_access/smda_access.py index 342ca9df1..152d53c15 100644 --- a/backend_py/primary/primary/services/smda_access/smda_access.py +++ b/backend_py/primary/primary/services/smda_access/smda_access.py @@ -84,12 +84,20 @@ async def get_wellbore_headers(self) -> List[WellboreHeader]: wellbore_headers_results = await self._smda_get_request(endpoint=SmdaEndpoints.WELLHEADERS, params=params) + # Create a dictionary to map unique wellbore identifiers to wellbore headers for faster lookup + wellbore_headers_dict = { + wellbore_header["unique_wellbore_identifier"]: wellbore_header + for wellbore_header in wellbore_headers_results + } + + # Iterate over the survey headers and update the information from wellbore headers if available for survey_header in survey_header_results: - for wellbore_header in wellbore_headers_results: - if survey_header["unique_wellbore_identifier"] == wellbore_header["unique_wellbore_identifier"]: - survey_header["wellbore_purpose"] = wellbore_header.get("wellbore_purpose") - survey_header["wellbore_status"] = wellbore_header.get("wellbore_status") - break + unique_id = survey_header["unique_wellbore_identifier"] + + wellbore_header = wellbore_headers_dict.get(unique_id) + if wellbore_header: + survey_header["wellbore_purpose"] = wellbore_header.get("wellbore_purpose") + survey_header["wellbore_status"] = wellbore_header.get("wellbore_status") return [WellboreHeader(**result) for result in survey_header_results] diff --git a/backend_py/primary/primary/services/ssdl_access/_ssdl_get_request.py b/backend_py/primary/primary/services/ssdl_access/_ssdl_get_request.py index baa896e94..8e0dffd81 100644 --- a/backend_py/primary/primary/services/ssdl_access/_ssdl_get_request.py +++ b/backend_py/primary/primary/services/ssdl_access/_ssdl_get_request.py @@ -16,7 +16,7 @@ LOGGER = logging.getLogger(__name__) -async def smda_get_request(access_token: str, endpoint: str, params: Optional[dict] = None) -> List[dict]: +async def ssdl_get_request(access_token: str, endpoint: str, params: Optional[dict] = None) -> List[dict]: """ Generic GET request to SSDL API. Uses `next` pagination to get all results. diff --git a/backend_py/primary/primary/services/ssdl_access/well_access.py b/backend_py/primary/primary/services/ssdl_access/well_access.py index e5101796c..90ff4c45a 100644 --- a/backend_py/primary/primary/services/ssdl_access/well_access.py +++ b/backend_py/primary/primary/services/ssdl_access/well_access.py @@ -4,7 +4,7 @@ Service, InvalidDataError, ) -from ._ssdl_get_request import smda_get_request +from ._ssdl_get_request import ssdl_get_request from . import types @@ -17,7 +17,7 @@ async def get_completions_for_wellbore(self, wellbore_uuid: str) -> List[types.W endpoint = f"Wellbores/{wellbore_uuid}/completion" params = {"normalized_data": True} - ssdl_data = await smda_get_request(access_token=self._ssdl_token, endpoint=endpoint, params=params) + ssdl_data = await ssdl_get_request(access_token=self._ssdl_token, endpoint=endpoint, params=params) try: result = [types.WellboreCompletion.model_validate(casing) for casing in ssdl_data] except ValidationError as error: @@ -29,7 +29,7 @@ async def get_completions_for_wellbore(self, wellbore_uuid: str) -> List[types.W async def get_casings_for_wellbore(self, wellbore_uuid: str) -> List[types.WellboreCasing]: endpoint = f"Wellbores/{wellbore_uuid}/casing" params = {"source": "dbr"} - ssdl_data = await smda_get_request(access_token=self._ssdl_token, endpoint=endpoint, params=params) + ssdl_data = await ssdl_get_request(access_token=self._ssdl_token, endpoint=endpoint, params=params) try: result = [types.WellboreCasing.model_validate(casing) for casing in ssdl_data] except ValidationError as error: @@ -40,7 +40,7 @@ async def get_perforations_for_wellbore(self, wellbore_uuid: str) -> List[types. endpoint = f"Wellbores/{wellbore_uuid}/perforations" params = {"normalized-data": False, "details": True} - ssdl_data = await smda_get_request(access_token=self._ssdl_token, endpoint=endpoint, params=params) + ssdl_data = await ssdl_get_request(access_token=self._ssdl_token, endpoint=endpoint, params=params) try: result = [types.WellborePerforation.model_validate(casing) for casing in ssdl_data] except ValidationError as error: @@ -49,7 +49,7 @@ async def get_perforations_for_wellbore(self, wellbore_uuid: str) -> List[types. async def get_log_curve_headers_for_wellbore(self, wellbore_uuid: str) -> List[types.WellboreLogCurveHeader]: endpoint = f"WellLog/{wellbore_uuid}" - ssdl_data = await smda_get_request(access_token=self._ssdl_token, endpoint=endpoint, params=None) + ssdl_data = await ssdl_get_request(access_token=self._ssdl_token, endpoint=endpoint, params=None) try: result = [types.WellboreLogCurveHeader.model_validate(log_curve) for log_curve in ssdl_data] except ValidationError as error: @@ -58,7 +58,7 @@ async def get_log_curve_headers_for_wellbore(self, wellbore_uuid: str) -> List[t async def get_log_curve_headers_for_field(self, field_uuid: str) -> List[types.WellboreLogCurveHeader]: endpoint = f"WellLog/field/{field_uuid}" - ssdl_data = await smda_get_request(access_token=self._ssdl_token, endpoint=endpoint, params=None) + ssdl_data = await ssdl_get_request(access_token=self._ssdl_token, endpoint=endpoint, params=None) try: result = [types.WellboreLogCurveHeader.model_validate(log_curve) for log_curve in ssdl_data] except ValidationError as error: @@ -68,7 +68,7 @@ async def get_log_curve_headers_for_field(self, field_uuid: str) -> List[types.W async def get_log_curve_data(self, wellbore_uuid: str, curve_name: str) -> types.WellboreLogCurveData: params = {"normalized_data": False} endpoint = f"WellLog/{wellbore_uuid}/{curve_name}" - ssdl_data = await smda_get_request(access_token=self._ssdl_token, endpoint=endpoint, params=params) + ssdl_data = await ssdl_get_request(access_token=self._ssdl_token, endpoint=endpoint, params=params) try: result = types.WellboreLogCurveData.model_validate(ssdl_data) except ValidationError as error: diff --git a/frontend/src/modules/Intersection/view/view.tsx b/frontend/src/modules/Intersection/view/view.tsx index 24217cf33..36d73025f 100644 --- a/frontend/src/modules/Intersection/view/view.tsx +++ b/frontend/src/modules/Intersection/view/view.tsx @@ -84,10 +84,7 @@ export function View(props: ModuleViewProps): React.ReactNode { React.useEffect( function handleTitleChange() { - let fieldName = ""; - if (fieldIdentifier) { - fieldName = fieldIdentifier; - } + const fieldName = fieldIdentifier ?? ""; props.viewContext.setInstanceTitle( `${wellboreHeader?.identifier ?? "Intersection"}