Skip to content

Commit d8828bf

Browse files
Sort surface names and well picks by stratigraphic order (#1130)
1 parent e64fefd commit d8828bf

File tree

7 files changed

+66
-35
lines changed

7 files changed

+66
-35
lines changed

frontend/src/lib/utils/arrays.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,26 @@ export function arrayMove<T>(array: T[], from: number, to: number, moveAmt = 1):
1212

1313
return newArrray.toSpliced(to, 0, ...movedItems);
1414
}
15+
16+
/**
17+
* Sort an array of strings according to a specified order, with values not in the order list sorted alphabetically at the end.
18+
*
19+
* @param values List of values to sort
20+
* @param valuesByOrder A list of values defining the desired order. Values not in this list will be sorted alphabetically after the ordered values.
21+
* @returns Returns a new array with the values sorted according to the specified order.
22+
*/
23+
export function sortStringArray(values: string[], valuesByOrder: string[]): string[] {
24+
// Build quick lookup for order indices to avoid repeated indexOf
25+
const orderIndex = new Map(valuesByOrder.map((value, idx) => [value, idx]));
26+
27+
return values.sort((a, b) => {
28+
const ia = orderIndex.has(a) ? orderIndex.get(a)! : -1;
29+
const ib = orderIndex.has(b) ? orderIndex.get(b)! : -1;
30+
31+
if (ia !== -1 && ib !== -1) return ia - ib; // both in order list
32+
if (ia !== -1) return -1; // only a in order
33+
if (ib !== -1) return 1; // only b in order
34+
35+
return a.localeCompare(b); // neither in order list
36+
});
37+
}

frontend/src/modules/2DViewer/DataProviderFramework/customDataProviderImplementations/ObservedSurfaceProvider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { isEqual } from "lodash";
22

33
import type { SurfaceDataPng_api } from "@api";
44
import { SurfaceTimeType_api, getObservedSurfacesMetadataOptions, getSurfaceDataOptions } from "@api";
5+
import { sortStringArray } from "@lib/utils/arrays";
56
import type {
67
CustomDataProviderImplementation,
78
DataProviderInformationAccessors,
@@ -129,8 +130,7 @@ export class ObservedSurfaceProvider
129130
),
130131
),
131132
];
132-
133-
return availableSurfaceNames;
133+
return sortStringArray(availableSurfaceNames, data.surface_names_in_strat_order);
134134
});
135135

136136
availableSettingsUpdater(Setting.TIME_OR_INTERVAL, ({ getLocalSetting, getHelperDependency }) => {

frontend/src/modules/Intersection/DataProviderFramework/customDataProviderImplementations/EnsembleWellborePicksProvider.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,7 @@ export class EnsembleWellborePicksProvider
108108
return [];
109109
}
110110

111-
return wellborePicks
112-
.filter((elm) => elm.interpreter === selectedInterpreter)
113-
.sort((a, b) => {
114-
return a.pickIdentifier.localeCompare(b.pickIdentifier);
115-
});
111+
return wellborePicks.filter((elm) => elm.interpreter === selectedInterpreter);
116112
});
117113
}
118114

frontend/src/modules/Intersection/DataProviderFramework/customDataProviderImplementations/RealizationSurfacesProvider.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
postGetSurfaceIntersectionOptions,
88
} from "@api";
99
import { IntersectionType } from "@framework/types/intersection";
10+
import { sortStringArray } from "@lib/utils/arrays";
1011
import { assertNonNull } from "@lib/utils/assertNonNull";
1112
import {
1213
createIntersectionPolylineWithSectionLengthsForField,
@@ -151,7 +152,7 @@ export class RealizationSurfacesProvider
151152
return getAvailableIntersectionOptions(wellboreHeaders, fieldIntersectionPolylines);
152153
});
153154

