_dp_fct (DP function)

You can assign a function to a data point element via a config panel. In this way you can implement mathematical links between data points. The data point function contains one or more parameters used to calculate the value of the defined function and to assign it to the original value of the data point element. The permissible parameters p1...pn are the "original" or "online" values of elements of other data points.

In order to rule out endless loops during internal processing of the respective data points, do not use a data point element as a parameter in its function.

The function itself is defined as a mathematical link of the parameters. Of course, you can also assign DP functions to data points in Control scripts using dpSet() (see User Manual, Control Functions).

Only use data point elements of the own system as parameters!

When you select the "dp_fct" config the following panel is displayed. The top field displays the name of the data point element to be edited. In the Function type combo box you can choose between

  • DPE connection
  • Statistical function

Click the Configure button to open the panel to configure the selected function. Click the button Close to leave the panel.

Figure 1. DP function panel

Dp function

The config attributes can be found in the Appendix.

DP function panel

If you selected DPE link as the function type, pressing the button Configure will open the following panel:

Figure 2. Data point function panel

Parameters

The Parameters list lists the parameters to be linked when calculating the function.

  • Enter new parameters in the Parameters list.
  • The order of parameters is specified using the buttons (see Buttons). The current item is displayed selected in the list of parameters.
  • Selected items can be removed from the list by pressing Delete.
  • You can edit selected items in the "Value of a DPE as parameter p.." table by left-clicking the item in the table, entering a new DPE into the "p..=" text field and then clicking the button . The selected item is replaced by the item in the "p..=" text field.
  • The button DP is used to enter data point parameters. Click this button to open the Data pointSelector dialog box.

Configure equal data point elements (with different configs) only sequentially, to avoid equal internal times. Otherwise you cause error messages.

In the same way you can define the global variable for data point functions. Global variables are, however, only called once, after which changes in values are not taken into account. This means that the function value is always multiplied by the same value of g1.

Function

This field is used to define the data point function and to link parameters with each other. Permissible inputs are defined parameters p1, p2, ... and mathematical links. Mathematical operators +,-,*,/,%,&,|,^,~,<<,>>, &&, ||, ?, <,>,<=,>=,==,!=,++ can be used, see chapter Operators in CONTROL.

An assignment by using = is not permitted!

You can also use a Control function with a return value. Note that waiting functions ( dpSetWait, delay, dpQuery …) are not permitted. Furthermore, the system() function is not permitted.

The following code is generated for a dpFunction:

anytype work(anytype p1, … anytype pn)
{
  return <string of the edit line in PARA>;
}
EXAMPLE: p1 + p2 are used as follows:
anytype work(anytype p1, anytype p2)
{
  return p1 + p2;
}
The expression must be a valid CTRL script. By using a function, you can also use it as follows:
If a dp_fct dynlen(p1) is configured for an integer DPE and p1 is a dyn DPE:
anytype work(anytype p1)
{
  return dynlen(p1);
}

If you call a function of a CTRL library ( <proj_path>/libs) in the "Function" text field you can use the return value of the function for the calculation.

Example

This example describes how to use the DP function. In this example the sum C=A+B is calculated. There are three data points of the type int - "datapoint_C", "datapoint_A" and "datapoint_B".

  • Add a _dp_fct config to the data point "datapoint_C" via the PARA module:
Figure 3. Insert config -> Datapoint function
  • Click on the item "_dp_fct" of "datapoint_C" to open the "DP function" panel. Select the Function Type: DPE connection.
Figure 4. datapoint_C and the DP function
  • Click on the Configure ... button to open the Configuration panel.
  • Enter the first parameter "datapoint_A.:_original.._value" in the text field below the "Value of a DPE as parameter p" table or select the data point via the data point selector.
Figure 5. DP Function - "Value of a DPE as parameter p.."
  • Click the button "To" to add the item to the list of parameters and display it.
  • Enter the second parameter "datapoint_B.:_original.._value" and click again the button to add it.
  • Add the calculation "p1+p2" to the "Function" text field:
