Generic Objects in Expression Language

From QPR ProcessAnalyzer Wiki
Jump to navigation Jump to search

Generic Context

In the generic context, the following properties are available.

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

A special value which, when traversing through a hierarchical object, means that an item in the hierarchical object should be removed.

Examples:

[1, 2, 3, 4].(2 * _)
Returns: [2, 4, 6, 8]

[1, 2, 3, 4].if(_ == 2,_remove,_)
Returns: [1, 3, 4]

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 among all QPR ProcessAnalyzer objects in the server. CalcId 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.

CalculationContextTypeName (String)

Returns the type of the current calculation context.

Examples:

CalculationContextTypeName
Returns: "GenericCalculationContext"

[1, "a", [1, 2], TimeSpan(1, 2, 3, 4), DateTime(2016,1,1), Def("", _ + 1)].CalculationContextTypeName
Returns: ["GenericCalculationContext", "StringCalculationContext", "GenericCalculationContext", "TimeSpanCalculationContext", "DateTimeCalculationContext", "ExpressionCalculationContext"]

EventLogById(<event log id>).CalculationContextTypeName
Returns: EventLogCalculationContext
ComparisonEventLog (EventLog)

Returns the current comparison EventLog in which context the expression is being evaluated. Comparison EventLog is available only when the KPI analysis request has been initialized with RuntimeComparison parameter set to 1.

CurrentUser (User) Returns the current user as User object.
EventLog (EventLog)

Returns the current EventLog object in whose context the expression is being evaluated.

Models (Model*) All Model objects in the QPR ProcessAnalyzer server (that the user have rights).
Now (DateTime) DateTime object representing the current date and time.
null Returns a special null value. Usually null represents non-existing or missing value. Null value is similar to EMPTY value, except null values can also be recursed.
Projects (Project*) All Projects in the QPR ProcessAnalyzer server (that the user have rights).
UserGroups (User*) Returns an array of user groups visible for the current user as User objects.
Users (User*) Returns an array of users visible for the current user as User objects.

DateTime

DateTime represents a timestamp.

DateTime properties Description
Day (Integer) The day of the calendar month represented by the DateTime. Number between 1 and 31. Based on QPR ProcessAnalyzer server local time.
Hour (Integer) The hour component of the date represented by the DateTime. Number between 0 and 23. Based on QPR ProcessAnalyzer server local time.
Millisecond (Integer) The millisecond component of the date represented by the DateTime. Number between 0 and 999. Based on QPR ProcessAnalyzer server local time.
Minute (Integer) The minute component of the date represented by the DateTime. Number between 0 and 59. Based on QPR ProcessAnalyzer server local time.
Month (Integer) The calendar month component of the date represented by the DateTime. Number between 1 and 12. Based on QPR ProcessAnalyzer server local time.
Second (Integer) The second component of the date represented by the DateTime. Number between 0 and 59. Based on QPR ProcessAnalyzer server local time.
Ticks (Integer) Number of ticks represented by the DateTime. The value of this property represents the number of 100-nanosecond intervals that have elapsed since 12:00:00 midnight, January 1, 0001 (0:00:00 UTC on January 1, 0001, in the Gregorian calendar). A single tick represents one hundred nanoseconds or one ten-millionth of a second. There are 10,000 ticks in a millisecond, or 10 million ticks in a second.
Year (Integer) The year component of the date represented by the DateTime. Number between 1 and 9999. Based on QPR ProcessAnalyzer server local time.
DateTime functions Parameters Description
Round (DateTime)
  • TimeSpan or Integer

Rounds given date time by given TimeSpan or given number of seconds.

Example:

Round to the nearest hour:
Round(DateTime(2017, 1, 1, 14, 48), TimeSpan(0, 1))

DateTime(2017, 1, 2, 3, 4, 5).Round(10)
Returns: DateTime(2017, 1, 2, 3, 4, 10)

DateTime(2017, 1, 2, 3, 4, 5).Round(TimeSpan(1))
Returns: DateTime(2017, 1, 2)
Truncate (DateTime)
  • Period (String)

Truncates given DateTime value to given precision. Truncating means that the provided DateTime (i.e. timestamp) is converted into a timestamp representing the beginning of the period. For example, if period is year, the Truncate function returns the first date of the year where the input DateTime is belonging. Truncate function is useful e.g. when dimensioning data into different periods.

Supported precision values are: year, quarter, month, week, day, hour, minute and second.

Examples:

DateTime(2018, 5, 14, 3, 4, 5).Truncate("year")
Returns: DateTime(2018)

DateTime(2018, 5, 20, 3, 4, 5).Truncate("quarter")
Returns: DateTime(2018, 4, 1)

DateTime(2019, 8, 14, 3, 4, 5).Truncate("day")
Returns: DateTime(2019, 8, 14)

DateTime(2019, 8, 14, 3, 4, 5).Truncate("hour")
Returns: DateTime(2019, 8, 14, 3)

The following functions can be used to initialize DateTime objects:

