Skip to content

Commit

Permalink
add initial fdm rule type definitions for rule based thresholds
Browse files Browse the repository at this point in the history
  • Loading branch information
danpriori committed Aug 12, 2024
1 parent e409112 commit 7bb3ff2
Show file tree
Hide file tree
Showing 2 changed files with 163 additions and 9 deletions.
124 changes: 117 additions & 7 deletions react-components/src/components/RuleBasedOutputs/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@

import { type TreeIndexNodeCollection, type NumericRange } from '@cognite/reveal';
import { type FdmNode, type EdgeItem, type DmsUniqueIdentifier } from '../../data-providers/FdmSDK';
import { type AssetStylingGroup, type FdmPropertyType } from '../Reveal3DResources/types';
import {
type FdmAssetStylingGroup,
type AssetStylingGroup,
type FdmPropertyType
} from '../Reveal3DResources/types';
import { type Datapoints, type Asset, type Timeseries } from '@cognite/sdk';
import {
type FdmTyping,
type FdmInstanceNodeWithConnectionAndProperties
} from '../../data-providers/types';

// =========== RULE BASED OUTPUT DATA MODEL

export type TriggerType = 'timeseries' | 'metadata';
export type TriggerType = 'timeseries' | 'metadata' | 'fdm';

export type TimeseriesRuleTrigger = {
type: 'timeseries';
Expand All @@ -21,13 +29,50 @@ export type MetadataRuleTrigger = {
key: string;
};

export type FdmRuleTrigger = {
type: 'fdm';
key: FdmInstanceNodeDataKey;
};

export type FdmInstanceNodeDataKey = {
space: string;
externalId: string;
view: Source;
typing: FdmTyping;
property: string;
};

export type StringTrigger = MetadataRuleTrigger;

export type BooleanCondition = {
type: 'true' | 'false';
parameter: boolean;
};

export type StringCondition = {
type: 'equals' | 'notEquals' | 'contains' | 'startsWith' | 'endsWith';
parameter: string;
};

export type DatetimeCondition =
| {
type:
| 'before'
| 'notBefore'
| 'onOrBefore'
| 'after'
| 'notAfter'
| 'onOrAfter'
| 'on'
| 'notOn';
parameter: string;
}
| {
type: 'between' | 'notBetween';
lowerBound: number;
upperBound: number;
};

export type NumericCondition =
| {
type:
Expand All @@ -52,16 +97,28 @@ export type NumericCondition =

export type StringExpression = {
type: 'stringExpression';
trigger: StringTrigger;
trigger: StringTrigger | FdmRuleTrigger;
condition: StringCondition;
};

export type NumericExpression = {
type: 'numericExpression';
trigger: MetadataRuleTrigger | TimeseriesRuleTrigger;
trigger: MetadataRuleTrigger | TimeseriesRuleTrigger | FdmRuleTrigger;
condition: NumericCondition;
};

export type DatetimeExpression = {
type: 'datetimeExpression';
trigger: FdmRuleTrigger;
condition: DatetimeCondition;
};

export type BooleanExpression = {
type: 'booleanExpression';
trigger: FdmRuleTrigger;
condition: BooleanCondition;
};

export type ExpressionOperator =
| {
type: 'or';
Expand All @@ -76,7 +133,11 @@ export type ExpressionOperator =
expression: Expression;
};

export type ConcreteExpression = StringExpression | NumericExpression;
export type ConcreteExpression =
| StringExpression
| NumericExpression
| DatetimeExpression
| BooleanExpression;

export type Expression = ConcreteExpression | ExpressionOperator;

Expand Down Expand Up @@ -156,6 +217,8 @@ export type FdmRuleOutputSet = {

export type ExpressionOperatorsTypes = 'and' | 'or' | 'not';

export type BooleanConditionTypes = 'true' | 'false';

export type StringConditionTypes = 'equals' | 'notEquals' | 'contains' | 'startsWith' | 'endsWith';

export type NumericConditionTypes =
Expand All @@ -180,11 +243,38 @@ export type NumericOutsideConditionType = {
upperBoundExclusive: number;
};

export type DatetimeConditionTypes =
| 'before'
| 'notBefore'
| 'onOrBefore'
| 'between'
| 'notBetween'
| 'after'
| 'notAfter'
| 'onOrAfter'
| 'on'
| 'notOn';

export type DatetimeBetweenConditionType = {
type: 'between';
lowerBoundInclusive: number;
upperBoundInclusive: number;
};

export type DatetimeNotBetweenConditionType = {
type: 'notBetween';
lowerBoundExclusive: number;
upperBoundExclusive: number;
};

export type CriteriaTypes =
| BooleanConditionTypes
| string
| number
| NumericWithinConditionType
| NumericOutsideConditionType;
| NumericOutsideConditionType
| DatetimeBetweenConditionType
| DatetimeNotBetweenConditionType;

export type RuleAndStyleIndex = {
styleIndex: TreeIndexNodeCollection;
Expand All @@ -196,6 +286,21 @@ export type AssetStylingGroupAndStyleIndex = {
assetStylingGroup: AssetStylingGroup;
};

export type FdmStylingGroupAndStyleIndex = {
styleIndex: TreeIndexNodeCollection;
fdmStylingGroup: FdmAssetStylingGroup;
};

export type AllRuleBasedStylingGroups = {
assetStylingGroup: AssetStylingGroup[];
fdmStylingGroup: FdmAssetStylingGroup[];
};

export type AllMappingStylingGroupAndStyleIndex = {
assetMappingsStylingGroupAndIndex: AssetStylingGroupAndStyleIndex;
fdmStylingGroupAndStyleIndex: FdmStylingGroupAndStyleIndex;
};

export type NodeAndRange = {
treeIndex: number;
nodeId: number;
Expand Down Expand Up @@ -271,7 +376,7 @@ export type EmptyRuleForSelectionProps = {
isNoSelection: boolean;
};

export type TriggerTypeData = TriggerMetadataType | TriggerTimeseriesType;
export type TriggerTypeData = TriggerMetadataType | TriggerTimeseriesType | TriggerFdmType;

export type TriggerMetadataType = {
type: 'metadata';
Expand All @@ -286,4 +391,9 @@ export type TriggerTimeseriesType = {
};
};

export type TriggerFdmType = {
type: 'fdm';
instanceNode: FdmInstanceNodeWithConnectionAndProperties;
};

export type TimeseriesAndDatapoints = Timeseries & Datapoints;
48 changes: 46 additions & 2 deletions react-components/src/data-providers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,56 @@ import {
type ExternalId,
type InternalId,
type Metadata,
type Relationship
type Relationship,
type Node3D
} from '@cognite/sdk/';
import { type DmsUniqueIdentifier, type Source } from './FdmSDK';
import { type NodeItem, type DmsUniqueIdentifier, type Source, type EdgeItem } from './FdmSDK';
import { type FdmCadConnection } from '../components/CacheProvider/types';
import { type FdmPropertyType } from '../components/Reveal3DResources/types';

export type FdmInstanceWithView = DmsUniqueIdentifier & { view: Source };

export type FdmInstanceWithProperties = NodeItem<unknown> | EdgeItem<unknown>;

export type FdmInstanceWithPropertiesAndTyping = {
items: FdmInstanceWithProperties[];
typing: FdmTyping;
};

export type FdmTyping = Record<
string,
Record<
string,
Record<
string,
{
nullable?: boolean;
autoIncrement?: boolean;
defaultValue?: any;
description?: string;
name?: string;
immutable?: boolean;
type: { collation?: string; list?: boolean; type: string };
}
>
>
>;

export type FdmInstanceNodeWithConnectionAndProperties = {
instanceType: 'node';
version: number;
space: string;
externalId: string;
createdTime: number;
lastUpdatedTime: number;
deletedTime: number;
properties: FdmPropertyType<unknown>;
connection?: FdmCadConnection | undefined;
cadNode?: Node3D | undefined;
view?: Source | undefined;
typing: FdmTyping;
};

export type AssetInstanceReference = { assetId: number };
export type InstanceReference = AssetInstanceReference | DmsUniqueIdentifier;

Expand Down

0 comments on commit 7bb3ff2

Please sign in to comment.