Skip to content

Commit

Permalink
Further implementation, switched to ReactQuery v5
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenthoms committed Oct 27, 2023
1 parent 2efa9ab commit fe563a4
Show file tree
Hide file tree
Showing 43 changed files with 521 additions and 673 deletions.
4 changes: 4 additions & 0 deletions backend/src/backend/primary/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class ResultNotMatchingExpectations(Exception):
def __init__(self, message: str):
self.message = message
super().__init__(self.message)
16 changes: 15 additions & 1 deletion backend/src/backend/primary/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import datetime
import logging

from fastapi import FastAPI
from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse
from fastapi.routing import APIRoute
from fastapi.responses import ORJSONResponse
from uvicorn.middleware.proxy_headers import ProxyHeadersMiddleware
Expand All @@ -24,6 +25,7 @@
from .routers.surface_polygons.router import router as surface_polygons_router
from .routers.graph.router import router as graph_router
from .routers.observations.router import router as observations_router
from .exceptions import ResultNotMatchingExpectations

logging.basicConfig(
level=logging.WARNING,
Expand Down Expand Up @@ -83,3 +85,15 @@ def custom_generate_unique_id(route: APIRoute) -> str:
@app.get("/")
async def root() -> str:
return f"Backend is alive at this time: {datetime.datetime.now()}"

@app.exception_handler(Exception)
async def exception_handler(request: Request, exc: Exception):
if isinstance(exc, ResultNotMatchingExpectations):
return JSONResponse(
status_code=404,
content={"message": exc.message},
)
return JSONResponse(
status_code=500,
content={"message": exc},
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,26 @@

from src.backend.auth.auth_helper import AuthHelper

from src.backend.primary.exceptions import ResultNotMatchingExpectations


router = APIRouter()


@router.get("/table_names_and_descriptions/", tags=["inplace_volumetrics"])
async def get_table_names_and_descriptions(
@router.get("/table_names_and_metadata/", tags=["inplace_volumetrics"])
async def get_table_names_and_metadata(
# 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"),
# fmt:on
) -> List[InplaceVolumetricsTableMetaData]:
"""Get all volumetric tables for a given ensemble."""

access = await InplaceVolumetricsAccess.from_case_uuid(
authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name
)
table_names = access.get_table_names_and_metadata()
return table_names
table_names_and_metadata = await access.get_table_names_and_metadata()
return table_names_and_metadata


@router.post("/realizations_response/", tags=["inplace_volumetrics"])
Expand Down
13 changes: 7 additions & 6 deletions backend/src/services/sumo_access/inplace_volumetrics_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ def has_value(cls, value: str) -> bool:
class InplaceVolumetricsCategoricalMetaData(BaseModel):
name: str
unique_values: List[Union[str, int, float]]
model_config = ConfigDict(from_attributes=True)
model_config = ConfigDict(from_attributes=True) # Might be removed


class InplaceVolumetricsTableMetaData(BaseModel):
name: str
categorical_column_metadata: List[InplaceVolumetricsCategoricalMetaData]
numerical_column_names: List[str]
model_config = ConfigDict(from_attributes=True)
model_config = ConfigDict(from_attributes=True) # Might be removed


class InplaceVolumetricsAccess(SumoEnsemble):
Expand All @@ -73,11 +73,12 @@ async def get_table_names_and_metadata(self) -> List[InplaceVolumetricsTableMeta
vol_table_collections: TableCollection = self._case.tables.filter(
aggregation="collection", tagname="vol", iteration=self._iteration_name
)

vol_tables_metadata = []
async for vol_table_name in vol_table_collections.names:
async for vol_table in vol_table_collections:
vol_table_collection: TableCollection = self._case.tables.filter(
aggregation="collection",
name=vol_table_name,
name=vol_table.name,
tagname="vol",
iteration=self._iteration_name,
)
Expand All @@ -86,7 +87,7 @@ async def get_table_names_and_metadata(self) -> List[InplaceVolumetricsTableMeta
for col in vol_table_collection.columns
if PossibleInplaceVolumetricsNumericalColumnNames.has_value(col)
]
first_numerical_column_table = self.get_table(vol_table_name, numerical_column_names[0])
first_numerical_column_table = self.get_table(vol_table.name, numerical_column_names[0])
categorical_column_metadata = [
InplaceVolumetricsCategoricalMetaData(
name=col,
Expand All @@ -96,7 +97,7 @@ async def get_table_names_and_metadata(self) -> List[InplaceVolumetricsTableMeta
if PossibleInplaceVolumetricsCategoricalColumnNames.has_value(col)
]
vol_table_metadata = InplaceVolumetricsTableMetaData(
name=vol_table_name,
name=vol_table.name,
categorical_column_metadata=categorical_column_metadata,
numerical_column_names=numerical_column_names,
)
Expand Down
98 changes: 24 additions & 74 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"@headlessui/react": "^1.7.8",
"@mui/base": "^5.0.0-beta.3",
"@mui/icons-material": "^5.14.9",
"@tanstack/react-query": "^4.24.10",
"@tanstack/react-query-devtools": "^4.24.12",
"@tanstack/react-query": "^5.0.5",
"@tanstack/react-query-devtools": "^5.4.2",
"@webviz/subsurface-viewer": "^0.3.1",
"@webviz/well-completions-plot": "^0.0.1-alpha.1",
"animate.css": "^4.1.1",
Expand Down
5 changes: 1 addition & 4 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ function App() {

const storedEnsembleIdents = workbench.current.maybeLoadEnsembleSetFromLocalStorage();
if (storedEnsembleIdents) {
workbench.current.getGuiMessageBroker().setState(GuiState.LoadingEnsembleSet, true);
workbench.current.loadAndSetupEnsembleSetInSession(queryClient, storedEnsembleIdents).then(() => {
workbench.current.getGuiMessageBroker().setState(GuiState.LoadingEnsembleSet, false);
});
workbench.current.loadAndSetupEnsembleSetInSession(queryClient, storedEnsembleIdents);
}

return function handleUnmount() {
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/api/services/InplaceVolumetricsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ export class InplaceVolumetricsService {
constructor(public readonly httpRequest: BaseHttpRequest) {}

/**
* Get Table Names And Descriptions
* Get Table Names And Metadata
* Get all volumetric tables for a given ensemble.
* @param caseUuid Sumo case uuid
* @param ensembleName Ensemble name
* @returns InplaceVolumetricsTableMetaData Successful Response
* @throws ApiError
*/
public getTableNamesAndDescriptions(
public getTableNamesAndMetadata(
caseUuid: string,
ensembleName: string,
): CancelablePromise<Array<InplaceVolumetricsTableMetaData>> {
return this.httpRequest.request({
method: 'GET',
url: '/inplace_volumetrics/table_names_and_descriptions/',
url: '/inplace_volumetrics/table_names_and_metadata/',
query: {
'case_uuid': caseUuid,
'ensemble_name': ensembleName,
Expand Down
3 changes: 0 additions & 3 deletions frontend/src/framework/GuiMessageBroker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export enum DrawerContent {
export enum GuiState {
DrawerContent = "drawerContent",
SettingsPanelWidthInPercent = "settingsPanelWidthInPercent",
LoadingEnsembleSet = "loadingEnsembleSet",
ActiveModuleInstanceId = "activeModuleInstanceId",
DataChannelConnectionLayerVisible = "dataChannelConnectionLayerVisible",
}
Expand Down Expand Up @@ -69,15 +68,13 @@ export type GuiEventPayloads = {
type GuiStateValueTypes = {
[GuiState.DrawerContent]: DrawerContent;
[GuiState.SettingsPanelWidthInPercent]: number;
[GuiState.LoadingEnsembleSet]: boolean;
[GuiState.ActiveModuleInstanceId]: string;
[GuiState.DataChannelConnectionLayerVisible]: boolean;
};

const defaultStates: Map<GuiState, any> = new Map();
defaultStates.set(GuiState.DrawerContent, DrawerContent.ModuleSettings);
defaultStates.set(GuiState.SettingsPanelWidthInPercent, 30);
defaultStates.set(GuiState.LoadingEnsembleSet, false);
defaultStates.set(GuiState.ActiveModuleInstanceId, "");

const persistentStates: GuiState[] = [GuiState.SettingsPanelWidthInPercent];
Expand Down
1 change: 1 addition & 0 deletions frontend/src/framework/Workbench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ export class Workbench {
}

console.debug("loadAndSetupEnsembleSetInSession - starting load");
this._workbenchSession.setEnsembleSetLoadingState(true);
const newEnsembleSet = await loadEnsembleSetMetadataFromBackend(queryClient, ensembleIdentsToLoad);
console.debug("loadAndSetupEnsembleSetInSession - loading done");

Expand Down
Loading

0 comments on commit fe563a4

Please sign in to comment.