Skip to content

Commit

Permalink
async test - wip
Browse files Browse the repository at this point in the history
  • Loading branch information
anders-kiaer committed Sep 30, 2023
1 parent 8261e08 commit 09f4c17
Show file tree
Hide file tree
Showing 21 changed files with 167 additions and 247 deletions.
12 changes: 6 additions & 6 deletions backend/src/backend/primary/routers/grid/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@


@router.get("/grid_model_names/")
def get_grid_model_names(
async def get_grid_model_names(
authenticated_user: AuthenticatedUser = Depends(AuthHelper.get_authenticated_user),
case_uuid: str = Query(description="Sumo case uuid"),
ensemble_name: str = Query(description="Ensemble name"),
) -> List[str]:
"""
Get a list of grid model names
"""
access = GridAccess(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name)
return access.grid_model_names()
access = await GridAccess.from_case_uuid(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name)
return await access.grid_model_names()


@router.get("/parameter_names/")
def get_parameter_names(
async def get_parameter_names(
authenticated_user: AuthenticatedUser = Depends(AuthHelper.get_authenticated_user),
case_uuid: str = Query(description="Sumo case uuid"),
ensemble_name: str = Query(description="Ensemble name"),
Expand All @@ -36,8 +36,8 @@ def get_parameter_names(
"""
Get a list of grid parameter names
"""
access = GridAccess(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name)
return access.static_parameter_names(grid_name)
access = await GridAccess.from_case_uuid(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name)
return await access.static_parameter_names(grid_name)


# Primary backend
Expand Down
16 changes: 10 additions & 6 deletions backend/src/backend/primary/routers/inplace_volumetrics/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


@router.get("/table_names_and_descriptions/", tags=["inplace_volumetrics"])
def get_table_names_and_descriptions(
async def get_table_names_and_descriptions(
# fmt:off
authenticated_user: AuthenticatedUser = Depends(AuthHelper.get_authenticated_user),
case_uuid: str = Query(description="Sumo case uuid"),
Expand All @@ -26,13 +26,15 @@ def get_table_names_and_descriptions(
) -> List[InplaceVolumetricsTableMetaData]:
"""Get all volumetric tables for a given ensemble."""

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


@router.post("/realizations_response/", tags=["inplace_volumetrics"])
def get_realizations_response(
async def get_realizations_response(
# fmt:off
authenticated_user: AuthenticatedUser = Depends(AuthHelper.get_authenticated_user),
case_uuid: str = Query(description="Sumo case uuid"),
Expand All @@ -44,8 +46,10 @@ def get_realizations_response(
# fmt:on
) -> EnsembleScalarResponse:
"""Get response for a given table and index filter."""
access = InplaceVolumetricsAccess(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name)
response = access.get_response(table_name, response_name, categorical_filter, realizations)
access = await InplaceVolumetricsAccess.from_case_uuid(
authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name
)
response = await access.get_response(table_name, response_name, categorical_filter, realizations)
return response


Expand Down
14 changes: 7 additions & 7 deletions backend/src/backend/primary/routers/pvt/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


@router.get("/table_data/")
def table_data(
async def table_data(
# fmt:off
authenticated_user: AuthenticatedUser = Depends(AuthHelper.get_authenticated_user),
case_uuid: str = Query(description="Sumo case uuid"),
Expand All @@ -26,18 +26,18 @@ def table_data(
) -> List[PvtData]:
"""Get pvt table data for a given Sumo ensemble and realization"""

access = TableAccess(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name)
access = await TableAccess.from_case_uuid(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name)

# Get all table schemas for a given realization and find the pvt table
table_schemas = access.get_table_schemas_single_realization(realization=realization)
table_schemas = await access.get_table_schemas_single_realization(realization=realization)
for schema in table_schemas:
if schema.tagname == "pvt":
table_schema = schema

if table_schema is None:
raise HTTPException(status_code=404, detail="PVT table not found")

sumo_table_data = access.get_realization_table(table_schema, realization=realization)
sumo_table_data = await access.get_realization_table(table_schema, realization=realization)

pvt_data = pvt_dataframe_to_api_data(sumo_table_data.to_pandas())

Expand All @@ -46,7 +46,7 @@ def table_data(

# DOES NOT CURRENTLY WORK
@router.get("/realizations_tables_are_equal/")
def realizations_tables_are_equal(
async def realizations_tables_are_equal(
# fmt:off
authenticated_user: AuthenticatedUser = Depends(AuthHelper.get_authenticated_user),
case_uuid: str = Query(description="Sumo case uuid"),
Expand All @@ -55,10 +55,10 @@ def realizations_tables_are_equal(
) -> bool:
"""Check if all realizations has the same pvt table"""

access = TableAccess(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name)
access = await TableAccess.from_case_uuid(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name)

# Get all table schemas for a given realization and find the pvt table
table_schemas = access.get_table_schemas_single_realization(realization=0)
table_schemas = await access.get_table_schemas_single_realization(realization=0)
for schema in table_schemas:
if schema.tagname == "pvt":
# Check if all realizations of this table are equal
Expand Down
6 changes: 3 additions & 3 deletions backend/src/backend/primary/routers/seismic/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@


@router.get("/seismic_directory/")
def get_seismic_directory(
async def get_seismic_directory(
authenticated_user: AuthenticatedUser = Depends(AuthHelper.get_authenticated_user),
case_uuid: str = Query(description="Sumo case uuid"),
ensemble_name: str = Query(description="Ensemble name"),
) -> List[schemas.SeismicCubeMeta]:
"""
Get a directory of seismic cubes.
"""
access = SeismicAccess(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name)
seismic_cube_metas = access.get_seismic_directory()
access = await SeismicAccess.from_case_uuid(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name)
seismic_cube_metas = await access.get_seismic_directory()
try:
return [schemas.SeismicCubeMeta(**meta.__dict__) for meta in seismic_cube_metas]
except ValueError as exc:
Expand Down
22 changes: 12 additions & 10 deletions backend/src/backend/primary/routers/surface/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,17 @@


@router.get("/surface_directory/")
def get_surface_directory(
async def get_surface_directory(
authenticated_user: AuthenticatedUser = Depends(AuthHelper.get_authenticated_user),
case_uuid: str = Query(description="Sumo case uuid"),
ensemble_name: str = Query(description="Ensemble name"),
) -> List[schemas.SurfaceMeta]:
"""
Get a directory of surfaces in a Sumo ensemble
"""
surface_access = SurfaceAccess(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name)
surface_access = await SurfaceAccess.from_case_uuid(
authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name
)
sumo_surf_dir = surface_access.get_surface_directory()

case_inspector = CaseInspector(authenticated_user.get_sumo_access_token(), case_uuid)
Expand All @@ -51,7 +53,7 @@ def get_surface_directory(


@router.get("/realization_surface_data/")
def get_realization_surface_data(
async def get_realization_surface_data(
authenticated_user: AuthenticatedUser = Depends(AuthHelper.get_authenticated_user),
case_uuid: str = Query(description="Sumo case uuid"),
ensemble_name: str = Query(description="Ensemble name"),
Expand All @@ -62,7 +64,7 @@ def get_realization_surface_data(
) -> schemas.SurfaceData:
timer = PerfTimer()

access = SurfaceAccess(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name)
access = await SurfaceAccess.from_case_uuid(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name)
xtgeo_surf = access.get_realization_surface_data(
real_num=realization_num, name=name, attribute=attribute, time_or_interval_str=time_or_interval
)
Expand All @@ -78,7 +80,7 @@ def get_realization_surface_data(


@router.get("/statistical_surface_data/")
def get_statistical_surface_data(
async def get_statistical_surface_data(
authenticated_user: AuthenticatedUser = Depends(AuthHelper.get_authenticated_user),
case_uuid: str = Query(description="Sumo case uuid"),
ensemble_name: str = Query(description="Ensemble name"),
Expand All @@ -89,7 +91,7 @@ def get_statistical_surface_data(
) -> schemas.SurfaceData:
timer = PerfTimer()

access = SurfaceAccess(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name)
access = await SurfaceAccess.from_case_uuid(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name)

service_stat_func_to_compute = StatisticFunction.from_string_value(statistic_function)
if service_stat_func_to_compute is not None:
Expand All @@ -112,7 +114,7 @@ def get_statistical_surface_data(

# pylint: disable=too-many-arguments
@router.get("/property_surface_resampled_to_static_surface/")
def get_property_surface_resampled_to_static_surface(
async def get_property_surface_resampled_to_static_surface(
authenticated_user: AuthenticatedUser = Depends(AuthHelper.get_authenticated_user),
case_uuid: str = Query(description="Sumo case uuid"),
ensemble_name: str = Query(description="Ensemble name"),
Expand All @@ -126,7 +128,7 @@ def get_property_surface_resampled_to_static_surface(
) -> schemas.SurfaceData:
timer = PerfTimer()

access = SurfaceAccess(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name)
access = await SurfaceAccess.from_case_uuid(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name)
xtgeo_surf_mesh = access.get_realization_surface_data(
real_num=realization_num_mesh, name=name_mesh, attribute=attribute_mesh
)
Expand All @@ -150,7 +152,7 @@ def get_property_surface_resampled_to_static_surface(


@router.get("/property_surface_resampled_to_statistical_static_surface/")
def get_property_surface_resampled_to_statistical_static_surface(
async def get_property_surface_resampled_to_statistical_static_surface(
authenticated_user: AuthenticatedUser = Depends(AuthHelper.get_authenticated_user),
case_uuid: str = Query(description="Sumo case uuid"),
ensemble_name: str = Query(description="Ensemble name"),
Expand All @@ -164,7 +166,7 @@ def get_property_surface_resampled_to_statistical_static_surface(
) -> schemas.SurfaceData:
timer = PerfTimer()

access = SurfaceAccess(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name)
access = await SurfaceAccess.from_case_uuid(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name)
service_stat_func_to_compute = StatisticFunction.from_string_value(statistic_function)
if service_stat_func_to_compute is not None:
xtgeo_surf_mesh = access.get_statistical_surface_data(
Expand Down
16 changes: 11 additions & 5 deletions backend/src/backend/primary/routers/timeseries/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,17 @@ async def get_statistical_vector_data_per_sensitivity(
) -> list[schemas.VectorStatisticSensitivityData]:
"""Get statistical vector data for an ensemble per sensitivity"""

summmary_access = await SummaryAccess.from_case_uuid(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name)
parameter_access = ParameterAccess(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name)
sensitivities = parameter_access.get_parameters_and_sensitivities().sensitivities
summmary_access = await SummaryAccess.from_case_uuid(
authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name
)
parameter_access = await ParameterAccess.from_case_uuid(
authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name
)
sensitivities = await parameter_access.get_parameters_and_sensitivities().sensitivities

service_freq = Frequency.from_string_value(resampling_frequency.value)
service_stat_funcs_to_compute = converters.to_service_statistic_functions(statistic_functions)
vector_table, vector_metadata = summmary_access.get_vector_table(
vector_table, vector_metadata = await summmary_access.get_vector_table(
vector_name=vector_name, resampling_frequency=service_freq, realizations=None
)
ret_data: list[schemas.VectorStatisticSensitivityData] = []
Expand Down Expand Up @@ -221,7 +225,9 @@ async def get_realization_vector_at_timestamp(
# realizations: Annotated[list[int] | None, Query(description="Optional list of realizations to include. If not specified, all realizations will be returned.")] = None,
# fmt:on
) -> EnsembleScalarResponse:
summary_access = await SummaryAccess.from_case_uuid(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name)
summary_access = await SummaryAccess.from_case_uuid(
authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name
)
ensemble_response = summary_access.get_vector_values_at_timestamp(
vector_name=vector_name, timestamp_utc_ms=timestamp_utc_ms, realizations=None
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@


@router.get("/well_completions_data/")
def 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."),
# fmt:on
) -> WellCompletionsData:
access = WellCompletionsAccess(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name)
access = await WellCompletionsAccess.from_case_uuid(
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:
Expand Down
1 change: 0 additions & 1 deletion backend/src/backend/shared_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@


def add_shared_middlewares(app: FastAPI) -> None:

# Add out custom middleware to enforce that user is logged in
# Also redirects to /login endpoint for some select paths
unprotected_paths = ["/logged_in_user", "/alive", "/openapi.json"]
Expand Down
Loading

0 comments on commit 09f4c17

Please sign in to comment.