Function Parameters Description
DateTime
  1. Year (1-9999) (Integer)
  2. Month (1-12) (Integer)
  3. Day (>= 1) (Integer)
  4. Hour (>= 0) (Integer)
  5. Minute (>= 0) (Integer)
  6. Second (>= 0) (Integer)
  7. Millisecond (>= 0) (Integer)

Creates a new DateTime object. Only the first (year) parameter is mandatory.

Examples:

DateTime(2017)
Returns: A datetime for 1st January 2017 at 0:00:00.

DateTime(2017, 5)
Returns: A datetime for 5th January 2017 at 0:00:00.

DateTime(2017, 5, 6, 13, 34, 56, 123)
Returns: A date time object for 6th May 2017 at 13:34:56.123.
DateTimeFromTicks
  1. Number of ticks (Integer)

Creates a new DateTime object from an integer representing ticks. A single tick represents one hundred nanoseconds or one ten-millionth of a second. There are 10,000 ticks in a millisecond, or 10 million ticks in a second.

Examples:

DateTimeFromTicks(DateTime(2018, 5, 6, 13, 34, 56, 123).Ticks)
Returns: A date time object for 6th May 2018 at 13:34:56.123.

Dictionary

Dictionary properties Description
Count (Integer) Returns the number of elements stored into this dictionary.
Keys Returns the array of all the keys in this dictionary.
Values Returns the array of all the values in this dictionary.


Dictionary Functions Parameters Description
Add

Adds possibly multiple values into the dictionary. Takes even number of parameters, where every odd parameter represents key. Every even parameter represents the value to be added for the preceding key. Returns the dictionary itself.

Will throw an exception if a value with the same key already exists in the dictionary.

Examples:
ToDictionary().Add("a", 1, "b", 2).(Get("a") + Get("b"))
Returns: 3

ToDictionary().Add("a", 1, "a", 2).Get("a")
Throws an exception.
ContainsKey Key to search for (String)

Check whether given key exists in the dictionary. Returns true only if there is a stored value for given key.

Examples:

ToDictionary().Set("a", 1).ContainsKey("a")
Returns: True

ToDictionary().Set("a", 1).ContainsKey("b")
Returns: False
Get Key to search for (String)

Get the value associated with the given key from the dictionary. Returns the value associated with the key in the dictionary. Will throw an exception if there is no value associated with the given key in the dictionary.

Examples:

ToDictionary().Set("a", 1, "b", 2).Get("b")
Returns: 2

ToDictionary().Set("a", 1, "b", 2).Get("c")
Throws an exception.
Remove * Key to remove (String)

Removes value of given key from the dictionary. Returns true only if the a value associated with given key was found and successfully removed from the dictionary.

Examples:

ToDictionary().Set("a", 1, "b", 2).Remove("b")
Returns: True

ToDictionary().Set("a", 1, "b", 2).Remove("c")
Returns: False

Let("dictionary", ToDictionary().Set("a", 1, "b", 2));
dictionary.Remove("b");
dictionary.Keys
Returns: ["a"]
Set

Sets possibly multiple values into the dictionary. Will overwrite any possible earlier values the key had in the dictionary. Takes even number of parameters, where every odd parameter represents key. Every even parameter represents the value to be set for the preceding key. Returns the dictionary itself.

Examples:

ToDictionary().Set("a", 1, "b", 2).(Get("a") + Get("b"))
Returns: 3

ToDictionary().Set("a", 1, "a", 2).Get("a")
Returns: 2
ToArray

Converts dictionary object into a hierarchical array. Returns the dictionary object converted into a hierarchical array.

Examples:

ToDictionary().ToArray()
Returls: []

ToDictionary().Add("a", 1, "b", 2).ToArray()
Returns: [ "a": [1], "b": [2] ]
TryGetValue * Key to search for (String)

Tries to get the value associated with the given key from the dictionary. If the key was found in the dictionary, returns the value associated with the key in the dictionary. Otherwise, returns _empty.

Examples:

ToDictionary().Set("a", 1, "b", 2).TryGetValue("b")
Returns: 2

ToDictionary().Set("a", 1, "b", 2).TryGetValue("c")
Returns: _empty

Expression

Expression is an object type that encapsulates a KPI expression language expression. Expression inside expression object can be evaluated by using the expression object as if it was a function by using <expression object name>(<parameter list>) syntax. Expression objects can be created in the following ways:

  • Using Def function
  • Whenever & prefix is used in Def function for an attribute

Examples:

Def(null, "a", "b", a+b)._(1,2)
Returns: 3

[Def("", "a", "b", a+b), Def("", "a", "b", a*b)].(_(1,2))
Returns: [3, 2]

String

String properties Description
Length

Return the number of characters in the input string. Example:

"Test".Length 
Returns: 4.

"".Length
Returns: 0.
String functions Parameters Description
CharAt
  • Index number (Integer)

Return a character (as a String) in the index number position in the input string. The indexing starts from zero. Negative index numbers are not allowed.

