Skip to content

Commit

Permalink
Merge branch 'main' into refactor-make-smda-access-use-field-ident-on…
Browse files Browse the repository at this point in the history
…ly-when-neccessary
  • Loading branch information
HansKallekleiv authored Dec 9, 2024
2 parents f6ba8dd + cbb406c commit 5bb6d7f
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 58 deletions.
3 changes: 2 additions & 1 deletion backend_py/primary/primary/routers/polygons/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from primary.services.sumo_access.case_inspector import CaseInspector
from primary.services.sumo_access.polygons_access import PolygonsAccess
from primary.services.utils.authenticated_user import AuthenticatedUser
from primary.utils.drogon import is_drogon_identifier

from . import converters, schemas

Expand All @@ -37,7 +38,7 @@ async def get_polygons_directory(
strat_column_identifier = await case_inspector.get_stratigraphic_column_identifier_async()
smda_access: Union[SmdaAccess, DrogonSmdaAccess]

if strat_column_identifier == "DROGON_HAS_NO_STRATCOLUMN":
if is_drogon_identifier(strat_column_identifier=strat_column_identifier):
smda_access = DrogonSmdaAccess()
else:
smda_access = SmdaAccess(authenticated_user.get_smda_access_token())
Expand Down
3 changes: 2 additions & 1 deletion backend_py/primary/primary/routers/surface/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from primary.services.surface_query_service.surface_query_service import batch_sample_surface_in_points_async
from primary.services.surface_query_service.surface_query_service import RealizationSampleResult
from primary.utils.response_perf_metrics import ResponsePerfMetrics
from primary.utils.drogon import is_drogon_identifier

from . import converters
from . import schemas
Expand Down Expand Up @@ -323,7 +324,7 @@ async def _get_stratigraphic_units_for_case_async(
perf_metrics.record_lap("get-strat-ident")

smda_access: SmdaAccess | DrogonSmdaAccess
if strat_column_identifier == "DROGON_HAS_NO_STRATCOLUMN":
if is_drogon_identifier(strat_column_identifier=strat_column_identifier):
smda_access = DrogonSmdaAccess()
else:
smda_access = SmdaAccess(authenticated_user.get_smda_access_token())
Expand Down
6 changes: 6 additions & 0 deletions backend_py/primary/primary/routers/surface/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ class PointSetXY(BaseModel):


class StratigraphicUnit(BaseModel):
"""
Stratigraphic unit from SMDA
Camel case attributes needed for esvIntersection component in front-end
"""

identifier: str
top: str
base: str
Expand Down
21 changes: 1 addition & 20 deletions backend_py/primary/primary/routers/well/converters.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from primary.services.smda_access.types import WellboreHeader, WellboreTrajectory, WellborePick, StratigraphicUnit
from primary.services.smda_access.types import WellboreHeader, WellboreTrajectory, WellborePick
from primary.services.ssdl_access.types import (
WellboreCasing,
WellboreCompletion,
Expand Down Expand Up @@ -27,25 +27,6 @@ def convert_wellbore_pick_to_schema(wellbore_pick: WellborePick) -> schemas.Well
)


def convert_stratigraphic_unit_to_schema(
stratigraphic_unit: StratigraphicUnit,
) -> schemas.StratigraphicUnit:
return schemas.StratigraphicUnit(
identifier=stratigraphic_unit.identifier,
top=stratigraphic_unit.top,
base=stratigraphic_unit.base,
stratUnitLevel=stratigraphic_unit.strat_unit_level,
stratUnitType=stratigraphic_unit.strat_unit_type,
topAge=stratigraphic_unit.top_age,
baseAge=stratigraphic_unit.base_age,
stratUnitParent=stratigraphic_unit.strat_unit_parent,
colorR=stratigraphic_unit.color_r,
colorG=stratigraphic_unit.color_g,
colorB=stratigraphic_unit.color_b,
lithologyType=stratigraphic_unit.lithology_type,
)


def convert_wellbore_header_to_schema(
drilled_wellbore_header: WellboreHeader,
) -> schemas.WellboreHeader:
Expand Down
22 changes: 12 additions & 10 deletions backend_py/primary/primary/routers/well/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from primary.services.smda_access import SmdaAccess
from primary.services.utils.authenticated_user import AuthenticatedUser
from primary.auth.auth_helper import AuthHelper
from primary.utils.drogon import is_drogon_identifier

from primary.services.ssdl_access.well_access import WellAccess as SsdlWellAccess

Expand All @@ -27,7 +28,7 @@ async def get_drilled_wellbore_headers(
) -> List[schemas.WellboreHeader]:
"""Get wellbore headers for all wells in the field"""
well_access: Union[SmdaAccess, DrogonSmdaAccess]
if field_identifier == "DROGON":
if is_drogon_identifier(field_identifier=field_identifier):
# Handle DROGON
well_access = DrogonSmdaAccess()
else:
Expand All @@ -48,7 +49,7 @@ async def get_well_trajectories(
) -> List[schemas.WellboreTrajectory]:
"""Get well trajectories for field"""
well_access: Union[SmdaAccess, DrogonSmdaAccess]
if field_identifier == "DROGON":
if is_drogon_identifier(field_identifier=field_identifier):
# Handle DROGON
well_access = DrogonSmdaAccess()
else:
Expand All @@ -74,7 +75,7 @@ async def get_wellbore_pick_identifiers(
) -> List[str]:
"""Get wellbore pick identifiers for field and stratigraphic column"""
well_access: Union[SmdaAccess, DrogonSmdaAccess]
if strat_column_identifier == "DROGON_HAS_NO_STRATCOLUMN":
if is_drogon_identifier(strat_column_identifier=strat_column_identifier):
# Handle DROGON
well_access = DrogonSmdaAccess()

Expand All @@ -97,7 +98,7 @@ async def get_wellbore_picks_for_pick_identifier(
) -> List[schemas.WellborePick]:
"""Get wellbore picks for field and pick identifier"""
well_access: Union[SmdaAccess, DrogonSmdaAccess]
if field_identifier == "DROGON":
if is_drogon_identifier(field_identifier=field_identifier):
# Handle DROGON
well_access = DrogonSmdaAccess()

Expand All @@ -120,7 +121,8 @@ async def get_wellbore_picks_for_wellbore(
) -> List[schemas.WellborePick]:
"""Get wellbore picks for field and pick identifier"""
well_access: Union[SmdaAccess, DrogonSmdaAccess]
if wellbore_uuid in ["drogon_horizontal", "drogon_vertical"]:

if is_drogon_identifier(wellbore_uuid=wellbore_uuid):
# Handle DROGON
well_access = DrogonSmdaAccess()

Expand All @@ -141,7 +143,7 @@ async def get_wellbore_completions(
"""Get well bore completions for a single well bore"""

# Handle DROGON
if wellbore_uuid in ["drogon_horizontal", "drogon_vertical"]:
if is_drogon_identifier(wellbore_uuid=wellbore_uuid):
return []

well_access = SsdlWellAccess(authenticated_user.get_ssdl_access_token())
Expand All @@ -163,7 +165,7 @@ async def get_wellbore_casings(
"""Get well bore casings for a single well bore"""

# Handle DROGON
if wellbore_uuid in ["drogon_horizontal", "drogon_vertical"]:
if is_drogon_identifier(wellbore_uuid=wellbore_uuid):
return []

well_access = SsdlWellAccess(authenticated_user.get_ssdl_access_token())
Expand All @@ -183,7 +185,7 @@ async def get_wellbore_perforations(
"""Get well bore casing for a single well bore"""

# Handle DROGON
if wellbore_uuid in ["drogon_horizontal", "drogon_vertical"]:
if is_drogon_identifier(wellbore_uuid=wellbore_uuid):
return []

well_access = SsdlWellAccess(authenticated_user.get_ssdl_access_token())
Expand All @@ -206,7 +208,7 @@ async def get_wellbore_log_curve_headers(
"""Get all log curve headers for a single well bore"""

# Handle DROGON
if wellbore_uuid in ["drogon_horizontal", "drogon_vertical"]:
if is_drogon_identifier(wellbore_uuid=wellbore_uuid):
return []

well_access = SsdlWellAccess(authenticated_user.get_ssdl_access_token())
Expand All @@ -232,7 +234,7 @@ async def get_log_curve_data(
"""Get log curve data"""

# Handle DROGON
if wellbore_uuid in ["drogon_horizontal", "drogon_vertical"]:
if is_drogon_identifier(wellbore_uuid=wellbore_uuid):
raise NotImplementedError("DROGON log curve data not implemented")

well_access = SsdlWellAccess(authenticated_user.get_ssdl_access_token())
Expand Down
26 changes: 0 additions & 26 deletions backend_py/primary/primary/routers/well/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,6 @@
from pydantic import BaseModel


class StratigraphicUnit(BaseModel):
"""
Stratigraphic unit from SMDA
Camel case attributes needed for esvIntersection component in front-end
"""

identifier: str
top: str
base: str
stratUnitLevel: int
stratUnitType: str
topAge: int | float
baseAge: int | float
stratUnitParent: Optional[str] = None
colorR: int
colorG: int
colorB: int
lithologyType: int | float | str = "unknown"


class WellboreHeader(BaseModel):
wellboreUuid: str
uniqueWellboreIdentifier: str
Expand Down Expand Up @@ -66,11 +45,6 @@ class WellborePick(BaseModel):
mdUnit: str


class WellborePicksAndStratigraphicUnits(BaseModel):
wellbore_picks: List[WellborePick] = []
stratigraphic_units: List[StratigraphicUnit] = []


class WellboreCompletion(BaseModel):
mdTop: float
mdBottom: float
Expand Down
19 changes: 19 additions & 0 deletions backend_py/primary/primary/utils/drogon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from typing import Optional


def is_drogon_identifier(
field_identifier: Optional[str] = None,
wellbore_uuid: Optional[str] = None,
strat_column_identifier: Optional[str] = None,
) -> bool:
"""
Checks if an element's identifier is for the drogon mock.
"""
if field_identifier == "DROGON":
return True
if wellbore_uuid in ["drogon_horizontal", "drogon_vertical"]:
return True
if strat_column_identifier == "DROGON_HAS_NO_STRATCOLUMN":
return True

return False
5 changes: 5 additions & 0 deletions frontend/src/api/models/StratigraphicUnit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
/**
* Stratigraphic unit from SMDA
*
* Camel case attributes needed for esvIntersection component in front-end
*/
export type StratigraphicUnit = {
identifier: string;
top: string;
Expand Down

0 comments on commit 5bb6d7f

Please sign in to comment.