@infomaximum/widget-sdk 5.3.0 → 5.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -850,6 +850,15 @@ declare enum EWidgetIndicatorType {
850
850
  DIMENSION = "DIMENSION",
851
851
  SORTING = "SORTING"
852
852
  }
853
+ declare enum EOuterAggregation {
854
+ avg = "avg",
855
+ median = "median",
856
+ count = "count",
857
+ countDistinct = "countDistinct",
858
+ min = "min",
859
+ max = "max",
860
+ sum = "sum"
861
+ }
853
862
  interface IWidgetIndicator extends IAutoIdentifiedArrayItem {
854
863
  name: string;
855
864
  }
@@ -883,7 +892,10 @@ declare enum EWidgetIndicatorValueModes {
883
892
  /** Готовая формула (как правило, введенная пользователем через редактор формул) */
884
893
  FORMULA = "FORMULA",
885
894
  /** Шаблон формулы, предоставляемый системой */
886
- TEMPLATE = "TEMPLATE"
895
+ TEMPLATE = "TEMPLATE",
896
+ AGGREGATION = "AGGREGATION",
897
+ DURATION = "DURATION",
898
+ CONVERSION = "CONVERSION"
887
899
  }
888
900
  /** Режимы сортировки (на что ссылается сортировка) */
889
901
  declare enum ESortingValueModes {
@@ -921,7 +933,6 @@ type TColumnIndicatorValue = {
921
933
  };
922
934
  /** Общий интерфейс разреза и меры */
923
935
  interface IWidgetColumnIndicator extends IWidgetIndicator {
924
- value?: TColumnIndicatorValue;
925
936
  dbDataType?: string;
926
937
  format?: EFormatTypes;
927
938
  formatting?: EFormattingPresets;
@@ -934,10 +945,14 @@ interface IWidgetDimensionHierarchy<D extends IWidgetDimension = IWidgetDimensio
934
945
  hierarchyDimensions: D[];
935
946
  displayCondition?: TDisplayCondition;
936
947
  }
937
- interface IWidgetDimension extends IWidgetColumnIndicator {
948
+ interface IWidgetDimension extends Omit<IWidgetColumnIndicator, "value"> {
949
+ value?: TColumnIndicatorValue;
938
950
  hideEmptyValues: boolean;
939
951
  }
940
- interface IWidgetMeasure extends IWidgetColumnIndicator {
952
+ interface IWidgetMeasure extends Omit<IWidgetColumnIndicator, "value"> {
953
+ value?: TColumnIndicatorValue | (TWidgetIndicatorAggregationValue & {
954
+ outerAggregation: EOuterAggregation;
955
+ }) | TWidgetIndicatorConversionValue | TWidgetIndicatorDurationValue;
941
956
  }
942
957
  interface IMarkdownMeasure extends IWidgetMeasure {
943
958
  format: EFormatTypes;
@@ -1032,6 +1047,55 @@ interface IWidgetColumnListVariable extends IBaseWidgetVariable {
1032
1047
  }
1033
1048
  type TWidgetVariable = IWidgetStaticVariable | IWidgetStaticListVariable | IWidgetDynamicListVariable | IWidgetColumnListVariable;
1034
1049
  declare function isDimensionsHierarchy(indicator: IWidgetColumnIndicator): indicator is IWidgetDimensionHierarchy;
1050
+ declare enum OuterAggregation {
1051
+ avg = "avgIf",
1052
+ median = "medianIf",
1053
+ count = "countIf",
1054
+ countDistinct = "countIfDistinct",
1055
+ min = "minIf",
1056
+ max = "maxIf",
1057
+ sum = "sumIf"
1058
+ }
1059
+ declare enum EDurationTemplateName {
1060
+ avg = "avg",
1061
+ median = "median"
1062
+ }
1063
+ type TWidgetIndicatorAggregationValue = {
1064
+ mode: EWidgetIndicatorValueModes.AGGREGATION;
1065
+ templateName: string;
1066
+ processName: string | null;
1067
+ eventName: string | null;
1068
+ caseIdFormula: string | null;
1069
+ eventNameFormula: string | null;
1070
+ filters: TExtendedFormulaFilterValue[];
1071
+ tableName?: string;
1072
+ columnName?: string;
1073
+ eventTimeFormula?: string | null;
1074
+ };
1075
+ declare enum EEventAppearances {
1076
+ FIRST = "FIRST",
1077
+ LAST = "LAST"
1078
+ }
1079
+ type TWidgetIndicatorConversionValue = {
1080
+ mode: EWidgetIndicatorValueModes.CONVERSION;
1081
+ startEventNameFormula: string | null;
1082
+ startEventProcessName: string | null;
1083
+ startEventName: string | null;
1084
+ startEventFilters: TExtendedFormulaFilterValue[];
1085
+ startEventTimeFormula: string | null;
1086
+ endEventNameFormula: string | null;
1087
+ endEventProcessName: string | null;
1088
+ endEventName: string | null;
1089
+ endEventFilters: TExtendedFormulaFilterValue[];
1090
+ endCaseCaseIdFormula: string | null;
1091
+ endEventTimeFormula: string | null;
1092
+ };
1093
+ type TWidgetIndicatorDurationValue = {
1094
+ mode: EWidgetIndicatorValueModes.DURATION;
1095
+ templateName: string;
1096
+ startEventAppearances: EEventAppearances;
1097
+ endEventAppearances: EEventAppearances;
1098
+ } & Omit<TWidgetIndicatorConversionValue, "mode">;
1035
1099
 
1036
1100
  /** Формат входного параметра GeneralCalculator */
1037
1101
  interface IBaseDimensionsAndMeasuresCalculatorInput {
@@ -1291,6 +1355,13 @@ declare const escapeSpecialCharacters: (formula: string) => string;
1291
1355
  /** Удалить из строки символы экранирования */
1292
1356
  declare function unescapeSpecialCharacters(str: string): string;
1293
1357
 
1358
+ declare const prepareFormulaForSql: (formula: string, simpleType?: ESimpleDataType) => string;
1359
+ declare const clearSingleLineComments: (formula: string) => string;
1360
+ declare const clearMultiLineComments: (formula: string) => string;
1361
+
1362
+ declare const convertToFormulasChain: (values: TExtendedFormulaFilterValue[]) => string;
1363
+ declare const convertFiltersToFormula: (filters: TExtendedFormulaFilterValue[]) => string;
1364
+
1294
1365
  /** Фабрика вычислителей */
1295
1366
  interface ICalculatorFactory {
1296
1367
  /**
@@ -1390,6 +1461,44 @@ declare const measureTemplateFormulas: {
1390
1461
  readonly max: "max({columnFormula})";
1391
1462
  readonly sum: "sum({columnFormula})";
1392
1463
  };
1464
+ declare const prepareAggregationParams: (value: Extract<IWidgetMeasure["value"], {
1465
+ mode: EWidgetIndicatorValueModes.AGGREGATION;
1466
+ }>) => {
1467
+ outerAggregation: EOuterAggregation;
1468
+ eventNameFormula: string;
1469
+ caseIdFormula: string;
1470
+ eventName: string;
1471
+ objectFilters: string;
1472
+ filters: string;
1473
+ eventTimeFormula: string;
1474
+ columnFormula: string;
1475
+ } | null;
1476
+ declare const prepareConversionParams: (value: TWidgetIndicatorConversionValue) => {
1477
+ objectFilters: string;
1478
+ startEventTimeFormula: string;
1479
+ startEventNameFormula: string;
1480
+ startEventFilters: string;
1481
+ startEventName: string;
1482
+ endEventTimeFormula: string;
1483
+ endCaseCaseIdFormula: string;
1484
+ endEventNameFormula: string;
1485
+ endEventName: string;
1486
+ endEventFilters: string;
1487
+ } | null;
1488
+ declare const prepareDurationParams: (value: TWidgetIndicatorDurationValue) => {
1489
+ objectFilters: string;
1490
+ startEventTimeFormula: string;
1491
+ startEventNameFormula: string;
1492
+ startEventFilters: string;
1493
+ startEventName: string;
1494
+ startEventAggregationName: string;
1495
+ endEventTimeFormula: string;
1496
+ endCaseCaseIdFormula: string;
1497
+ endEventNameFormula: string;
1498
+ endEventName: string;
1499
+ endEventFilters: string;
1500
+ endEventAggregationName: string;
1501
+ } | null;
1393
1502
  declare function getMeasureFormula({ value }: IWidgetMeasure): string;
1394
1503
 
1395
1504
  declare enum EEventMeasureTemplateNames {
@@ -1412,6 +1521,26 @@ declare const transitionMeasureTemplateFormulas: {
1412
1521
  };
1413
1522
  declare function getTransitionMeasureFormula({ value }: IProcessIndicator, process: IWidgetProcess): string;
1414
1523
 
1524
+ declare enum EMeasureAggregationTemplateName {
1525
+ agvIf = "agvIf",
1526
+ medianIf = "medianIf",
1527
+ countIf = "countIf",
1528
+ countIfDistinct = "countIfDistinct",
1529
+ minIf = "minIf",
1530
+ maxIf = "maxIf",
1531
+ sumIf = "sumIf",
1532
+ top = "top",
1533
+ firstValue = "firstValue",
1534
+ lastValue = "lastValue",
1535
+ countExecutions = "countExecutions",
1536
+ countReworks = "countReworks"
1537
+ }
1538
+ declare const conversionTemplate = "countIf(\n process(\n minIf(\n {startEventTimeFormula}, \n {startEventNameFormula} = '{startEventName}'{startEventFilters}\n ), \n {endCaseCaseIdFormula}\n ) < \n process(\n maxIf(\n {endEventTimeFormula}, \n {endEventNameFormula} = '{endEventName}'{endEventFilters}\n ), \n {endCaseCaseIdFormula}\n ) \n and \n process(\n countIf(\n {startEventNameFormula} = '{startEventName}'{startEventFilters}\n ) != 0, \n {endCaseCaseIdFormula}\n ) != 0\n) * 100 / countIf(\n process(\n countIf(\n {startEventNameFormula} = '{startEventName}'{startEventFilters}\n ) != 0, \n {endCaseCaseIdFormula}\n ) != 0\n)";
1539
+ declare const durationTemplates: Record<EDurationTemplateName, string>;
1540
+ declare const countReworksTemplate = "{outerAggregation}If(process(if(countIf({eventNameFormula} = {eventName}) > 0, countIf({eventNameFormula} = {eventName}) - 1, 0), {caseIdFormula}),{objectFilters})";
1541
+ declare const countExecutionsTemplate = "process(countIf({eventNameFormula} in '{eventName}'{filters}), {caseIdFormula}";
1542
+ declare const measureAggregationTemplates: Record<EMeasureAggregationTemplateName, string>;
1543
+
1415
1544
  /**
1416
1545
  * Регулярное выражение для поиска имени ссылки внутри формулы.
1417
1546
  * Учитывает, что имя внутри формулы содержит экраны.
@@ -2022,4 +2151,4 @@ declare global {
2022
2151
  }
2023
2152
  }
2024
2153
 
2025
- export { EActionButtonsTypes, EActionTypes, EBlockingConditionMode, ECalculatorFilterMethods, EClickHouseBaseTypes, EColorMode, EControlType, ECustomSelectTemplates, EDimensionTemplateNames, EDisplayConditionMode, EDrawerPlacement, EDurationUnit, EEventMeasureTemplateNames, EFontWeight, EFormatTypes, EFormattingPresets, EFormulaFilterFieldKeys, EIndicatorType, ELastTimeUnit, EMarkdownDisplayMode, EMeasureTemplateNames, EProcessFilterNames, ESelectOptionTypes, ESimpleDataType, ESimpleInputType, ESortDirection, ESortingValueModes, ESystemRecordKey, ETransitionMeasureTemplateNames, EUnitMode, EViewMode, EViewOpenIn, EWidgetActionInputMethod, EWidgetFilterMode, EWidgetIndicatorType, EWidgetIndicatorValueModes, type IActionGoToUrl, type IActionRunScript, type IActionScript, type IActionUpdateVariable, type IAddButtonSelectOption, type IAddDurationOfTransitionFilter, type IAddPresenceOfEventFilter, type IAddPresenceOfTransitionFilter, type IAddRepetitionOfEventFilter, type IAutoIdentifiedArrayItem, type IBaseDimensionsAndMeasuresCalculator, type IBaseDimensionsAndMeasuresCalculatorInput, type IBaseDimensionsAndMeasuresCalculatorOutput, type IBaseWidgetSettings, type ICalculator, type ICalculatorDimensionInput, type ICalculatorDimensionOutput, type ICalculatorFactory, type ICalculatorFilter, type ICalculatorIndicatorInput, type ICalculatorIndicatorOutput, type ICalculatorMeasureInput, type ICalculatorMeasureOutput, type IColoredValue, type ICommonDimensions, type ICommonMeasures, type ICommonState, type IControlRecord, type ICustomAddButtonProps, type ICustomWidgetProps, type IDefinition, type IDimensionSelection, type IDimensionSelectionByFormula, type IDisplayPredicate, type IDisplayRule, type IDivePanelDescription, type IDividerRecord, type IEdge, type IExportColumnOrder, type IFillSettings, type IFormulaFilterValue, type IGeneralCalculator, type IGeneralCalculatorExportInput, type IGeneralCalculatorInput, type IGeneralCalculatorOutput, type IGlobalContext, type IGraphElement, type IGroupSetDescription, type IGroupSetRecord, type IGroupSettings, type IHistogramBin, type IHistogramCalculator, type IHistogramCalculatorInput, type IHistogramCalculatorOutput, type IIndicatorLink, type IInitialSettings, type ILens, type IMarkdownMeasure, type IMeasureAddButtonProps, type IPanelDescription, type IPanelDescriptionCreator, type IPieCalculator, type IPieCalculatorInput, type IPieCalculatorOutput, type IProcessEventFilterValue, type IProcessEventIndicator, type IProcessGraphCalculator, type IProcessGraphCalculatorInput, type IProcessGraphCalculatorOutput, type IProcessIndicator, type IProcessTransitionFilterValue, type IProcessTransitionIndicator, type IRange, type ISelectBranchOption, type ISelectDividerOption, type ISelectGroupOption, type ISelectLeafOption, type ISelectNode, type ISelectOption, type ISelectSystemOption, type ISettingsMigratorParams, type ISortOrder, type ISortingAddButtonProps, type IStagesFilterValue, type IStaticListLabeledOption, type ITwoLimitsCalculator, type ITwoLimitsCalculatorExportInput, type ITwoLimitsCalculatorInput, type ITwoLimitsCalculatorOutput, type ITypeCalculator, type ITypeCalculatorInput, type ITypeCalculatorOutput, type ITypeCalculatorOutputItem, type IVertex, type IViewContext, type IWidget, type IWidgetAction, type IWidgetColumnIndicator, type IWidgetColumnListVariable, type IWidgetDimension, type IWidgetDimensionHierarchy, type IWidgetDynamicListVariable, type IWidgetEntity, type IWidgetFilter, type IWidgetFiltration, type IWidgetFormatting, type IWidgetIndicator, type IWidgetIndicatorAddButtonProps, type IWidgetManifest, type IWidgetMeasure, type IWidgetMigrator, type IWidgetPersistValue, type IWidgetPlaceholderController, type IWidgetPlaceholderValues, type IWidgetPresetSettings, type IWidgetProcess, type IWidgetProps, type IWidgetSortingIndicator, type IWidgetStaticListVariable, type IWidgetStaticVariable, type IWidgetStruct, type IWidgetTable, type IWidgetTableColumn, type TAction, type TActionOnClickParameter, type TActionOpenView, type TActionValidator, type TActionsOnClick, type TAddButton, type TAppearanceSettings, type TBoundedContentWithIndicator, type TColor, type TColorBase, type TColorRule, type TColumnIndicatorValue, type TContextMenu, type TContextMenuButton, type TContextMenuButtonActions, type TContextMenuButtonApply, type TContextMenuButtonClose, type TContextMenuButtonCustom, type TContextMenuButtonGroup, type TContextMenuButtonOptions, type TContextMenuList, type TContextMenuPositionUnit, type TContextMenuRow, type TCustomAddButtonSelectOption, type TDefineWidgetOptions, type TDisplayCondition, type TDisplayMode, type TEmptyRecord, type TExtendedFormulaFilterValue, type TFiltrationAccessibility, type TGroupLevelRecord, type TLaunchActionParams, type TMeasureAddButtonSelectOption, type TMigrateProcessor, type TMigrationStruct, type TProcessIndicatorValue, type TRecordAccessor, type TSelectChildOptions, type TSelectFetchNodes, type TSelectivePartial, type TSortDirection, type TUpdateSelection, type TValuePath, type TVersion, type TWidgetActionParameter, type TWidgetContainer, type TWidgetDimensionData, type TWidgetFilterValue, type TWidgetFiltering, type TWidgetIndicatorData, type TWidgetLevelRecord, type TWidgetSortingValue, type TWidgetVariable, bindContentWithIndicator, bindContentsWithIndicators, checkDisplayCondition, colors, dashboardLinkRegExp, dimensionTemplateFormulas, escapeSpecialCharacters, eventMeasureTemplateFormulas, fillTemplateString, formattingConfig, formulaFilterMethods, generateColumnFormula, getColorByIndex, getDefaultSortOrders, getDimensionFormula, getDisplayConditionFormula, getEventMeasureFormula, getLocalizedText, getMeasureFormula, getRuleColor, getTransitionMeasureFormula, isDimensionsHierarchy, isFormulaFilterValue, isValidColor, linkNameRegExp, mapDimensionsToInputs, mapEventMeasuresToInputs, mapFormulaFilterToCalculatorInput, mapFormulaFiltersToInputs, mapMeasuresToInputs, mapSortingToInputs, mapTransitionMeasuresToInputs, measureTemplateFormulas, parseClickHouseType, parseIndicatorLink, prepareSortOrders, prepareValuesForSql, replaceDisplayCondition, replaceFiltersBySelection, replaceHierarchiesWithDimensions, selectDimensionFromHierarchy, transitionMeasureTemplateFormulas, unescapeSpecialCharacters, updateDefaultModeSelection, updateMultiModeSelection, updateSingleModeSelection, workspaceLinkRegExp };
2154
+ export { EActionButtonsTypes, EActionTypes, EBlockingConditionMode, ECalculatorFilterMethods, EClickHouseBaseTypes, EColorMode, EControlType, ECustomSelectTemplates, EDimensionTemplateNames, EDisplayConditionMode, EDrawerPlacement, EDurationTemplateName, EDurationUnit, EEventAppearances, EEventMeasureTemplateNames, EFontWeight, EFormatTypes, EFormattingPresets, EFormulaFilterFieldKeys, EIndicatorType, ELastTimeUnit, EMarkdownDisplayMode, EMeasureAggregationTemplateName, EMeasureTemplateNames, EOuterAggregation, EProcessFilterNames, ESelectOptionTypes, ESimpleDataType, ESimpleInputType, ESortDirection, ESortingValueModes, ESystemRecordKey, ETransitionMeasureTemplateNames, EUnitMode, EViewMode, EViewOpenIn, EWidgetActionInputMethod, EWidgetFilterMode, EWidgetIndicatorType, EWidgetIndicatorValueModes, type IActionGoToUrl, type IActionRunScript, type IActionScript, type IActionUpdateVariable, type IAddButtonSelectOption, type IAddDurationOfTransitionFilter, type IAddPresenceOfEventFilter, type IAddPresenceOfTransitionFilter, type IAddRepetitionOfEventFilter, type IAutoIdentifiedArrayItem, type IBaseDimensionsAndMeasuresCalculator, type IBaseDimensionsAndMeasuresCalculatorInput, type IBaseDimensionsAndMeasuresCalculatorOutput, type IBaseWidgetSettings, type ICalculator, type ICalculatorDimensionInput, type ICalculatorDimensionOutput, type ICalculatorFactory, type ICalculatorFilter, type ICalculatorIndicatorInput, type ICalculatorIndicatorOutput, type ICalculatorMeasureInput, type ICalculatorMeasureOutput, type IColoredValue, type ICommonDimensions, type ICommonMeasures, type ICommonState, type IControlRecord, type ICustomAddButtonProps, type ICustomWidgetProps, type IDefinition, type IDimensionSelection, type IDimensionSelectionByFormula, type IDisplayPredicate, type IDisplayRule, type IDivePanelDescription, type IDividerRecord, type IEdge, type IExportColumnOrder, type IFillSettings, type IFormulaFilterValue, type IGeneralCalculator, type IGeneralCalculatorExportInput, type IGeneralCalculatorInput, type IGeneralCalculatorOutput, type IGlobalContext, type IGraphElement, type IGroupSetDescription, type IGroupSetRecord, type IGroupSettings, type IHistogramBin, type IHistogramCalculator, type IHistogramCalculatorInput, type IHistogramCalculatorOutput, type IIndicatorLink, type IInitialSettings, type ILens, type IMarkdownMeasure, type IMeasureAddButtonProps, type IPanelDescription, type IPanelDescriptionCreator, type IPieCalculator, type IPieCalculatorInput, type IPieCalculatorOutput, type IProcessEventFilterValue, type IProcessEventIndicator, type IProcessGraphCalculator, type IProcessGraphCalculatorInput, type IProcessGraphCalculatorOutput, type IProcessIndicator, type IProcessTransitionFilterValue, type IProcessTransitionIndicator, type IRange, type ISelectBranchOption, type ISelectDividerOption, type ISelectGroupOption, type ISelectLeafOption, type ISelectNode, type ISelectOption, type ISelectSystemOption, type ISettingsMigratorParams, type ISortOrder, type ISortingAddButtonProps, type IStagesFilterValue, type IStaticListLabeledOption, type ITwoLimitsCalculator, type ITwoLimitsCalculatorExportInput, type ITwoLimitsCalculatorInput, type ITwoLimitsCalculatorOutput, type ITypeCalculator, type ITypeCalculatorInput, type ITypeCalculatorOutput, type ITypeCalculatorOutputItem, type IVertex, type IViewContext, type IWidget, type IWidgetAction, type IWidgetColumnIndicator, type IWidgetColumnListVariable, type IWidgetDimension, type IWidgetDimensionHierarchy, type IWidgetDynamicListVariable, type IWidgetEntity, type IWidgetFilter, type IWidgetFiltration, type IWidgetFormatting, type IWidgetIndicator, type IWidgetIndicatorAddButtonProps, type IWidgetManifest, type IWidgetMeasure, type IWidgetMigrator, type IWidgetPersistValue, type IWidgetPlaceholderController, type IWidgetPlaceholderValues, type IWidgetPresetSettings, type IWidgetProcess, type IWidgetProps, type IWidgetSortingIndicator, type IWidgetStaticListVariable, type IWidgetStaticVariable, type IWidgetStruct, type IWidgetTable, type IWidgetTableColumn, OuterAggregation, type TAction, type TActionOnClickParameter, type TActionOpenView, type TActionValidator, type TActionsOnClick, type TAddButton, type TAppearanceSettings, type TBoundedContentWithIndicator, type TColor, type TColorBase, type TColorRule, type TColumnIndicatorValue, type TContextMenu, type TContextMenuButton, type TContextMenuButtonActions, type TContextMenuButtonApply, type TContextMenuButtonClose, type TContextMenuButtonCustom, type TContextMenuButtonGroup, type TContextMenuButtonOptions, type TContextMenuList, type TContextMenuPositionUnit, type TContextMenuRow, type TCustomAddButtonSelectOption, type TDefineWidgetOptions, type TDisplayCondition, type TDisplayMode, type TEmptyRecord, type TExtendedFormulaFilterValue, type TFiltrationAccessibility, type TGroupLevelRecord, type TLaunchActionParams, type TMeasureAddButtonSelectOption, type TMigrateProcessor, type TMigrationStruct, type TProcessIndicatorValue, type TRecordAccessor, type TSelectChildOptions, type TSelectFetchNodes, type TSelectivePartial, type TSortDirection, type TUpdateSelection, type TValuePath, type TVersion, type TWidgetActionParameter, type TWidgetContainer, type TWidgetDimensionData, type TWidgetFilterValue, type TWidgetFiltering, type TWidgetIndicatorAggregationValue, type TWidgetIndicatorConversionValue, type TWidgetIndicatorData, type TWidgetIndicatorDurationValue, type TWidgetLevelRecord, type TWidgetSortingValue, type TWidgetVariable, bindContentWithIndicator, bindContentsWithIndicators, checkDisplayCondition, clearMultiLineComments, clearSingleLineComments, colors, conversionTemplate, convertFiltersToFormula, convertToFormulasChain, countExecutionsTemplate, countReworksTemplate, dashboardLinkRegExp, dimensionTemplateFormulas, durationTemplates, escapeSpecialCharacters, eventMeasureTemplateFormulas, fillTemplateString, formattingConfig, formulaFilterMethods, generateColumnFormula, getColorByIndex, getDefaultSortOrders, getDimensionFormula, getDisplayConditionFormula, getEventMeasureFormula, getLocalizedText, getMeasureFormula, getRuleColor, getTransitionMeasureFormula, isDimensionsHierarchy, isFormulaFilterValue, isValidColor, linkNameRegExp, mapDimensionsToInputs, mapEventMeasuresToInputs, mapFormulaFilterToCalculatorInput, mapFormulaFiltersToInputs, mapMeasuresToInputs, mapSortingToInputs, mapTransitionMeasuresToInputs, measureAggregationTemplates, measureTemplateFormulas, parseClickHouseType, parseIndicatorLink, prepareAggregationParams, prepareConversionParams, prepareDurationParams, prepareFormulaForSql, prepareSortOrders, prepareValuesForSql, replaceDisplayCondition, replaceFiltersBySelection, replaceHierarchiesWithDimensions, selectDimensionFromHierarchy, transitionMeasureTemplateFormulas, unescapeSpecialCharacters, updateDefaultModeSelection, updateMultiModeSelection, updateSingleModeSelection, workspaceLinkRegExp };
package/dist/index.esm.js CHANGED
@@ -71,13 +71,13 @@ var prepareValuesForSql = function (simpleType, values) {
71
71
  simpleType === ESimpleDataType.BOOLEAN
72
72
  ? values
73
73
  : values.map(function (value) {
74
- return value === null ? null : "'".concat(escapeSingularQuotes(escapeReverseSlash(value)), "'");
74
+ return value === null ? null : "'".concat(escapeSingularQuotes$1(escapeReverseSlash(value)), "'");
75
75
  });
76
76
  };
77
77
  var escapeReverseSlash = function (formula) {
78
78
  return formula.replaceAll(/\\/gm, "\\\\");
79
79
  };
80
- var escapeSingularQuotes = function (formula) {
80
+ var escapeSingularQuotes$1 = function (formula) {
81
81
  return formula.replaceAll("'", "\\'");
82
82
  };
83
83
 
@@ -799,6 +799,16 @@ var EWidgetIndicatorType;
799
799
  EWidgetIndicatorType["DIMENSION"] = "DIMENSION";
800
800
  EWidgetIndicatorType["SORTING"] = "SORTING";
801
801
  })(EWidgetIndicatorType || (EWidgetIndicatorType = {}));
802
+ var EOuterAggregation;
803
+ (function (EOuterAggregation) {
804
+ EOuterAggregation["avg"] = "avg";
805
+ EOuterAggregation["median"] = "median";
806
+ EOuterAggregation["count"] = "count";
807
+ EOuterAggregation["countDistinct"] = "countDistinct";
808
+ EOuterAggregation["min"] = "min";
809
+ EOuterAggregation["max"] = "max";
810
+ EOuterAggregation["sum"] = "sum";
811
+ })(EOuterAggregation || (EOuterAggregation = {}));
802
812
  /** Режимы значения показателя (на основе чего генерируется формула) */
803
813
  var EWidgetIndicatorValueModes;
804
814
  (function (EWidgetIndicatorValueModes) {
@@ -806,6 +816,9 @@ var EWidgetIndicatorValueModes;
806
816
  EWidgetIndicatorValueModes["FORMULA"] = "FORMULA";
807
817
  /** Шаблон формулы, предоставляемый системой */
808
818
  EWidgetIndicatorValueModes["TEMPLATE"] = "TEMPLATE";
819
+ EWidgetIndicatorValueModes["AGGREGATION"] = "AGGREGATION";
820
+ EWidgetIndicatorValueModes["DURATION"] = "DURATION";
821
+ EWidgetIndicatorValueModes["CONVERSION"] = "CONVERSION";
809
822
  })(EWidgetIndicatorValueModes || (EWidgetIndicatorValueModes = {}));
810
823
  /** Режимы сортировки (на что ссылается сортировка) */
811
824
  var ESortingValueModes;
@@ -854,8 +867,28 @@ var ESimpleInputType;
854
867
  function isDimensionsHierarchy(indicator) {
855
868
  return "hierarchyDimensions" in indicator;
856
869
  }
870
+ var OuterAggregation;
871
+ (function (OuterAggregation) {
872
+ OuterAggregation["avg"] = "avgIf";
873
+ OuterAggregation["median"] = "medianIf";
874
+ OuterAggregation["count"] = "countIf";
875
+ OuterAggregation["countDistinct"] = "countIfDistinct";
876
+ OuterAggregation["min"] = "minIf";
877
+ OuterAggregation["max"] = "maxIf";
878
+ OuterAggregation["sum"] = "sumIf";
879
+ })(OuterAggregation || (OuterAggregation = {}));
880
+ var EDurationTemplateName;
881
+ (function (EDurationTemplateName) {
882
+ EDurationTemplateName["avg"] = "avg";
883
+ EDurationTemplateName["median"] = "median";
884
+ })(EDurationTemplateName || (EDurationTemplateName = {}));
885
+ var EEventAppearances;
886
+ (function (EEventAppearances) {
887
+ EEventAppearances["FIRST"] = "FIRST";
888
+ EEventAppearances["LAST"] = "LAST";
889
+ })(EEventAppearances || (EEventAppearances = {}));
857
890
 
858
- var _a$3;
891
+ var _a$4;
859
892
  var EDimensionTemplateNames;
860
893
  (function (EDimensionTemplateNames) {
861
894
  EDimensionTemplateNames["dateTime"] = "dateTime";
@@ -870,19 +903,19 @@ var EDimensionTemplateNames;
870
903
  EDimensionTemplateNames["dayOfWeek"] = "dayOfWeek";
871
904
  EDimensionTemplateNames["hour"] = "hour";
872
905
  })(EDimensionTemplateNames || (EDimensionTemplateNames = {}));
873
- var dimensionTemplateFormulas = (_a$3 = {},
874
- _a$3[EDimensionTemplateNames.dateTime] = "toDateTime({columnFormula})",
875
- _a$3[EDimensionTemplateNames.date] = "toDate({columnFormula})",
876
- _a$3[EDimensionTemplateNames.year] = "if(defaultValueOfArgumentType({columnFormula}) = {columnFormula}, 0, toYear({columnFormula}))",
877
- _a$3[EDimensionTemplateNames.yearAndQuarter] = "if(defaultValueOfArgumentType({columnFormula}) = {columnFormula}, 0, toYear({columnFormula}) * 10 + toQuarter({columnFormula}))",
878
- _a$3[EDimensionTemplateNames.quarter] = "if(defaultValueOfArgumentType({columnFormula}) = {columnFormula}, 0, toQuarter({columnFormula}))",
879
- _a$3[EDimensionTemplateNames.yearAndMonth] = "if(defaultValueOfArgumentType({columnFormula}) = {columnFormula}, 0, toYYYYMM({columnFormula}))",
880
- _a$3[EDimensionTemplateNames.month] = "if(defaultValueOfArgumentType({columnFormula}) = {columnFormula}, 0, toMonth({columnFormula}))",
881
- _a$3[EDimensionTemplateNames.dayOfMonth] = "if(defaultValueOfArgumentType({columnFormula}) = {columnFormula}, 0, toDayOfMonth({columnFormula}))",
882
- _a$3[EDimensionTemplateNames.week] = "if(defaultValueOfArgumentType({columnFormula}) = {columnFormula}, 0, toWeek({columnFormula}))",
883
- _a$3[EDimensionTemplateNames.dayOfWeek] = "if(defaultValueOfArgumentType({columnFormula}) = {columnFormula}, 0, toDayOfWeek({columnFormula}))",
884
- _a$3[EDimensionTemplateNames.hour] = "if(defaultValueOfArgumentType({columnFormula}) = {columnFormula}, 0, toHour({columnFormula}))",
885
- _a$3);
906
+ var dimensionTemplateFormulas = (_a$4 = {},
907
+ _a$4[EDimensionTemplateNames.dateTime] = "toDateTime({columnFormula})",
908
+ _a$4[EDimensionTemplateNames.date] = "toDate({columnFormula})",
909
+ _a$4[EDimensionTemplateNames.year] = "if(defaultValueOfArgumentType({columnFormula}) = {columnFormula}, 0, toYear({columnFormula}))",
910
+ _a$4[EDimensionTemplateNames.yearAndQuarter] = "if(defaultValueOfArgumentType({columnFormula}) = {columnFormula}, 0, toYear({columnFormula}) * 10 + toQuarter({columnFormula}))",
911
+ _a$4[EDimensionTemplateNames.quarter] = "if(defaultValueOfArgumentType({columnFormula}) = {columnFormula}, 0, toQuarter({columnFormula}))",
912
+ _a$4[EDimensionTemplateNames.yearAndMonth] = "if(defaultValueOfArgumentType({columnFormula}) = {columnFormula}, 0, toYYYYMM({columnFormula}))",
913
+ _a$4[EDimensionTemplateNames.month] = "if(defaultValueOfArgumentType({columnFormula}) = {columnFormula}, 0, toMonth({columnFormula}))",
914
+ _a$4[EDimensionTemplateNames.dayOfMonth] = "if(defaultValueOfArgumentType({columnFormula}) = {columnFormula}, 0, toDayOfMonth({columnFormula}))",
915
+ _a$4[EDimensionTemplateNames.week] = "if(defaultValueOfArgumentType({columnFormula}) = {columnFormula}, 0, toWeek({columnFormula}))",
916
+ _a$4[EDimensionTemplateNames.dayOfWeek] = "if(defaultValueOfArgumentType({columnFormula}) = {columnFormula}, 0, toDayOfWeek({columnFormula}))",
917
+ _a$4[EDimensionTemplateNames.hour] = "if(defaultValueOfArgumentType({columnFormula}) = {columnFormula}, 0, toHour({columnFormula}))",
918
+ _a$4);
886
919
  function getDimensionFormula(_a) {
887
920
  var _b;
888
921
  var value = _a.value;
@@ -905,6 +938,135 @@ function getDimensionFormula(_a) {
905
938
  return "";
906
939
  }
907
940
 
941
+ var _a$3, _b;
942
+ var EMeasureAggregationTemplateName;
943
+ (function (EMeasureAggregationTemplateName) {
944
+ EMeasureAggregationTemplateName["agvIf"] = "agvIf";
945
+ EMeasureAggregationTemplateName["medianIf"] = "medianIf";
946
+ EMeasureAggregationTemplateName["countIf"] = "countIf";
947
+ EMeasureAggregationTemplateName["countIfDistinct"] = "countIfDistinct";
948
+ EMeasureAggregationTemplateName["minIf"] = "minIf";
949
+ EMeasureAggregationTemplateName["maxIf"] = "maxIf";
950
+ EMeasureAggregationTemplateName["sumIf"] = "sumIf";
951
+ EMeasureAggregationTemplateName["top"] = "top";
952
+ EMeasureAggregationTemplateName["firstValue"] = "firstValue";
953
+ EMeasureAggregationTemplateName["lastValue"] = "lastValue";
954
+ EMeasureAggregationTemplateName["countExecutions"] = "countExecutions";
955
+ EMeasureAggregationTemplateName["countReworks"] = "countReworks";
956
+ })(EMeasureAggregationTemplateName || (EMeasureAggregationTemplateName = {}));
957
+ var conversionTemplate = "countIf(\n process(\n minIf(\n {startEventTimeFormula}, \n {startEventNameFormula} = '{startEventName}'{startEventFilters}\n ), \n {endCaseCaseIdFormula}\n ) < \n process(\n maxIf(\n {endEventTimeFormula}, \n {endEventNameFormula} = '{endEventName}'{endEventFilters}\n ), \n {endCaseCaseIdFormula}\n ) \n and \n process(\n countIf(\n {startEventNameFormula} = '{startEventName}'{startEventFilters}\n ) != 0, \n {endCaseCaseIdFormula}\n ) != 0\n) * 100 / countIf(\n process(\n countIf(\n {startEventNameFormula} = '{startEventName}'{startEventFilters}\n ) != 0, \n {endCaseCaseIdFormula}\n ) != 0\n)";
958
+ var durationTemplate = "\n timeDiff(\n process(\n {startEventAggregationName}(\n {startEventTimeFormula}, \n {startEventNameFormula} = '{startEventName}'{startEventFilters}\n ), \n {endCaseCaseIdFormula}\n ), \n process(\n {endEventAggregationName}(\n {endEventTimeFormula}, \n {endEventNameFormula} = '{endEventName}'{endEventFilters}\n ), \n {endCaseCaseIdFormula}\n )\n ), \n process(\n {startEventAggregationName}(\n {startEventTimeFormula}, \n {startEventNameFormula} = '{startEventName}'{startEventFilters}\n ), \n {endCaseCaseIdFormula}\n ) < \n process(\n {endEventAggregationName}(\n {endEventTimeFormula}, \n {endEventNameFormula} = '{endEventName}'{endEventFilters}\n ), \n {endCaseCaseIdFormula}\n ) \n and \n process(\n countIf(\n {startEventNameFormula} = '{startEventName}'{startEventFilters}\n ) != 0, \n {endCaseCaseIdFormula}\n ) != 0\n";
959
+ var durationTemplates = (_a$3 = {},
960
+ _a$3[EDurationTemplateName.avg] = "avgIf(".concat(durationTemplate, ")"),
961
+ _a$3[EDurationTemplateName.median] = "medianIf(".concat(durationTemplate, ")"),
962
+ _a$3);
963
+ var countReworksTemplate = "{outerAggregation}If(process(if(countIf({eventNameFormula} = {eventName}) > 0, countIf({eventNameFormula} = {eventName}) - 1, 0), {caseIdFormula}),{objectFilters})";
964
+ var countExecutionsTemplate = "process(countIf({eventNameFormula} in '{eventName}'{filters}), {caseIdFormula}";
965
+ var measureAggregationTemplates = (_b = {},
966
+ _b[EMeasureAggregationTemplateName.agvIf] = "{outerAggregation}If(process(avgIf({columnFormula}, {eventNameFormula} = '{eventName}'{filters}), {caseIdFormula}), {objectFilters})",
967
+ _b[EMeasureAggregationTemplateName.medianIf] = "{outerAggregation}If(process(medianIf({columnFormula}, {eventNameFormula} = '{eventName}'{filters}), {caseIdFormula}), {objectFilters})",
968
+ _b[EMeasureAggregationTemplateName.countIf] = "{outerAggregation}If(process(countIf({eventNameFormula} = '{eventName}'{filters}), {caseIdFormula}), {objectFilters})",
969
+ _b[EMeasureAggregationTemplateName.countIfDistinct] = "{outerAggregation}If(process(countIf(distinct {columnFormula}, {eventNameFormula} = '{eventName}'{filters}), {caseIdFormula}), {objectFilters})",
970
+ _b[EMeasureAggregationTemplateName.minIf] = "{outerAggregation}If(process(minIf({columnFormula}, {eventNameFormula} = '{eventName}'{filters}), {caseIdFormula}), {objectFilters})",
971
+ _b[EMeasureAggregationTemplateName.maxIf] = "{outerAggregation}If(process(maxIf({columnFormula}, {eventNameFormula} = '{eventName}'{filters}), {caseIdFormula}), {objectFilters})",
972
+ _b[EMeasureAggregationTemplateName.sumIf] = "{outerAggregation}If(process(sumIf({columnFormula}, {eventNameFormula} = '{eventName}'{filters}), {caseIdFormula}), {objectFilters})",
973
+ _b[EMeasureAggregationTemplateName.top] = "{outerAggregation}If(process(topKIf(1)({columnFormula}, {eventNameFormula} = '{eventName}'{filters})[1], {caseIdFormula}), {objectFilters})",
974
+ _b[EMeasureAggregationTemplateName.firstValue] = "{outerAggregation}If(process(argMinIf({columnFormula}, {eventTimeFormula}, {eventNameFormula} = '{eventName}'{filters}), {caseIdFormula}), {objectFilters})",
975
+ _b[EMeasureAggregationTemplateName.lastValue] = "{outerAggregation}If(process(argMaxIf({columnFormula}, {eventTimeFormula}, {eventNameFormula} = '{eventName}'{filters}), {caseIdFormula}), {objectFilters})",
976
+ _b[EMeasureAggregationTemplateName.countExecutions] = "{outerAggregation}If(".concat(countExecutionsTemplate, "),{objectFilters})"),
977
+ _b[EMeasureAggregationTemplateName.countReworks] = countReworksTemplate,
978
+ _b);
979
+
980
+ var escapeSingularQuotes = function (formula) {
981
+ if (typeof formula !== "string") {
982
+ return formula;
983
+ }
984
+ return formula.replaceAll("'", "\\'");
985
+ };
986
+
987
+ var prepareFormulaForSql = function (formula, simpleType) {
988
+ formula = clearSingleLineComments(clearMultiLineComments(formula)).trim();
989
+ return simpleType === ESimpleDataType.OTHER ? "toString(".concat(formula, ")") : formula;
990
+ };
991
+ var clearSingleLineComments = function (formula) {
992
+ return formula.replaceAll(/--.*$/gm, "");
993
+ };
994
+ var clearMultiLineComments = function (formula) {
995
+ return formula.replace(/\/\*[\s\S]*?\*\//g, "");
996
+ };
997
+
998
+ function isDateSimpleType(simpleType) {
999
+ return [ESimpleDataType.DATE, ESimpleDataType.DATETIME, ESimpleDataType.DATETIME64].includes(simpleType);
1000
+ }
1001
+ var castToDateValue = function (simpleType) { return function (value) {
1002
+ return simpleType === ESimpleDataType.DATE ? "toDate('".concat(value, "')") : "toDateTime('".concat(value, "')");
1003
+ }; };
1004
+ var convertCalculatorFilterToFormula = function (calculatorFilter) {
1005
+ var filterValueFormula = calculatorFilter.formula, filteringMethod = calculatorFilter.filteringMethod, dbDataType = calculatorFilter.dbDataType, rawValues = calculatorFilter.values;
1006
+ var simpleType = parseClickHouseType(dbDataType).simpleType;
1007
+ var formula = prepareFormulaForSql(filterValueFormula, simpleType);
1008
+ var values = isDateSimpleType(simpleType)
1009
+ ? rawValues.map(castToDateValue(simpleType))
1010
+ : rawValues.map(function (value) {
1011
+ return simpleType === ESimpleDataType.INTEGER ||
1012
+ simpleType === ESimpleDataType.FLOAT ||
1013
+ value === null
1014
+ ? value
1015
+ : "'".concat(escapeSingularQuotes(value), "'");
1016
+ });
1017
+ switch (filteringMethod) {
1018
+ case formulaFilterMethods.EQUAL_TO:
1019
+ return "".concat(formula, " = ").concat(values[0]);
1020
+ case formulaFilterMethods.NOT_EQUAL_TO:
1021
+ return "".concat(formula, " != ").concat(values[0]);
1022
+ case formulaFilterMethods.GREATER_THAN:
1023
+ return "".concat(formula, " > ").concat(values[0]);
1024
+ case formulaFilterMethods.GREATER_THAN_OR_EQUAL_TO:
1025
+ return "".concat(formula, " >= ").concat(values[0]);
1026
+ case formulaFilterMethods.LESS_THAN:
1027
+ return "".concat(formula, " < ").concat(values[0]);
1028
+ case formulaFilterMethods.LESS_THAN_OR_EQUAL_TO:
1029
+ return "".concat(formula, " <= ").concat(values[0]);
1030
+ case formulaFilterMethods.STARTS_WITH:
1031
+ return "startsWith(".concat(formula, ", ").concat(values[0], ")");
1032
+ case formulaFilterMethods.ENDS_WITH:
1033
+ return "endsWith(".concat(formula, ", ").concat(values[0], ")");
1034
+ case formulaFilterMethods.CONTAINS:
1035
+ return "ilike(".concat(formula, ", ").concat(values[0], ")");
1036
+ case formulaFilterMethods.NOT_CONTAINS:
1037
+ return "not ilike(".concat(formula, ", ").concat(values[0], ")");
1038
+ case formulaFilterMethods.EMPTY:
1039
+ return "assumeNotNull(".concat(formula, ") = assumeNotNull(defaultValueOfArgumentType(").concat(formula, "))");
1040
+ case formulaFilterMethods.NONEMPTY:
1041
+ return "assumeNotNull(".concat(formula, ") != assumeNotNull(defaultValueOfArgumentType(").concat(formula, "))");
1042
+ case formulaFilterMethods.INCLUDE:
1043
+ return "".concat(formula, " IN [").concat(String(values), "]");
1044
+ case formulaFilterMethods.EXCLUDE:
1045
+ return "".concat(formula, " NOT IN [").concat(String(values), "]");
1046
+ case formulaFilterMethods.IN_RANGE:
1047
+ case formulaFilterMethods.LAST_TIME:
1048
+ return "".concat(formula, " BETWEEN ").concat(values[0], " AND ").concat(values[1]);
1049
+ case formulaFilterMethods.NOT_IN_RANGE:
1050
+ return "".concat(formula, " NOT BETWEEN ").concat(values[0], " AND ").concat(values[1]);
1051
+ }
1052
+ };
1053
+ function convertToFormula(filterValue) {
1054
+ var calculatorFilter = mapFormulaFilterToCalculatorInput(filterValue);
1055
+ if (!calculatorFilter) {
1056
+ return;
1057
+ }
1058
+ return convertCalculatorFilterToFormula(calculatorFilter);
1059
+ }
1060
+ var convertToFormulasChain = function (values) {
1061
+ return compactMap(values, function (value) {
1062
+ var formula = isFormulaFilterValue(value) ? convertToFormula(value) : value.formula;
1063
+ return formula && "(".concat(formula, ")");
1064
+ }).join(" AND ");
1065
+ };
1066
+ var convertFiltersToFormula = function (filters) {
1067
+ return filters.length > 0 ? " AND ".concat(convertToFormulasChain(filters)) : "";
1068
+ };
1069
+
908
1070
  var _a$2;
909
1071
  var EMeasureTemplateNames;
910
1072
  (function (EMeasureTemplateNames) {
@@ -925,6 +1087,95 @@ var measureTemplateFormulas = (_a$2 = {},
925
1087
  _a$2[EMeasureTemplateNames.max] = "max({columnFormula})",
926
1088
  _a$2[EMeasureTemplateNames.sum] = "sum({columnFormula})",
927
1089
  _a$2);
1090
+ var prepareAggregationParams = function (value) {
1091
+ if (!value.eventName ||
1092
+ !value.caseIdFormula ||
1093
+ !value.eventNameFormula ||
1094
+ !value.outerAggregation ||
1095
+ !value.processName ||
1096
+ !value.templateName) {
1097
+ return null;
1098
+ }
1099
+ var commonParams = {
1100
+ outerAggregation: value.outerAggregation,
1101
+ eventNameFormula: value.eventNameFormula,
1102
+ caseIdFormula: value.caseIdFormula,
1103
+ eventName: value.eventName,
1104
+ objectFilters: "1",
1105
+ filters: convertFiltersToFormula(value.filters),
1106
+ eventTimeFormula: "",
1107
+ columnFormula: "",
1108
+ };
1109
+ if (value.templateName === "countReworks" || value.templateName === "countExecutions") {
1110
+ return commonParams;
1111
+ }
1112
+ if (!value.tableName || !value.columnName) {
1113
+ return null;
1114
+ }
1115
+ var columnParams = __assign(__assign({}, commonParams), { columnFormula: generateColumnFormula(value.tableName, value.columnName) });
1116
+ if (value.templateName === "lastValue" || value.templateName === "firstValue") {
1117
+ if (!value.eventTimeFormula) {
1118
+ return null;
1119
+ }
1120
+ return __assign(__assign({}, columnParams), { eventTimeFormula: value.eventTimeFormula });
1121
+ }
1122
+ return columnParams;
1123
+ };
1124
+ var prepareConversionParams = function (value) {
1125
+ if (!value.startEventName ||
1126
+ !value.endEventName ||
1127
+ !value.endCaseCaseIdFormula ||
1128
+ !value.endEventNameFormula ||
1129
+ !value.endEventProcessName ||
1130
+ !value.endEventTimeFormula ||
1131
+ !value.startEventNameFormula ||
1132
+ !value.startEventProcessName ||
1133
+ !value.startEventTimeFormula) {
1134
+ return null;
1135
+ }
1136
+ return {
1137
+ objectFilters: "1",
1138
+ startEventTimeFormula: value.startEventTimeFormula,
1139
+ startEventNameFormula: value.startEventNameFormula,
1140
+ startEventFilters: convertFiltersToFormula(value.startEventFilters),
1141
+ startEventName: value.startEventName,
1142
+ endEventTimeFormula: value.endEventTimeFormula,
1143
+ endCaseCaseIdFormula: value.endCaseCaseIdFormula,
1144
+ endEventNameFormula: value.endEventNameFormula,
1145
+ endEventName: value.endEventName,
1146
+ endEventFilters: convertFiltersToFormula(value.endEventFilters),
1147
+ };
1148
+ };
1149
+ var prepareDurationParams = function (value) {
1150
+ if (!value.startEventName ||
1151
+ !value.endEventName ||
1152
+ !value.endCaseCaseIdFormula ||
1153
+ !value.endEventNameFormula ||
1154
+ !value.endEventProcessName ||
1155
+ !value.endEventTimeFormula ||
1156
+ !value.startEventNameFormula ||
1157
+ !value.startEventProcessName ||
1158
+ !value.startEventTimeFormula) {
1159
+ return null;
1160
+ }
1161
+ var getAggregationNameByAppearances = function (appearance) {
1162
+ return appearance === "FIRST" ? "minIf" : "maxIf";
1163
+ };
1164
+ return {
1165
+ objectFilters: "1",
1166
+ startEventTimeFormula: value.startEventTimeFormula,
1167
+ startEventNameFormula: value.startEventNameFormula,
1168
+ startEventFilters: convertFiltersToFormula(value.startEventFilters),
1169
+ startEventName: value.startEventName,
1170
+ startEventAggregationName: getAggregationNameByAppearances(value.startEventAppearances),
1171
+ endEventTimeFormula: value.endEventTimeFormula,
1172
+ endCaseCaseIdFormula: value.endCaseCaseIdFormula,
1173
+ endEventNameFormula: value.endEventNameFormula,
1174
+ endEventName: value.endEventName,
1175
+ endEventFilters: convertFiltersToFormula(value.endEventFilters),
1176
+ endEventAggregationName: getAggregationNameByAppearances(value.endEventAppearances),
1177
+ };
1178
+ };
928
1179
  function getMeasureFormula(_a) {
929
1180
  var _b;
930
1181
  var value = _a.value;
@@ -944,6 +1195,28 @@ function getMeasureFormula(_a) {
944
1195
  columnFormula: generateColumnFormula(tableName, columnName),
945
1196
  });
946
1197
  }
1198
+ if (value.mode === EWidgetIndicatorValueModes.AGGREGATION) {
1199
+ var preparedParams = prepareAggregationParams(value);
1200
+ if (!preparedParams) {
1201
+ return "";
1202
+ }
1203
+ var templateFormula = measureAggregationTemplates[value.templateName];
1204
+ return fillTemplateString(templateFormula, preparedParams);
1205
+ }
1206
+ if (value.mode === EWidgetIndicatorValueModes.CONVERSION) {
1207
+ var preparedParams = prepareConversionParams(value);
1208
+ if (!preparedParams) {
1209
+ return "";
1210
+ }
1211
+ return fillTemplateString(conversionTemplate, preparedParams);
1212
+ }
1213
+ if (value.mode === EWidgetIndicatorValueModes.DURATION) {
1214
+ var preparedParams = prepareDurationParams(value);
1215
+ if (!preparedParams) {
1216
+ return "";
1217
+ }
1218
+ return fillTemplateString(conversionTemplate, preparedParams);
1219
+ }
947
1220
  return "";
948
1221
  }
949
1222
 
@@ -1508,4 +1781,4 @@ var getColorByIndex = function (index) {
1508
1781
  return color;
1509
1782
  };
1510
1783
 
1511
- export { EActionButtonsTypes, EActionTypes, EBlockingConditionMode, ECalculatorFilterMethods, EClickHouseBaseTypes, EColorMode, EControlType, ECustomSelectTemplates, EDimensionTemplateNames, EDisplayConditionMode, EDrawerPlacement, EDurationUnit, EEventMeasureTemplateNames, EFontWeight, EFormatTypes, EFormattingPresets, EFormulaFilterFieldKeys, EIndicatorType, ELastTimeUnit, EMarkdownDisplayMode, EMeasureTemplateNames, EProcessFilterNames, ESelectOptionTypes, ESimpleDataType, ESimpleInputType, ESortDirection, ESortingValueModes, ESystemRecordKey, ETransitionMeasureTemplateNames, EUnitMode, EViewMode, EViewOpenIn, EWidgetActionInputMethod, EWidgetFilterMode, EWidgetIndicatorType, EWidgetIndicatorValueModes, bindContentWithIndicator, bindContentsWithIndicators, checkDisplayCondition, colors, dashboardLinkRegExp, dimensionTemplateFormulas, escapeSpecialCharacters, eventMeasureTemplateFormulas, fillTemplateString, formattingConfig, formulaFilterMethods, generateColumnFormula, getColorByIndex, getDefaultSortOrders, getDimensionFormula, getDisplayConditionFormula, getEventMeasureFormula, getLocalizedText, getMeasureFormula, getRuleColor, getTransitionMeasureFormula, isDimensionsHierarchy, isFormulaFilterValue, isValidColor, linkNameRegExp, mapDimensionsToInputs, mapEventMeasuresToInputs, mapFormulaFilterToCalculatorInput, mapFormulaFiltersToInputs, mapMeasuresToInputs, mapSortingToInputs, mapTransitionMeasuresToInputs, measureTemplateFormulas, parseClickHouseType, parseIndicatorLink, prepareSortOrders, prepareValuesForSql, replaceDisplayCondition, replaceFiltersBySelection, replaceHierarchiesWithDimensions, selectDimensionFromHierarchy, transitionMeasureTemplateFormulas, unescapeSpecialCharacters, updateDefaultModeSelection, updateMultiModeSelection, updateSingleModeSelection, workspaceLinkRegExp };
1784
+ export { EActionButtonsTypes, EActionTypes, EBlockingConditionMode, ECalculatorFilterMethods, EClickHouseBaseTypes, EColorMode, EControlType, ECustomSelectTemplates, EDimensionTemplateNames, EDisplayConditionMode, EDrawerPlacement, EDurationTemplateName, EDurationUnit, EEventAppearances, EEventMeasureTemplateNames, EFontWeight, EFormatTypes, EFormattingPresets, EFormulaFilterFieldKeys, EIndicatorType, ELastTimeUnit, EMarkdownDisplayMode, EMeasureAggregationTemplateName, EMeasureTemplateNames, EOuterAggregation, EProcessFilterNames, ESelectOptionTypes, ESimpleDataType, ESimpleInputType, ESortDirection, ESortingValueModes, ESystemRecordKey, ETransitionMeasureTemplateNames, EUnitMode, EViewMode, EViewOpenIn, EWidgetActionInputMethod, EWidgetFilterMode, EWidgetIndicatorType, EWidgetIndicatorValueModes, OuterAggregation, bindContentWithIndicator, bindContentsWithIndicators, checkDisplayCondition, clearMultiLineComments, clearSingleLineComments, colors, conversionTemplate, convertFiltersToFormula, convertToFormulasChain, countExecutionsTemplate, countReworksTemplate, dashboardLinkRegExp, dimensionTemplateFormulas, durationTemplates, escapeSpecialCharacters, eventMeasureTemplateFormulas, fillTemplateString, formattingConfig, formulaFilterMethods, generateColumnFormula, getColorByIndex, getDefaultSortOrders, getDimensionFormula, getDisplayConditionFormula, getEventMeasureFormula, getLocalizedText, getMeasureFormula, getRuleColor, getTransitionMeasureFormula, isDimensionsHierarchy, isFormulaFilterValue, isValidColor, linkNameRegExp, mapDimensionsToInputs, mapEventMeasuresToInputs, mapFormulaFilterToCalculatorInput, mapFormulaFiltersToInputs, mapMeasuresToInputs, mapSortingToInputs, mapTransitionMeasuresToInputs, measureAggregationTemplates, measureTemplateFormulas, parseClickHouseType, parseIndicatorLink, prepareAggregationParams, prepareConversionParams, prepareDurationParams, prepareFormulaForSql, prepareSortOrders, prepareValuesForSql, replaceDisplayCondition, replaceFiltersBySelection, replaceHierarchiesWithDimensions, selectDimensionFromHierarchy, transitionMeasureTemplateFormulas, unescapeSpecialCharacters, updateDefaultModeSelection, updateMultiModeSelection, updateSingleModeSelection, workspaceLinkRegExp };
package/dist/index.js CHANGED
@@ -72,13 +72,13 @@ var prepareValuesForSql = function (simpleType, values) {
72
72
  simpleType === exports.ESimpleDataType.BOOLEAN
73
73
  ? values
74
74
  : values.map(function (value) {
75
- return value === null ? null : "'".concat(escapeSingularQuotes(escapeReverseSlash(value)), "'");
75
+ return value === null ? null : "'".concat(escapeSingularQuotes$1(escapeReverseSlash(value)), "'");
76
76
  });
77
77
  };
78
78
  var escapeReverseSlash = function (formula) {
79
79
  return formula.replaceAll(/\\/gm, "\\\\");
80
80
  };
81
- var escapeSingularQuotes = function (formula) {
81
+ var escapeSingularQuotes$1 = function (formula) {
82
82
  return formula.replaceAll("'", "\\'");
83
83
  };
84
84
 
@@ -800,6 +800,16 @@ exports.EWidgetIndicatorType = void 0;
800
800
  EWidgetIndicatorType["DIMENSION"] = "DIMENSION";
801
801
  EWidgetIndicatorType["SORTING"] = "SORTING";
802
802
  })(exports.EWidgetIndicatorType || (exports.EWidgetIndicatorType = {}));
803
+ exports.EOuterAggregation = void 0;
804
+ (function (EOuterAggregation) {
805
+ EOuterAggregation["avg"] = "avg";
806
+ EOuterAggregation["median"] = "median";
807
+ EOuterAggregation["count"] = "count";
808
+ EOuterAggregation["countDistinct"] = "countDistinct";
809
+ EOuterAggregation["min"] = "min";
810
+ EOuterAggregation["max"] = "max";
811
+ EOuterAggregation["sum"] = "sum";
812
+ })(exports.EOuterAggregation || (exports.EOuterAggregation = {}));
803
813
  /** Режимы значения показателя (на основе чего генерируется формула) */
804
814
  exports.EWidgetIndicatorValueModes = void 0;
805
815
  (function (EWidgetIndicatorValueModes) {
@@ -807,6 +817,9 @@ exports.EWidgetIndicatorValueModes = void 0;
807
817
  EWidgetIndicatorValueModes["FORMULA"] = "FORMULA";
808
818
  /** Шаблон формулы, предоставляемый системой */
809
819
  EWidgetIndicatorValueModes["TEMPLATE"] = "TEMPLATE";
820
+ EWidgetIndicatorValueModes["AGGREGATION"] = "AGGREGATION";
821
+ EWidgetIndicatorValueModes["DURATION"] = "DURATION";
822
+ EWidgetIndicatorValueModes["CONVERSION"] = "CONVERSION";
810
823
  })(exports.EWidgetIndicatorValueModes || (exports.EWidgetIndicatorValueModes = {}));
811
824
  /** Режимы сортировки (на что ссылается сортировка) */
812
825
  exports.ESortingValueModes = void 0;
@@ -855,8 +868,28 @@ exports.ESimpleInputType = void 0;
855
868
  function isDimensionsHierarchy(indicator) {
856
869
  return "hierarchyDimensions" in indicator;
857
870
  }
871
+ exports.OuterAggregation = void 0;
872
+ (function (OuterAggregation) {
873
+ OuterAggregation["avg"] = "avgIf";
874
+ OuterAggregation["median"] = "medianIf";
875
+ OuterAggregation["count"] = "countIf";
876
+ OuterAggregation["countDistinct"] = "countIfDistinct";
877
+ OuterAggregation["min"] = "minIf";
878
+ OuterAggregation["max"] = "maxIf";
879
+ OuterAggregation["sum"] = "sumIf";
880
+ })(exports.OuterAggregation || (exports.OuterAggregation = {}));
881
+ exports.EDurationTemplateName = void 0;
882
+ (function (EDurationTemplateName) {
883
+ EDurationTemplateName["avg"] = "avg";
884
+ EDurationTemplateName["median"] = "median";
885
+ })(exports.EDurationTemplateName || (exports.EDurationTemplateName = {}));
886
+ exports.EEventAppearances = void 0;
887
+ (function (EEventAppearances) {
888
+ EEventAppearances["FIRST"] = "FIRST";
889
+ EEventAppearances["LAST"] = "LAST";
890
+ })(exports.EEventAppearances || (exports.EEventAppearances = {}));
858
891
 
859
- var _a$3;
892
+ var _a$4;
860
893
  exports.EDimensionTemplateNames = void 0;
861
894
  (function (EDimensionTemplateNames) {
862
895
  EDimensionTemplateNames["dateTime"] = "dateTime";
@@ -871,19 +904,19 @@ exports.EDimensionTemplateNames = void 0;
871
904
  EDimensionTemplateNames["dayOfWeek"] = "dayOfWeek";
872
905
  EDimensionTemplateNames["hour"] = "hour";
873
906
  })(exports.EDimensionTemplateNames || (exports.EDimensionTemplateNames = {}));
874
- var dimensionTemplateFormulas = (_a$3 = {},
875
- _a$3[exports.EDimensionTemplateNames.dateTime] = "toDateTime({columnFormula})",
876
- _a$3[exports.EDimensionTemplateNames.date] = "toDate({columnFormula})",
877
- _a$3[exports.EDimensionTemplateNames.year] = "if(defaultValueOfArgumentType({columnFormula}) = {columnFormula}, 0, toYear({columnFormula}))",
878
- _a$3[exports.EDimensionTemplateNames.yearAndQuarter] = "if(defaultValueOfArgumentType({columnFormula}) = {columnFormula}, 0, toYear({columnFormula}) * 10 + toQuarter({columnFormula}))",
879
- _a$3[exports.EDimensionTemplateNames.quarter] = "if(defaultValueOfArgumentType({columnFormula}) = {columnFormula}, 0, toQuarter({columnFormula}))",
880
- _a$3[exports.EDimensionTemplateNames.yearAndMonth] = "if(defaultValueOfArgumentType({columnFormula}) = {columnFormula}, 0, toYYYYMM({columnFormula}))",
881
- _a$3[exports.EDimensionTemplateNames.month] = "if(defaultValueOfArgumentType({columnFormula}) = {columnFormula}, 0, toMonth({columnFormula}))",
882
- _a$3[exports.EDimensionTemplateNames.dayOfMonth] = "if(defaultValueOfArgumentType({columnFormula}) = {columnFormula}, 0, toDayOfMonth({columnFormula}))",
883
- _a$3[exports.EDimensionTemplateNames.week] = "if(defaultValueOfArgumentType({columnFormula}) = {columnFormula}, 0, toWeek({columnFormula}))",
884
- _a$3[exports.EDimensionTemplateNames.dayOfWeek] = "if(defaultValueOfArgumentType({columnFormula}) = {columnFormula}, 0, toDayOfWeek({columnFormula}))",
885
- _a$3[exports.EDimensionTemplateNames.hour] = "if(defaultValueOfArgumentType({columnFormula}) = {columnFormula}, 0, toHour({columnFormula}))",
886
- _a$3);
907
+ var dimensionTemplateFormulas = (_a$4 = {},
908
+ _a$4[exports.EDimensionTemplateNames.dateTime] = "toDateTime({columnFormula})",
909
+ _a$4[exports.EDimensionTemplateNames.date] = "toDate({columnFormula})",
910
+ _a$4[exports.EDimensionTemplateNames.year] = "if(defaultValueOfArgumentType({columnFormula}) = {columnFormula}, 0, toYear({columnFormula}))",
911
+ _a$4[exports.EDimensionTemplateNames.yearAndQuarter] = "if(defaultValueOfArgumentType({columnFormula}) = {columnFormula}, 0, toYear({columnFormula}) * 10 + toQuarter({columnFormula}))",
912
+ _a$4[exports.EDimensionTemplateNames.quarter] = "if(defaultValueOfArgumentType({columnFormula}) = {columnFormula}, 0, toQuarter({columnFormula}))",
913
+ _a$4[exports.EDimensionTemplateNames.yearAndMonth] = "if(defaultValueOfArgumentType({columnFormula}) = {columnFormula}, 0, toYYYYMM({columnFormula}))",
914
+ _a$4[exports.EDimensionTemplateNames.month] = "if(defaultValueOfArgumentType({columnFormula}) = {columnFormula}, 0, toMonth({columnFormula}))",
915
+ _a$4[exports.EDimensionTemplateNames.dayOfMonth] = "if(defaultValueOfArgumentType({columnFormula}) = {columnFormula}, 0, toDayOfMonth({columnFormula}))",
916
+ _a$4[exports.EDimensionTemplateNames.week] = "if(defaultValueOfArgumentType({columnFormula}) = {columnFormula}, 0, toWeek({columnFormula}))",
917
+ _a$4[exports.EDimensionTemplateNames.dayOfWeek] = "if(defaultValueOfArgumentType({columnFormula}) = {columnFormula}, 0, toDayOfWeek({columnFormula}))",
918
+ _a$4[exports.EDimensionTemplateNames.hour] = "if(defaultValueOfArgumentType({columnFormula}) = {columnFormula}, 0, toHour({columnFormula}))",
919
+ _a$4);
887
920
  function getDimensionFormula(_a) {
888
921
  var _b;
889
922
  var value = _a.value;
@@ -906,6 +939,135 @@ function getDimensionFormula(_a) {
906
939
  return "";
907
940
  }
908
941
 
942
+ var _a$3, _b;
943
+ exports.EMeasureAggregationTemplateName = void 0;
944
+ (function (EMeasureAggregationTemplateName) {
945
+ EMeasureAggregationTemplateName["agvIf"] = "agvIf";
946
+ EMeasureAggregationTemplateName["medianIf"] = "medianIf";
947
+ EMeasureAggregationTemplateName["countIf"] = "countIf";
948
+ EMeasureAggregationTemplateName["countIfDistinct"] = "countIfDistinct";
949
+ EMeasureAggregationTemplateName["minIf"] = "minIf";
950
+ EMeasureAggregationTemplateName["maxIf"] = "maxIf";
951
+ EMeasureAggregationTemplateName["sumIf"] = "sumIf";
952
+ EMeasureAggregationTemplateName["top"] = "top";
953
+ EMeasureAggregationTemplateName["firstValue"] = "firstValue";
954
+ EMeasureAggregationTemplateName["lastValue"] = "lastValue";
955
+ EMeasureAggregationTemplateName["countExecutions"] = "countExecutions";
956
+ EMeasureAggregationTemplateName["countReworks"] = "countReworks";
957
+ })(exports.EMeasureAggregationTemplateName || (exports.EMeasureAggregationTemplateName = {}));
958
+ var conversionTemplate = "countIf(\n process(\n minIf(\n {startEventTimeFormula}, \n {startEventNameFormula} = '{startEventName}'{startEventFilters}\n ), \n {endCaseCaseIdFormula}\n ) < \n process(\n maxIf(\n {endEventTimeFormula}, \n {endEventNameFormula} = '{endEventName}'{endEventFilters}\n ), \n {endCaseCaseIdFormula}\n ) \n and \n process(\n countIf(\n {startEventNameFormula} = '{startEventName}'{startEventFilters}\n ) != 0, \n {endCaseCaseIdFormula}\n ) != 0\n) * 100 / countIf(\n process(\n countIf(\n {startEventNameFormula} = '{startEventName}'{startEventFilters}\n ) != 0, \n {endCaseCaseIdFormula}\n ) != 0\n)";
959
+ var durationTemplate = "\n timeDiff(\n process(\n {startEventAggregationName}(\n {startEventTimeFormula}, \n {startEventNameFormula} = '{startEventName}'{startEventFilters}\n ), \n {endCaseCaseIdFormula}\n ), \n process(\n {endEventAggregationName}(\n {endEventTimeFormula}, \n {endEventNameFormula} = '{endEventName}'{endEventFilters}\n ), \n {endCaseCaseIdFormula}\n )\n ), \n process(\n {startEventAggregationName}(\n {startEventTimeFormula}, \n {startEventNameFormula} = '{startEventName}'{startEventFilters}\n ), \n {endCaseCaseIdFormula}\n ) < \n process(\n {endEventAggregationName}(\n {endEventTimeFormula}, \n {endEventNameFormula} = '{endEventName}'{endEventFilters}\n ), \n {endCaseCaseIdFormula}\n ) \n and \n process(\n countIf(\n {startEventNameFormula} = '{startEventName}'{startEventFilters}\n ) != 0, \n {endCaseCaseIdFormula}\n ) != 0\n";
960
+ var durationTemplates = (_a$3 = {},
961
+ _a$3[exports.EDurationTemplateName.avg] = "avgIf(".concat(durationTemplate, ")"),
962
+ _a$3[exports.EDurationTemplateName.median] = "medianIf(".concat(durationTemplate, ")"),
963
+ _a$3);
964
+ var countReworksTemplate = "{outerAggregation}If(process(if(countIf({eventNameFormula} = {eventName}) > 0, countIf({eventNameFormula} = {eventName}) - 1, 0), {caseIdFormula}),{objectFilters})";
965
+ var countExecutionsTemplate = "process(countIf({eventNameFormula} in '{eventName}'{filters}), {caseIdFormula}";
966
+ var measureAggregationTemplates = (_b = {},
967
+ _b[exports.EMeasureAggregationTemplateName.agvIf] = "{outerAggregation}If(process(avgIf({columnFormula}, {eventNameFormula} = '{eventName}'{filters}), {caseIdFormula}), {objectFilters})",
968
+ _b[exports.EMeasureAggregationTemplateName.medianIf] = "{outerAggregation}If(process(medianIf({columnFormula}, {eventNameFormula} = '{eventName}'{filters}), {caseIdFormula}), {objectFilters})",
969
+ _b[exports.EMeasureAggregationTemplateName.countIf] = "{outerAggregation}If(process(countIf({eventNameFormula} = '{eventName}'{filters}), {caseIdFormula}), {objectFilters})",
970
+ _b[exports.EMeasureAggregationTemplateName.countIfDistinct] = "{outerAggregation}If(process(countIf(distinct {columnFormula}, {eventNameFormula} = '{eventName}'{filters}), {caseIdFormula}), {objectFilters})",
971
+ _b[exports.EMeasureAggregationTemplateName.minIf] = "{outerAggregation}If(process(minIf({columnFormula}, {eventNameFormula} = '{eventName}'{filters}), {caseIdFormula}), {objectFilters})",
972
+ _b[exports.EMeasureAggregationTemplateName.maxIf] = "{outerAggregation}If(process(maxIf({columnFormula}, {eventNameFormula} = '{eventName}'{filters}), {caseIdFormula}), {objectFilters})",
973
+ _b[exports.EMeasureAggregationTemplateName.sumIf] = "{outerAggregation}If(process(sumIf({columnFormula}, {eventNameFormula} = '{eventName}'{filters}), {caseIdFormula}), {objectFilters})",
974
+ _b[exports.EMeasureAggregationTemplateName.top] = "{outerAggregation}If(process(topKIf(1)({columnFormula}, {eventNameFormula} = '{eventName}'{filters})[1], {caseIdFormula}), {objectFilters})",
975
+ _b[exports.EMeasureAggregationTemplateName.firstValue] = "{outerAggregation}If(process(argMinIf({columnFormula}, {eventTimeFormula}, {eventNameFormula} = '{eventName}'{filters}), {caseIdFormula}), {objectFilters})",
976
+ _b[exports.EMeasureAggregationTemplateName.lastValue] = "{outerAggregation}If(process(argMaxIf({columnFormula}, {eventTimeFormula}, {eventNameFormula} = '{eventName}'{filters}), {caseIdFormula}), {objectFilters})",
977
+ _b[exports.EMeasureAggregationTemplateName.countExecutions] = "{outerAggregation}If(".concat(countExecutionsTemplate, "),{objectFilters})"),
978
+ _b[exports.EMeasureAggregationTemplateName.countReworks] = countReworksTemplate,
979
+ _b);
980
+
981
+ var escapeSingularQuotes = function (formula) {
982
+ if (typeof formula !== "string") {
983
+ return formula;
984
+ }
985
+ return formula.replaceAll("'", "\\'");
986
+ };
987
+
988
+ var prepareFormulaForSql = function (formula, simpleType) {
989
+ formula = clearSingleLineComments(clearMultiLineComments(formula)).trim();
990
+ return simpleType === exports.ESimpleDataType.OTHER ? "toString(".concat(formula, ")") : formula;
991
+ };
992
+ var clearSingleLineComments = function (formula) {
993
+ return formula.replaceAll(/--.*$/gm, "");
994
+ };
995
+ var clearMultiLineComments = function (formula) {
996
+ return formula.replace(/\/\*[\s\S]*?\*\//g, "");
997
+ };
998
+
999
+ function isDateSimpleType(simpleType) {
1000
+ return [exports.ESimpleDataType.DATE, exports.ESimpleDataType.DATETIME, exports.ESimpleDataType.DATETIME64].includes(simpleType);
1001
+ }
1002
+ var castToDateValue = function (simpleType) { return function (value) {
1003
+ return simpleType === exports.ESimpleDataType.DATE ? "toDate('".concat(value, "')") : "toDateTime('".concat(value, "')");
1004
+ }; };
1005
+ var convertCalculatorFilterToFormula = function (calculatorFilter) {
1006
+ var filterValueFormula = calculatorFilter.formula, filteringMethod = calculatorFilter.filteringMethod, dbDataType = calculatorFilter.dbDataType, rawValues = calculatorFilter.values;
1007
+ var simpleType = parseClickHouseType(dbDataType).simpleType;
1008
+ var formula = prepareFormulaForSql(filterValueFormula, simpleType);
1009
+ var values = isDateSimpleType(simpleType)
1010
+ ? rawValues.map(castToDateValue(simpleType))
1011
+ : rawValues.map(function (value) {
1012
+ return simpleType === exports.ESimpleDataType.INTEGER ||
1013
+ simpleType === exports.ESimpleDataType.FLOAT ||
1014
+ value === null
1015
+ ? value
1016
+ : "'".concat(escapeSingularQuotes(value), "'");
1017
+ });
1018
+ switch (filteringMethod) {
1019
+ case formulaFilterMethods.EQUAL_TO:
1020
+ return "".concat(formula, " = ").concat(values[0]);
1021
+ case formulaFilterMethods.NOT_EQUAL_TO:
1022
+ return "".concat(formula, " != ").concat(values[0]);
1023
+ case formulaFilterMethods.GREATER_THAN:
1024
+ return "".concat(formula, " > ").concat(values[0]);
1025
+ case formulaFilterMethods.GREATER_THAN_OR_EQUAL_TO:
1026
+ return "".concat(formula, " >= ").concat(values[0]);
1027
+ case formulaFilterMethods.LESS_THAN:
1028
+ return "".concat(formula, " < ").concat(values[0]);
1029
+ case formulaFilterMethods.LESS_THAN_OR_EQUAL_TO:
1030
+ return "".concat(formula, " <= ").concat(values[0]);
1031
+ case formulaFilterMethods.STARTS_WITH:
1032
+ return "startsWith(".concat(formula, ", ").concat(values[0], ")");
1033
+ case formulaFilterMethods.ENDS_WITH:
1034
+ return "endsWith(".concat(formula, ", ").concat(values[0], ")");
1035
+ case formulaFilterMethods.CONTAINS:
1036
+ return "ilike(".concat(formula, ", ").concat(values[0], ")");
1037
+ case formulaFilterMethods.NOT_CONTAINS:
1038
+ return "not ilike(".concat(formula, ", ").concat(values[0], ")");
1039
+ case formulaFilterMethods.EMPTY:
1040
+ return "assumeNotNull(".concat(formula, ") = assumeNotNull(defaultValueOfArgumentType(").concat(formula, "))");
1041
+ case formulaFilterMethods.NONEMPTY:
1042
+ return "assumeNotNull(".concat(formula, ") != assumeNotNull(defaultValueOfArgumentType(").concat(formula, "))");
1043
+ case formulaFilterMethods.INCLUDE:
1044
+ return "".concat(formula, " IN [").concat(String(values), "]");
1045
+ case formulaFilterMethods.EXCLUDE:
1046
+ return "".concat(formula, " NOT IN [").concat(String(values), "]");
1047
+ case formulaFilterMethods.IN_RANGE:
1048
+ case formulaFilterMethods.LAST_TIME:
1049
+ return "".concat(formula, " BETWEEN ").concat(values[0], " AND ").concat(values[1]);
1050
+ case formulaFilterMethods.NOT_IN_RANGE:
1051
+ return "".concat(formula, " NOT BETWEEN ").concat(values[0], " AND ").concat(values[1]);
1052
+ }
1053
+ };
1054
+ function convertToFormula(filterValue) {
1055
+ var calculatorFilter = mapFormulaFilterToCalculatorInput(filterValue);
1056
+ if (!calculatorFilter) {
1057
+ return;
1058
+ }
1059
+ return convertCalculatorFilterToFormula(calculatorFilter);
1060
+ }
1061
+ var convertToFormulasChain = function (values) {
1062
+ return compactMap(values, function (value) {
1063
+ var formula = isFormulaFilterValue(value) ? convertToFormula(value) : value.formula;
1064
+ return formula && "(".concat(formula, ")");
1065
+ }).join(" AND ");
1066
+ };
1067
+ var convertFiltersToFormula = function (filters) {
1068
+ return filters.length > 0 ? " AND ".concat(convertToFormulasChain(filters)) : "";
1069
+ };
1070
+
909
1071
  var _a$2;
910
1072
  exports.EMeasureTemplateNames = void 0;
911
1073
  (function (EMeasureTemplateNames) {
@@ -926,6 +1088,95 @@ var measureTemplateFormulas = (_a$2 = {},
926
1088
  _a$2[exports.EMeasureTemplateNames.max] = "max({columnFormula})",
927
1089
  _a$2[exports.EMeasureTemplateNames.sum] = "sum({columnFormula})",
928
1090
  _a$2);
1091
+ var prepareAggregationParams = function (value) {
1092
+ if (!value.eventName ||
1093
+ !value.caseIdFormula ||
1094
+ !value.eventNameFormula ||
1095
+ !value.outerAggregation ||
1096
+ !value.processName ||
1097
+ !value.templateName) {
1098
+ return null;
1099
+ }
1100
+ var commonParams = {
1101
+ outerAggregation: value.outerAggregation,
1102
+ eventNameFormula: value.eventNameFormula,
1103
+ caseIdFormula: value.caseIdFormula,
1104
+ eventName: value.eventName,
1105
+ objectFilters: "1",
1106
+ filters: convertFiltersToFormula(value.filters),
1107
+ eventTimeFormula: "",
1108
+ columnFormula: "",
1109
+ };
1110
+ if (value.templateName === "countReworks" || value.templateName === "countExecutions") {
1111
+ return commonParams;
1112
+ }
1113
+ if (!value.tableName || !value.columnName) {
1114
+ return null;
1115
+ }
1116
+ var columnParams = __assign(__assign({}, commonParams), { columnFormula: generateColumnFormula(value.tableName, value.columnName) });
1117
+ if (value.templateName === "lastValue" || value.templateName === "firstValue") {
1118
+ if (!value.eventTimeFormula) {
1119
+ return null;
1120
+ }
1121
+ return __assign(__assign({}, columnParams), { eventTimeFormula: value.eventTimeFormula });
1122
+ }
1123
+ return columnParams;
1124
+ };
1125
+ var prepareConversionParams = function (value) {
1126
+ if (!value.startEventName ||
1127
+ !value.endEventName ||
1128
+ !value.endCaseCaseIdFormula ||
1129
+ !value.endEventNameFormula ||
1130
+ !value.endEventProcessName ||
1131
+ !value.endEventTimeFormula ||
1132
+ !value.startEventNameFormula ||
1133
+ !value.startEventProcessName ||
1134
+ !value.startEventTimeFormula) {
1135
+ return null;
1136
+ }
1137
+ return {
1138
+ objectFilters: "1",
1139
+ startEventTimeFormula: value.startEventTimeFormula,
1140
+ startEventNameFormula: value.startEventNameFormula,
1141
+ startEventFilters: convertFiltersToFormula(value.startEventFilters),
1142
+ startEventName: value.startEventName,
1143
+ endEventTimeFormula: value.endEventTimeFormula,
1144
+ endCaseCaseIdFormula: value.endCaseCaseIdFormula,
1145
+ endEventNameFormula: value.endEventNameFormula,
1146
+ endEventName: value.endEventName,
1147
+ endEventFilters: convertFiltersToFormula(value.endEventFilters),
1148
+ };
1149
+ };
1150
+ var prepareDurationParams = function (value) {
1151
+ if (!value.startEventName ||
1152
+ !value.endEventName ||
1153
+ !value.endCaseCaseIdFormula ||
1154
+ !value.endEventNameFormula ||
1155
+ !value.endEventProcessName ||
1156
+ !value.endEventTimeFormula ||
1157
+ !value.startEventNameFormula ||
1158
+ !value.startEventProcessName ||
1159
+ !value.startEventTimeFormula) {
1160
+ return null;
1161
+ }
1162
+ var getAggregationNameByAppearances = function (appearance) {
1163
+ return appearance === "FIRST" ? "minIf" : "maxIf";
1164
+ };
1165
+ return {
1166
+ objectFilters: "1",
1167
+ startEventTimeFormula: value.startEventTimeFormula,
1168
+ startEventNameFormula: value.startEventNameFormula,
1169
+ startEventFilters: convertFiltersToFormula(value.startEventFilters),
1170
+ startEventName: value.startEventName,
1171
+ startEventAggregationName: getAggregationNameByAppearances(value.startEventAppearances),
1172
+ endEventTimeFormula: value.endEventTimeFormula,
1173
+ endCaseCaseIdFormula: value.endCaseCaseIdFormula,
1174
+ endEventNameFormula: value.endEventNameFormula,
1175
+ endEventName: value.endEventName,
1176
+ endEventFilters: convertFiltersToFormula(value.endEventFilters),
1177
+ endEventAggregationName: getAggregationNameByAppearances(value.endEventAppearances),
1178
+ };
1179
+ };
929
1180
  function getMeasureFormula(_a) {
930
1181
  var _b;
931
1182
  var value = _a.value;
@@ -945,6 +1196,28 @@ function getMeasureFormula(_a) {
945
1196
  columnFormula: generateColumnFormula(tableName, columnName),
946
1197
  });
947
1198
  }
1199
+ if (value.mode === exports.EWidgetIndicatorValueModes.AGGREGATION) {
1200
+ var preparedParams = prepareAggregationParams(value);
1201
+ if (!preparedParams) {
1202
+ return "";
1203
+ }
1204
+ var templateFormula = measureAggregationTemplates[value.templateName];
1205
+ return fillTemplateString(templateFormula, preparedParams);
1206
+ }
1207
+ if (value.mode === exports.EWidgetIndicatorValueModes.CONVERSION) {
1208
+ var preparedParams = prepareConversionParams(value);
1209
+ if (!preparedParams) {
1210
+ return "";
1211
+ }
1212
+ return fillTemplateString(conversionTemplate, preparedParams);
1213
+ }
1214
+ if (value.mode === exports.EWidgetIndicatorValueModes.DURATION) {
1215
+ var preparedParams = prepareDurationParams(value);
1216
+ if (!preparedParams) {
1217
+ return "";
1218
+ }
1219
+ return fillTemplateString(conversionTemplate, preparedParams);
1220
+ }
948
1221
  return "";
949
1222
  }
950
1223
 
@@ -1520,9 +1793,17 @@ Object.defineProperty(exports, "EFilteringMethodValues", {
1520
1793
  exports.bindContentWithIndicator = bindContentWithIndicator;
1521
1794
  exports.bindContentsWithIndicators = bindContentsWithIndicators;
1522
1795
  exports.checkDisplayCondition = checkDisplayCondition;
1796
+ exports.clearMultiLineComments = clearMultiLineComments;
1797
+ exports.clearSingleLineComments = clearSingleLineComments;
1523
1798
  exports.colors = colors;
1799
+ exports.conversionTemplate = conversionTemplate;
1800
+ exports.convertFiltersToFormula = convertFiltersToFormula;
1801
+ exports.convertToFormulasChain = convertToFormulasChain;
1802
+ exports.countExecutionsTemplate = countExecutionsTemplate;
1803
+ exports.countReworksTemplate = countReworksTemplate;
1524
1804
  exports.dashboardLinkRegExp = dashboardLinkRegExp;
1525
1805
  exports.dimensionTemplateFormulas = dimensionTemplateFormulas;
1806
+ exports.durationTemplates = durationTemplates;
1526
1807
  exports.escapeSpecialCharacters = escapeSpecialCharacters;
1527
1808
  exports.eventMeasureTemplateFormulas = eventMeasureTemplateFormulas;
1528
1809
  exports.fillTemplateString = fillTemplateString;
@@ -1549,9 +1830,14 @@ exports.mapFormulaFiltersToInputs = mapFormulaFiltersToInputs;
1549
1830
  exports.mapMeasuresToInputs = mapMeasuresToInputs;
1550
1831
  exports.mapSortingToInputs = mapSortingToInputs;
1551
1832
  exports.mapTransitionMeasuresToInputs = mapTransitionMeasuresToInputs;
1833
+ exports.measureAggregationTemplates = measureAggregationTemplates;
1552
1834
  exports.measureTemplateFormulas = measureTemplateFormulas;
1553
1835
  exports.parseClickHouseType = parseClickHouseType;
1554
1836
  exports.parseIndicatorLink = parseIndicatorLink;
1837
+ exports.prepareAggregationParams = prepareAggregationParams;
1838
+ exports.prepareConversionParams = prepareConversionParams;
1839
+ exports.prepareDurationParams = prepareDurationParams;
1840
+ exports.prepareFormulaForSql = prepareFormulaForSql;
1555
1841
  exports.prepareSortOrders = prepareSortOrders;
1556
1842
  exports.prepareValuesForSql = prepareValuesForSql;
1557
1843
  exports.replaceDisplayCondition = replaceDisplayCondition;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infomaximum/widget-sdk",
3
- "version": "5.3.0",
3
+ "version": "5.4.0",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.esm.js",
6
6
  "types": "./dist/index.d.ts",