Skip to content

Commit

Permalink
Minor bug fixes and improvements
Browse files Browse the repository at this point in the history
Refactored SMDA get function, fixed issue with field selector, added placeholder layer
  • Loading branch information
rubenthoms committed Nov 13, 2024
1 parent 6928469 commit dcedae7
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import httpx
import logging
from typing import List

import httpx
from dotenv import load_dotenv
from webviz_pkg.core_utils.perf_timer import PerfTimer

from primary import config
from primary.services.service_exceptions import ServiceRequestError, Service

load_dotenv()
LOGGER = logging.getLogger(__name__)


async def smda_get_request(access_token: str, endpoint: str, params: dict) -> List[dict]:
Expand All @@ -24,24 +25,37 @@ async def smda_get_request(access_token: str, endpoint: str, params: dict) -> Li
"Ocp-Apim-Subscription-Key": config.SMDA_SUBSCRIPTION_KEY,
}
timer = PerfTimer()
single_lap_timer = PerfTimer()

async with httpx.AsyncClient() as client:
response = await client.get(urlstring, params=params, headers=headers, timeout=60)
results = []
if response.status_code == 200:
results = response.json()["data"]["results"]
next_request = response.json()["data"]["next"]
while next_request is not None:
params["_next"] = next_request
response = await client.get(urlstring, params=params, headers=headers, timeout=60)
results: List[dict] = []
page: int = 1
while True:
response = await client.get(urlstring, params=params, headers=headers, timeout=60)
LOGGER.info(f"TIME SMDA fetch '{endpoint}', page {page}, took {single_lap_timer.lap_s():.2f} seconds")
page += 1
if response.status_code == 200:
result = response.json()["data"]["results"]
if result:
results.extend(response.json()["data"]["results"])
if not result:
raise ServiceRequestError(f"No data found for endpoint: '{endpoint}'", Service.SMDA)

results.extend(result)

next_request = response.json()["data"]["next"]
elif response.status_code == 404:
print(f"{str(response.status_code) } {endpoint} either does not exists or can not be found")
else:
print(f"[WARNING:] Can not fetch data from endpont {endpoint} ({ str(response.status_code)})")
print(f"TIME SMDA fetch {endpoint} took {timer.lap_s():.2f} seconds")
if next_request is None:
break
params["_next"] = next_request
elif response.status_code == 404:
LOGGER.error(f"{str(response.status_code) } {endpoint} either does not exists or can not be found")
raise ServiceRequestError(
f"[{str(response.status_code)}] '{endpoint}' either does not exists or can not be found",
Service.SMDA,
)
else:
raise ServiceRequestError(
f"[{str(response.status_code)}] Cannot fetch data from endpoint: '{endpoint}'", Service.SMDA
)

LOGGER.info(f"TIME SMDA fetch '{endpoint}' took {timer.lap_s():.2f} seconds")

return results
8 changes: 4 additions & 4 deletions frontend/src/modules/2DViewer/settings/settings.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from "react";

import { ModuleSettingsProps } from "@framework/Module";
import { useEnsembleSet } from "@framework/WorkbenchSession";
import { FieldDropdown } from "@framework/components/FieldDropdown";
import { CollapsibleGroup } from "@lib/components/CollapsibleGroup";
import { useQueryClient } from "@tanstack/react-query";
Expand All @@ -15,15 +16,14 @@ import { LayerManager, LayerManagerTopic } from "../layers/LayerManager";
import { GroupDelegateTopic } from "../layers/delegates/GroupDelegate";

export function Settings(props: ModuleSettingsProps<any>): React.ReactNode {
const [layerManager, setLayerManager] = useAtom(layerManagerAtom);

const ensembleSet = useEnsembleSet(props.workbenchSession);
const queryClient = useQueryClient();

const [layerManager, setLayerManager] = useAtom(layerManagerAtom);

const fieldIdentifier = useAtomValue(selectedFieldIdentifierAtom);
const setFieldIdentifier = useSetAtom(userSelectedFieldIdentifierAtom);

const ensembleSet = props.workbenchSession.getEnsembleSet();

React.useEffect(
function onMountEffect() {
const newLayerManager = new LayerManager(props.workbenchSession, props.workbenchSettings, queryClient);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { ViewsType } from "@webviz/subsurface-viewer/dist/SubsurfaceViewer";

import { ReadoutWrapper } from "./ReadoutWrapper";

import { PlaceholderLayer } from "../customDeckGlLayers/PlaceholderLayer";
import { DeckGlLayerWithPosition, recursivelyMakeViewsAndLayers } from "../utils/makeViewsAndLayers";

export type LayersWrapperProps = {
Expand Down Expand Up @@ -72,7 +73,7 @@ export function LayersWrapper(props: LayersWrapperProps): React.ReactNode {
id: view.id,
name: view.name,
isSync: true,
layerIds: [...globalLayerIds, ...view.layers.map((layer) => layer.layer.id)],
layerIds: [...globalLayerIds, ...view.layers.map((layer) => layer.layer.id), "placeholder"],
});
viewerLayers.push(...view.layers);

Expand Down Expand Up @@ -135,6 +136,7 @@ export function LayersWrapper(props: LayersWrapperProps): React.ReactNode {
}

const layers = viewerLayers.toSorted((a, b) => b.position - a.position).map((layer) => layer.layer);
layers.push(new PlaceholderLayer({ id: "placeholder" }));

return (
<div ref={mainDivRef} className="relative w-full h-full flex flex-col">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Layer } from "@deck.gl/core";

type PlaceholderLayerProps = {
id: string;
};

export class PlaceholderLayer extends Layer<PlaceholderLayerProps> {
static layerName: string = "PlaceholderLayer";

constructor(props: PlaceholderLayerProps) {
super(props);
}

initializeState(): void {
return;
}

render() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,6 @@ export class WellborePicksLayer extends CompositeLayer<WellBorePicksLayerProps>
this._textData = textData;
}

shouldUpdateState(
params: UpdateParameters<Layer<WellBorePicksLayerProps & Required<CompositeLayerProps>>>
): boolean {
// console.debug(params.context.viewport.zoom);
return false;
}

renderLayers() {
const fontSize = 16;
const sizeMinPixels = 16;
Expand Down

0 comments on commit dcedae7

Please sign in to comment.