-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Refactor front-end - Minor adjustments back-end for statistics end-point (should use real filter)
- Loading branch information
1 parent
e823898
commit 6b9b179
Showing
22 changed files
with
702 additions
and
358 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
frontend/src/modules/SimulationTimeSeriesSensitivity/dataGenerators.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { VectorRealizationData_api } from "@api"; | ||
import { DataGenerator } from "@framework/DataChannelTypes"; | ||
import { Ensemble } from "@framework/Ensemble"; | ||
|
||
import { indexOf } from "lodash"; | ||
|
||
export function makeVectorDataGenerator( | ||
ensemble: Ensemble | null, | ||
vectorRealizationData: VectorRealizationData_api[] | null, | ||
activeTimestampUtcMs: number | null | ||
): DataGenerator { | ||
return () => { | ||
const data: { key: number; value: number }[] = []; | ||
|
||
if (ensemble && vectorRealizationData) { | ||
vectorRealizationData.forEach((vec) => { | ||
const indexOfTimestamp = indexOf(vec.timestamps_utc_ms, activeTimestampUtcMs); | ||
data.push({ | ||
key: vec.realization, | ||
value: indexOfTimestamp === -1 ? 0 : vec.values[indexOfTimestamp], | ||
}); | ||
}); | ||
} | ||
return { | ||
data, | ||
metaData: { | ||
ensembleIdentString: ensemble?.getIdent().toString() ?? "", | ||
unit: "unit", | ||
}, | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 11 additions & 4 deletions
15
frontend/src/modules/SimulationTimeSeriesSensitivity/settings/atoms/baseAtoms.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,19 @@ | ||
import { Frequency_api } from "@api"; | ||
import { VectorSpec } from "@modules/SimulationTimeSeriesSensitivity/typesAndEnums"; | ||
import { EnsembleIdent } from "@framework/EnsembleIdent"; | ||
import { atomWithCompare } from "@framework/utils/atomUtils"; | ||
|
||
import { atom } from "jotai"; | ||
import { isEqual } from "lodash"; | ||
|
||
export const syncedEnsembleIdentsAtom = atom<EnsembleIdent[] | null>(null); | ||
export const syncedVectorNameAtom = atom<string | null>(null); | ||
|
||
export const vectorSpecAtom = atom<VectorSpec | null>(null); | ||
export const resamplingFrequencyAtom = atom<Frequency_api | null>(Frequency_api.MONTHLY); | ||
export const selectedSensitivitiesAtom = atom<string[] | null>(null); | ||
export const showStatisticsAtom = atom<boolean>(true); | ||
export const showRealizationsAtom = atom<boolean>(false); | ||
export const realizationsToIncludeAtom = atom<number[] | null>(null); | ||
export const showHistoricalAtom = atom<boolean>(true); | ||
|
||
export const userSelectedEnsembleIdentAtom = atom<EnsembleIdent | null>(null); | ||
export const userSelectedVectorNameAtom = atom<string | null>(null); | ||
export const userSelectedVectorTagAtom = atom<string | null>(null); | ||
export const userSelectedSensitivityNamesAtom = atomWithCompare<string[] | null>(null, isEqual); |
132 changes: 132 additions & 0 deletions
132
frontend/src/modules/SimulationTimeSeriesSensitivity/settings/atoms/derivedAtoms.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import { EnsembleIdent } from "@framework/EnsembleIdent"; | ||
import { EnsembleSetAtom } from "@framework/GlobalAtoms"; | ||
import { fixupEnsembleIdent, maybeAssignFirstSyncedEnsemble } from "@framework/utils/ensembleUiHelpers"; | ||
import { VectorSpec } from "@modules/SimulationTimeSeriesSensitivity/typesAndEnums"; | ||
import { createVectorSelectorDataFromVectors } from "@modules/_shared/components/VectorSelector"; | ||
|
||
import { atom } from "jotai"; | ||
|
||
import { | ||
syncedEnsembleIdentsAtom, | ||
syncedVectorNameAtom, | ||
userSelectedEnsembleIdentAtom, | ||
userSelectedSensitivityNamesAtom, | ||
userSelectedVectorNameAtom, | ||
userSelectedVectorTagAtom, | ||
} from "./baseAtoms"; | ||
import { vectorListQueryAtom } from "./queryAtoms"; | ||
|
||
import { fixupVectorName } from "../utils/fixupVectorName"; | ||
|
||
export const selectedEnsembleIdentAtom = atom<EnsembleIdent | null>((get) => { | ||
const syncedEnsembleIdents = get(syncedEnsembleIdentsAtom); | ||
const userSelectedEnsembleIdent = get(userSelectedEnsembleIdentAtom); | ||
const ensembleSet = get(EnsembleSetAtom); | ||
|
||
const candidateEnsembleIdent = maybeAssignFirstSyncedEnsemble(userSelectedEnsembleIdent, syncedEnsembleIdents); | ||
const fixedUpEnsembleIdent = fixupEnsembleIdent(candidateEnsembleIdent, ensembleSet); | ||
return fixedUpEnsembleIdent; | ||
}); | ||
|
||
export const availableSensitivityNamesAtom = atom<string[]>((get) => { | ||
const ensembleSet = get(EnsembleSetAtom); | ||
const selectedEnsembleIdent = get(selectedEnsembleIdentAtom); | ||
|
||
const ensemble = selectedEnsembleIdent ? ensembleSet.findEnsemble(selectedEnsembleIdent) : null; | ||
const ensembleSensitivityNames = ensemble?.getSensitivities()?.getSensitivityNames() ?? []; | ||
|
||
return ensembleSensitivityNames; | ||
}); | ||
|
||
export const selectedSensitivityNamesAtom = atom<string[]>((get) => { | ||
const userSelectedSensitivityNames = get(userSelectedSensitivityNamesAtom); | ||
const availableSensitivityNames = get(availableSensitivityNamesAtom); | ||
|
||
// If userSelectedSensitivityNames is empty, do not override it | ||
if (!userSelectedSensitivityNames || userSelectedSensitivityNames.length === 0) { | ||
return []; | ||
} | ||
|
||
// Fixup invalid sensitivity names | ||
// - If no valid sensitivity names are selected, the change can be due to new available sensitivity names | ||
const fixedUpSensitivityNames = | ||
userSelectedSensitivityNames?.filter((sens) => availableSensitivityNames.includes(sens)) ?? []; | ||
if (fixedUpSensitivityNames.length === 0) { | ||
return availableSensitivityNames; | ||
} | ||
|
||
return fixedUpSensitivityNames; | ||
}); | ||
|
||
export const availableVectorNamesAtom = atom<string[]>((get) => { | ||
const vectorListQuery = get(vectorListQueryAtom); | ||
return vectorListQuery.data?.map((vec) => vec.name) ?? []; | ||
}); | ||
|
||
export const vectorSelectorDataAtom = atom((get) => { | ||
const isFetching = get(vectorListQueryAtom).isFetching; | ||
const availableVectorNames = get(availableVectorNamesAtom); | ||
|
||
if (isFetching) { | ||
return []; | ||
} | ||
|
||
return createVectorSelectorDataFromVectors(availableVectorNames); | ||
}); | ||
|
||
/** | ||
* Atom that handles vector name and tag in synch with fixup | ||
*/ | ||
const fixedUpVectorNameAndTagAtom = atom<{ name: string | null; tag: string | null }>((get) => { | ||
const syncedVectorName = get(syncedVectorNameAtom); | ||
const userSelectedVectorName = get(userSelectedVectorNameAtom); | ||
const userSelectedVectorTag = get(userSelectedVectorTagAtom); | ||
const availableVectorNames = get(availableVectorNamesAtom); | ||
|
||
// Override with synced vector name if available | ||
if (syncedVectorName) { | ||
return { name: syncedVectorName, tag: syncedVectorName }; | ||
} | ||
|
||
// If vector name is fixed up, adjust tag as well | ||
const fixedUpVectorName = fixupVectorName(userSelectedVectorName, availableVectorNames); | ||
if (fixedUpVectorName !== userSelectedVectorName) { | ||
return { name: fixedUpVectorName, tag: fixedUpVectorName }; | ||
} | ||
|
||
return { name: userSelectedVectorName, tag: userSelectedVectorTag }; | ||
}); | ||
|
||
export const selectedVectorNameAtom = atom<string | null>((get) => { | ||
const fixedUpVectorName = get(fixedUpVectorNameAndTagAtom).name; | ||
return fixedUpVectorName; | ||
}); | ||
|
||
export const selectedVectorTagAtom = atom<string | null>((get) => { | ||
const fixedUpVectorTag = get(fixedUpVectorNameAndTagAtom).tag; | ||
return fixedUpVectorTag; | ||
}); | ||
|
||
export const selectedVectorNameHasHistoricalAtom = atom<boolean>((get) => { | ||
const selectedVectorName = get(selectedVectorNameAtom); | ||
const vectorListQuery = get(vectorListQueryAtom); | ||
|
||
const selectedVector = vectorListQuery.data?.find((vec) => vec.name === selectedVectorName); | ||
return !!selectedVector?.has_historical; | ||
}); | ||
|
||
export const vectorSpecificationAtom = atom<VectorSpec | null>((get) => { | ||
const selectedEnsembleIdent = get(selectedEnsembleIdentAtom); | ||
const selectedVectorName = get(selectedVectorNameAtom); | ||
const selectedVectorNameHasHistorical = get(selectedVectorNameHasHistoricalAtom); | ||
|
||
if (!selectedEnsembleIdent || !selectedVectorName) { | ||
return null; | ||
} | ||
|
||
return { | ||
ensembleIdent: selectedEnsembleIdent, | ||
vectorName: selectedVectorName, | ||
hasHistorical: selectedVectorNameHasHistorical, | ||
}; | ||
}); |
26 changes: 26 additions & 0 deletions
26
frontend/src/modules/SimulationTimeSeriesSensitivity/settings/atoms/queryAtoms.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { apiService } from "@framework/ApiService"; | ||
|
||
import { atomWithQuery } from "jotai-tanstack-query"; | ||
|
||
import { selectedEnsembleIdentAtom } from "./derivedAtoms"; | ||
|
||
const STALE_TIME = 60 * 1000; | ||
const CACHE_TIME = 60 * 1000; | ||
|
||
export const vectorListQueryAtom = atomWithQuery((get) => { | ||
const selectedEnsembleIdent = get(selectedEnsembleIdentAtom); | ||
|
||
const query = { | ||
queryKey: ["getVectorList", selectedEnsembleIdent?.getCaseUuid(), selectedEnsembleIdent?.getEnsembleName()], | ||
queryFn: () => | ||
apiService.timeseries.getVectorList( | ||
selectedEnsembleIdent?.getCaseUuid() ?? "", | ||
selectedEnsembleIdent?.getEnsembleName() ?? "" | ||
), | ||
staleTime: STALE_TIME, | ||
gcTime: CACHE_TIME, | ||
enabled: !!(selectedEnsembleIdent?.getCaseUuid() && selectedEnsembleIdent?.getEnsembleName()), | ||
}; | ||
|
||
return query; | ||
}); |
19 changes: 0 additions & 19 deletions
19
frontend/src/modules/SimulationTimeSeriesSensitivity/settings/hooks/queryHooks.tsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.