Skip to content

Commit

Permalink
Add realization filter functionality to SimulationTimeSeries module (e…
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgenherje authored Aug 1, 2024
1 parent 23d3cb7 commit 0a37bf7
Showing 1 changed file with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
VectorStatisticData_api,
} from "@api";
import { apiService } from "@framework/ApiService";
import { EnsembleIdent } from "@framework/EnsembleIdent";
import { EnsembleRealizationFilterFunctionAtom, EnsembleSetAtom } from "@framework/GlobalAtoms";
import { ModuleAtoms } from "@framework/Module";
import { UniDirectionalModuleComponentsInterface } from "@framework/UniDirectionalModuleComponentsInterface";
import { atomWithQueries } from "@framework/utils/atomUtils";
Expand Down Expand Up @@ -59,30 +61,47 @@ export function viewAtomsInitialization(
): ModuleAtoms<ViewAtoms> {
const userSelectedActiveTimestampUtcMsAtom = atom<number | null>(null);

const validEnsembleRealizationsFunctionAtom = atom((get) => {
const ensembleSet = get(EnsembleSetAtom);
let validEnsembleRealizationsFunction = get(EnsembleRealizationFilterFunctionAtom);

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

return validEnsembleRealizationsFunction;
});

const vectorDataQueriesAtom = atomWithQueries((get) => {
const vectorSpecifications = get(settingsToViewInterface.getAtom("vectorSpecifications"));
const resampleFrequency = get(settingsToViewInterface.getAtom("resampleFrequency"));
const visualizationMode = get(settingsToViewInterface.getAtom("visualizationMode"));
const validEnsembleRealizationsFunction = get(validEnsembleRealizationsFunctionAtom);

const enabled =
visualizationMode === VisualizationMode.INDIVIDUAL_REALIZATIONS ||
visualizationMode === VisualizationMode.STATISTICS_AND_REALIZATIONS;

const queries = vectorSpecifications.map((item) => {
const realizations = [...validEnsembleRealizationsFunction(item.ensembleIdent)];
return () => ({
queryKey: [
"getRealizationsVectorData",
item.ensembleIdent.getCaseUuid(),
item.ensembleIdent.getEnsembleName(),
item.vectorName,
resampleFrequency,
realizations,
],
queryFn: () =>
apiService.timeseries.getRealizationsVectorData(
item.ensembleIdent.getCaseUuid() ?? "",
item.ensembleIdent.getEnsembleName() ?? "",
item.vectorName ?? "",
resampleFrequency
resampleFrequency,
realizations
),
staleTime: STALE_TIME,
gcTime: CACHE_TIME,
Expand All @@ -104,20 +123,23 @@ export function viewAtomsInitialization(
const vectorSpecifications = get(settingsToViewInterface.getAtom("vectorSpecifications"));
const resampleFrequency = get(settingsToViewInterface.getAtom("resampleFrequency"));
const visualizationMode = get(settingsToViewInterface.getAtom("visualizationMode"));
const validEnsembleRealizationsFunction = get(validEnsembleRealizationsFunctionAtom);

const enabled =
visualizationMode === VisualizationMode.STATISTICAL_FANCHART ||
visualizationMode === VisualizationMode.STATISTICAL_LINES ||
visualizationMode === VisualizationMode.STATISTICS_AND_REALIZATIONS;

const queries = vectorSpecifications.map((item) => {
const realizations = [...validEnsembleRealizationsFunction(item.ensembleIdent)];
return () => ({
queryKey: [
"getStatisticalVectorData",
item.ensembleIdent.getCaseUuid(),
item.ensembleIdent.getEnsembleName(),
item.vectorName,
resampleFrequency,
realizations,
],
queryFn: () =>
apiService.timeseries.getStatisticalVectorData(
Expand All @@ -126,7 +148,7 @@ export function viewAtomsInitialization(
item.vectorName ?? "",
resampleFrequency ?? Frequency_api.MONTHLY,
undefined,
undefined
realizations
),
staleTime: STALE_TIME,
gcTime: CACHE_TIME,
Expand Down

0 comments on commit 0a37bf7

Please sign in to comment.