// Copyright 2020 Cognite AS import { CogniteWellsClient, DistanceRange, WellFilterRequest, WellNptFilter, } from "src"; import { DateRange } from "src/model/dateRange"; import { PropertyFilter } from "src/model/propertyFilter"; import { WellItems } from "src/model/wellItems"; import { setupLoggedInClient } from "../testUtils"; import { WellByIdsRequest } from "src/model/wellByIdsRequest"; import { expectContainAll } from "./utils/expectContainAll"; import { WellDepthMeasurementFilter } from "src/model/wellDepthMeasurementFilter"; import { MeasurementType } from "../fixtures/measurementFixtures"; import { WellTrajectoryFilter } from "src/model/wellTrajectoryFilter"; import { IdentifierItems } from "src/model/identifierItems"; export enum DistanceUnitEnum { METER = "meter", FOOT = "foot", INCH = "inch", YARD = "yard", } export enum AngleUnitEnum { DEGREE = "degree", RADIAN = "radian", } enum LengthUnitEnum { METER = "meter", FOOT = "foot", INCH = "inch", YARD = "yard", } let client: CogniteWellsClient; beforeAll(async () => { client = await setupLoggedInClient(); }); test("get by id - well returned for id", async () => { expect(client).not.toBeUndefined(); const request: IdentifierItems = { items: [ { assetExternalId: "VOLVE:15/9-F-15" }, { assetExternalId: "VOLVE:13/10-F-11" }, ], }; const wells = await client.wells.retrieveMultiple(request); const actual = wells.items.flatMap((well) => well.sources.map((source) => source.assetExternalId) ); expectContainAll(actual, ["VOLVE:15/9-F-15", "VOLVE:13/10-F-11"]); }); test("get by id - output crs EPSG:23031", async () => { expect(client).not.toBeUndefined(); const request: WellByIdsRequest = { items: [ { assetExternalId: "VOLVE:15/9-F-15" }, { assetExternalId: "VOLVE:13/10-F-11" }, ], outputCrs: "EPSG:23031", }; const wells = await client.wells.retrieveMultiple(request); const actual = wells.items.flatMap((well) => well.sources.map((source) => source.assetExternalId) ); expectContainAll(actual, ["VOLVE:15/9-F-15", "VOLVE:13/10-F-11"]); wells.items.forEach((well) => expect(well.wellhead.crs).toBe("EPSG:23031")); }); test("get list of wells", async () => { expect(client).not.toBeUndefined(); const wells: WellItems = await client.wells.list({}); expect(wells).not.toBeUndefined(); expect(wells.items.length).not.toBe(0); }); test("list with limit, then cursor and limit", async () => { const wellsWithLimit: WellItems = await client.wells.list({ limit: 3 }); expect(wellsWithLimit).not.toBeUndefined(); expect(wellsWithLimit.items.length).toBe(3); const wellsWithCursor: WellItems = await client.wells.list({ cursor: wellsWithLimit.nextCursor, limit: 2, }); expect(wellsWithCursor).not.toBeUndefined(); expect(wellsWithCursor.items.length).toBe(2); }); test("gets wells in wkt polygon", async () => { const testPolygon = "POLYGON ((0.0 0.0, 0.0 61.0, 61.0 61.0, 61.0 0.0, 0.0 0.0))"; const filter: WellFilterRequest = { filter: { polygon: { geometry: testPolygon, crs: "epsg:4326", geometryType: "WKT" }, }, outputCrs: "epsg:4326", }; const wells = await client.wells.list(filter); expect(wells).not.toBeUndefined(); const crs = wells.items.map((well) => well.wellhead.crs.toLowerCase()); expectContainAll(["epsg:4326"], crs); }); test("fuzzy search on name string matching 1", async () => { const filter: WellFilterRequest = { search: { query: "15/9-F-15" } }; const wells = await client.wells.search(filter); expect(wells).not.toBeUndefined(); const retrievedNames = wells.items.map((well) => well.name); expect(retrievedNames).toStrictEqual(["15/9-F-15", "15/9-F-4"]); }); test("get all wells with edm source", async () => { const testPolygon = "POLYGON ((0.0 0.0, 0.0 80.0, 80.0 80.0, 80.0 0.0, 0.0 0.0))"; const filter: WellFilterRequest = { filter: { polygon: { geometry: testPolygon, crs: "epsg:4326", geometryType: "WKT" }, sources: ["edm"], }, }; const wells = await client.wells.list(filter); wells.items.forEach((well) => { expect(well.sources).toContain("EDM"); }); }); test("get all wells with trajectory", async () => { const filter: WellFilterRequest = { filter: { trajectories: {} } }; const wells = await client.wells.list(filter); expect(wells).not.toBeUndefined(); expect(wells.items.length).not.toBe(0); }); test("get all wells with trajectory in range", async () => { const filter: WellFilterRequest = { filter: { trajectories: { maxMeasuredDepth: { min: 1000.0, max: 8000.0, unit: DistanceUnitEnum.METER, }, }, }, }; const wells = await client.wells.list(filter); expect(wells).not.toBeUndefined(); expect(wells.items.length).not.toBe(0); }); test("get wells with max md - no returned in range", async () => { const filter: WellFilterRequest = { filter: { trajectories: { maxMeasuredDepth: { min: 0.0, max: 0.0, unit: DistanceUnitEnum.METER }, }, }, }; const wells = await client.wells.list(filter); expect(wells).not.toBeUndefined(); expect(wells.items.length).toBe(0); }); test("list wells - aggregate on count", async () => { const request: WellFilterRequest = { aggregates: ["count"], }; const wells = await client.wells.list(request); expect(wells.wellboresCount).toBeGreaterThan(0); expect(wells.wellsCount).toBeGreaterThan(0); }); test.skip("has density measurement", async () => { const measurementFilter: WellDepthMeasurementFilter = { measurementTypes: { containsAny: [MeasurementType.Density] }, }; const filter: WellFilterRequest = { filter: { depthMeasurements: measurementFilter }, }; const wells = await client.wells.list(filter); expect(wells).not.toBeUndefined(); expect(wells.items.length).not.toBe(0); }); test("has multiple measurements, can match on any", async () => { const measurementFilter: WellDepthMeasurementFilter = { measurementTypes: { containsAny: [ MeasurementType.GammaRay, MeasurementType.Density, MeasurementType.porosity, ], }, }; const filter: WellFilterRequest = { filter: { depthMeasurements: measurementFilter, }, }; const wells = await client.wells.list(filter); expect(wells).not.toBeUndefined(); expect(wells.items.length).not.toBe(0); }); test("filter wells on water depth", async () => { const waterDepthFilter: DistanceRange = { unit: LengthUnitEnum.METER, min: 125.0, max: 250.0, }; const filter: WellFilterRequest = { filter: { waterDepth: waterDepthFilter, }, }; const wells = await client.wells.list(filter); expect(wells).not.toBeUndefined(); expect(wells.items.length).not.toBe(0); }); test("filter on spud date", async () => { const dateFilter: DateRange = { min: "2017-01-01", max: "2019-01-01", }; const filter: WellFilterRequest = { filter: { spudDate: dateFilter } }; const wells = await client.wells.list(filter); expect(wells).not.toBeUndefined(); expect(wells.items.length).not.toBe(0); }); test("filter on well type", async () => { const wellTypeFilter: PropertyFilter = { oneOf: ["EXPLORATION"] }; const filter: WellFilterRequest = { filter: { wellType: wellTypeFilter } }; const wells = await client.wells.list(filter); expect(wells).not.toBeUndefined(); expect(wells.items.length).not.toBe(0); }); test("filter on license", async () => { const wellLicenseFilter: PropertyFilter = { oneOf: ["license"] }; const filter: WellFilterRequest = { filter: { license: wellLicenseFilter } }; const wells = await client.wells.list(filter); expect(wells).not.toBeUndefined(); expect(wells.items.length).not.toBe(0); }); test("filter on max dogleg severity", async () => { const trajectoryFilter: WellTrajectoryFilter = { maxDoglegSeverity: { unit: { angleUnit: "degree", distanceUnit: "meter", distanceInterval: 30, }, min: 0.0, }, }; const filter: WellFilterRequest = { filter: { trajectories: trajectoryFilter }, }; const wells = await client.wells.list(filter); expect(wells).not.toBeUndefined(); expect(wells.items.length).not.toBe(0); }); test("filter wells with dataAvailibility filter", async () => { try { client.experimental.enable(); const wells = await client.wells.list({ filter: { dataAvailability: { containsAny: ["npt", "nds", "casings", "holeSections", "wellTops"], }, }, }); expect(wells.items.length).toBeGreaterThan(0); } finally { client.experimental.disable(); } }); test("filter well on npt depth and duration", async () => { const nptFilter: WellNptFilter = { duration: { unit: "hour", max: 30.0 }, measuredDepth: { min: 0.0, max: 45.0, unit: LengthUnitEnum.METER }, }; const filter: WellFilterRequest = { filter: { npt: nptFilter } }; const wells = await client.wells.list(filter); expect(wells).not.toBeUndefined(); expect(wells.items.length).not.toBe(0); }); test("filter well on npt criterias matching on all", async () => { const nptFilter: WellNptFilter = { measuredDepth: { min: 8.0, max: 45.0, unit: LengthUnitEnum.METER }, duration: { unit: "hour", min: 1.0, max: 30000.0 }, nptCodeDetails: { containsAll: ["CODE2", "CODE"] }, }; const filter: WellFilterRequest = { filter: { npt: nptFilter } }; const wells = await client.wells.list(filter); expect(wells).not.toBeUndefined(); expect(wells.items.length).not.toBe(0); }); test("filter well on npt depth", async () => { const filter: WellFilterRequest = { filter: { npt: { measuredDepth: { min: 0.0, max: Number.MAX_SAFE_INTEGER, unit: LengthUnitEnum.METER, }, }, }, }; const wells = await client.wells.list(filter); expect(wells).not.toBeUndefined(); expect(wells.items.length).not.toBe(0); }); test("filter well on nds severity", async () => { const filter: WellFilterRequest = { filter: { nds: { severities: { containsAny: [2, 3] }, }, }, }; const wells = await client.wells.list(filter); expect(wells).not.toBeUndefined(); expect(wells.items.length).not.toBe(0); }); test("filter well on risk types", async () => { const filter: WellFilterRequest = { filter: { nds: { riskTypes: { containsAny: ["RISKTYPE3", "RISKTYPE4"] }, }, }, }; const wells = await client.wells.list(filter); expect(wells).not.toBeUndefined(); expect(wells.items.length).not.toBe(0); }); test("filter well on well tops", async () => { const filter: WellFilterRequest = { filter: { wellTops: { exists: true, }, }, }; const wells = await client.wells.list(filter); expect(wells).not.toBeUndefined(); expect(wells.items.length).not.toBe(0); }); test("filter well on well tops surface", async () => { const filter: WellFilterRequest = { filter: { wellTops: { exists: true, surfaceNames: { containsAll: ["HORDALAND GP."], }, }, }, }; const wells = await client.wells.list(filter); expect(wells).not.toBeUndefined(); const wellBoreNames = wells.items .map((well) => well.wellbores) .reduce((a, b) => a?.concat(b || []), []) ?.map((bore) => bore.name); expect(wellBoreNames?.length).toEqual(2); expect(wellBoreNames).toContain("15/9-F-15 A"); expect(wellBoreNames).toContain("13/10-F-11 A"); }); test("filter well on max dogleg severity", async () => { const filter: WellFilterRequest = { filter: { trajectories: { maxDoglegSeverity: { unit: { angleUnit: "degree", distanceUnit: "meter", distanceInterval: 30, }, max: 100, }, }, }, }; const wells = await client.wells.list(filter); expect(wells).not.toBeUndefined(); expect(wells.items.length).not.toBe(0); }); test("filter well on holesections", async () => { const filter: WellFilterRequest = { filter: { holeSections: { bitSize: { value: 8, unit: DistanceUnitEnum.INCH, }, holeSize: { value: 8.5, unit: DistanceUnitEnum.INCH, }, }, }, }; const wells = await client.wells.list(filter); expect(wells).not.toBeUndefined(); expect(wells.items.length).not.toBe(0); }); test("set merge rules from list of sources", async () => { const order = ["VOLVE", "EDM", "test_source"]; const actual = await client.wells.mergeRules!.set(order); expect(actual.name).toEqual(order); expect(actual.license).toEqual(order); // Also test the get endpoint const retrieved = await client.wells.mergeRules.retrieve(); expect(retrieved.name).toEqual(order); expect(retrieved.license).toEqual(order); }); test("set merge rules from merge rules object", async () => { const current = await client.wells.mergeRules.retrieve(); const actual = await client.wells.mergeRules.set({ ...current, name: ["EDM", "VOLVE"], waterDepth: ["VOLVE", "test_source"], }); expect(actual.name).toEqual(["EDM", "VOLVE"]); expect(actual.waterDepth).toEqual(["VOLVE", "test_source"]); expect(actual.license).toEqual(current.license); }); test("get all wellheads", async () => { const wellheads = await client.wells.wellheads(); // Check that we have at least one result expect(wellheads.items.length).toBeGreaterThan(1); }); test("get a single wellhead", async () => { const wellheads = await client.wells.wellheads({ limit: 1 }); // Check that we get at least one element back. expect(wellheads.items.length).toBe(1); expect(wellheads.nextCursor).not.toBeNull(); // check pagination const nextWellheads = await client.wells.wellheads({ limit: 1, cursor: wellheads.nextCursor, }); expect(wellheads.nextCursor).not.toBe(nextWellheads.nextCursor); });