Examples:

"test".CharAt(1)
Returns: "e"

"test".For("i", 0, i < Length, i + 1, CharAt(i))
Returns: ["t", "e", "s", "t"]
Contains
  • searched string

Returns true if the input string contains the searched string; otherwise false. String comparison is case sensitive. Example:

"test".Contains("st")
Returns: true
EndsWith
  • searched string

Return true if the input string ends with the searched string; otherwise false. String comparison is case sensitive.

"test".EndsWith("st")
Returns: true
IndexOf
  • searched string
  • start index (Integer) (optional)

Return the index number of the first occurrence of the searched string in the input string. Indexing starts from zero. If the start index is provided, the search is started from that index. The function returns -1 if match is not found.

The start index is optional. Invalid start index is negative or more than input string length.

Examples:

"test".IndexOf("t")
Returns: 0

"test".IndexOf("t", 1)
Returns: 3
LastIndexOf
  • searched string
  • start index (Integer)

Return the index number of the last occurrence of the searched string in the input string. Indexing starts from zero. If the start index is provided, the search is started from that index (calculated from the start of the string) towards the beginning of the string. Return -1 if match not found. Invalid start index is negative or more than input string length.

Replace
  • first string
  • second string

Replaces all occurrences of the first string with the second string in the input string. String comparison is case sensitive.

Example:

"abcd".Replace("b", "e") 
Returns: "aecd"
Split
  • Split character (string or string array)
  • Remove empties (Boolean) (optional)

Splits input string into array of substrings. The string is splitted based on a character or array of characters (that are provided as strings). String comparison is case sensitive.

When remove empties parameter is true, empty strings are excluded (by default false).

Examples:

"1,2,3".Split([","]).ToInteger(_)
Returns: [1,2,3]

"a,b,,c".Split(",", true)
Returns: ["a","b","c"]

"a,b,,c".Split(",")
Returns: ["a","b","","c"]
StartsWith
  • searched string

Return true if the input string starts with the searched string; otherwise false. String comparison is case sensitive.

"test".StartsWith("t")
Returns: true
Substring
  • start index (Integer)
  • length (Integer) (optional)

Returns a substring of the input string starting from the start index. If the length is provided, the returned string contains maximum of that number of characters. Invalid start index is negative or more than input string length. Invalid length is negative or start index plus length is more then input string length.

ToLower [none] Return a string where all the characters of the input string have been converted to lower case characters.
"Test".ToLower()
Returns: "test"
ToUpper [none] Return a string where all the characters of the input string have been converted to upper case characters.
Trim
  • string or arrays of strings (optional)

Removes spaces from the start and end of the input string (if array of strings is not provided). If the array of strings is provided, all leading and trailing characters in the array of strings are removed from the input string. Accepts also a single string in which case it is treated as if an array containing only that string was given as parameter.

Examples:

" Test".Trim() 
Returns: "Test"

"Test".Trim(["T", "t"])
Returns: "es"

"Test".Trim("t")
Returns: "Tes"

TimeSpan

TimeSpan represents a time interval (duration of time or elapsed time) that is measured as a positive or negative number of days, hours, minutes, seconds, and fractions of a second. The TimeSpan is not bound to calendar time, so a TimeSpan can be used to represent the time of day, but only if the time is unrelated to a particular date.

Difference between two TimeStamps is TimeSpan. TimeStamp added by TimeSpan is TimeStamp.

Minimum possible value of a TimeSpan is -10 675 199 days 2 hours 48 minutes 5.4775808 seconds and maximum possible value is 10 675 199 days 2 hour 48 minutes 5.4775807 seconds.

TimeSpan properties Description
Ticks (Integer) Number of ticks represented by the TimeSpan. A single tick represents one hundred nanoseconds or one ten-millionth of a second. There are 10,000 ticks in a millisecond, or 10 million ticks in a second.
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).

The following functions can be used to initialize Timespan objects.

Function Parameters Description
TimeSpan
  1. Days (Integer)
  2. Hours (Integer)
  3. Minutes (Integer)
  4. Seconds (Integer)
  5. Milliseconds (Integer)

Creates a new TimeSpan object. Only the first parameter (number of days) is mandatory. By default, other parameters are assumed to be zero.

Examples:

TimeSpan(1)
Returns: Time span for the duration of 1 day.

TimeSpan(12,3,4,5,6)
Returns: Time span for the duration of 12 days, 3 hours, 4 minutes, 5 seconds and 6 milliseconds.
TimeSpanFromTicks
  1. Number of ticks (Integer)

Creates a new TimeSpan object from an integer representing ticks. A single tick represents one hundred nanoseconds or one ten-millionth of a second. There are 10,000 ticks in a millisecond, or 10 million ticks in a second.

Examples:

TimeSpanFromTicks(TimeSpan(12,3,4,5,6).Ticks)
Returns: A time span object representing 12 days, 3 hours, 4 minutes, 5 seconds and 6 milliseconds.