Skip to the content.

Writing patterns

(Work in progress)

Pattern language syntax

For patterns, TSP uses a special (domain-specific) language which specifies various conditions.

Literals

Integers, floating-point numbers and strings are written as usual (strings are in single quotes), for example:

123.456
7890
'this is a string'

Time literals

They consist of a number (either integer or floating-point) and unit (full or abbreviated). Examples (and all supported units):

2 hours
1.5 hr (same as 90 minutes)
10 minutes
3 min
0.75 seconds (same as 750 ms)
20 sec
568 milliseconds
100 ms

(Note that it’s possible to specify a fractional number of milliseconds, but it will be still rounded down to the nearest integer.)

Time literals with different units can be combined, for example:

2 hours 20 minutes 16 seconds 358 ms  (same as 8416358 ms, etc.)

Database (source) columns

They are written simply “as-is” if they are identifiers (thus beginning with a letter, and containing only alpha-numeric characters). For example:

ThisIsAnIdentifier1234

If they are not identifiers (contain spaces, for example), they can be escaped by double-quoting, like this:

"this is an identifier"

Operators

The DSL supports following operators:

In all cases, parentheses can be used to override the default priority.

Conditions

Simple condition consists only of a boolean expression, such as:

Column1 > 0 and Column2 = 1

This means “the condition above holds once”.

Timed condition consists of a boolean expression, for keyword 1

and a time literal, for example:

Column1 > 0 for 10 minutes

This rule requires that the boolean condition (Column1 > 0) must hold for 10 (consecutive) minutes.

Timed condition with constraint has an additional constraint for total time or the number of times held. It consists of a timed condition and a constraint of one of the following forms (<unit> can be either a time unit or keyword times):

Examples of patterns:

Column1 > 0 for 30 sec >= 5 times (at least five times during the thirty-second window)
Column2 = 0 for 1 min < 5 seconds (less than five seconds during the minute window)

Note: the success interval of the timed condition starts after the window ends (i.e. when it becomes known that the condition holds. E.g. in the pattern A > 0 for 2 hours, if A holds from 9:00 to 12:00 hours (during the same day), the reported interval of success will be from 11:00 to 12:00. See also wait)

Combined pattern is a combination of the conditions (simple or timed) via the operators and, or, and andThen.

Examples:

Column1 = 0 for 20 min andThen Column1 > 0 for 3 sec

Functions

Mathematical functions

  1. all keywords are case insensitive