154-
const depthSurfaceMetadataDep = helperDependency(async ({ getLocalSetting, abortSignal }) => {
155+
const surfaceMetadataSetDep = helperDependency(async ({ getLocalSetting, abortSignal }) => {
155156
const ensembleIdent = getLocalSetting(Setting.ENSEMBLE);
156157

157158
if (!ensembleIdent) {
@@ -168,15 +169,17 @@ export class RealizationSurfacesProvider
168169
}),
169170
});
170171

171-
const depthSurfacesMetadata = surfaceMetadata.surfaces.filter(
172-
(elm) => elm.attribute_type === SurfaceAttributeType_api.DEPTH,
173-
);
174-
return depthSurfacesMetadata;
172+
return surfaceMetadata;
175173
});
176174

177175
availableSettingsUpdater(Setting.ATTRIBUTE, ({ getHelperDependency }) => {
178-
const depthSurfacesMetadata = getHelperDependency(depthSurfaceMetadataDep);
179-
176+
const surfaceMetadataSet = getHelperDependency(surfaceMetadataSetDep);
177+
if (!surfaceMetadataSet) {
178+
return [];
179+
}
180+
const depthSurfacesMetadata = surfaceMetadataSet.surfaces.filter(
181+
(elm) => elm.attribute_type === SurfaceAttributeType_api.DEPTH,
182+
);
180183
if (!depthSurfacesMetadata) {
181184
return [];
182185
}
@@ -186,16 +189,19 @@ export class RealizationSurfacesProvider
186189

187190
availableSettingsUpdater(Setting.SURFACE_NAMES, ({ getLocalSetting, getHelperDependency }) => {
188191
const attribute = getLocalSetting(Setting.ATTRIBUTE);
189-
const depthSurfacesMetadata = getHelperDependency(depthSurfaceMetadataDep);
192+
const surfaceMetadataSet = getHelperDependency(surfaceMetadataSetDep);
190193

191-
if (!attribute || !depthSurfacesMetadata) {
194+
if (!attribute || !surfaceMetadataSet) {
192195
return [];
193196
}
197+
const depthSurfacesMetadata = surfaceMetadataSet.surfaces.filter(
198+
(elm) => elm.attribute_type === SurfaceAttributeType_api.DEPTH,
199+
);
194200

195-
// Filter depth surfaces metadata by the selected attribute
196-
return Array.from(
201+
const filteredSurfaceNames = Array.from(
197202
new Set(depthSurfacesMetadata.filter((elm) => elm.attribute_name === attribute).map((elm) => elm.name)),
198-
).sort();
203+
);
204+
return sortStringArray(filteredSurfaceNames, surfaceMetadataSet.surface_names_in_strat_order);
199205
});
200206

201207
// Create intersection polyline and actual section lengths data asynchronously

frontend/src/modules/Intersection/DataProviderFramework/customDataProviderImplementations/SurfacesPerRealizationValuesProvider.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
postGetSampleSurfaceInPointsOptions,
88
} from "@api";
99
import { IntersectionType } from "@framework/types/intersection";
10+
import { sortStringArray } from "@lib/utils/arrays";
1011
import { assertNonNull } from "@lib/utils/assertNonNull";
1112
import {
1213
createIntersectionPolylineWithSectionLengthsForField,
@@ -155,7 +156,7 @@ export class SurfacesPerRealizationValuesProvider
155156
return getAvailableIntersectionOptions(wellboreHeaders, fieldIntersectionPolylines);
156157
});
157158

158-
const depthSurfaceMetadataDep = helperDependency(async ({ getLocalSetting, abortSignal }) => {
159+
const surfaceMetadataSetDep = helperDependency(async ({ getLocalSetting, abortSignal }) => {
159160
const ensembleIdent = getLocalSetting(Setting.ENSEMBLE);
160161

161162
if (!ensembleIdent) {
@@ -172,15 +173,17 @@ export class SurfacesPerRealizationValuesProvider
172173
}),
173174
});
174175

175-
const depthSurfacesMetadata = surfaceMetadata.surfaces.filter(
176-
(elm) => elm.attribute_type === SurfaceAttributeType_api.DEPTH,
177-
);
178-
return depthSurfacesMetadata;
176+
return surfaceMetadata;
179177
});
180178

