Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenthoms committed Sep 13, 2024
1 parent 55dba4f commit cf82c95
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import { SettingsContext } from "../../../interfaces";
import { Ensemble } from "../../settings/Ensemble";
import { Realization } from "../../settings/Realization";
import { SurfaceAttribute } from "../../settings/SurfaceAttribute";
import { SurfaceLayer } from "../../settings/SurfaceLayer";
import { SurfaceName } from "../../settings/SurfaceName";
import { extractSurfaceNamesAndLayers } from "../../utils/surfaceNamesAndLayers";

export class RealizationFaultPolygonsContext implements SettingsContext<RealizationFaultPolygonsSettings> {
private _contextDelegate: SettingsContextDelegate<RealizationFaultPolygonsSettings>;
Expand All @@ -27,6 +29,7 @@ export class RealizationFaultPolygonsContext implements SettingsContext<Realizat
[SettingType.REALIZATION]: new Realization(),
[SettingType.FAULT_POLYGONS_ATTRIBUTE]: new SurfaceAttribute(),
[SettingType.SURFACE_NAME]: new SurfaceName(),
[SettingType.SURFACE_LAYER]: new SurfaceLayer(),
});
}

Expand All @@ -42,6 +45,7 @@ export class RealizationFaultPolygonsContext implements SettingsContext<Realizat
const settings = this.getDelegate().getSettings();
settings[SettingType.FAULT_POLYGONS_ATTRIBUTE].getDelegate().setLoadingState(false);
settings[SettingType.SURFACE_NAME].getDelegate().setLoadingState(false);
settings[SettingType.SURFACE_LAYER].getDelegate().setLoadingState(false);

if (!this._fetchDataCache) {
return;
Expand Down Expand Up @@ -81,15 +85,33 @@ export class RealizationFaultPolygonsContext implements SettingsContext<Realizat
)
);
}
this._contextDelegate.setAvailableValues(SettingType.SURFACE_NAME, availableSurfaceNames);

const surfaceNamesAndLayers = extractSurfaceNamesAndLayers(availableSurfaceNames);
const surfaceNames = surfaceNamesAndLayers.map((el) => el.surfaceName);