Figure 6. Function p1 + p2
  • Click the button Apply and then OK to store the function for the data point "datapoint_C".
  • Set values for the data points "datapoint_A" and "datapoint_B". Check the original value of the data point "datapoint_C". The sum of the data points "datapoint_A" and "datapoint_B" is written to the data point "datapoint_C".

Old new Comparison

You can activate old/new comparison for this data point function by ticking this check box.

Statistical functions

Statistical functions are used to obtain interval-based statistical values (e.g. mean, maximum, etc.) from online values, original values and offline values (see Correction values and statistical functions). Depending on the settings, the quality information in the status bits is also taken into account. The panel consists of three tabs.
Note: With NGA in a redundant system note that a statistical function is initialized with the existing data in the database.

If buffers are still pending at the time of initialization and these buffers contain data that is relevant for the function calculations, the correctness of the results of the statistical functions cannot be guaranteed, as the data that still needs to be written to the database has not been taken into account.

Figure 7. Statistical functions - Parameters tab

Parameters tab

  • The name (and description or alias) of the data point element to be edited is displayed at the top right of the panel in the combo box.
  • The data point attributes are selected using the DP selector button or entered directly in the input box. This input is mandatory.
  • The 4 buttons are used to add the item before or after the last item, and to edit or delete the item.
  • Alongside there is a combo box in which you can select various statistical functions.
  • Below that you can specify the global variable (optional). The variable is only called once, as in DP functions, changes of values are not taken into account (see above).
  • The result of the function is defined in the bottom input box.
Type int / float bit all Control constant Comment
Minimum yes SF_MIN
Maximum yes SF_MAX
Minimum time no (time) SF_MIN_TIME Time when minimum occurs
Maximum time no (time) SF_MAX_TIME Time when maximum occurs
Number yes yes yes SF_NUMBER
Sum yes SF_SUM
Integral 0 yes SF_INTEGRAL0 Integral by stepped curve (0 order)
Integral 1 yes SF_INTEGRAL1 Integral by linear interpolation (1 order)
Average yes SF_AVG Sum/number
Average 0 yes SF_AVG_WT0 Integral by stepped curve (0 order)/time
Average 1 yes SF_AVG_WT1 Integral by linear interpolation (1 order)/time
Time 0 yes SF_TIME0 Time for which state 0 existed
Time 1 yes SF_TIME1 Time for which state 1 existed
State change yes SF_CHANGES Number of state changes (both 0 -> 1 and 1 -> 0)
Change 0 -> 1 yes SF_CHANGES01 Number of state changes 0-> 1
Change 1>0 yes SF_CHANGES10 Number of state changes 1 > 0
Start value yes SF_SAMPLE Value at start of interval
End value yes SF_ENDVALUE Value at end of interval
Difference yes SF_DIFF End value less start value

Minimum and maximum values are calculated from the stepped curve interpolation and not from the series of values, i.e. minimum and maximum time are always in the current range and if no new values occur during an interval, minimum and maximum contain the first known value of an interval as time stamp.

Both integral functions return their result in the unit: unit of base variable multiplied by seconds.

Synchronization tab

Figure 8. Synchronization tab

The time of calculation is set on the Synchronization tab.

Example

  • Select a calculation time interval (Calc.time interval), e.g., 86400 for a calculation for one day. The button with the clock opens a dialog box (see figure below) which allows you to define longer periods.
Figure 9. Calc time interval
  • Enter the time(s) at which you want a calculation to take place: the calculation can be restricted to a month, to a day of the week, to a day of month or to a combination of these. On the "Parameter" tab, select what type of calculation (e.g. average) should be executed.

Example

You can start a calculation, for example, each Sunday 0h00m00s. Select the calculation time interval 1 hour (3600 seconds) via the button with the clock symbol. Check the check box "On day of week" and select "Sunday". Set the time to 0h00m00s. Select the function average value from the "p" combo box on the "Parameter" tab. Note that the calculation is not executed only once but starting from the synchronization time, every x (Calc.time interval) seconds. In this case every 3600 seconds, meaning every hour on Sundays.

