forked from equinor/webviz
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'equinor/main' into new-2d-viewer
- Loading branch information
Showing
46 changed files
with
1,795 additions
and
1,096 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from primary.services.sumo_access.vfp_types import VfpProdTable, VfpInjTable, VfpType | ||
|
||
from . import schemas | ||
|
||
|
||
def to_api_table_definitions( | ||
vfp_table: VfpProdTable | VfpInjTable, | ||
) -> schemas.VfpProdTable | schemas.VfpInjTable: | ||
"""Converts the vfp table definitions from the sumo service to the API format""" | ||
if isinstance(vfp_table, VfpProdTable): | ||
return schemas.VfpProdTable( | ||
tableNumber=vfp_table.table_number, | ||
datum=vfp_table.datum, | ||
thpType=vfp_table.thp_type, | ||
wfrType=vfp_table.wfr_type, | ||
gfrType=vfp_table.gfr_type, | ||
alqType=vfp_table.alq_type, | ||
flowRateType=vfp_table.flow_rate_type, | ||
unitType=vfp_table.unit_type, | ||
tabType=vfp_table.tab_type, | ||
thpValues=vfp_table.thp_values, | ||
wfrValues=vfp_table.wfr_values, | ||
gfrValues=vfp_table.gfr_values, | ||
alqValues=vfp_table.alq_values, | ||
flowRateValues=vfp_table.flow_rate_values, | ||
bhpValues=vfp_table.bhp_values, | ||
flowRateUnit=vfp_table.flow_rate_unit, | ||
thpUnit=vfp_table.thp_unit, | ||
wfrUnit=vfp_table.wfr_unit, | ||
gfrUnit=vfp_table.gfr_unit, | ||
alqUnit=vfp_table.alq_unit, | ||
bhpUnit=vfp_table.bhp_unit, | ||
) | ||
if isinstance(vfp_table, VfpInjTable): | ||
return schemas.VfpInjTable( | ||
tableNumber=vfp_table.table_number, | ||
datum=vfp_table.datum, | ||
flowRateType=vfp_table.flow_rate_type, | ||
unitType=vfp_table.unit_type, | ||
tabType=vfp_table.tab_type, | ||
thpValues=vfp_table.thp_values, | ||
flowRateValues=vfp_table.flow_rate_values, | ||
bhpValues=vfp_table.bhp_values, | ||
flowRateUnit=vfp_table.flow_rate_unit, | ||
thpUnit=vfp_table.thp_unit, | ||
bhpUnit=vfp_table.bhp_unit, | ||
) | ||
raise ValueError("Unhandled VFP table type when converting to schema") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from pydantic import BaseModel | ||
|
||
from primary.services.sumo_access.vfp_types import THP, WFR, GFR, ALQ, FlowRateType, UnitType, TabType | ||
|
||
|
||
class VfpProdTable(BaseModel): | ||
isProdTable: bool = True | ||
tableNumber: int | ||
datum: float | ||
thpType: THP | ||
wfrType: WFR | ||
gfrType: GFR | ||
alqType: ALQ | ||
flowRateType: FlowRateType | ||
unitType: UnitType | ||
tabType: TabType | ||
thpValues: list[float] | ||
wfrValues: list[float] | ||
gfrValues: list[float] | ||
alqValues: list[float] | ||
flowRateValues: list[float] | ||
bhpValues: list[float] | ||
flowRateUnit: str | ||
thpUnit: str | ||
wfrUnit: str | ||
gfrUnit: str | ||
alqUnit: str | ||
bhpUnit: str | ||
|
||
|
||
class VfpInjTable(BaseModel): | ||
isInjTable: bool = True | ||
tableNumber: int | ||
datum: float | ||
flowRateType: FlowRateType | ||
unitType: UnitType | ||
tabType: TabType | ||
thpValues: list[float] | ||
flowRateValues: list[float] | ||
bhpValues: list[float] | ||
flowRateUnit: str | ||
thpUnit: str | ||
bhpUnit: str |
41 changes: 41 additions & 0 deletions
41
backend_py/primary/primary/routers/well_completions/converters.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from primary.services.sumo_access.well_completions_types import ( | ||
Completions, | ||
WellCompletionsData, | ||
WellCompletionsUnitInfo, | ||
WellCompletionsUnits, | ||
WellCompletionsWell, | ||
WellCompletionsZone, | ||
) | ||
|
||
from . import schemas | ||
|
||
|
||
def convert_completions_to_schema(completions: Completions) -> schemas.Completions: | ||
return schemas.Completions( | ||
sortedCompletionDateIndices=completions.sorted_completion_date_indices, | ||
open=completions.open, | ||
shut=completions.shut, | ||
khMean=completions.kh_mean, | ||
khMin=completions.kh_min, | ||
khMax=completions.kh_max, | ||
) | ||
|
||
|
||
def convert_well_to_schema(well: WellCompletionsWell) -> schemas.WellCompletionsWell: | ||
completions = {k: convert_completions_to_schema(v) for k, v in well.completions.items()} | ||
return schemas.WellCompletionsWell(name=well.name, attributes=well.attributes, completions=completions) | ||
|
||
|
||
def convert_unit_info_to_schema(unit_info: WellCompletionsUnitInfo) -> schemas.WellCompletionsUnitInfo: | ||
return schemas.WellCompletionsUnitInfo(unit=unit_info.unit, decimalPlaces=unit_info.decimalPlaces) | ||
|
||
|
||
def convert_units_to_schema(units: WellCompletionsUnits) -> schemas.WellCompletionsUnits: | ||
return schemas.WellCompletionsUnits(kh=convert_unit_info_to_schema(units.kh)) | ||
|
||
|
||
def convert_zone_to_schema(zone: WellCompletionsZone) -> schemas.WellCompletionsZone: | ||
return schemas.WellCompletionsZone( | ||
name=zone.name, | ||
subzones=[convert_zone_to_schema(subzone) for subzone in zone.subzones] if zone.subzones else None, | ||
) |
47 changes: 37 additions & 10 deletions
47
backend_py/primary/primary/routers/well_completions/router.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,58 @@ | ||
from typing import Optional | ||
from typing import Annotated | ||
|
||
from fastapi import APIRouter, Depends, HTTPException, Query | ||
|
||
from primary.auth.auth_helper import AuthHelper | ||
from primary.services.utils.authenticated_user import AuthenticatedUser | ||
|
||
from primary.services.sumo_access.well_completions_access import WellCompletionsAccess | ||
from primary.services.sumo_access.well_completions_types import WellCompletionsData | ||
from primary.services.well_completions_assembler.well_completions_assembler import WellCompletionsAssembler | ||
|
||
from . import converters | ||
from . import schemas | ||
|
||
router = APIRouter() | ||
|
||
|
||
@router.get("/well_completions_data/") | ||
async def get_well_completions_data( | ||
# fmt:off | ||
authenticated_user: AuthenticatedUser = Depends(AuthHelper.get_authenticated_user), | ||
case_uuid: str = Query(description="Sumo case uuid"), | ||
ensemble_name: str = Query(description="Ensemble name"), | ||
realization: Optional[int] = Query(None, description="Optional realization to include. If not specified, all realizations will be returned."), | ||
authenticated_user: Annotated[AuthenticatedUser, Depends(AuthHelper.get_authenticated_user)], | ||
case_uuid: Annotated[str, Query(description="Sumo case uuid")], | ||
ensemble_name: Annotated[str, Query(description="Ensemble name")], | ||
realization: Annotated[int | list[int] | None, Query( description="Optional realizations to include. Provide single realization or list of realizations. If not specified, all realizations will be returned.")] = None, | ||
# fmt:on | ||
) -> WellCompletionsData: | ||
) -> schemas.WellCompletionsData: | ||
access = await WellCompletionsAccess.from_case_uuid_async( | ||
authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name | ||
) | ||
well_completions_data = access.get_well_completions_data(realization=realization) | ||
|
||
if not well_completions_data: | ||
well_completions_assembler = WellCompletionsAssembler(well_completions_access=access) | ||
|
||
# Fetch and initialize table data | ||
if isinstance(realization, int): | ||
await well_completions_assembler.fetch_and_initialize_well_completions_single_realization_table_data_async( | ||
realization=realization | ||
) | ||
elif realization is not None and len(realization) == 1: | ||
await well_completions_assembler.fetch_and_initialize_well_completions_single_realization_table_data_async( | ||
realization=realization[0] | ||
) | ||
else: | ||
await well_completions_assembler.fetch_and_initialize_well_completions_table_data_async( | ||
realizations=realization | ||
) | ||
|
||
# Create well completions data object | ||
data = well_completions_assembler.create_well_completions_data() | ||
|
||
if not data: | ||
raise HTTPException(status_code=404, detail="Well completions data not found") | ||
|
||
return well_completions_data | ||
return schemas.WellCompletionsData( | ||
version=data.version, | ||
units=converters.convert_units_to_schema(data.units), | ||
zones=[converters.convert_zone_to_schema(zone) for zone in data.zones], | ||
sortedCompletionDates=data.sorted_completion_dates, | ||
wells=[converters.convert_well_to_schema(well) for well in data.wells], | ||
) |
42 changes: 42 additions & 0 deletions
42
backend_py/primary/primary/routers/well_completions/schemas.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from pydantic import BaseModel | ||
|
||
from primary.services.sumo_access.well_completions_types import WellCompletionsAttributeType | ||
|
||
|
||
class Completions(BaseModel): | ||
sortedCompletionDateIndices: list[int] | ||
open: list[float] | ||
shut: list[float] | ||
khMean: list[float] | ||
khMin: list[float] | ||
khMax: list[float] | ||
|
||
|
||
class WellCompletionsWell(BaseModel): | ||
name: str | ||
attributes: dict[str, WellCompletionsAttributeType] | ||
completions: dict[str, Completions] | ||
|
||
|
||
class WellCompletionsZone(BaseModel): | ||
name: str | ||
subzones: list["WellCompletionsZone"] | None = None | ||
|
||
|
||
class WellCompletionsUnitInfo(BaseModel): | ||
unit: str | ||
decimalPlaces: int | ||
|
||
|
||
class WellCompletionsUnits(BaseModel): | ||
kh: WellCompletionsUnitInfo | ||
|
||
|
||
class WellCompletionsData(BaseModel): | ||
"""Type definition for well completions data""" | ||
|
||
version: str | ||
units: WellCompletionsUnits | ||
zones: list[WellCompletionsZone] | ||
sortedCompletionDates: list[str] | ||
wells: list[WellCompletionsWell] |
Oops, something went wrong.