let currentSurfaceName = settings[SettingType.SURFACE_NAME].getDelegate().getValue();
if (!currentSurfaceName || !availableSurfaceNames.includes(currentSurfaceName)) {
if (availableSurfaceNames.length > 0) {
currentSurfaceName = availableSurfaceNames[0];
if (!currentSurfaceName || !surfaceNames.includes(currentSurfaceName)) {
if (surfaceNames.length > 0) {
currentSurfaceName = surfaceNames[0];
settings[SettingType.SURFACE_NAME].getDelegate().setValue(currentSurfaceName);
}
}
this._contextDelegate.setAvailableValues(SettingType.SURFACE_NAME, surfaceNames);

const surfaceLayers =
surfaceNamesAndLayers.find((el) => el.surfaceName === currentSurfaceName)?.surfaceLayers ?? [];
let currentSurfaceLayer = settings[SettingType.SURFACE_LAYER].getDelegate().getValue();
if (!currentSurfaceLayer || !surfaceLayers.includes(currentSurfaceLayer)) {
if (surfaceLayers.length > 0) {
currentSurfaceLayer = surfaceLayers[0];
settings[SettingType.SURFACE_LAYER].getDelegate().setValue(currentSurfaceLayer);
}
}
if (surfaceLayers.length === 0) {
surfaceLayers.push("DEFAULT");
settings[SettingType.SURFACE_LAYER].getDelegate().setValue("DEFAULT");
}
this._contextDelegate.setAvailableValues(SettingType.SURFACE_LAYER, surfaceLayers);
}

fetchData(oldValues: RealizationFaultPolygonsSettings, newValues: RealizationFaultPolygonsSettings): void {
Expand Down Expand Up @@ -136,6 +158,7 @@ export class RealizationFaultPolygonsContext implements SettingsContext<Realizat

settings[SettingType.FAULT_POLYGONS_ATTRIBUTE].getDelegate().setLoadingState(true);
settings[SettingType.SURFACE_NAME].getDelegate().setLoadingState(true);
settings[SettingType.SURFACE_LAYER].getDelegate().setLoadingState(true);

queryClient
.fetchQuery({
Expand Down Expand Up @@ -163,7 +186,8 @@ export class RealizationFaultPolygonsContext implements SettingsContext<Realizat
settings[SettingType.FAULT_POLYGONS_ATTRIBUTE].getDelegate().getValue() !== null &&
settings[SettingType.SURFACE_NAME].getDelegate().getValue() !== null &&
settings[SettingType.REALIZATION].getDelegate().getValue() !== null &&
settings[SettingType.ENSEMBLE].getDelegate().getValue() !== null
settings[SettingType.ENSEMBLE].getDelegate().getValue() !== null &&
settings[SettingType.SURFACE_LAYER].getDelegate().getValue() !== null
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { RealizationFaultPolygonsContext } from "./RealizationFaultPolygonsConte
import { RealizationFaultPolygonsSettings } from "./types";

import { Layer } from "../../../interfaces";
import { combineSurfaceNameAndLayer } from "../../utils/surfaceNamesAndLayers";

export class RealizationFaultPolygonsLayer implements Layer<RealizationFaultPolygonsSettings, PolygonData_api[]> {
private _layerDelegate: LayerDelegate<RealizationFaultPolygonsSettings, PolygonData_api[]>;
Expand Down Expand Up @@ -46,14 +47,16 @@ export class RealizationFaultPolygonsLayer implements Layer<RealizationFaultPoly
const ensembleIdent = settings[SettingType.ENSEMBLE].getDelegate().getValue();
const realizationNum = settings[SettingType.REALIZATION].getDelegate().getValue();
const surfaceName = settings[SettingType.SURFACE_NAME].getDelegate().getValue();
const surfaceLayer = settings[SettingType.SURFACE_LAYER].getDelegate().getValue();
const combinedSurfaceName = combineSurfaceNameAndLayer(surfaceName, surfaceLayer);
const attribute = settings[SettingType.FAULT_POLYGONS_ATTRIBUTE].getDelegate().getValue();

const queryKey = [
"getPolygonsData",
ensembleIdent?.getCaseUuid() ?? "",
ensembleIdent?.getEnsembleName() ?? "",
realizationNum ?? 0,
surfaceName ?? "",
combinedSurfaceName ?? "",
attribute ?? "",
];
this._layerDelegate.registerQueryKey(queryKey);
Expand All @@ -65,7 +68,7 @@ export class RealizationFaultPolygonsLayer implements Layer<RealizationFaultPoly
ensembleIdent?.getCaseUuid() ?? "",
ensembleIdent?.getEnsembleName() ?? "",
realizationNum ?? 0,
surfaceName ?? "",
combinedSurfaceName ?? "",
attribute ?? ""
),
staleTime: STALE_TIME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export type RealizationFaultPolygonsSettings = {
[SettingType.REALIZATION]: number | null;
[SettingType.FAULT_POLYGONS_ATTRIBUTE]: string | null;
[SettingType.SURFACE_NAME]: string | null;
[SettingType.SURFACE_LAYER]: string | null;
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ import { SettingsContext } from "../../../interfaces";
import { Ensemble } from "../../settings/Ensemble";
import { Realization } from "../../settings/Realization";
import { SurfaceAttribute } from "../../settings/SurfaceAttribute";
import { SurfaceLayer } from "../../settings/SurfaceLayer";
import { SurfaceName } from "../../settings/SurfaceName";
import { TimeOrInterval } from "../../settings/TimeOrInterval";
import { combineSurfaceNameAndLayer, extractSurfaceNamesAndLayers } from "../../utils/surfaceNamesAndLayers";

export class RealizationSurfaceContext implements SettingsContext<RealizationSurfaceSettings> {
private _contextDelegate: SettingsContextDelegate<RealizationSurfaceSettings>;
Expand All @@ -29,6 +31,7 @@ export class RealizationSurfaceContext implements SettingsContext<RealizationSur
[SettingType.REALIZATION]: new Realization(),
[SettingType.SURFACE_ATTRIBUTE]: new SurfaceAttribute(),
[SettingType.SURFACE_NAME]: new SurfaceName(),
[SettingType.SURFACE_LAYER]: new SurfaceLayer(),
[SettingType.TIME_OR_INTERVAL]: new TimeOrInterval(),
});
}
Expand All @@ -46,6 +49,7 @@ export class RealizationSurfaceContext implements SettingsContext<RealizationSur
settings[SettingType.SURFACE_ATTRIBUTE].getDelegate().setLoadingState(false);
settings[SettingType.SURFACE_NAME].getDelegate().setLoadingState(false);
settings[SettingType.TIME_OR_INTERVAL].getDelegate().setLoadingState(false);
settings[SettingType.SURFACE_LAYER].getDelegate().setLoadingState(false);

if (!this._fetchDataCache) {
return;
Expand Down Expand Up @@ -78,26 +82,45 @@ export class RealizationSurfaceContext implements SettingsContext<RealizationSur
)
);
}
this._contextDelegate.setAvailableValues(SettingType.SURFACE_NAME, availableSurfaceNames);

const surfaceNamesAndLayers = extractSurfaceNamesAndLayers(availableSurfaceNames);
const surfaceNames = surfaceNamesAndLayers.map((el) => el.surfaceName);

let currentSurfaceName = settings[SettingType.SURFACE_NAME].getDelegate().getValue();
if (!currentSurfaceName || !availableSurfaceNames.includes(currentSurfaceName)) {
if (availableSurfaceNames.length > 0) {
currentSurfaceName = availableSurfaceNames[0];
if (!currentSurfaceName || !surfaceNames.includes(currentSurfaceName)) {
if (surfaceNames.length > 0) {
currentSurfaceName = surfaceNames[0];
settings[SettingType.SURFACE_NAME].getDelegate().setValue(currentSurfaceName);
}
}
this._contextDelegate.setAvailableValues(SettingType.SURFACE_NAME, surfaceNames);

const surfaceLayers =
surfaceNamesAndLayers.find((el) => el.surfaceName === currentSurfaceName)?.surfaceLayers ?? [];
let currentSurfaceLayer = settings[SettingType.SURFACE_LAYER].getDelegate().getValue();
if (!currentSurfaceLayer || !surfaceLayers.includes(currentSurfaceLayer)) {
if (surfaceLayers.length > 0) {
currentSurfaceLayer = surfaceLayers[0];
settings[SettingType.SURFACE_LAYER].getDelegate().setValue(currentSurfaceLayer);
}
}
if (surfaceLayers.length === 0) {
surfaceLayers.push("DEFAULT");
settings[SettingType.SURFACE_LAYER].getDelegate().setValue("DEFAULT");
}
this._contextDelegate.setAvailableValues(SettingType.SURFACE_LAYER, surfaceLayers);

const availableTimeOrIntervals: string[] = [];
if (currentAttribute && currentSurfaceName) {
const combinedSurfaceName = combineSurfaceNameAndLayer(currentSurfaceName, currentSurfaceLayer);
const availableTimeTypes: SurfaceTimeType_api[] = [];
availableTimeTypes.push(
...Array.from(
new Set(
this._fetchDataCache.surfaces
.filter(
(surface) =>
surface.attribute_name === currentAttribute && surface.name === currentSurfaceName
surface.attribute_name === currentAttribute && surface.name === combinedSurfaceName
)
.map((el) => el.time_type)
)
Expand Down Expand Up @@ -168,7 +191,9 @@ export class RealizationSurfaceContext implements SettingsContext<RealizationSur

settings[SettingType.SURFACE_ATTRIBUTE].getDelegate().setLoadingState(true);
settings[SettingType.SURFACE_NAME].getDelegate().setLoadingState(true);
settings[SettingType.SURFACE_LAYER].getDelegate().setLoadingState(true);
settings[SettingType.TIME_OR_INTERVAL].getDelegate().setLoadingState(true);

settings[SettingType.TIME_OR_INTERVAL].getDelegate().setValue(null);

queryClient
Expand Down Expand Up @@ -200,6 +225,7 @@ export class RealizationSurfaceContext implements SettingsContext<RealizationSur
return (
settings[SettingType.SURFACE_ATTRIBUTE].getDelegate().getValue() !== null &&
settings[SettingType.SURFACE_NAME].getDelegate().getValue() !== null &&
settings[SettingType.SURFACE_LAYER].getDelegate().getValue() !== null &&
settings[SettingType.REALIZATION].getDelegate().getValue() !== null &&
settings[SettingType.ENSEMBLE].getDelegate().getValue() !== null &&
settings[SettingType.TIME_OR_INTERVAL].getDelegate().getValue() !== null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { RealizationSurfaceContext } from "./RealizationSurfaceContext";
import { RealizationSurfaceSettings } from "./types";

import { Layer } from "../../../interfaces";
import { combineSurfaceNameAndLayer } from "../../utils/surfaceNamesAndLayers";

export class RealizationSurfaceLayer
implements Layer<RealizationSurfaceSettings, SurfaceDataFloat_trans | SurfaceDataPng_api>
Expand Down Expand Up @@ -54,12 +55,14 @@ export class RealizationSurfaceLayer
const ensembleIdent = settings[SettingType.ENSEMBLE].getDelegate().getValue();
const realizationNum = settings[SettingType.REALIZATION].getDelegate().getValue();
const surfaceName = settings[SettingType.SURFACE_NAME].getDelegate().getValue();
const surfaceLayer = settings[SettingType.SURFACE_LAYER].getDelegate().getValue();
const combinedSurfaceName = combineSurfaceNameAndLayer(surfaceName, surfaceLayer);
const attribute = settings[SettingType.SURFACE_ATTRIBUTE].getDelegate().getValue();
const timeOrInterval = settings[SettingType.TIME_OR_INTERVAL].getDelegate().getValue();

if (ensembleIdent && surfaceName && attribute && realizationNum !== null) {
if (ensembleIdent && combinedSurfaceName && attribute && realizationNum !== null) {
addrBuilder.withEnsembleIdent(ensembleIdent);
addrBuilder.withName(surfaceName);
addrBuilder.withName(combinedSurfaceName);
addrBuilder.withAttribute(attribute);
addrBuilder.withRealization(realizationNum);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ export type RealizationSurfaceSettings = {
[SettingType.REALIZATION]: number | null;
[SettingType.SURFACE_ATTRIBUTE]: string | null;
[SettingType.SURFACE_NAME]: string | null;
[SettingType.SURFACE_LAYER]: string | null;
[SettingType.TIME_OR_INTERVAL]: string | null;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React from "react";

import { Dropdown, DropdownOption } from "@lib/components/Dropdown";

import { SettingDelegate } from "../../delegates/SettingDelegate";
import { Setting, SettingComponentProps } from "../../interfaces";
import { SettingType } from "../../settingsTypes";

type ValueType = string | null;

export class SurfaceLayer implements Setting<ValueType> {
private _delegate: SettingDelegate<ValueType> = new SettingDelegate<ValueType>(null);

getType(): SettingType {
return SettingType.SURFACE_LAYER;
}

getLabel(): string {
return "Surface layer";
}

getDelegate(): SettingDelegate<ValueType> {
return this._delegate;
}

makeComponent(): (props: SettingComponentProps<ValueType>) => React.ReactNode {
return function SurfaceLayer(props: SettingComponentProps<ValueType>) {
const options: DropdownOption[] = props.availableValues.map((value) => {
return {
value: value.toString(),
label: value === null ? "None" : value.toString(),
};
});

return (
<Dropdown
options={options}
value={!props.isOverridden ? props.value?.toString() : props.overriddenValue?.toString()}
onChange={props.onValueChange}
disabled={props.isOverridden}
showArrows
/>
);
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
export function extractSurfaceNamesAndLayers(surfaceNamesAndLayers: string[]): {
surfaceName: string;
surfaceLayers: string[];
}[] {
const surfaceNamesAndLayersMap: Map<string, Set<string>> = new Map();

const regex = /^([\w .]+?)( (top|bottom))?$/i;

for (const surfaceNameOrLayer of surfaceNamesAndLayers) {
const match = regex.exec(surfaceNameOrLayer);
if (match) {
const [, surfaceName, , surfaceLayer] = match;
const surfaceLayers = surfaceNamesAndLayersMap.get(surfaceName) || new Set();
if (surfaceLayer) {
surfaceLayers.add(surfaceLayer);
}
surfaceNamesAndLayersMap.set(surfaceName, surfaceLayers);
}
}

return Array.from(surfaceNamesAndLayersMap.entries()).map(([surfaceName, surfaceLayers]) => ({
surfaceName,
surfaceLayers: Array.from(surfaceLayers),
}));
}

export function combineSurfaceNameAndLayer(surfaceName: string | null, surfaceLayer: string | null): string | null {
if (!surfaceName || !surfaceLayer) {
return null;
}
return surfaceLayer !== "DEFAULT" ? `${surfaceName} ${surfaceLayer}` : surfaceName;
}
1 change: 1 addition & 0 deletions frontend/src/modules/LayerSpike/layers/settingsTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export enum SettingType {
SENSITIVITY = "sensitivity",
SURFACE_NAME = "surfaceName",
SURFACE_ATTRIBUTE = "surfaceAttribute",
SURFACE_LAYER = "surfaceLayer",
TIME_OR_INTERVAL = "timeOrInterval",
FAULT_POLYGONS_ATTRIBUTE = "faultPolygonsAttribute",
SMDA_WELLBORE_HEADERS = "smdaWellboreHeaders",
Expand Down

0 comments on commit cf82c95

Please sign in to comment.