Example

  • A calculation can be restricted to a month. Select the month 6 from the "In month. no." combo box. The calculation is executed every day in June.
  • A calculation can be restricted to a day of month. Activate in addition to the option "In month. no." the check box "On day of month" and select the number 2. The calculation is only executed on the 2nd of June (2.6)
  • Activate in addition to the above described options the check box "On day of week" and select the day "Wednesday". The calculation is executed on the 2nd of June but only if the 2nd of June is a Wednesday.
  • Enter a value for the auto delay. The calculation is automatically delayed until the first value that does not fit in the interval, occurs (can be used, for example, when editing laboratory values manually).

Delay: You can also enter a value that delays the calculation accordingly. The calculation is automatically delayed as long as the first value that does not fit the interval, occurs. You can, for example, calculate the day average so that the function also includes the last hourly average in the calculation.

In case of a new data point, you can set the time for the delayed calculation, for a value, up to a week before the date you created the data point. For example, today is the 24th of July. You can create a new data point with a statistical function and delayed calculation and then enter a historic value, for example, 20th of July.

Consider the following for data points that contain compression levels: If you set the delay time of a master data point equal to the calculation time interval, random delay times are created for the data points of the master data point, as follows:

Minute value -> 10 - 50

5 minute value -> 70 - 200

10, 15 minute value -> 210 - 600

Hourly value -> 610 - 1800

Daily value -> 1810 - 3600

Monthly value -> 3610 - 10000

>Monthly value -> 14410 - 18010 -> after 5 hours also the annual values are calculated!!

The times above are time intervals of compression levels. For more information, see chapter Archiving and Compression, basics

If you have e.g. a data point type with the compression level "5 Minute value" and set the auto delay of the statistical function of the master data point, equal to the calc.time interval, the auto delay for the element "C1" (5 minute value) of the data point (created via the AC compression) is set to a value between 70 and 200 (see the list above).

  • Floating calculation. This option allows you to calculate a value of an arbitrary function. The floating calculation can be used for all statistical functions. How many values are calculated results from the "Calculation time interval" and the "Part interval" (see figure below). The average of the, for example, last four fifteen minute values of the last hour. Note that the Part interval has to be an integer. If the Calculation time interval (Calc. time interval) is one hour and the Part interval is 10 minutes, 6 values are calculated (the value of the last hour is calculated every 10 minutes).
Figure 10. Statistical Function/ Floating Calculation/ Part interval
  • Initialize calculation from archive. Click on the option to obtain the values from the entire month. If this option is set, the data for the actual period is read from the archive at system startup and will then be used in the calculation.
  • This option shall be set for all calculation intervals
    • which use input signals that are saved inside the archive.
    • with a calculation interval higher then the average startup time of the project.
  • With the selection of this option the statistical functions allow you to display intermediate results cyclically. The user can, for example, view the daily maximum so far while saving a daily maximum. Enter the time intervals for the floating calculation into the "Part interval" text field. The text field is only shown after selecting the "Floating calculation" option. See step 4 for part interval and floating calculation.

Each value, that coincide with the intervals limit, is computed only once at the beginning of the interval.

If the Event Manager does not manage to calculate the statistical functions in time (e.g. because of overload), all older periods (Calc.time interval) in the buffer beginning from a delay of n intervals (regardless of possible delay time!) are discarded, a message is shown and the last n interval is calculated. n can be specified via the config entry statFctMaxIntervalsInPast (Default is 3). 3 intervals are considered (interval beginning from the end of the interval until the current time). This is also valid for functions with delayed calculation. These have to be executed within 3 periods otherwise the lapsed periods are discarded.

Bit tab

On the Bit tab you can specify what effect status bits have on calculations.

Figure 11. Tab for setting bits

It is also possible to add the quality information to the result value.

checked status bit added status bit
invalid aut_inv
default exp_default
userbit1 userbit1
.... ....
userbit8 userbit8

A column lists all bits that can affect the calculation. You can set one threshold per bit. To do so, enter a value in the appropriate field.

