import { MeasurementType, DateRange, WaterDepthLimits, WellPropertiesSummaryRow, } from "src"; import CogniteWellsClient from "src/client/cogniteWellsClient"; import { expectedWelltypes } from "../fixtures/wellTypesFixtures"; import { setupLoggedInClient } from "../testUtils"; import { expectContainAll } from "./utils/expectContainAll"; let client: CogniteWellsClient; beforeAll(async () => { client = await setupLoggedInClient(); }); test("retrieve welltypes", async () => { expect(client).not.toBe(undefined); const welltypes = await client.summaries.welltypes(); expectedWelltypes.items.forEach((expectedWellType) => { expect(welltypes).toContainEqual(expectedWellType); }); }); test("get datum limits", async () => { const datumRange = await client.summaries.datumLimits(); expect(datumRange.min).not.toBeNull(); expect(datumRange.max).not.toBeNull(); }); test("get all fields", async () => { const fields = await client.summaries.fields(); expect(fields.length).toBeGreaterThan(0); }); test("get all operators", async () => { const operators = await client.summaries.operators(); expect(operators.length).toBeGreaterThan(0); }); test("get all quadrants", async () => { const quadrants = await client.summaries.quadrants(); expect(quadrants.length).toBeGreaterThan(0); }); test("get all regions", async () => { const regions = await client.summaries.regions(); expect(regions.map((r) => r.property)).toContainEqual("North Sea"); }); test("get water depth limits", async () => { expect(client).not.toBeUndefined(); const waterDepthLimits: WaterDepthLimits = await client.summaries.waterDepthLimits(); expect(waterDepthLimits.max!.value).toBe(222.0); expect(waterDepthLimits.max!.unit).toBe("meter"); expect(waterDepthLimits.min!.value).toBe(50.0); }); test("get spud date limits", async () => { expect(client).not.toBeUndefined(); const spudDateLimits: DateRange = await client.summaries.spudDateLimits(); expect(spudDateLimits.min!.toString()).toBe("2011-05-05"); expect(spudDateLimits.max!.toString()).toBe("2020-01-12"); }); test("get active measurement types", async () => { expect(client).not.toBeUndefined(); const activeMeasurementTypes: MeasurementType[] = await client.summaries.measurementTypes(); expect(activeMeasurementTypes).not.toHaveLength(0); }); test("get all nds risk types", async () => { expect(client).not.toBe(undefined); const riskTypes = await client.summaries.ndsRiskTypes(); const actual = riskTypes.map((it) => it.property); expectContainAll(actual, [ "RISKTYPE1", "RISKTYPE2", "RISKTYPE3", "RISKTYPE4", "RISKTYPE5", ]); }); test("get all npt codes", async () => { expect(client).not.toBe(undefined); const codes = await client.summaries.nptCodes(); const actual = codes.map((it) => it.property); expectContainAll(actual, ["TESTCODE", "TESTCODE2", "TESTCODE3", "TESTCODE4"]); }); test("get all npt detail codes", async () => { expect(client).not.toBe(undefined); const codes = await client.summaries.nptDetailCodes(); const actual = codes.map((it) => it.property); expectContainAll(actual, ["CODE", "CODE2", "CODE3", "CODE4"]); }); test("get npt duration min max", async () => { expect(client).not.toBe(undefined); const durationRange = await client.summaries.nptDurations(); expect(durationRange.unit).toBe("hour"); expect(durationRange.min).not.toBe(null); expect(durationRange.max).not.toBe(null); expect(durationRange.min!).toBeLessThan(durationRange.max!); }); test("get trajectories measured depth limit", async () => { const mdRange = await client.summaries.trajectoriesMeasuredDepthLimits(); expect(mdRange.min).not.toBeNull(); expect(mdRange.max).not.toBeNull(); }); test("get trajectories true vertical depth limit", async () => { const tvdRange = await client.summaries.trajectoriesTrueVerticalDepthLimits(); expect(tvdRange.min).not.toBeNull(); expect(tvdRange.max).not.toBeNull(); }); test("get trajectories dogleg severity limit", async () => { const dlsRange = await client.summaries.trajectoriesDoglegSeverityLimits(); expect(dlsRange.min).not.toBeNull(); expect(dlsRange.max).not.toBeNull(); }); test("get trajectories maximum inclination limit", async () => { const inclinationRange = await client.summaries.trajectoriesMaximumInclinationLimits(); expect(inclinationRange.min).not.toBeNull(); expect(inclinationRange.max).not.toBeNull(); }); test("Get well properties summary", async () => { const wellProperties = await client.summaries.wellProperties({ items: ["field", "region", "block"], }); expect(wellProperties.items.length).toBeGreaterThan(0); }); test("Get well properties summary and group blocks by region", async () => { const wellProperties = await client.summaries.wellProperties({ items: ["region", "block"], }); const regionToBlocks = groupByMap( wellProperties.items, (row) => row.region || "", (value) => value.block || "" ); const northSeaBlocks = regionToBlocks.get("North Sea"); expect(northSeaBlocks).toContain("5"); expect(northSeaBlocks).toContain("8"); expect(northSeaBlocks).toContain("9"); expect(northSeaBlocks).toContain("10"); expect(northSeaBlocks).toContain(""); }); /** * A combination of groupBy and map that makes sure each value in the map is * unique. This is mean as en example for how to consume the wellProperties * response. * * The following snippet groups the wells by region and block into a Map. * ``` * groupByMap( * client.summaries.wellProperties(["region", "block"]), * row => row.region, * row => row.block * ) * ``` * * @param arr Input array * @param fn Group by key * @param map map each value * @returns Map from key */ function groupByMap( arr: T[], fn: (key: T) => K, map: (val: T) => U ): Map { const mapToSet = arr .map((val: T) => { const key = fn(val); return { key, val }; }) .reduce((acc, val) => { const nextValue = map(val.val); const set = acc.get(val.key) || new Set(); set.add(nextValue); acc.set(val.key, set); return acc; }, new Map>()); const nextMap = new Map(); mapToSet.forEach((value, key) => { const array = Array.from(value); array.sort(); nextMap.set(key, array); }); return nextMap; }