Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
HansKallekleiv committed Oct 31, 2023
1 parent e269382 commit 56ac4cc
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 68 deletions.
12 changes: 6 additions & 6 deletions backend/src/backend/primary/routers/rft/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions backend/src/backend/primary/routers/rft/schemas.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
22 changes: 11 additions & 11 deletions backend/src/services/sumo_access/rft_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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]],
Expand All @@ -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))
Expand Down
19 changes: 2 additions & 17 deletions backend/src/services/sumo_access/rft_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* tslint:disable */
/* eslint-disable */

export type RftWellInfo = {
export type RftInfo = {
well_name: string;
timestamps_utc_ms: Array<number>;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* tslint:disable */
/* eslint-disable */

export type RftWellRealizationData = {
export type RftRealizationData = {
well_name: string;
realization: number;
timestamp_utc_ms: number;
Expand Down
18 changes: 9 additions & 9 deletions frontend/src/api/services/RftService.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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<Array<RftWellInfo>> {
): CancelablePromise<Array<RftInfo>> {
return this.httpRequest.request({
method: 'GET',
url: '/rft/well_list',
url: '/rft/rft_info',
query: {
'case_uuid': caseUuid,
'ensemble_name': ensembleName,
Expand All @@ -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(
Expand All @@ -53,7 +53,7 @@ export class RftService {
responseName: string,
timestampsUtcMs?: (Array<number> | null),
realizations?: (Array<number> | null),
): CancelablePromise<Array<RftWellRealizationData>> {
): CancelablePromise<Array<RftRealizationData>> {
return this.httpRequest.request({
method: 'GET',
url: '/rft/realization_data',
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/modules/Rft/queryHooks.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -8,10 +8,10 @@ const CACHE_TIME = 60 * 1000;
export function useRftWellList(
caseUuid: string | undefined,
ensembleName: string | undefined,
): UseQueryResult<RftWellInfo_api[]> {
): UseQueryResult<RftInfo_api[]> {
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,
Expand All @@ -25,7 +25,7 @@ export function useRftRealizationData(
responseName: string | undefined,
timePoints: number[] | undefined,
realizationNums: number[] | null | undefined,
): UseQueryResult<RftWellRealizationData_api[]> {
): UseQueryResult<RftRealizationData_api[]> {
return useQuery({
queryKey: ["getRftRealizationData", caseUuid, ensembleName, wellName, responseName, timePoints, realizationNums],
queryFn: () => apiService.rft.getRealizationData(caseUuid ?? "", ensembleName ?? "", wellName ?? "", responseName ?? "", timePoints ?? undefined, realizationNums ?? undefined),
Expand Down
17 changes: 7 additions & 10 deletions frontend/src/modules/Rft/settings.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
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";

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(),
Expand Down
10 changes: 5 additions & 5 deletions frontend/src/modules/Rft/view.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -11,7 +11,7 @@ import { PlotData } from "plotly.js";
import { useRftRealizationData } from "./queryHooks";
import State from "./state";

export const view = ({ moduleContext, workbenchSession, workbenchSettings }: ModuleFCProps<State>) => {
export const view = ({ moduleContext }: ModuleFCProps<State>) => {
const wrapperDivRef = React.useRef<HTMLDivElement>(null);
const wrapperDivSize = useElementSize(wrapperDivRef);
const rftWellAddress = moduleContext.useStoreValue("rftWellAddress");
Expand All @@ -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) {
Expand Down Expand Up @@ -57,7 +57,7 @@ export const view = ({ moduleContext, workbenchSession, workbenchSettings }: Mod
);
};

function createRftRealizationTrace(rftRealizationData: RftWellRealizationData_api): Partial<PlotData> {
function createRftRealizationTrace(rftRealizationData: RftRealizationData_api): Partial<PlotData> {
const trace: Partial<PlotData> = {
x: rftRealizationData.value_arr,
y: rftRealizationData.depth_arr,
Expand All @@ -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) {
Expand Down

0 comments on commit 56ac4cc

Please sign in to comment.