Select from the following options in the Status bit handling combo box:

  • None: The status bit is not taken into account for calculation (default).
  • Ignore Value: values for which this bit is set are processed as if they had never occurred, the calculation period for statistical functions is not affected by this. If you have specified that value or time bits are processed for several bits, the affected bits are combined by an OR and the result bit is used for calculation. Moreover, all of these bits must have the same status bit treatment configured. Otherwise a parameter error will occur (if, e.g., the ASCII Manager inputs such data).
  • Ignore Period: the period in which the bit was set is not taken into account for calculation. If you have specified that value or time bits are processed for several bits, the affected bits are combined by an OR and the result bit is used for calculation. Moreover, all of these bits must have the same status bit treatment configured. Otherwise a parameter error will occur (if, e.g., the ASCII Manager inputs such data).
  • Transfer Bits: The status bit is not taken into account for the calculation. Additionally the status bit is transferred according to the selected threshold. In other words the status bit is set for the _original config of the data point element for which the _dp_fct was activated.

The threshold is a value in per cent and is evaluated as follows:

  • If the bit is set the same length or longer from the calculation interval than the time Threshold %, the bit from the column "added status bit" is set in the result bit (the bits "invalid" and "default" are read-only attributes and cannot be added directly).
  • If threshold = 0%, every occurrence causes the bit to be added.
  • If it is a negative value (default = -1) the bit is never added. The "aut_inv" bit is already set in the current statistical functions when internal errors occur. This invalid state is linked with the OR derived from the "invalid" bit.
Figure 12. Examples of statistical function calculations

Correction values and statistical functions

Correction value handling has been added to the statistical DP functions. This is performed automatically when you register the DP function to the config "_offline.._value" (but not for _original/_online.._value). Details:

The user sends a correction value xx.:_corr.._value to a data point that is the source for another statistical function. In this case, the Event Manager recalculates the statistical function. Two cases are possible:

Interval not yet calculated:

If the interval has not been calculated, the correction value is included in the current calculation at the end of the interval. The following also applies:

  • the dependent value (the daily value in the examples) is only marked as a correction value if the change is greater than statFctLimitForMarkAsCorrcted (default: 0; see below) in relation to the non-corrected daily value.
  • Otherwise, the value is sent without correction. For this decision, the value WITHOUT corrections (online value) is compared to the value WITH corrections (offline value) (see Config entry statFctInheritCorrValues).

Example

To obtain an hourly mean, a daily mean and a monthly mean from a reading. The hour value of 02:00 is corrected by 06:00, then a daily value that is not calculated until 24:00 must be calculated with this correction.

Interval already calculated

If the interval is already finished, the calculation must be performed from the history values in order to mark a value as a correction value.

This correction value can then be used for calculation of another statistical function (recursion!).

Example

Yesterday's hour value, 02:00, is corrected by 06:00 today. Then the daily value that was already calculated is recalculated. This daily value from yesterday, in turn, is contained in the monthly value that has not been calculated yet. This monthly value is reinitialized again according to the first method.

statFctInheritCorrValues

You can set the behavior of statistical functions in the config file. The config entry statFctInheritCorrValues (type: bool, default: 1) decides whether the correction values should be accepted. By default, the correction value changes are accepted.

[general]
statFctInheritCorrValues = 1

If 0, changes are not accepted, the statistical functions work as usual.

statFctLimitForMarkAsCorrected

The config entry statFctLimitForMarkAsCorrected (condition: statFctInheritCorrValue = 1) specifies the threshold for the accepted correction values (type: int, default: 0, range 0-1000 %% thousandths).
[general]
statFctLimitForMarkAsCorrected = 0

If 0, all values are marked as corrected. Values greater than 0 only mark values as of a change greater than x %%.

The correction values that are set for the statistical functions, trigger a recalculation exclusively in the period where they were set. The following periods are not recalculated.

If a correction value has an influence on the last value of the period, also the following period should be recalculated as long as the correction value does not cause a change in the following periods, compared to the original values.

Example

A constant value, for example, 10 existed for several days. A daily average was calculated from this value. If this value is corrected to 15, all following periods that were created in this period should be recalculated. The following periods are, however, not recalculated. Only the daily average of the DAY for which the correction value is set, is corrected. The daily average remains 10 for all following days. In the same way, the weekly value of the week during which the daily correction value was set, is corrected. The following weekly value is, however, not corrected.