The operators and functions shown in Table 12 are commonly used in defining or modifying infopads.
Table 12. Operators used for infopads
Operators/ functions
Description
:=
Assigns any value to a slot in a cell.
::=
Assigns the result of a functional expression (for example, min, max, avg) to a cell slot, where the first argument of the function is the cell slot itself. This notation enables you to avoid repeating the first argument (int this case, the cell slot itself) which is assumed to be the same as the expression on the left side.
+=
Adds the value in right hand side to the slot of a cell (numeric type only).
++
Adds 1 to the slot of a cell (numeric type only).
-=
Subtracts the value in right hand side to the slot of a cell (numeric type only).
--
Subtracts 1 from the slot of a cell (numeric type only).
*=
Multiplies the value in right hand side to the slot of a cell (numeric type only).
/=
Divides the value in right hand side to the slot of a cell (numeric type only).
add
Appends a new row for infopad (only for dynamic infopad)s.
avg
Recalculates an average value, given a new value and its weight.
The assignment operator (:= ) modifies the value of any slot of a cell. A cell is usually identified with an indexed infopad expression, as in the code example below:
dailyStats[4][3].avg_resp_time := 0;
Where the cell corresponding to row = 4 and column = 3 of the dailyStats infopad is identified.
You may also use labels instead of index values. The following expression denotes the same cell as the previous one:
dailyStats["Thursday"][3].avg_resp_time := 0;
An event attribute is always taken as a string value. If this string represents an index value, and is used as an actual index (and not a label), then you must explicitly convert it to an integer using the toInt() function. Assuming the event attribute: EVT1.myhours is equal to the string [3], then the following expression is correct and equivalent to the previous ones:
The functions max(V) and min(V) respectively replace the current value S of a numeric slot with max(S,V) and with min(S,V). Assuming a cell definition that collects the minimum response time for requests (slot: min_time) as well as the maximum time (slot: max_time), the action-items that achieve this monitoring are:
val x = myMonthlyTable[EVT1.date.month][EVT1.region];
x.max_time ::= max(EVT1.time);
val x = myMonthlyTable[EVT1.date.month][EVT1.region];
x.min_time ::= min(EVT1.time);
The operator ::= allows you to not repeat the slot expression (to the left of =) in the first argument of the function max() or min(), and to use a contracted version of these functions: max(V) instead of max(S, V). The following statements, therefore, are equivalent:
This assignment operator can generally be used on other functions that report the left hand expression (that is, to the left of =) as their first argument.
Using the avg() function
The function avg(V, slot_name, weight) replaces the current value of a numeric slot with a new averaging value involving V.
val x = myMonthTable[EVT1.date.month][EVT1.region];
x.avg_resp_time ::= avg(EVT1.time, x.count++, 1);
The function call: avg(V, countslot, weight) arguments are as follows:
V. A value element that is involved in the new average value.
Countslot (optional). The slot of the same cell that is used as divisor for calculating the new mean value, usually as a counter of the number of values. The default counter "count" is usually predominate. If an increment operator ++ is used, then the weight is added to the countslot. If not, the value of countslot does not change during the operation.
Weight. A positive number assigned to a new element that determines its relative importance for calculating the mean of the values. When an element is not weighted, it is equal to 1. Depending on the mode, the weight is or is not added to the value in countslot.
Assume that the previous value of myslot was already an average U calculated from N values (mean of N values). Involving the new value V with weight 1 requires it to recalculate the new average: its new value assigned to the slot myslot is (N*U + V)/(N+1). The value N was supposed to be in the slot count. It updates after the action-item, to N+1, if ++ is on the counter.
Using several averaging statements on the same cell
Consider, for example, a rule that averages two values: request response time and request size. Although two averaging statements are used, incrementing the counter "count" is done once. This rule uses avg() in the following way:
val x = myMonthTable[EVT1.date.month][EVT1.region];
x.avg_resp_time ::= avg(EVT1.time, x.count, 1);
x.avg_req_size ::= avg(EVT1.time, x.count++, 1);
The two average values avg_resp_time and avg_req_size use the same counter (count). However, the counter is incremented only once each time the action is executed. The operator ++ specifies which averaging statement does the update: it is the last one to use the counter in the rule. All other averaging statements with the same counter do not mention the ++ operator.
Assume the value in the counter slot count is N before the action is executed, V is the new value EVT1.resp_time to include in the average, and currreqtime is the value of the slot avg_resp_time. In the example above, the first averaging sets the slot avg_resp_time to: (N* currreqtime + V)/(N+1). The second averaging uses a similar formula. The weight value (here "1") is used in both averages to calculate the new counter value: N’ = N+weight.