QPR ProcessAnalyzer Expressions: Difference between revisions
Line 164: | Line 164: | ||
|| | || | ||
Rounds a value to the nearest integer or to the specified number of fractional digits. | Rounds a value to the nearest integer or to the specified number of fractional digits. | ||
|} | |} | ||
Revision as of 09:03, 14 December 2017
Expression and Evaluation Context
An expression is a text to be evaluated that has a result. Result can be any of the supported object types or empty. An expression may consist of multiple expressions, called sub-expressions.
Expression evaluation is always performed within some context. This context and its type defines which kind of functionalities are available. Current context is implicitly accessible in all the expressions. Whenever a function or property is called, functions and properties accessible in the current context are searched first. If function or property is not found in the current context, then more generic context is tried. Error is returned only if the requested functionality is not available in the current context or a generic context. Current context can be accessed explicitly by using variable named _ (underscore).
Expression Chaining and Hierarchies using . and :
Expressions can be chained together two ways:
- Contextless chaining: When . character is used to chain expressions, the resulting objects will not have context information.
- Hierarchical chaining: When : character is used to chain expressions, only the result of the whole chained expression will consist of hierarchical arrays (#29290#) where all the values in the first expression (=context object) will be bound to the arrays those values generated. If the second expression does not return an array, the result will be changed to be an array.
The second expression chained to the first one will be evaluated using the following rules:
- If the result of the first expression is not an array, the second expression will be evaluated with the result of the first expression as its context object.
- If the result of the first expression is an array, for every element in the array, the second expression will be evaluated with the array item as its context object. The result of the evaluation will be an array of evaluation results (one for each element in the array).
- If any of the second expression evaluations returns an array, the resulting object will be an array of arrays. If the first expression evaluation returns a typed array, the result will be hierarchic in a way that first level results are objects that contain the information about the actual object as well as the results generated by the second level expressions.
These rules apply also when chaining more than two expressions together. For example, it is possible to generate three level hierarchy with nodes of type: event log -> case -> event: EventLogById(1).Cases.Events or EventLogById(1):Cases:Events.
Examples:
Contextless chaining: First expression not an array, second expression not an array: "1".("Number is " + _) Returns: "Number is 1" Contextless chaining: First expression is an array, second expression not an array: [1,2,3].("Number is " + _) Returns: ["Number is 1", "Number is 2", "Number is 3"] Contextless chaining: First expression is an array, second expression is an array: [1,2,3].["Number is " + _, "" + _ + ". number"] Returns: [ ["Number is 1", "1. number"], ["Number is 2", "2. number"], ["Number is 3", "3. number"] ] Hierarchical chaining: First expression is an array, second expression is an array: [1,2,3]:["Number is " + _, "" + _ + ". number"] Returns: [ HierarchicalArray(1, ["Number is 1", "1. number"]), HierarchicalArray(2, ["Number is 2", "2. number"]), HierarchicalArray(3, ["Number is 3", "3. number"]) ]
- Hierarchical arrays: Whenever traversing a relation in expression language using hierarchical chaining operator ':' for chaining expressions, a hierarchical array will be returned. It is an object which behaves just like a normal array except it stores also context/root/key/label object which usually represents the object from which the array originated from, for example the original case object when querying events of a case.
- Hierarchical objects: Arrays where at least one object in the array is itself an array is considered to be a hierarchical object. Hierarchical arrays are treated in similar way as normal arrays in hierarchical objects.
- Depth of a hierarchical object is the number of inner arrays that there are in the object, i.e. how deep is the hierarchy.
- Level in hierarchical object consists of all the nodes that are at specific depth in object's array hierarchy. 0 is the level at the root of the object, consisting only of the object itself as single item. Levels increase when moving towards leaves.
- Leaf level is a level that doesn't have any sub levels.
Evaluation Scopes
Scope defines the region of a expression where a specific variable or function name-value binding is valid. In expressions, a variable or function is valid in the following scopes:
- Scope the variable or function was created.
- All the child scopes created from the scope in which the variable or function was created.
A new scope is created based on the previous one in the following cases:
- When starting to evaluate a expression.
- When recursing the chain of expressions and the type of the current calculation context object is not the same as the previously used one.
- When evaluating user defined function and its parameters.
- When evaluating KPI analysis dimensions.
- When evaluating KPI analysis column names in dynamic values.
User Defined Variables
Variables are properties originating from the current variable scope. Variables can be defined by user into the current scope using Let function. Variables defined in parent scope are available also in all the child scopes. Variables can't be used to override properties. Properties are always checked first before checking scope for variables. For example, you can't override Models property by specifying Models variable.
Aggregation Functions
Aggregation functions are performed by default to the leaf level (the deepest level). Aggregation means that leaf level arrays are replaced by the aggregated values, and thus the depth of the hierarchy decreases by one. There are following aggregation functions available: Average, Count, Min, Max and Sum.
Examples:
Count([[1, 2], [3, 4, 5]]) Returns: [2, 3] Sum([[1, 2], [3, 4, 5]]) Returns: [3, 12]
In addition to the aggregation functions, functions that modify the contents of leaf arrays (OrderBy, Distinct, ...), the operation will be performed separately for every leaf array.
OrderByValue([[4, 3], [2, 1]]) Returns: [[3, 4], [1, 2]]
Generic Properties
Generic Properties and Functions are available for all objects.
Property | Description |
---|---|
_ |
Refers to the current context. |
_empty |
Returns an object which represent a non-existent value. Textual representation of this value is "EMPTY". |
_remove |
Returns an object which represent a value that should automatically be recursively pruned out of the resulting hierarchy object when processing chained expressions. If all the child values of one context object used in chaining expressions return this object, the root object itself will also be pruned out of the resulting hierarchy object. Examples: Both: [1,2]._remove [1,2].Where(_==3, _remove) Return EMPTY whereas [1,2].Where(_==3, _empty) [1,2].Where(_==3) [1,2]._empty Returns an empty collection (collection of length 0). For("i", 0, i < 10, i + 1, i).Where(_ % 2 == 0) For("i", 0, i < 10, i + 1, i).If(_ % 2 == 0, _, _remove) Both return: [0, 2, 4, 6, 8] |
CalcId (string) |
Returns an id that is unique between all QPR ProcessAnalyzer objects. CalcId is remains the same at least for the duration of the expression calculation. It is possible that CalcId for an object is different in the next calculation. CalcId is EMPTY for other than QPR ProcessAnalyzer objects. |
Models (Model*) | All Models in the QPR ProcessAnalyzer server (that the user have rights). |
Now (DateTime) | Timestamp representing the current date and time. |
Null |
Returns a special null value. Null value is similar to EMPTY value, except null values can also be recursed. In some cases null values can be converted into numbers in which case they act as 0. |
Projects (Project*) | All Projects in the QPR ProcessAnalyzer server (that the user have rights). |
Mathematical functions
Function | Parameters | Description |
---|---|---|
Ceiling (Integer) |
|
Returns the smallest integer greater than or equal to the specified number. |
Floor (Integer) |
|
Returns the largest integer less than or equal to the specified number. |
Round (Float) |
|
Rounds a value to the nearest integer or to the specified number of fractional digits. |
Properties and Functions by Object Types
This chapter lists all the object types in the expresssion language and properties and functions that they support. After the property or function name there is the type of the returned object mentioned. Asterisk (*) after the type means that it returns an array of objects.
Array
Array functions | Parameters | Description |
---|---|---|
IndexOfSubArray (integer) |
|
Returns the indexes of given sub-array (1. parameter) within the given array (2. parameter). If not given, the array in the current context object is used. Returns starting indexes of all the occurrences of given sub-array within given array.
Examples: [[1,2,3,4,1,2,5]].IndexOfSubArray([1,2]) IndexOfSubArray([1,2], [1,2,3,4,1,2,5]) Return: [0, 4] [[1,2,3,4,1,2,5]].IndexOfSubArray([1,2,3,4,5]) Returns: [] [[1,2,3,4,1,2,5],[3,4],[0,1,2,3]]:IndexOfSubArray([1,2]) Returns: [ HierarchicalArray([1,2,3,4,1,2,5], [0,4]), HierarchicalArray([0,1,2,3], [1]) ] |
AttributeType
Case properties | Description |
---|---|
Id (Integer) | AttributeType Id. |
Name (String) | Attribute name. |
Case
Case properties | Description |
---|---|
Duration (TimeSpan) | Case duration, i.e. duration between case start and case end time. |
EndTime (DateTime) | Case end time, i.e. timestamp of the last event. |
Events (Event) | All events of the case. |
FlowOccurrences (FlowOccurrency) | All flow occurrences the case contains. |
Flows (Flow) | All flows the case goes through. |
Id (String) | Case Id. |
Name (String) | Case name |
StartTime (DateTime) | Case start time, i.e. timestamp of the first event. |
Variation (Variation) | Variation the case belongs to. |
Case functions | Parameters | Description |
---|---|---|
Attribute (Object) |
|
Case attribute value. Case attribute name is provided as a parameter. |
Event
Event properties | Description |
---|---|
Case (Case) | Case the event belongs to. |
Id (Integer) | Event id. |
IndexInCase (Integer) | Index (running) number of the event in the case (ordered temporally). The first event has index number 0. |
Model (Model) | Model the event belongs to. |
NextInCase (Event) | Temporally next event in the case. For the last event, return EMPTY. |
PreviousInCase (Event) | Temporally previous event in the case. For the first event, return EMPTY. |
TimeStamp (DateTime) | Timestamp of the event. |
Type (EvenType) | Event type of the event. |
Event functions | Parameters | Description |
---|---|---|
Attribute (object) |
|
Event attribute value. Event attribute name is provided as a parameter. |
EventLog
EventLog is a list of events that is a result of a filtering operation. Also Model contain an EventLog composing of the whole model contents. i.e. filters have been applied yet. EventLogs can be fetched by the filter id using function EventLogById(filterId).
Event properties | Description |
---|---|
CaseAttributes (AttributeType*) | Used case attribute in the EventLog. |
Cases (Case*) | Cases that belong to the EventLog. |
EventAttributes (AttributeType*) | Used event attributes in the EventLog. |
Events (Event*) | Events that belong to the EventLog. |
EventTypes (EventType*) | EventTypes in the EventLog. |
Flows (Flow*) | Flows that the part of the EventLog. |
Id | EventLog Id. |
Model (Model) | Model where the EventLog belongs. |
Name | EventLog name. |
Variations (Variation*) | Variations that are in the EventLog |
EventType
EventType properties | Description |
---|---|
Cases (Case*) | Cases that contain the EventType. |
Count (Integer) | Event count that have this EventType. |
Events (Event*) | Events of that EventType. |
IncomingFlows (Flow*) | All Flows that start from the EventType. |
Id (Integer) | EventType Id. |
Name (string) | EventType name. |
OutgoingFlows (Flow*) | All Flows that end to the EventType. |
Flow
Flow is a combination of two EventTypes where there are FlowOccurrences between them. Unlike FlowOccurrencies, a Flow is not related to a single case. Flowchart shows Flows and EventTypes (not FlowOccurences or Events). In a Case, the may be several FlowOccurrences of a single Flow.
Variation properties | Description |
---|---|
Cases (Case*) | Cases that contain the flow, i.e. there is a flow occurrence between Flow's starting and ending events. |
FlowOccurrences (FlowOccurrence*) | Flow occurrences the flow belongs to. |
From (EventType) | EventType where the Flow starts. |
Id (Integer) | Flow Id. |
Name (String) | Identifying name of the Flow. |
To (EventType) | EventType where the Flow ends. |
FlowOccurrence
FlowOccurrence represents a transition from an event to another event in a case. Thus, FlowOccurrence is related to a single case. There is also a FlowOccurrence from the "start" of the case to the first event of the case, and a FlowOccurrence from the last event of the case to the "end" of the case. Corresponding flow is visible in BPMN kind of flowcharts showing separate start and event icons. Thus, there are one more FlowOccurrences in a case than the number of events.
Variation properties | Description |
---|---|
Case (Case) | Case the current FlowOccurrence belongs to. |
Flow (Flow) | Corresponding Flow of the current FlowOccurrence. |
From (Event) | Event where the current FlowOccurrence starts. |
Id (Integer) | Current FlowOccurrence Id. |
Name (String) | Identifying name of the current FlowOccurrence. |
OccurrenceIndex (Integer) | Number tells how many times the current FlowOccurrence has occurred in the case until that point. |
To (Event) | Event where the current FlowOccurrency ends. |
Model
Variation properties | Description |
---|---|
CaseAttributes (AttributeType*) | CaseAttributes of the model. |
EventAttributes (AttributeType*) | EventAttributes of the model. |
EventLog (EventLog) | EventLog of the model. Model EventLog contains all events of the model, i.e. no filters have been applied. |
Id (Integer) | Model Id. |
Name (String) | Name of the model. |
Project (Project) | The Project the current model belong to. |
TimeSpan
TimeSpan represents a temporal duration (for example: 5 hours or 8 days). TimeSpan is not bound to calendar time. Difference between two TimeStamps is TimeSpan. TimeStamp added by TimeSpan is TimeStamp.
TimeSpan properties | Description |
---|---|
TotalDays (Float) | Timespan value in days (one day is 24 hours) (both whole and fractional). |
TotalHours (Float) | Timespan value in hours (both whole and fractional). |
TotalMilliseconds (Float) | Timespan value in milliseconds(both whole and fractional). |
TotalMinutes (Float) | Timespan value in minutes (both whole and fractional). |
TotalSeconds (Float) | Timespan value in seconds (both whole and fractional). |
Variation
Variation properties | Description |
---|---|
CaseCount (Integer) | Number of cases in the variation. |
Cases (Case*) | Cases that belong to the variation. |
EventTypeCount (Integer) | Number of events in the variation. |
EventTypes (EventType*) | Event types belonging to the variation. |
Id (Integer) | Variation Id. |
UniqueEventTypeCount (Integer) | Number of different (unique) event types in the variation. |
DateTime
DateTime represents a timestamp.
DateTime properties | Description |
---|---|
Day | The day of the calendar month represented by the DateTime. Number between 1 and 31. |
Hour | The hour component of the date represented by the DateTime. Number between 0 and 23. |
Millisecond | The millisecond component of the date represented by the DateTime. Number between 0 and 999. |
Minute | The minute component of the date represented by the DateTime. Number between 0 and 59. |
Month | The calendar month component of the date represented by the DateTime. Number between 1 and 12. |
Second | The second component of the date represented by the DateTime. Number between 0 and 59. |
Year | The year component of the date represented by the DateTime. Number between 1 and 9999. |
DateTime functions | Parameters | Description |
---|---|---|
Round (DateTime) |
|
Rounds the DateTime to the defined TimeSpan. Example: Round to the nearest hour: Round(DateTime(2017, 1, 1, 14, 48), TimeSpan(0, 1)) |
Expression Examples
See expression examples here: QPR ProcessAnalyzer Expression Examples.