NAME
Schedule::Activity::NodeFilter - Evaluate if attributes match logical expressions
SYNOPSIS
my $filter=Schedule::Activity::NodeFilter->new(
f =>'value/avg/elapsed'
attr =>'attribute name'
op =>'lt/gt/le/ge/eq/ne'
value=>number
#
boolean=>'and/or/nand'
filters=>[...]
);
if($filter->matches($tm,%attributes)) { ... }
DESCRIPTION
TODO.
VALUE FILTERS
Attribute values
A filter that directly checks attribute values as attribute op value can be created with
f =>'value',
attr =>'name',
op =>'lt/gt/le/ge/eq/ne',
value=>number,
mod =>number, # optional
It is not necessary to pass f=value, which is the default. If the attribute value is undefined, the match is false. All other operators are numeric and are self explanatory. (This might change, but currently there is no proposal/use case to support setting attributes with string values.)
The mod is an optional floating-point modulus value. Due to potential accumulation and rounding errors, inequality comparisons are recommend, such as op=>'lt', value=<1. The floating modulus works for integer and real-valued attributes, as well as negative numbers, with the value of x modulo m for positive x defined as:
x-m*int(x/m)
Attribute averages
A filter that uses the current average value of an attribute as average op value can be created with
f =>'avg',
attr =>'name',
op =>'operator',
value=>number,
When used from Schedule::Activity, the average will be provided by the attribute as if no change in value occurred between the last recorded entry and the current time. The meaning of the average depends on the type.
Elapsed time
To control "time between actions", a filter can be used to check the elapsed time since an integer attribute was stored by evaluating (now-attribute time) op value with
f =>'elapsed',
attr =>'name',
op =>'operator'
value=>seconds,
mod =>number, # optional
For any attribute, the most recent recorded event is used as the attribute time. To record a timestamp for an integer attribute without changing its value, use incr=0. For mod, see "Attribute values" above. Negative times never match this filter.
BOOLEAN EXPRESSIONS
A boolean filter supports AND, OR, and NAND expressions as follows:
boolean=>'and/or/nand',
filters=>[...],
The filters are any list of one or more filters of any type. That is, AND is the conjunction over all filters in the list (all must be true). The OR is the disjunction over all filters in the list (at least one must be true).
The Boolean NOT may be implemented as boolean=nand, filters=[filter], because the NAND operator is implemented via DeMorgan's Laws as !A || !B || ....
All operators support short-circuiting.