| Prev | Next | Start of Chapter | End of Chapter | Contents | Glossary | Index | Comments | (9 out of 14)

History Expressions

G2 provides many expressions that reason about a variable or parameter history values.

Most history expressions require you to specify a time-expression, consisting of time units (seconds, minutes, hours, days, or weeks) or an arithmetic expression. If the time interval is an arithmetic expression, G2 interprets its result as a number of seconds. Some examples of valid time-intervals are:


Note: When using the between time-expression ago and time-expression ago phrase in these expressions, you must specify the longer time interval before the shorter time interval.

Each of these expressions calculates a statistic, using the history values stored in a quantitative variable (or its subclasses) or a quantitative parameter (or its subclasses).

Obtaining a History Value

To obtain a history value:

For a variable or parameter that is keeping history values, this expression produces the value that the variable or parameter had at the specified time interval ago or at a number of datapoints ago.

Two examples are:


Specifying a time interval causes G2 to return the value from the specified time. If G2 did not collect a value then, it returns the value collected immediately prior to the specified time-interval. For instance, in the example shown here (as of 1 hour ago), if no value were collected at that time, G2 would return the value collected before that time, perhaps 1 hour and 1 minute ago. If no previous time existed, G2 returns no value, expressed as **** (asterisks). Note that this behavior differs from the behavior of the interpolated value of expression.

If you specify a number of data points ago, as in the second example, G2 returns the value at that data point. History data points are zero-based, meaning that if 10 data points are collected, the number of data points ranges from 0 - 9, and specifying 10 is invalid.

If G2 did not collect a value at the specified data point, it returns no value, expressed as **** (asterisks).

If you specify a number of history values ago, G2 produces that history value. For example:

In this example, if G2 did not collect a value at the Temperature attribute's 36th history value, the expression produces a no value condition.

Computing the Number of History Datapoints

To obtain the total number of history datapoints within, and on, the boundaries of the time interval you specify:

This expression produces the number of history values contained in the specified variable or parameter, or the number of history values received during the specified time interval. G2 counts the values within and on the boundaries of the specified time interval.

Here are two examples:


Computing the Average History Value

To compute the average history value over a specified period of time:

If the specified variable or parameter contains at least one history value for the specified time interval, this expression produces a value that G2 calculates based on those history values. If the specified variable or parameter does not contain at least one history value, this expression produces a no value condition.

The calculated average is the sum of the variable's or parameter's values divided by the number of values. G2 does not calculate a time-weighted average, in which the distribution of values over time can produce differing results.

Here are two examples:



Tip: G2 does not compute a time-weighted average where the distribution produces differing results. This average value is simply the sum of the variable or parameter's values divided by the number of values.

Computing the Integral

To compute the integral over a selected period of time:

If the specified variable or parameter contains at least one history value for the specified time interval, this expression produces a value that G2 calculates based on those history values. If the specified variable or parameter does not contain at least one history value, this expression produces a no value condition.

Two examples are:


G2 performs a true integration over time of the most recently received value for the variable or parameter at each instant of the specified time interval.

Computing the Interpolated Value

To compute the interpolated value of a variable or a parameter:

If the specified variable or parameter contains at least two history values for the specified time interval, this expression produces an interpolated value that G2 calculates based on those history values. If the specified variable or parameter does not contain at least two history values, this expression produces a no value condition.

If G2 did not collect a value for the variable or parameter at the time interval you specify, it performs straight-line interpolation of the values that were collected immediately before and after that time interval. For instance, if the expression states 1 hour ago and collections occurred at 50 minutes and 1 hour 5 minutes ago, G2 interpolates those two values. In this way, interpolation differs from the value of expression, which returns the value received prior to the specified time interval, if no value was received as of the specified time interval.

Here is an example:



Note: When obtaining interpolated values at a maximum time period value, it is possible for the value to not be returned. For example, if you keep history for 30 seconds, and then try to obtain the interpolated value of the variable as of 30 seconds ago, G2 returns no value.

Computing Maximum and Minimum Values

To compute the maximum or minimum value of a variable or a parameter over a period of time:

If the specified variable or parameter contains at least one history value for the specified time interval, this expression produces the maximum or minimum of the history values received within the specified time interval. If the specified variable or parameter does not contain at least one history value within the specified time interval, this expression produces a no value condition.

Two examples are:


Computing the Rate of Change

To compute the rate of change within a particular time unit over a time period:

If the specified variable or parameter contains at least one history value for the specified time interval, this expression produces a rate of change statistic that G2 calculates based on those history values. If the specified variable or parameter does not contain at least one history value, this expression produces a no value condition.

The expression calculates the rate of change per second, minute, hour, day, or week of the specified variable or parameter over the specified time interval. G2 calculates the rate of change by dividing the total accumulated change during the specified time interval by the length of the time interval.

Two examples are:


G2 computes the rate of change by dividing the total accumulated change during the time period by the length of the time period.

Computing the Standard Deviation

To compute the standard deviation of the value over a selected period of time:

If the specified variable or parameter contains at least one history value for the specified time interval, this expression produces a standard deviation statistic that G2 calculates based on those history values. If the specified variable or parameter does not contain at least one history value within the specified time interval, this expression produces a no value condition.

Two examples are:


| Prev | Next | Start of Chapter | End of Chapter | Contents | Glossary | Index | Comments | (9 out of 14)

Copyright © 1997 Gensym Corporation, Inc.