Filtering in QPR ProcessAnalyzer Queries: Difference between revisions

From QPR ProcessAnalyzer Wiki
Jump to navigation Jump to search
Line 56: Line 56:
== Filter Rule Types ==
== Filter Rule Types ==
=== Expression ===
=== Expression ===
Filter rule type '''ExpressionValue''' (for in-memory calculation) or '''SqlExpressionValue''' (for dataframe calculation) selects cases or event types that match the given expression. It has property '''Configuration''' which has properties:
Filter rule type '''ExpressionValue''' (for in-memory calculation) or '''SqlExpressionValue''' (for dataframe calculation) selects cases or events that match the given expression. There is property '''Configuration''' which has properties:
* '''Root''': Specifies the root expression to return QPR ProcessAnalyzer objects that are used to evaluate the ''Expressions'' (see below). If not defined, all the cases in the current event log are used as root objects. The expression should return following types of objects: for case filters cases, events, event types, flows or flow occurrences. For event types filters, only event types. For event filters, only events are supported.
* '''Root''': The root expression returning objects that are used to evaluate the ''Expressions'' (see below). If not defined, all the cases in the current event log are used as root objects. The root expression should return following types of objects: (1) for case filters: cases, events, event types, flows or flow occurrences, (2) for event filters: events and (3) for event type filters: event types.
* '''Expressions''': Array of expressions specifying the filter rules. The is an AND logic between the filter rules, so all expressions need to match for the objects to come to the filter. In the CAses filter, the resulting matched objects are converted to Cases to get the actual filtered Cases. If not defined, all the objects returned from the ''Root expression'' will be selected to the filter. Properties:
* '''Expressions''': Array of expressions specifying the filter rules. The is the AND logic between the filter rules, so all expressions need to match for the objects to come to the filter.
** '''Expression''': When filter rule type is ''ExpressionValue'', eventlog based expression that is evaluated for each root object. When filter rule type is ''SqlExpressionValue'', SQL expression that is evaluated for each root object.  
Properties:
** '''Expression''': When filter rule type is ''ExpressionValue'', eventlog based expression can be specified that is evaluated for each root object. When filter rule type is ''SqlExpressionValue'', SQL expression can be specified that is evaluated for each root object.  
** '''Values''': Array of values to match to the expression result. Suitable only for strings, numeric and boolean values.
** '''Values''': Array of values to match to the expression result. Suitable only for strings, numeric and boolean values.
** '''StringifiedValues''': Array of values to match to the expression result, and the values are defined in the [[Stringified_Value_Format|stringified format]]. This has a better support for different data types than in the Values property.
** '''StringifiedValues''': Array of values to match to the expression result, and the values are defined in the [[Stringified_Value_Format|stringified format]]. This has a better support for different data types than in the Values property.
Line 66: Line 67:
** '''TimespanPrecision''': Similar setting as the [[Web_API:_Expression/query#Dimensions|expression analysis dimensions]] have to round timespan type of result of the expression.
** '''TimespanPrecision''': Similar setting as the [[Web_API:_Expression/query#Dimensions|expression analysis dimensions]] have to round timespan type of result of the expression.
** '''Comparison''': Defines the type of comparison operation among the following: '''equal''', '''notequal''', '''greaterthan''', '''lessthan''', '''greaterthanorequal''' and '''lessthanorequal'''. If Comparison is not defined, ''equal'' is used. When comparison is ''equal'' or ''notequal'', several Values/Stringified values can be specified. For other comparison types, the Values/Stringified array must contain only one item. The lower and greater than comparisons work with numbers, datatimes and timespans. In the lower and greater than comparisons, ''null'' values both as the expression result and in the Values/StringifiedValues result in non-match. Rounding or truncation performed by the NumberPrecision, DateTimeTruncation or TimespanPrecision are done before comparison, so do not use them if comparison should be based on the original values.
** '''Comparison''': Defines the type of comparison operation among the following: '''equal''', '''notequal''', '''greaterthan''', '''lessthan''', '''greaterthanorequal''' and '''lessthanorequal'''. If Comparison is not defined, ''equal'' is used. When comparison is ''equal'' or ''notequal'', several Values/Stringified values can be specified. For other comparison types, the Values/Stringified array must contain only one item. The lower and greater than comparisons work with numbers, datatimes and timespans. In the lower and greater than comparisons, ''null'' values both as the expression result and in the Values/StringifiedValues result in non-match. Rounding or truncation performed by the NumberPrecision, DateTimeTruncation or TimespanPrecision are done before comparison, so do not use them if comparison should be based on the original values.
** '''ValueConversionExpression''': (only supported for expression type ''ExpressionValue'') Expression used to convert the array of ''Values'' before they are used in the actual comparison. The function is useful e.g. for comparing date values (as dates cannot be expressed in json directly). The ValueConversionExpression gets the entire array of Values as a context, so it's also possible to add and remove values from the array using the ValueConversionExpression. Example: _.DateTimeFromTicks(_).
* '''Variables''': (only supported for expression type ''ExpressionValue'') An object specifying key-value pairs, where each key-value pair generates one variable into the expression language where key is the name of the variable and value is its value. The values will be converted to strings.
* '''Variables''': (only supported for expression type ''ExpressionValue'') An object specifying key-value pairs, where each key-value pair generates one variable into the expression language where key is the name of the variable and value is its value. The values will be converted to strings.



Revision as of 20:32, 22 August 2022

QPR ProcessAnalyzer queries for models data can be filtered to include only selected cases or events to the calculation. The expression query have the parameter Filter to pass a filter definition. The Root cause analysis has also the parameter Comparison which divides the analyzed data into two groups to compare them in the analysis. The Comparison parameter has the same structure as in the Filter parameter.

If a filter (or comparison) refers to information that doesn't exist in the model, e.g. non-existing event type names or case attribute values, the non-existing values are ignored. Still, if the CaseAttributeValue or EventAttributeValue filter refers to an attribute name that doesn't exist, an error is given.

Filter and Comparison parameters

The filter definition has syntax demonstrated by the following example:

{
  Items: [
    {
      Type: "IncludeCases",
      Items: [
        {
          Type: "EventType",
          Values: ["Sales Order Created", "Payment Received"]
        },
        {
          Type: "CaseAttributeValue",
          Attribute: "Region",
          Values: ["Dallas", "Austin"]
        }
      ]
    },
    {
      Type: "ExcludeCases",
      Items: [
        {
          Type: "Case",
          Values: ["Case1", "Case2", "Case3"]
        },
        {
          Type: "flow",
          Values: [
            {
              From: "Shipment",
              To: "Invoice"
            }
          ]
        }
      ]
    }
  ]
}

The outmost object has a property Items which is an array of object with following properties:

  • Type: Specifies the type of the filtering operation with following options:
    • IncludeCases / ExcludeCases: Includes / excludes cases. All filter rule types can be used with this option.
    • IncludeEvents / ExcludeEvents: Includes / excludes events. Only Attribute filter rule types can be used with this option.
    • IncludeEventTypes / ExcludeEventTypes: Includes / excludes events based on the event type. Only Event type and Expression filter rule types can be used with this option.
  • Disabled: (boolean) Defines whether the filter rule is applied or not. This is used by the UI to temporarily disable filter rule without removing them.

The following chapters list different filter rule types that can be used in the above defined Items property.

Filter Rule Types

Expression

Filter rule type ExpressionValue (for in-memory calculation) or SqlExpressionValue (for dataframe calculation) selects cases or events that match the given expression. There is property Configuration which has properties:

  • Root: The root expression returning objects that are used to evaluate the Expressions (see below). If not defined, all the cases in the current event log are used as root objects. The root expression should return following types of objects: (1) for case filters: cases, events, event types, flows or flow occurrences, (2) for event filters: events and (3) for event type filters: event types.
  • Expressions: Array of expressions specifying the filter rules. The is the AND logic between the filter rules, so all expressions need to match for the objects to come to the filter.

Properties:

    • Expression: When filter rule type is ExpressionValue, eventlog based expression can be specified that is evaluated for each root object. When filter rule type is SqlExpressionValue, SQL expression can be specified that is evaluated for each root object.
    • Values: Array of values to match to the expression result. Suitable only for strings, numeric and boolean values.
    • StringifiedValues: Array of values to match to the expression result, and the values are defined in the stringified format. This has a better support for different data types than in the Values property.
    • NumberPrecision: Similar setting as the expression analysis dimensions have to round numerical type of result of the expression.
    • DatetimeTruncation: Similar setting as the expression analysis dimensions have to round date type of result of the expression.
    • TimespanPrecision: Similar setting as the expression analysis dimensions have to round timespan type of result of the expression.
    • Comparison: Defines the type of comparison operation among the following: equal, notequal, greaterthan, lessthan, greaterthanorequal and lessthanorequal. If Comparison is not defined, equal is used. When comparison is equal or notequal, several Values/Stringified values can be specified. For other comparison types, the Values/Stringified array must contain only one item. The lower and greater than comparisons work with numbers, datatimes and timespans. In the lower and greater than comparisons, null values both as the expression result and in the Values/StringifiedValues result in non-match. Rounding or truncation performed by the NumberPrecision, DateTimeTruncation or TimespanPrecision are done before comparison, so do not use them if comparison should be based on the original values.
  • Variables: (only supported for expression type ExpressionValue) An object specifying key-value pairs, where each key-value pair generates one variable into the expression language where key is the name of the variable and value is its value. The values will be converted to strings.

Examples:

Select cases named "case1" and "case2".

{
  Type: "ExpressionValue",
  Configuration: {
    Root: "Cases",
    Expressions: [
      {
        Expression: "Name",
        Values: ["case1", "case2"]
      }
    ]
  }
}

Cases where duration is as rounded 3 or 4 days.

{
  Type: "ExpressionValue",
  Configuration: {
    Root: "Cases",
    Expressions: [
      {
        Expression: "Duration.TotalDays",
        NumberPrecision: 0,
        StringifiedValues: ["43", "44"]
      }
    ]
  }
}

Cases where duration is as rounded 3 or 4 days.

{
  Type: "ExpressionValue",
  Configuration: {
    Root: "Cases",
    Expressions: [
      {
        Expression: "Duration",
        TimespanPrecision: "day",
        StringifiedValues: ["73.00:00:00.000", "74.00:00:00.000"]
      }
    ]
  }
}

Cases that have started in October or November 2020.

{
  Type: "ExpressionValue",
  Configuration: {
    Root: "Cases",
    Expressions: [
      {
        Expression: "StartTime",
        DatetimeTruncation: "month",
        StringifiedValues: ["22020-10-01T00:00:00.000", "22020-11-01T00:00:00.000"]
      }
    ]
  }
}

Selects cases whose duration is longer than one day.

{
  Type: "ExpressionValue",
  Configuration: {
    Root: "Cases.Where(Duration.TotalDays > 1)"
  }
}

Same as previous using the Comparison property:

{
  Type: "ExpressionValue",
  Configuration: {
    Root: "Cases",
    Expressions: [
      {
        Expression: "Duration.TotalDays",
        Comparison: "greaterthan",
        Values: [1]
      }
    ]
  }
}

All Cases that have started before year 2020:

{
  Type: "ExpressionValue",
  Configuration: {
    Root: "Cases",
    Expressions: [
      {
        Expression: "StartTime",
        Comparison: "lessthan",
        StringifiedValues: ["22020-01-01T00:00:00.000"]
      }
    ]
  }
}

Returns all cases that are conformant with the specified BPNM model.

{
  Type: "ExpressionValue",
  Configuration: {
    Variables: {
      bpmnXml: "<XML BPMN model>"
    },
    Root: "Let(\"myConformanceModel\", DesignModelFromXml(bpmnXml));Cases.Where(IsConformant(myConformanceModel));"
  }
}

Pass date values as ticks and convert them into date objects (that are used in the actual comparison).

{
  Type: "ExpressionValue",
  Configuration: {
    Root: "Cases",
    Expressions: [
      {
        Expression: "myDatetimeAttribute",
        ValueConversionExpression: "_.DateTimeFromTicks(_)",
        Values: [636214968000000000, 636239160000000000, 636291828000000000]
      }
    ]
  }
}
{
  Type: "SqlExpressionValue",
  Configuration: {
    Root: "Cases",
    Expressions: [{ Expression: "AggregateFrom(Events, \"Count\")", Values: [4,5] }]
  }
}

Attribute

Filter rule type Attribute selects events having given event attribute values. This filter rule is available only when processing method is DataFrame, and when filter operation type is IncludeEvents/ExcludeEvents. Properties:

  • Attribute: Event attribute name.
  • Values: Array of event attribute values. Suitable only for string, integer and boolean values.
  • StringifiedValues: Array of event attribute values in the stringified format. Better support for different data types. Note that due to the equality comparison, float values cannot be used.

Examples:

{
  Type: "Attribute",
  Attribute: "Role",
  Values: ["Consultant", "Sales", "Support"]
}

Case attribute value

Filter rule type CaseAttributeValue selects cases having given value in given case attribute. Properties:

  • Attribute: Case attribute name.
  • Values: Array of case attribute values. Suitable only for string, integer and boolean values.
  • StringifiedValues: Array of case attribute values in the stringified format. Better support for different data types. Note that due to the equality comparison, float values cannot be used.

Example:

{
  Type: "CaseAttributeValue",
  Attribute: "Region",
  Values: ["Dallas", "Austin", "New York"]
}
{
  Type: "CaseAttributeValue",
  Attribute: "Region",
  StringifiedValues: ["0Dallas", "0Austin", "0New York"]
}

Event attribute value

Filter rule type EventAttributeValue selects cases having events with given event attribute values. Properties:

  • Attribute: Name of the event attribute.
  • Values: An array of event attribute values. Suitable only for string, integer and boolean values.
  • StringifiedValues: Array of event attribute values in the stringified format. Better support for different data types. Note that due to the equality comparison, float values cannot be used.

Example:

{
  Type: "EventAttributeValue",
  Attribute: "Organization",
  Values: ["Organization 1", "Organization 2"]
}
{
  Type: "EventAttributeValue",
  Attribute: "Organization",
  StringifiedValues: ["0Organization 1", "0Organization 2"]
}

Event type

Filter rule type EventType selects cases containing selected event types (Type=IncludeCases/ExcludeCases) or selects event types (Type=IncludeEventTypes/ExcludeEventTypes). It has property Values which is an array of event type names.

Example:

{
  Type: "EventType",
  Values: ["Sales Order Created", "Payment Received", "Delivery Sent"]
}

Variation

Filter rule type Variation selects cases belonging to selected variations. It has the property Paths which is an array of variations. Each variation is a string array of event type names in the variation.

Example:

{
  Type: "Variation",
  Paths: [
    ["Activity 1", "Activity 2", "Activity 3"],
    ["Activity 3"],
    ["Activity 2", "Activity 4"]
  ]
}

Flow

Filter rule type Flow selects cases having the defined flows. It has property Flows which selects an array of objects with following properties:

  • From: Event type name which starts the flow.
  • To: Event type name into which the flow goes.
  • Occurrence: Zero-based occurrence index of the selected flow within its case. If not specified, represents all occurrences.

Example:

{
  Type: "Flow",
  Flows: [ {From: "EventType1", To: "EventType2", "Occurrence": 1} ]
}

Case ID

Filter rule type Case selects individual cases. It supports property Values which is an array of case ID's (strings).

Example:

{
  Type: "Case",
  Values: ["case1", "case2", "case3"]
}

Same example in the whole JSON configuration:

{
  Items: [
    {
      Type: "IncludeCases",
      Items: [
        {
          Type: "Case",
          Values: ["case1", "case2", "case3"]
        }
      ]
    }
  ]
}