Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into remove-state-store
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenthoms committed Aug 8, 2024
2 parents 946999d + 1604fa3 commit b4c63b9
Show file tree
Hide file tree
Showing 11 changed files with 438 additions and 93 deletions.
8 changes: 4 additions & 4 deletions backend_py/primary/poetry.lock

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

3 changes: 2 additions & 1 deletion backend_py/primary/primary/routers/group_tree/schemas.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import List
from enum import Enum
from primary.services.sumo_access.group_tree_types import GroupTreeMetadata, DatedTree
from primary.services.sumo_access.group_tree_types import DatedTree, GroupTreeMetadata

from pydantic import BaseModel


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from primary.services.sumo_access.group_tree_access import GroupTreeAccess
from primary.services.sumo_access.group_tree_types import (
DataType,
DataTypeToStringLabelMap,
DatedTree,
EdgeOrNode,
GroupTreeMetadata,
Expand Down Expand Up @@ -654,17 +655,7 @@ def _create_leaf_node_classification_map(

def _get_label(datatype: DataType) -> str:
"""Returns a more readable label for the summary datatypes"""
labels = {
DataType.OILRATE: "Oil Rate",
DataType.GASRATE: "Gas Rate",
DataType.WATERRATE: "Water Rate",
DataType.WATERINJRATE: "Water Inj Rate",
DataType.GASINJRATE: "Gas Inj Rate",
DataType.PRESSURE: "Pressure",
DataType.BHP: "BHP",
DataType.WMCTL: "WMCTL",
}
label = labels.get(datatype)
label = DataTypeToStringLabelMap.get(datatype)
if label is None:
raise ValueError(f"Label for datatype {datatype.value} not implemented.")
return label
Expand Down
24 changes: 11 additions & 13 deletions backend_py/primary/primary/services/sumo_access/queries/grid3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,31 +78,30 @@ async def get_grid_geometry_and_property_blob_ids_async(
{
"bool": {
"must": [
{"match": {"_sumo.parent_object.keyword": case_id}},
{"match": {"class": "cpgrid"}},
{"match": {"fmu.iteration.name": iteration}},
{"match": {"fmu.realization.id": realization}},
{"match": {"data.name.keyword": grid_name}},
{"term": {"_sumo.parent_object.keyword": case_id}},
{"term": {"class.keyword": "cpgrid"}},
{"term": {"fmu.iteration.name.keyword": iteration}},
{"term": {"fmu.realization.id": realization}},
{"term": {"data.name.keyword": grid_name}},
]
}
},
{
"bool": {
"must": [
{"match": {"_sumo.parent_object.keyword": case_id}},
{"match": {"class": "cpgrid_property"}},
{"match": {"fmu.iteration.name": iteration}},
{"match": {"fmu.realization.id": realization}},
{"match": {"data.name.keyword": parameter_name}},
{"match": {"data.tagname.keyword": grid_name}},
{"term": {"_sumo.parent_object.keyword": case_id}},
{"term": {"class.keyword": "cpgrid_property"}},
{"term": {"fmu.iteration.name.keyword": iteration}},
{"term": {"fmu.realization.id": realization}},
{"term": {"data.name.keyword": parameter_name}},
{"term": {"data.tagname.keyword": grid_name}},
]
}
},
],
"minimum_should_match": 1,
}
}

time_filter = get_time_filter(parameter_time_or_interval_str)

