Browse Source

Added rolling argument functions autocompletes

pull/12796/head
mpetrov 2 years ago
parent
commit
96f7a90a7b
  1. 5
      ui-ngx/src/app/modules/home/components/calculated-fields/components/dialog/calculated-field-dialog.component.html
  2. 6
      ui-ngx/src/app/modules/home/components/calculated-fields/components/dialog/calculated-field-dialog.component.scss
  3. 2
      ui-ngx/src/app/modules/home/components/calculated-fields/components/test-dialog/calculated-field-script-test-dialog.component.scss
  4. 156
      ui-ngx/src/app/shared/models/calculated-field.models.ts
  5. 3
      ui-ngx/src/assets/locale/locale.constant-en_US.json

5
ui-ngx/src/app/modules/home/components/calculated-fields/components/dialog/calculated-field-dialog.component.html

@ -78,7 +78,7 @@
<div class="tb-form-panel-title tb-required">{{ 'calculated-fields.expression' | translate }}</div> <div class="tb-form-panel-title tb-required">{{ 'calculated-fields.expression' | translate }}</div>
@if (fieldFormGroup.get('type').value === CalculatedFieldType.SIMPLE) { @if (fieldFormGroup.get('type').value === CalculatedFieldType.SIMPLE) {
<mat-form-field class="mt-3" appearance="outline" subscriptSizing="dynamic"> <mat-form-field class="mt-3" appearance="outline" subscriptSizing="dynamic">
<input matInput formControlName="expressionSIMPLE" maxlength="255" [placeholder]="'action.set' | translate" required> <input matInput formControlName="expressionSIMPLE" maxlength="255" [placeholder]="'(temperature - 32) / 1.8'" required>
@if (configFormGroup.get('expressionSIMPLE').errors && configFormGroup.get('expressionSIMPLE').touched) { @if (configFormGroup.get('expressionSIMPLE').errors && configFormGroup.get('expressionSIMPLE').touched) {
<mat-error> <mat-error>
@if (configFormGroup.get('expressionSIMPLE').hasError('required')) { @if (configFormGroup.get('expressionSIMPLE').hasError('required')) {
@ -91,6 +91,9 @@
</mat-error> </mat-error>
} }
</mat-form-field> </mat-form-field>
@if (!configFormGroup.get('expressionSIMPLE').errors || !configFormGroup.get('expressionSIMPLE').touched) {
<span class="tb-form-hint expression-hint">{{ 'calculated-fields.hint.expression' | translate }}</span>
}
} @else { } @else {
<tb-js-func <tb-js-func
required required

6
ui-ngx/src/app/modules/home/components/calculated-fields/components/dialog/calculated-field-dialog.component.scss

@ -17,6 +17,10 @@
.dialog-container { .dialog-container {
width: 869px; width: 869px;
max-width: 100%; max-width: 100%;
.tb-form-hint.expression-hint {
padding-bottom: 0;
}
} }
.script-lang-chip { .script-lang-chip {
@ -40,7 +44,7 @@
&-key { &-key {
color: #C52F00; color: #C52F00;
} }
&-ts, &-time-window, &-values, &-value { &-ts, &-time-window, &-values, &-value, &-func {
color: #7214D0; color: #7214D0;
} }
&-start-ts, &-end-ts, &-limit { &-start-ts, &-end-ts, &-limit {

2
ui-ngx/src/app/modules/home/components/calculated-fields/components/test-dialog/calculated-field-script-test-dialog.component.scss

@ -78,7 +78,7 @@
&-key { &-key {
color: #C52F00; color: #C52F00;
} }
&-ts, &-time-window, &-values, &-value { &-ts, &-time-window, &-values, &-value, &-func {
color: #7214D0; color: #7214D0;
} }
&-start-ts, &-end-ts, &-limit { &-start-ts, &-end-ts, &-limit {

156
ui-ngx/src/app/shared/models/calculated-field.models.ts

@ -29,6 +29,7 @@ import { AliasFilterType } from '@shared/models/alias.models';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { TbEditorCompleter } from '@shared/models/ace/completion.models'; import { TbEditorCompleter } from '@shared/models/ace/completion.models';
import { import {
AceHighlightRule,
AceHighlightRules, AceHighlightRules,
dotOperatorHighlightRule, dotOperatorHighlightRule,
endGroupHighlightRule endGroupHighlightRule
@ -268,12 +269,159 @@ export const CalculatedFieldAttributeValueArgumentAutocomplete = {
} }
}, },
}; };
export const CalculatedFieldRollingValueArgumentFunctionsAutocomplete = {
max: {
meta: 'function',
description: 'Computes the maximum value in the list of rolling argument values. Returns NaN if any value is NaN and ignoreNaN is false.',
args: [
{
name: 'ignoreNaN',
description: 'Whether to ignore NaN values. Equals true by default.',
type: 'boolean',
optional: true,
}
],
return: {
description: 'The maximum value, or NaN if applicable',
type: 'number'
}
},
min: {
meta: 'function',
description: 'Computes the minimum value in the list of rolling argument values. Returns NaN if any value is NaN and ignoreNaN is false.',
args: [
{
name: 'ignoreNaN',
description: 'Whether to ignore NaN values. Equals true by default.',
type: 'boolean',
optional: true,
}
],
return: {
description: 'The minimum value, or NaN if applicable',
type: 'number'
}
},
mean: {
meta: 'function',
description: 'Computes the mean value of the rolling argument values list. Returns NaN if any value is NaN and ignoreNaN is false.',
args: [
{
name: 'ignoreNaN',
description: 'Whether to ignore NaN values. Equals true by default.',
type: 'boolean',
optional: true,
}
],
return: {
description: 'The mean value, or NaN if applicable',
type: 'number'
}
},
std: {
meta: 'function',
description: 'Computes the standard deviation in the list of rolling argument values. Returns NaN if any value is NaN and ignoreNaN is false.',
args: [
{
name: 'ignoreNaN',
description: 'Whether to ignore NaN values. Equals true by default.',
type: 'boolean',
optional: true,
}
],
return: {
description: 'The standard deviation, or NaN if applicable',
type: 'number'
}
},
median: {
meta: 'function',
description: 'Computes the median value of the rolling argument values list. Returns NaN if any value is NaN and ignoreNaN is false.',
args: [
{
name: 'ignoreNaN',
description: 'Whether to ignore NaN values. Equals true by default.',
type: 'boolean',
optional: true,
}
],
return: {
description: 'The median value, or NaN if applicable',
type: 'number'
}
},
count: {
meta: 'function',
description: 'Counts values in the list of rolling argument values. Counts non-NaN values if ignoreNaN is true, otherwise - total size.',
args: [
{
name: 'ignoreNaN',
description: 'Whether to ignore NaN values. Equals true by default.',
type: 'boolean',
optional: true,
}
],
return: {
description: 'The count of values',
type: 'number'
}
},
last: {
meta: 'function',
description: 'Returns the last non-NaN value in the list of rolling argument values if ignoreNaN is true, otherwise - the last value.',
args: [
{
name: 'ignoreNaN',
description: 'Whether to ignore NaN values. Equals true by default.',
type: 'boolean',
optional: true,
}
],
return: {
description: 'The last value, or NaN if applicable',
type: 'number'
}
},
first: {
meta: 'function',
description: 'Returns the first non-NaN value in the list of rolling argument values if ignoreNaN is true, otherwise - the first value.',
args: [
{
name: 'ignoreNaN',
description: 'Whether to ignore NaN values. Equals true by default.',
type: 'boolean',
optional: true,
}
],
return: {
description: 'The first value, or NaN if applicable',
type: 'number'
}
},
sum: {
meta: 'function',
description: 'Computes the sum of values in the list of rolling argument values. Returns NaN if any value is NaN and ignoreNaN is false.',
args: [
{
name: 'ignoreNaN',
description: 'Whether to ignore NaN values. Equals true by default.',
type: 'boolean',
optional: true,
}
],
return: {
description: 'The sum of values, or NaN if applicable',
type: 'number'
}
}
};
export const CalculatedFieldRollingValueArgumentAutocomplete = { export const CalculatedFieldRollingValueArgumentAutocomplete = {
meta: 'object', meta: 'object',
type: '{ values: { ts: number; value: any; }[]; timeWindow: { startTs: number; endTs: number; limit: number } }; }', type: '{ values: { ts: number; value: any; }[]; timeWindow: { startTs: number; endTs: number; limit: number } }; }',
description: 'Calculated field rolling value argument.', description: 'Calculated field rolling value argument.',
children: { children: {
...CalculatedFieldRollingValueArgumentFunctionsAutocomplete,
values: { values: {
meta: 'array', meta: 'array',
type: '{ ts: number; value: any; }[]', type: '{ ts: number; value: any; }[]',
@ -355,6 +503,13 @@ const calculatedFieldSingleArgumentValueHighlightRules: AceHighlightRules = {
], ],
} }
const calculatedFieldRollingArgumentValueFunctionsHighlightRules: Array<AceHighlightRule> =
['max', 'min', 'mean', 'std', 'median', 'count', 'last', 'first', 'sum'].map(funcName => ({
token: 'tb.calculated-field-func',
regex: `\\b${funcName}\\b`,
next: 'no_regex'
}));
const calculatedFieldRollingArgumentValueHighlightRules: AceHighlightRules = { const calculatedFieldRollingArgumentValueHighlightRules: AceHighlightRules = {
calculatedFieldRollingArgumentValue: [ calculatedFieldRollingArgumentValue: [
dotOperatorHighlightRule, dotOperatorHighlightRule,
@ -368,6 +523,7 @@ const calculatedFieldRollingArgumentValueHighlightRules: AceHighlightRules = {
regex: /timeWindow/, regex: /timeWindow/,
next: 'calculatedFieldRollingArgumentTimeWindow' next: 'calculatedFieldRollingArgumentTimeWindow'
}, },
...calculatedFieldRollingArgumentValueFunctionsHighlightRules,
endGroupHighlightRule endGroupHighlightRule
], ],
} }

3
ui-ngx/src/assets/locale/locale.constant-en_US.json

@ -1069,7 +1069,8 @@
"argument-name-duplicate": "Argument with such name already exists.", "argument-name-duplicate": "Argument with such name already exists.",
"argument-name-max-length": "Argument name should be less than 256 characters.", "argument-name-max-length": "Argument name should be less than 256 characters.",
"argument-type-required": "Argument type is required.", "argument-type-required": "Argument type is required.",
"max-args": "Maximum number of arguments reached." "max-args": "Maximum number of arguments reached.",
"expression": "Default expression demonstrates how to transform a temperature from Fahrenheit to Celsius."
} }
}, },
"confirm-on-exit": { "confirm-on-exit": {

Loading…
Cancel
Save