Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(alpha-simint): update to the latest simint APIs #1059

Merged
merged 2 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions packages/alpha/src/__tests__/api/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ export const stepFields = [
name: 'objectName',
label: 'Simulation Object Name',
info: 'Enter the name of the DWSIM object, i.e. Feed',
options: null,
},
{
name: 'objectProperty',
label: 'Simulation Object Property',
info: 'Enter the property of the DWSIM object, i.e. Temperature',
options: null,
},
],
},
Expand All @@ -58,12 +60,12 @@ export const stepFields = [
{
name: 'type',
label: 'Command',
// options: [
// {
// label: 'Solve',
// value: 'Solve',
// },
// ],
options: [
{
label: 'Solve',
value: 'Solve',
},
],
info: 'Select a command',
},
],
Expand Down
15 changes: 11 additions & 4 deletions packages/alpha/src/__tests__/api/simulationRunsApi.int.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ describeIf('simulator integrations api', () => {
test('run a simulation', async () => {
const res = await client.simulators.runSimulation([
{
simulatorName: 'DWSIM',
modelName: 'ShowerMixerIntegrationTest',
routineName: 'ShowerMixerCalculation',
routineExternalId: 'ShowerMixerIntegrationTestConstInputs',
runType: 'external',
validationEndTime: new Date(ts),
queue: true,
Expand All @@ -33,7 +31,7 @@ describeIf('simulator integrations api', () => {

expect(item.simulatorName).toBe('DWSIM');
expect(item.modelName).toBe('ShowerMixerIntegrationTest');
expect(item.routineName).toBe('ShowerMixerCalculation');
expect(item.routineName).toBe('ShowerMixerIntegrationTest');
expect(item.status).toBe('ready');
expect(item.runType).toBe('external');
expect(item.validationEndTime?.valueOf()).toBe(ts);
Expand All @@ -46,7 +44,16 @@ describeIf('simulator integrations api', () => {
filter: {
simulatorName: 'DWSIM',
status: 'success',
createdTime: {
max: new Date(),
},
},
sort: [
{
property: 'createdTime',
order: 'desc',
},
],
});

expect(res).toBeDefined();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const describeIf = SHOULD_RUN_TESTS ? describe : describe.skip;

describeIf('simulator integrations api', () => {
const ts = Date.now();
const simulatorExternalId = `test_sim_${ts}`;
const simulatorExternalId = `test_sim_${ts}_a`;
const simulatorIntegrationExternalId = `test_sim_integration_${ts}`;
const simulatorName = `TestSim - ${ts}`;
const client: CogniteClientAlpha = setupLoggedInClient();
Expand Down Expand Up @@ -50,15 +50,15 @@ describeIf('simulator integrations api', () => {
{
externalId: simulatorIntegrationExternalId,
simulatorExternalId: simulatorExternalId,
heartbeat: ts,
heartbeat: new Date(ts),
dataSetId: 4097666328084896,
connectorVersion: '1.0.0',
simulatorVersion: '1.0.0',
runApiEnabled: true,
licenseStatus: 'active',
licenseLastCheckedTime: 0,
licenseLastCheckedTime: new Date(),
connectorStatus: 'unknown',
connectorStatusUpdatedTime: 0,
connectorStatusUpdatedTime: new Date(),
},
]);
expect(response.length).toBe(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const describeIf = SHOULD_RUN_TESTS ? describe : describe.skip;

describeIf('simulator models api', () => {
const ts = Date.now();
const simulatorExternalId = `test_sim_${ts}`;
const simulatorExternalId = `test_sim_${ts}_b`;
const modelExternalId = `test_sim_model_${ts}`;
const modelRevisionExternalId = `test_sim_model_revision_${ts}`;
const simulatorName = `TestSim - ${ts}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const describeIf = SHOULD_RUN_TESTS ? describe : describe.skip;

describeIf('simulator routines api', () => {
const ts = Date.now();
const simulatorExternalId = `test_sim_${ts}`;
const simulatorExternalId = `test_sim_${ts}_c`;
const modelExternalId = `test_sim_model_${ts}`;
const modelRevisionExternalId = `test_sim_model_revision_${ts}`;
const routineExternalId = `test_sim_routine_${ts}`;
Expand Down Expand Up @@ -56,15 +56,13 @@ describeIf('simulator routines api', () => {
{
externalId: simulatorIntegrationExternalId,
simulatorExternalId: simulatorExternalId,
heartbeat: ts,
heartbeat: new Date(ts),
dataSetId: 4097666328084896,
connectorVersion: '1.0.0',
simulatorVersion: '1.0.0',
runApiEnabled: true,
licenseStatus: 'active',
licenseLastCheckedTime: 0,
connectorStatus: 'unknown',
connectorStatusUpdatedTime: 0,
},
]);
expect(response.length).toBe(1);
Expand Down
12 changes: 6 additions & 6 deletions packages/alpha/src/__tests__/api/simulatorsApi.int.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describeIf('simulators api', () => {
const client: CogniteClientAlpha = setupLoggedInClient();

const ts = Date.now();
const simulatorExternalId = `test_sim_${ts}`;
const simulatorExternalId = `test_sim_${ts}_d`;
const simulatorName = `TestSim - ${ts}`;
let simulatorId: number;

Expand All @@ -46,11 +46,11 @@ describeIf('simulators api', () => {
expect(response[0].externalId).toBe(simulatorExternalId);
expect(response[0].fileExtensionTypes).toEqual(['csv', 'yaml']);
expect(response[0].enabled).toBe(true);
// expect(response[0].stepFields).toEqual(stepFields);
// expect(response[0].units).toEqual({
// unitsMap,
// unitSystem
// });
expect(response[0].stepFields).toEqual(stepFields);
expect(response[0].units).toEqual({
unitsMap,
unitSystem,
});
expect(response[0].modelTypes).toEqual(modelTypes);
expect(response[0].boundaryConditions).toEqual(boundaryConditions);
expect(response[0].isCalculationsEnabled).toBe(true);
Expand Down
7 changes: 7 additions & 0 deletions packages/alpha/src/api/simulators/modelRevisionsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ import {
} from '../../types';

export class ModelRevisionsAPI extends BaseResourceAPI<SimulatorModelRevision> {
/**
* @hidden
*/
protected getDateProps() {
return this.pickDateProps(['items'], ['createdTime', 'lastUpdatedTime']);
}

constructor(...args: [string, CDFHttpClient, MetadataMap]) {
super(...args);
}
Expand Down
7 changes: 7 additions & 0 deletions packages/alpha/src/api/simulators/modelsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ import {
} from '../../types';

export class ModelsAPI extends BaseResourceAPI<SimulatorModel> {
/**
* @hidden
*/
protected getDateProps() {
return this.pickDateProps(['items'], ['createdTime', 'lastUpdatedTime']);
}

constructor(...args: [string, CDFHttpClient, MetadataMap]) {
super(...args);
}
Expand Down
7 changes: 7 additions & 0 deletions packages/alpha/src/api/simulators/routinesApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ import {
} from '../../types';

export class RoutinesAPI extends BaseResourceAPI<SimulatorRoutine> {
/**
* @hidden
*/
protected getDateProps() {
return this.pickDateProps(['items'], ['createdTime', 'lastUpdatedTime']);
}

constructor(...args: [string, CDFHttpClient, MetadataMap]) {
super(...args);
}
Expand Down
7 changes: 7 additions & 0 deletions packages/alpha/src/api/simulators/routinesRevisionsAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ import {
} from '../../types';

export class RoutineRevisionsAPI extends BaseResourceAPI<SimulatorRoutineRevision> {
/**
* @hidden
*/
protected getDateProps() {
return this.pickDateProps(['items'], ['createdTime', 'lastUpdatedTime']);
}

constructor(...args: [string, CDFHttpClient, MetadataMap]) {
super(...args);
}
Expand Down
7 changes: 1 addition & 6 deletions packages/alpha/src/api/simulators/simulationRunsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@ export class SimulationRunsAPI extends BaseResourceAPI<SimulationRun> {
protected getDateProps() {
return this.pickDateProps(
['items'],
[
'createdTime',
'lastUpdatedTime',
'validationEndTime',
'validationEndTime',
]
['createdTime', 'lastUpdatedTime', 'validationEndTime', 'simulationTime']
);
}

Expand Down
8 changes: 8 additions & 0 deletions packages/alpha/src/api/simulators/simulatorsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ export class SimulatorsAPI extends BaseResourceAPI<Simulator> {
private modelRevisionsApi: ModelRevisionsAPI;
private routinesApi: RoutinesAPI;
private routineRevisionsApi: RoutineRevisionsAPI;

/**
* @hidden
*/
protected getDateProps() {
return this.pickDateProps(['items'], ['createdTime', 'lastUpdatedTime']);
}

constructor(...args: [string, CDFHttpClient, MetadataMap]) {
super(...args);

Expand Down
56 changes: 33 additions & 23 deletions packages/alpha/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2020 Cognite AS

import { SinglePatch, SortOrder, Timestamp, DateRange } from '@cognite/sdk';
import { SinglePatch, SortOrder, DateRange } from '@cognite/sdk';
import {
CogniteExternalId,
CogniteInternalId,
Expand Down Expand Up @@ -76,8 +76,8 @@ export interface Simulator {
enabled: boolean;
stepFields?: SimulatorStep[];
units?: SimulatorUnits;
createdTime: Timestamp;
lastUpdatedTime: Timestamp;
createdTime: Date;
lastUpdatedTime: Date;
}

export interface SimulatorFilter {
Expand Down Expand Up @@ -105,31 +105,31 @@ export interface SimulatorIntegration {
id: CogniteInternalId;
externalId: CogniteExternalId;
simulatorExternalId: CogniteExternalId;
heartbeat: Timestamp;
heartbeat: Date;
dataSetId: CogniteInternalId;
connectorVersion: string;
simulatorVersion: string;
runApiEnabled: boolean;
licenseStatus: string;
licenseLastCheckedTime: Timestamp;
licenseLastCheckedTime: Date;
connectorStatus: string;
connectorStatusUpdatedTime: Timestamp;
createdTime: Timestamp;
lastUpdatedTime: Timestamp;
connectorStatusUpdatedTime: Date;
createdTime: Date;
lastUpdatedTime: Date;
}

export interface SimulatorIntegrationCreate {
externalId: CogniteExternalId;
simulatorExternalId: CogniteExternalId;
dataSetId?: CogniteInternalId;
heartbeat?: Timestamp;
heartbeat?: Date;
connectorVersion?: string;
simulatorVersion?: string;
runApiEnabled?: boolean;
licenseStatus?: string;
licenseLastCheckedTime?: Timestamp;
licenseLastCheckedTime?: Date;
connectorStatus?: string;
connectorStatusUpdatedTime?: Timestamp;
connectorStatusUpdatedTime?: Date;
}

export interface SimulatorIntegrationFilter {
Expand All @@ -145,6 +145,12 @@ export interface SimulationRunFilter {
modelName?: string;
routineName?: string;
status?: SimulationRunStatus;
simulatorIntegrationExternalIds?: CogniteExternalId[];
simulatorExternalIds?: CogniteExternalId[];
routineRevisionExternalIds?: CogniteExternalId[];
modelRevisionExternalIds?: CogniteExternalId[];
createdTime?: DateRange;
simulationTime?: DateRange;
}

export interface SortItem {
Expand Down Expand Up @@ -182,10 +188,8 @@ export const SimulationRunType = {
};

export interface SimulationRunCreate {
simulatorName: string;
modelName: string;
routineName: string;
runType: SimulationRunType;
routineExternalId: CogniteExternalId;
runType?: SimulationRunType;
validationEndTime?: Date;
queue?: boolean;
}
Expand All @@ -204,9 +208,15 @@ export interface SimulationRun {
simulatorName: string;
modelName: string;
routineName: string;
simulatorExternalId: CogniteExternalId;
simulatorIntegrationExternalId: CogniteExternalId;
modelRevisionExternalId: CogniteExternalId;
routineRevisionExternalId: CogniteExternalId;
status: SimulationRunStatus;
validationEndTime?: Date;
simulationTime?: Date;
statusMessage?: string;
dataSetId?: CogniteInternalId;
eventId?: CogniteInternalId;
runType: SimulationRunType;
userId?: string;
Expand All @@ -224,8 +234,8 @@ export interface SimulatorModel {
labels?: ExternalId[];
type?: string;
unitSystem?: string;
createdTime: Timestamp;
lastUpdatedTime: Timestamp;
createdTime: Date;
lastUpdatedTime: Date;
}

export interface SimulatorModelCreate {
Expand Down Expand Up @@ -279,8 +289,8 @@ export interface SimulatorModelRevision {
boundaryConditionsStatus?: string;
versionNumber: number;
metadata?: Record<string, string>;
createdTime: Timestamp;
lastUpdatedTime: Timestamp;
createdTime: Date;
lastUpdatedTime: Date;
}

export interface SimulatorModelRevisionCreate {
Expand Down Expand Up @@ -347,8 +357,8 @@ export interface SimulatorRoutine {
name: string;
dataSetId: number;
description?: string;
createdTime: Timestamp;
lastUpdatedTime: Timestamp;
createdTime: Date;
lastUpdatedTime: Date;
}

export interface SimulatorRoutineCreate {
Expand Down Expand Up @@ -474,8 +484,8 @@ export interface SimulatorRoutineRevision {
modelExternalId: CogniteExternalId;
dataSetId: CogniteInternalId;
createdByUserId: string;
createdTime: Timestamp;
lastUpdatedTime: Timestamp;
createdTime: Date;
lastUpdatedTime: Date;
configuration: RoutineRevisionConfiguration;
script: RoutineScript[];
calculationType?: CalculationType;
Expand Down
Loading