From 56ac4cc024c6f5c24f8e7a4061edd315ac876191 Mon Sep 17 00:00:00 2001 From: Hans Kallekleiv <16436291+HansKallekleiv@users.noreply.github.com> Date: Tue, 31 Oct 2023 10:40:20 +0100 Subject: [PATCH] wip --- .../src/backend/primary/routers/rft/router.py | 12 +++++----- .../backend/primary/routers/rft/schemas.py | 4 ++-- .../src/services/sumo_access/rft_access.py | 22 +++++++++---------- backend/src/services/sumo_access/rft_types.py | 19 ++-------------- frontend/src/api/index.ts | 4 ++-- .../api/models/{RftWellInfo.ts => RftInfo.ts} | 2 +- ...alizationData.ts => RftRealizationData.ts} | 2 +- frontend/src/api/services/RftService.ts | 18 +++++++-------- frontend/src/modules/Rft/queryHooks.ts | 8 +++---- frontend/src/modules/Rft/settings.tsx | 17 ++++++-------- frontend/src/modules/Rft/view.tsx | 10 ++++----- 11 files changed, 50 insertions(+), 68 deletions(-) rename frontend/src/api/models/{RftWellInfo.ts => RftInfo.ts} (82%) rename frontend/src/api/models/{RftWellRealizationData.ts => RftRealizationData.ts} (84%) diff --git a/backend/src/backend/primary/routers/rft/router.py b/backend/src/backend/primary/routers/rft/router.py index c3968b151..178313a1d 100644 --- a/backend/src/backend/primary/routers/rft/router.py +++ b/backend/src/backend/primary/routers/rft/router.py @@ -19,14 +19,14 @@ router = APIRouter() -@router.get("/well_list") -async def get_well_list( +@router.get("/rft_info") +async def get_rft_info( 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")], -) -> list[schemas.RftWellInfo]: +) -> list[schemas.RftInfo]: access = await RftAccess.from_case_uuid(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name) - rft_well_list = await access.get_well_list() + rft_well_list = await access.get_rft_info() return rft_well_list @@ -40,9 +40,9 @@ async def get_realization_data( response_name: Annotated[str, Query(description="Response name")], timestamps_utc_ms: Annotated[list[int] | None, Query(description="Timestamps utc ms")] = None, realizations: Annotated[list[int] | None, Query(description="Realizations")] = None, -) -> list[schemas.RftWellRealizationData]: +) -> list[schemas.RftRealizationData]: access = await RftAccess.from_case_uuid(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name) - data = await access.get_rft_realization_data( + data = await access.get_rft_well_realization_data( well_name=well_name, response_name=response_name, timestamps_utc_ms=timestamps_utc_ms, diff --git a/backend/src/backend/primary/routers/rft/schemas.py b/backend/src/backend/primary/routers/rft/schemas.py index bb8b4a447..14a021457 100644 --- a/backend/src/backend/primary/routers/rft/schemas.py +++ b/backend/src/backend/primary/routers/rft/schemas.py @@ -1,12 +1,12 @@ from pydantic import BaseModel -class RftWellInfo(BaseModel): +class RftInfo(BaseModel): well_name: str timestamps_utc_ms: list[int] -class RftWellRealizationData(BaseModel): +class RftRealizationData(BaseModel): well_name: str realization: int timestamp_utc_ms: int diff --git a/backend/src/services/sumo_access/rft_access.py b/backend/src/services/sumo_access/rft_access.py index 35e2d01ca..44af302d2 100644 --- a/backend/src/services/sumo_access/rft_access.py +++ b/backend/src/services/sumo_access/rft_access.py @@ -11,47 +11,47 @@ from ._helpers import SumoEnsemble from ..utils.perf_timer import PerfTimer -from .rft_types import RftWellInfo, RftWellRealizationData +from .rft_types import RftInfo, RftRealizationData LOGGER = logging.getLogger(__name__) class RftAccess(SumoEnsemble): - async def get_well_list(self) -> list[RftWellInfo]: + async def get_rft_info(self) -> list[RftInfo]: table = await get_concatenated_rft_table(self._case, self._iteration_name, column_names=["PRESSURE"]) - rft_well_infos: list[RftWellInfo] = [] + rft_well_infos: list[RftInfo] = [] well_names = table["WELL"].unique().tolist() for well_name in well_names: well_table = table.filter(pc.equal(table["WELL"], well_name)) timestamps_utc_ms = sorted(list(set(well_table["DATE"].to_numpy().astype(int).tolist()))) - rft_well_infos.append(RftWellInfo(well_name=well_name, timestamps_utc_ms=timestamps_utc_ms)) + rft_well_infos.append(RftInfo(well_name=well_name, timestamps_utc_ms=timestamps_utc_ms)) return rft_well_infos - async def get_rft_realization_data( + async def get_rft_well_realization_data( self, well_name: str, response_name: str, timestamps_utc_ms: Optional[int], realizations: Optional[Sequence[int]], - ) -> List[RftWellRealizationData]: + ) -> List[RftRealizationData]: column_names = [response_name, "DEPTH"] table = await self.get_rft_table( - well_name=well_name, + well_names=[well_name], column_names=column_names, timestamps_utc_ms=timestamps_utc_ms, realizations=realizations, ) pandas_table = table.to_pandas(types_mapper=pd.ArrowDtype) - ret_arr: List[RftWellRealizationData] = [] + ret_arr: List[RftRealizationData] = [] for real, real_df in pandas_table.groupby("REAL"): for datetime, date_df in real_df.groupby("DATE"): ret_arr.append( - RftWellRealizationData( + RftRealizationData( well_name=well_name, realization=real, timestamp_utc_ms=datetime.timestamp() * 1000, @@ -64,7 +64,7 @@ async def get_rft_realization_data( async def get_rft_table( self, - well_name: str, + well_names: List[str], column_names: List[str], timestamps_utc_ms: Optional[int], realizations: Optional[Sequence[int]], @@ -74,7 +74,7 @@ async def get_rft_table( if realizations is not None: mask = pc.is_in(table["REAL"], value_set=pa.array(realizations)) table = table.filter(mask) - mask = pc.equal(table["WELL"], well_name) + mask = pc.is_in(table["WELL"], value_set=pa.array(well_names)) table = table.filter(mask) if timestamps_utc_ms is not None: mask = pc.is_in(table["DATE"], value_set=pa.array(timestamps_utc_ms)) diff --git a/backend/src/services/sumo_access/rft_types.py b/backend/src/services/sumo_access/rft_types.py index 35af47370..7793017a5 100644 --- a/backend/src/services/sumo_access/rft_types.py +++ b/backend/src/services/sumo_access/rft_types.py @@ -14,28 +14,13 @@ class RftSumoTableSchema(BaseModel): column_names: list[str] -class RftWellInfo(BaseModel): +class RftInfo(BaseModel): well_name: str timestamps_utc_ms: list[int] -# class RftRealizationResponse(BaseModel): -# realization: int -# depth: list[float] -# pressure: list[float] - -# class RftTimestampResponse(BaseModel): -# timestamp_utc_ms: int -# realizations_response: list[RftRealizationResponse] - - -# class RftWellResponse(BaseModel): -# well_name: str -# timestamps_response: list[RftTimestampResponse] - - -class RftWellRealizationData(BaseModel): +class RftRealizationData(BaseModel): well_name: str realization: int timestamp_utc_ms: int diff --git a/frontend/src/api/index.ts b/frontend/src/api/index.ts index 3694dc043..25693d389 100644 --- a/frontend/src/api/index.ts +++ b/frontend/src/api/index.ts @@ -32,10 +32,10 @@ export type { InplaceVolumetricsTableMetaData as InplaceVolumetricsTableMetaData export type { Observations as Observations_api } from './models/Observations'; export type { PolygonData as PolygonData_api } from './models/PolygonData'; export type { PvtData as PvtData_api } from './models/PvtData'; +export type { RftInfo as RftInfo_api } from './models/RftInfo'; export type { RftObservation as RftObservation_api } from './models/RftObservation'; export type { RftObservations as RftObservations_api } from './models/RftObservations'; -export type { RftWellInfo as RftWellInfo_api } from './models/RftWellInfo'; -export type { RftWellRealizationData as RftWellRealizationData_api } from './models/RftWellRealizationData'; +export type { RftRealizationData as RftRealizationData_api } from './models/RftRealizationData'; export type { SeismicCubeMeta as SeismicCubeMeta_api } from './models/SeismicCubeMeta'; export { SensitivityType as SensitivityType_api } from './models/SensitivityType'; export { StatisticFunction as StatisticFunction_api } from './models/StatisticFunction'; diff --git a/frontend/src/api/models/RftWellInfo.ts b/frontend/src/api/models/RftInfo.ts similarity index 82% rename from frontend/src/api/models/RftWellInfo.ts rename to frontend/src/api/models/RftInfo.ts index 69bf309b8..c43a2c1ab 100644 --- a/frontend/src/api/models/RftWellInfo.ts +++ b/frontend/src/api/models/RftInfo.ts @@ -2,7 +2,7 @@ /* tslint:disable */ /* eslint-disable */ -export type RftWellInfo = { +export type RftInfo = { well_name: string; timestamps_utc_ms: Array; }; diff --git a/frontend/src/api/models/RftWellRealizationData.ts b/frontend/src/api/models/RftRealizationData.ts similarity index 84% rename from frontend/src/api/models/RftWellRealizationData.ts rename to frontend/src/api/models/RftRealizationData.ts index 7060fac46..cab5166b7 100644 --- a/frontend/src/api/models/RftWellRealizationData.ts +++ b/frontend/src/api/models/RftRealizationData.ts @@ -2,7 +2,7 @@ /* tslint:disable */ /* eslint-disable */ -export type RftWellRealizationData = { +export type RftRealizationData = { well_name: string; realization: number; timestamp_utc_ms: number; diff --git a/frontend/src/api/services/RftService.ts b/frontend/src/api/services/RftService.ts index 0e9a4f8e4..a582c9024 100644 --- a/frontend/src/api/services/RftService.ts +++ b/frontend/src/api/services/RftService.ts @@ -1,8 +1,8 @@ /* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -import type { RftWellInfo } from '../models/RftWellInfo'; -import type { RftWellRealizationData } from '../models/RftWellRealizationData'; +import type { RftInfo } from '../models/RftInfo'; +import type { RftRealizationData } from '../models/RftRealizationData'; import type { CancelablePromise } from '../core/CancelablePromise'; import type { BaseHttpRequest } from '../core/BaseHttpRequest'; @@ -12,19 +12,19 @@ export class RftService { constructor(public readonly httpRequest: BaseHttpRequest) {} /** - * Get Well List + * Get Rft Info * @param caseUuid Sumo case uuid * @param ensembleName Ensemble name - * @returns RftWellInfo Successful Response + * @returns RftInfo Successful Response * @throws ApiError */ - public getWellList( + public getRftInfo( caseUuid: string, ensembleName: string, - ): CancelablePromise> { + ): CancelablePromise> { return this.httpRequest.request({ method: 'GET', - url: '/rft/well_list', + url: '/rft/rft_info', query: { 'case_uuid': caseUuid, 'ensemble_name': ensembleName, @@ -43,7 +43,7 @@ export class RftService { * @param responseName Response name * @param timestampsUtcMs Timestamps utc ms * @param realizations Realizations - * @returns RftWellRealizationData Successful Response + * @returns RftRealizationData Successful Response * @throws ApiError */ public getRealizationData( @@ -53,7 +53,7 @@ export class RftService { responseName: string, timestampsUtcMs?: (Array | null), realizations?: (Array | null), - ): CancelablePromise> { + ): CancelablePromise> { return this.httpRequest.request({ method: 'GET', url: '/rft/realization_data', diff --git a/frontend/src/modules/Rft/queryHooks.ts b/frontend/src/modules/Rft/queryHooks.ts index 9ed337c87..df018180e 100644 --- a/frontend/src/modules/Rft/queryHooks.ts +++ b/frontend/src/modules/Rft/queryHooks.ts @@ -1,4 +1,4 @@ -import { RftWellInfo_api, RftWellRealizationData_api } from "@api"; +import { RftInfo_api, RftRealizationData_api } from "@api"; import { apiService } from "@framework/ApiService"; import { UseQueryResult, useQuery } from "@tanstack/react-query"; @@ -8,10 +8,10 @@ const CACHE_TIME = 60 * 1000; export function useRftWellList( caseUuid: string | undefined, ensembleName: string | undefined, -): UseQueryResult { +): UseQueryResult { return useQuery({ queryKey: ["getRftWellList", caseUuid, ensembleName], - queryFn: () => apiService.rft.getWellList(caseUuid ?? "", ensembleName ?? ""), + queryFn: () => apiService.rft.getRftInfo(caseUuid ?? "", ensembleName ?? ""), staleTime: STALE_TIME, cacheTime: CACHE_TIME, enabled: caseUuid && ensembleName ? true : false, @@ -25,7 +25,7 @@ export function useRftRealizationData( responseName: string | undefined, timePoints: number[] | undefined, realizationNums: number[] | null | undefined, -): UseQueryResult { +): UseQueryResult { return useQuery({ queryKey: ["getRftRealizationData", caseUuid, ensembleName, wellName, responseName, timePoints, realizationNums], queryFn: () => apiService.rft.getRealizationData(caseUuid ?? "", ensembleName ?? "", wellName ?? "", responseName ?? "", timePoints ?? undefined, realizationNums ?? undefined), diff --git a/frontend/src/modules/Rft/settings.tsx b/frontend/src/modules/Rft/settings.tsx index 8baf191cb..4ab7c4c61 100644 --- a/frontend/src/modules/Rft/settings.tsx +++ b/frontend/src/modules/Rft/settings.tsx @@ -1,20 +1,17 @@ -import React, { useEffect } from "react"; +import React from "react"; import { EnsembleIdent } from "@framework/EnsembleIdent"; import { ModuleFCProps } from "@framework/Module"; import { SyncSettingKey, SyncSettingsHelper } from "@framework/SyncSettings"; -import { useFirstEnsembleInEnsembleSet } from "@framework/WorkbenchSession"; + import { useEnsembleSet } from "@framework/WorkbenchSession"; import { SingleEnsembleSelect } from "@framework/components/SingleEnsembleSelect"; import { fixupEnsembleIdent, maybeAssignFirstSyncedEnsemble } from "@framework/utils/ensembleUiHelpers"; import { timestampUtcMsToCompactIsoString } from "@framework/utils/timestampUtils"; -import { ApiStateWrapper } from "@lib/components/ApiStateWrapper"; -import { Checkbox } from "@lib/components/Checkbox"; + import { CollapsibleGroup } from "@lib/components/CollapsibleGroup"; -import { Dropdown, DropdownOption } from "@lib/components/Dropdown"; -import { Label } from "@lib/components/Label"; -import { Select } from "@lib/components/Select"; -import { TimestampSlider } from "@lib/components/TimestampSlider"; + +import { Select, SelectOption } from "@lib/components/Select"; import { isEqual } from "lodash"; @@ -22,10 +19,10 @@ import { useRftWellList } from "./queryHooks"; import state, { RftWellAddress } from "./state"; //Helpers to populate dropdowns -const stringToOptions = (strings: string[]): DropdownOption[] => { +const stringToOptions = (strings: string[]): SelectOption[] => { return strings.map((string) => ({ label: string, value: string })); }; -const timepointOptions = (timePoints: number[]): DropdownOption[] => { +const timepointOptions = (timePoints: number[]): SelectOption[] => { return timePoints.map((timePoint) => ({ label: timestampUtcMsToCompactIsoString(timePoint), value: timePoint.toString(), diff --git a/frontend/src/modules/Rft/view.tsx b/frontend/src/modules/Rft/view.tsx index 86345e598..3e00db5eb 100644 --- a/frontend/src/modules/Rft/view.tsx +++ b/frontend/src/modules/Rft/view.tsx @@ -1,7 +1,7 @@ import React from "react"; import Plot from "react-plotly.js"; -import { RftWellRealizationData_api } from "@api"; +import { RftRealizationData_api } from "@api"; import { timestampUtcMsToCompactIsoString } from "@framework/utils/timestampUtils"; import { ModuleFCProps } from "@framework/Module"; import { useElementSize } from "@lib/hooks/useElementSize"; @@ -11,7 +11,7 @@ import { PlotData } from "plotly.js"; import { useRftRealizationData } from "./queryHooks"; import State from "./state"; -export const view = ({ moduleContext, workbenchSession, workbenchSettings }: ModuleFCProps) => { +export const view = ({ moduleContext }: ModuleFCProps) => { const wrapperDivRef = React.useRef(null); const wrapperDivSize = useElementSize(wrapperDivRef); const rftWellAddress = moduleContext.useStoreValue("rftWellAddress"); @@ -25,7 +25,7 @@ export const view = ({ moduleContext, workbenchSession, workbenchSettings }: Mod ); const timePoint = rftWellAddress?.timePoint; - const realizationDataForTimePoint: RftWellRealizationData_api[] = []; + const realizationDataForTimePoint: RftRealizationData_api[] = []; if (rftRealizationDataQuery.data && timePoint) { rftRealizationDataQuery.data.forEach((realizationData) => { if (realizationData.timestamp_utc_ms === timePoint) { @@ -57,7 +57,7 @@ export const view = ({ moduleContext, workbenchSession, workbenchSettings }: Mod ); }; -function createRftRealizationTrace(rftRealizationData: RftWellRealizationData_api): Partial { +function createRftRealizationTrace(rftRealizationData: RftRealizationData_api): Partial { const trace: Partial = { x: rftRealizationData.value_arr, y: rftRealizationData.depth_arr, @@ -78,7 +78,7 @@ function createRftRealizationTrace(rftRealizationData: RftWellRealizationData_ap return trace; } -function getResponseValueRange(rftRealizationData: RftWellRealizationData_api[] | null): [number, number] { +function getResponseValueRange(rftRealizationData: RftRealizationData_api[] | null): [number, number] { let minValue = Number.POSITIVE_INFINITY; let maxValue = Number.NEGATIVE_INFINITY; if (rftRealizationData !== null && rftRealizationData.length) {