if time_filter.time_type != TimeType.NONE:
Expand All @@ -118,7 +117,6 @@ async def get_grid_geometry_and_property_blob_ids_async(

result = response.json()
hits = result["hits"]["hits"]

if len(hits) != 2:
raise InvalidDataError(f"Expected 2 hits, got {len(hits)}", service=Service.SUMO)

Expand Down
2 changes: 1 addition & 1 deletion backend_py/primary/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ numpy = "^1.24.1"
orjson = "^3.8.10"
pandas = {version = "2.0.1", extras = ["performance"]}
httpx = "^0.24.0"
fmu-sumo = "1.2.2"
fmu-sumo = "1.2.4"
sumo-wrapper-python = "1.0.9"
azure-monitor-opentelemetry = "^1.1.0"
requests-toolbelt = "^1.0.0"
Expand Down
23 changes: 6 additions & 17 deletions frontend/src/framework/GlobalAtoms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { atomWithCompare } from "./utils/atomUtils";
export const EnsembleSetAtom = atomWithCompare<EnsembleSet>(new EnsembleSet([]), isEqual);

export const EnsembleRealizationFilterFunctionAtom = atom<EnsembleRealizationFilterFunction | null>((get) => {
const realizationFilterSet = get(RealizationFilterSetAtom);
const realizationFilterSet = get(RealizationFilterSetAtom)?.filterSet;

if (!realizationFilterSet) {
return null;
Expand All @@ -21,19 +21,8 @@ export const EnsembleRealizationFilterFunctionAtom = atom<EnsembleRealizationFil
realizationFilterSet.getRealizationFilterForEnsembleIdent(ensembleIdent).getFilteredRealizations();
});

function areRealizationFilterSetsEqual(a: RealizationFilterSet | null, b: RealizationFilterSet | null): boolean {
if (a === null && b === null) {
return true;
}

if (a === null || b === null) {
return false;
}

return a.isEqual(b);
}

export const RealizationFilterSetAtom = atomWithCompare<RealizationFilterSet | null>(
null,
areRealizationFilterSetsEqual
);
// RealizationFilterSetAtom needs to be packed into an object such that we can shallow-compare it with its previous value
// as the class instance of RealizationFilterSet will never change in the lifetime of the application.
export const RealizationFilterSetAtom = atom<{
filterSet: RealizationFilterSet;
} | null>(null);
3 changes: 3 additions & 0 deletions frontend/src/framework/internal/WorkbenchSessionPrivate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export class WorkbenchSessionPrivate extends WorkbenchSession {
}

notifyAboutEnsembleRealizationFilterChange(): void {
this._atomStoreMaster.setAtomValue(RealizationFilterSetAtom, {
filterSet: this._realizationFilterSet,
});
this.notifySubscribers(WorkbenchSessionEvent.RealizationFilterSetChanged);
}
}
46 changes: 28 additions & 18 deletions frontend/src/modules/FlowNetwork/settings/atoms/derivedAtoms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,23 @@ export const selectedDateTimeAtom = atom<string | null>((get) => {
return userSelectedDateTime;
});

export const availableEdgeKeysAtom = atom<string[]>((get) => {
export const edgeMetadataListAtom = atom<EdgeMetadata[]>((get) => {
const groupTreeQueryResult = get(groupTreeQueryResultAtom);
return groupTreeQueryResult.data?.edge_metadata_list.map((item) => item.key) ?? [];

const data = groupTreeQueryResult.data;
if (!data) {
return [];
}

return data.edge_metadata_list.map((elm) => ({ key: elm.key, label: elm.label }));
});

export const selectedEdgeKeyAtom = atom<string | null>((get) => {
const availableEdgeKeys = get(availableEdgeKeysAtom);
const availableEdgesMetadataList = get(edgeMetadataListAtom);
const availableEdgeKeys = availableEdgesMetadataList.map((item) => item.key);
const userSelectedEdgeKey = get(userSelectedEdgeKeyAtom);

if (availableEdgeKeys.length === 0) {
if (availableEdgesMetadataList.length === 0) {
return null;
}
if (!userSelectedEdgeKey || !availableEdgeKeys.includes(userSelectedEdgeKey)) {
Expand All @@ -108,16 +115,23 @@ export const selectedEdgeKeyAtom = atom<string | null>((get) => {
return userSelectedEdgeKey;
});

export const availableNodeKeysAtom = atom<string[]>((get) => {
export const nodeMetadataListAtom = atom<NodeMetadata[]>((get) => {
const groupTreeQueryResult = get(groupTreeQueryResultAtom);
return groupTreeQueryResult.data?.node_metadata_list.map((item) => item.key) ?? [];

const data = groupTreeQueryResult.data;
if (!data) {
return [];
}

return data.node_metadata_list.map((elm) => ({ key: elm.key, label: elm.label }));
});

export const selectedNodeKeyAtom = atom<string | null>((get) => {
const availableNodeKeys = get(availableNodeKeysAtom);
const availableNodesMetadataList = get(nodeMetadataListAtom);
const availableNodeKeys = availableNodesMetadataList.map((item) => item.key);
const userSelectedNodeKey = get(userSelectedNodeKeyAtom);

if (availableNodeKeys.length === 0) {
if (availableNodesMetadataList.length === 0) {
return null;
}
if (!userSelectedNodeKey || !availableNodeKeys.includes(userSelectedNodeKey)) {
Expand All @@ -127,17 +141,13 @@ export const selectedNodeKeyAtom = atom<string | null>((get) => {
return userSelectedNodeKey;
});

export const edgeMetadataListAtom = atom<EdgeMetadata[]>((get) => {
export const datedTreesAtom = atom<DatedTree[]>((get) => {
const groupTreeQueryResult = get(groupTreeQueryResultAtom);
return groupTreeQueryResult.data?.edge_metadata_list ?? [];
});

export const nodeMetadataListAtom = atom<NodeMetadata[]>((get) => {
const groupTreeQueryResult = get(groupTreeQueryResultAtom);
return groupTreeQueryResult.data?.node_metadata_list ?? [];
});
const data = groupTreeQueryResult.data;
if (!data) {
return [];
}

export const datedTreesAtom = atom<DatedTree[]>((get) => {
const groupTreeQueryResult = get(groupTreeQueryResultAtom);
return groupTreeQueryResult.data?.dated_trees ?? [];
return data.dated_trees;
});
16 changes: 8 additions & 8 deletions frontend/src/modules/FlowNetwork/settings/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ import {
} from "./atoms/baseAtoms";
import {
availableDateTimesAtom,
availableEdgeKeysAtom,
availableNodeKeysAtom,
edgeMetadataListAtom,
groupTreeQueryResultAtom,
nodeMetadataListAtom,
selectedDateTimeAtom,
selectedEdgeKeyAtom,
selectedEnsembleIdentAtom,
Expand All @@ -47,8 +47,8 @@ export function Settings({ workbenchSession, settingsContext }: ModuleSettingsPr
const statusWriter = useSettingsStatusWriter(settingsContext);

const availableDateTimes = useAtomValue(availableDateTimesAtom);
const availableEdgeKeys = useAtomValue(availableEdgeKeysAtom);
const availableNodeKeys = useAtomValue(availableNodeKeysAtom);
const edgeMetadataList = useAtomValue(edgeMetadataListAtom);
const nodeMetadataList = useAtomValue(nodeMetadataListAtom);

const [selectedResamplingFrequency, setSelectedResamplingFrequency] = useAtom(selectedResamplingFrequencyAtom);
const [selectedNodeTypes, setSelectedNodeTypes] = useAtom(selectedNodeTypesAtom);
Expand Down Expand Up @@ -191,17 +191,17 @@ export function Settings({ workbenchSession, settingsContext }: ModuleSettingsPr
<div className="flex flex-col gap-2">
<Label text="Edge options">
<Dropdown
options={availableEdgeKeys.map((item) => {
return { label: item, value: item };
options={edgeMetadataList.map((item) => {
return { label: item.label, value: item.key };
})}
value={selectedEdgeKey ?? ""}
onChange={handleSelectedEdgeKeyChange}
/>
</Label>
<Label text="Node options">
<Dropdown
options={availableNodeKeys.map((item) => {
return { label: item, value: item };
options={nodeMetadataList.map((item) => {
return { label: item.label, value: item.key };
})}
value={selectedNodeKey ?? ""}
onChange={handleSelectedNodeKeyChange}
Expand Down
21 changes: 1 addition & 20 deletions frontend/src/modules/Intersection/settings/atoms/derivedAtoms.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EnsembleIdent } from "@framework/EnsembleIdent";
import { EnsembleSet } from "@framework/EnsembleSet";
import { EnsembleRealizationFilterFunctionAtom, EnsembleSetAtom } from "@framework/GlobalAtoms";
import { EnsembleSetAtom } from "@framework/GlobalAtoms";
import { IntersectionPolylinesAtom } from "@framework/userCreatedItems/IntersectionPolylines";
import { LayerManager } from "@modules/Intersection/utils/layers/LayerManager";

Expand Down Expand Up @@ -37,25 +37,6 @@ export const selectedFieldIdentifierAtom = atom((get) => {
return selectedFieldIdentifier;
});

export const availableRealizationsAtom = atom((get) => {
const ensembleSet = get(EnsembleSetAtom);
const selectedEnsembleIdent = get(selectedEnsembleIdentAtom);

if (selectedEnsembleIdent === null) {
return [];
}

let ensembleRealizationFilterFunction = get(EnsembleRealizationFilterFunctionAtom);

if (ensembleRealizationFilterFunction === null) {
ensembleRealizationFilterFunction = (ensembleIdent: EnsembleIdent) => {
return ensembleSet.findEnsemble(ensembleIdent)?.getRealizations() ?? [];
};
}

return ensembleRealizationFilterFunction(selectedEnsembleIdent);
});

export const availableUserCreatedIntersectionPolylinesAtom = atom((get) => {
const intersectionPolylines = get(IntersectionPolylinesAtom);
return intersectionPolylines;
Expand Down
Loading

0 comments on commit b4c63b9

Please sign in to comment.