181179
availableSettingsUpdater(Setting.ATTRIBUTE, ({ getHelperDependency }) => {
182-
const depthSurfacesMetadata = getHelperDependency(depthSurfaceMetadataDep);
183-
180+
const surfaceMetadataSet = getHelperDependency(surfaceMetadataSetDep);
181+
if (!surfaceMetadataSet) {
182+
return [];
183+
}
184+
const depthSurfacesMetadata = surfaceMetadataSet.surfaces.filter(
185+
(elm) => elm.attribute_type === SurfaceAttributeType_api.DEPTH,
186+
);
184187
if (!depthSurfacesMetadata) {
185188
return [];
186189
}
@@ -190,16 +193,19 @@ export class SurfacesPerRealizationValuesProvider
190193

191194
availableSettingsUpdater(Setting.SURFACE_NAMES, ({ getLocalSetting, getHelperDependency }) => {
192195
const attribute = getLocalSetting(Setting.ATTRIBUTE);
193-
const depthSurfacesMetadata = getHelperDependency(depthSurfaceMetadataDep);
196+
const surfaceMetadataSet = getHelperDependency(surfaceMetadataSetDep);
194197

195-
if (!attribute || !depthSurfacesMetadata) {
198+
if (!attribute || !surfaceMetadataSet) {
196199
return [];
197200
}
201+
const depthSurfacesMetadata = surfaceMetadataSet.surfaces.filter(
202+
(elm) => elm.attribute_type === SurfaceAttributeType_api.DEPTH,
203+
);
198204

199-
// Filter depth surfaces metadata by the selected attribute
200-
return Array.from(
205+
const filteredSurfaceNames = Array.from(
201206
new Set(depthSurfacesMetadata.filter((elm) => elm.attribute_name === attribute).map((elm) => elm.name)),
202-
).sort();
207+
);
208+
return sortStringArray(filteredSurfaceNames, surfaceMetadataSet.surface_names_in_strat_order);
203209
});
204210

205211
// Create intersection polyline and actual section lengths data asynchronously

frontend/src/modules/_shared/DataProviderFramework/dataProviders/implementations/RealizationSurfaceProvider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
getRealizationSurfacesMetadataOptions,
88
getSurfaceDataOptions,
99
} from "@api";
10+
import { sortStringArray } from "@lib/utils/arrays";
1011
import type {
1112
CustomDataProviderImplementation,
1213
DataProviderInformationAccessors,
@@ -189,8 +190,7 @@ export class RealizationSurfaceProvider
189190
),
190191
),
191192
];
192-
193-
return availableSurfaceNames;
193+
return sortStringArray(availableSurfaceNames, data.surface_names_in_strat_order);
194194
});
195195

196196
availableSettingsUpdater(Setting.TIME_OR_INTERVAL, ({ getLocalSetting, getHelperDependency }) => {

frontend/src/modules/_shared/DataProviderFramework/dataProviders/implementations/StatisticalSurfaceProvider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
} from "@api";
1313
import { lroProgressBus } from "@framework/LroProgressBus";
1414
import { wrapLongRunningQuery } from "@framework/utils/lro/longRunningApiCalls";
15+
import { sortStringArray } from "@lib/utils/arrays";
1516
import type {
1617
CustomDataProviderImplementation,
1718
DataProviderInformationAccessors,
@@ -187,8 +188,7 @@ export class StatisticalSurfaceProvider
187188
),
188189
),
189190
];
190-
191-
return availableSurfaceNames;
191+
return sortStringArray(availableSurfaceNames, data.surface_names_in_strat_order);
192192
});
193193

194194
availableSettingsUpdater(Setting.TIME_OR_INTERVAL, ({ getLocalSetting, getHelperDependency }) => {

0 commit comments

Comments
 (0)