AFCalculation Class
- Last UpdatedNov 18, 2025
- 6 minute read
- PI System
- AF SDK 2024 R2
- Developer
Inheritance Hierarchy
OSIsoft.AF.DataAFCalculation
Namespace: OSIsoft.AF.Data
Assembly: OSIsoft.AFSDK (in OSIsoft.AFSDK.dll) Version: 3.1.1.1182
Syntax
public static class AFCalculation
Public NotInheritable Class AFCalculation
public ref class AFCalculation abstract sealed
[<AbstractClassAttribute>] [<SealedAttribute>] type AFCalculation = class end
The AFCalculation type exposes the following members.
Methods
| Name | Description | |
|---|---|---|
| CalculateAtIntervals |
This method returns an AFValues collection that contains the result of evaluating the passed expression over the passed time range
at a defined interval.
| |
| CalculateAtRecordedValues |
This method returns an AFValues collection that contains the result of evaluating the passed expression at each
point in time over the passed time range where a recorded value exists for a member of the expression.
| |
| CalculateAtTimes |
This method returns an AFValues collection that contains the result of evaluating the passed expression over the passed points in time.
| |
| CalculateSummaries |
This method evaluates the specified expression over the passed time range.
The passed time range is first divided into a number of summary intervals.
The method then computes the specified summaries over each interval.
| |
| ConvertExpressionTarget |
Convert a Performance Equation (PE) Expression from one target to another.
| |
| ConvertFilterTarget |
Convert a Performance Equation Filter (PE) Expression used in a from one target to another.
| |
| DetermineEvaluationServer |
This method returns the server that the expression, with the specified target, will execute on.
| |
| PercentTrue |
This method evaluates the passed boolean expression over the passed time range.
The passed time range is first divided into a number of calculation intervals.
The method then computes the percentage of time the passed expression evaluates
to true over each of the periods.
|
Remarks
Expression syntax follows PI Performance Equation syntax. Expression variables are references to Attributes or PI Points using relative syntax to the target, which is typically an AFDatabase, AFElement or a PIServer. Variables must be enclosed in single quotes. Calculations are limited to Attributes or PI Points which originate from a single PI Data Archive. Attributes which resolve to a static value (no data reference configured), are also acceptable.
Examples of valid target and expressions:
| Target | Example Expression |
|---|---|
| null | '\\myPIServer\sinusoid'*2 |
| null | '\\myAFServer\myDB\myElement|myAttribute'*2 |
| PIServer | 'sinusoid'*2 |
| AFDatabase | 'myRootElement\myChildElement|myAttribute'*2 |
| AFElement | 'myAttribute'*2 |
| AFElement | 'myAttribute|myChildAttribute'*2 |
| AFElement | '.\myChildElement|myAttribute'*2 |
| AFElement | '\\myPIServer\sinusoid'*2 |
| AFEventFrame | 'myAttribute'*2 |
| AFAttribute | '.'*2 |
| AFAttribute | 'myChildAttribute'*2 |
| AFAttribute | '..|mySiblingAttribute'*2 |
| This method, property, or class is not available in the legacy .NET 3.5 version of the SDK. |
Examples
// This example demonstrates how to use the AFCalculation // object to evaluate expressions for Attributes and PI Points. // Get a Database PISystems myPISystems = new PISystems(); PISystem myPISystem = myPISystems.DefaultPISystem; AFDatabase myDB = myPISystem.Databases.DefaultDatabase; // Create an Element AFElement myElement = myDB.Elements.Add("MyElement"); // Create some attributes AFAttribute myAttributeA = myElement.Attributes.Add("A"); myAttributeA.DataReferencePlugIn = AFDataReference.GetPIPointDataReference(myPISystem); myAttributeA.ConfigString = @"\\%Server%\cdt158"; AFAttribute myAttributeB = myElement.Attributes.Add("B"); myAttributeB.Type = typeof(Single); myAttributeB.SetValue(Math.PI, null); // Calculate some interpolated values with AF Attributes AFTimeRange timerange = new AFTimeRange("Y", "T", CultureInfo.CurrentCulture); AFValues values = AFCalculation.CalculateAtIntervals(myElement, "'A' * 'B'", timerange, AFTimeSpan.Parse("1 hour")); Console.WriteLine("Calculated Values at Intervals:"); foreach (AFValue value in values) { Console.WriteLine(" '{0:0.000}' at '{1}'", value.Value, value.Timestamp); } // Calculate some values with PI Points PIServer piserver = new PIServers().DefaultPIServer; values = AFCalculation.CalculateAtRecordedValues(piserver, "'sinusoidu' + 'sinusoid'", timerange); Console.WriteLine("Calculated Values at Recorded Values:"); foreach (AFValue value in values) { Console.WriteLine(" '{0:0.000}' at '{1}'", value.Value, value.Timestamp); } // Calculate summaries, use both attributes and pi points string expression = String.Format(CultureInfo.InvariantCulture, @"'A' * 'B' + '\\{0}\sinusoid'", piserver.Name); IDictionary<AFSummaryTypes, AFValues> results = AFCalculation.CalculateSummaries(myElement, expression, timerange, AFTimeSpan.Parse("1 hour"), AFSummaryTypes.All | AFSummaryTypes.Average | AFSummaryTypes.Maximum | AFSummaryTypes.Minimum, AFCalculationBasis.TimeWeighted, AFSampleType.Interval, AFTimeSpan.Parse("5 minutes"), AFTimestampCalculation.Auto); foreach (KeyValuePair<AFSummaryTypes, AFValues> result in results) { Console.WriteLine("Summary Type {0} Results", result.Key); foreach (AFValue value in result.Value) { Console.WriteLine(" '{0:0.000}' at '{1}'", value.Value, value.Timestamp); } }
' This example demonstrates how to use the AFCalculation ' object to evaluate expressions for Attributes and PI Points. ' Get the Database Dim myPISystems As New PISystems Dim myPISystem As PISystem = myPISystems.DefaultPISystem Dim myDB As AFDatabase = myPISystem.Databases.DefaultDatabase ' Create An Element Dim myElement As AFElement = myDB.Elements.Add("MyElement*") ' Create some Attributes Dim myAttributeA As AFAttribute = myElement.Attributes.Add("A") myAttributeA.DataReferencePlugIn = AFDataReference.GetPIPointDataReference(myPISystem) myAttributeA.ConfigString = "\\%Server%\cdt158" Dim myAttributeB As AFAttribute = myElement.Attributes.Add("B") myAttributeB.Type = GetType(Single) myAttributeB.SetValue(Math.PI, Nothing) ' Calculate some interpolated values with AF Attributes Dim value As AFValue Dim timerange As AFTimeRange = New AFTimeRange("Y", "T", CultureInfo.CurrentCulture) Dim values As AFValues = AFCalculation.CalculateAtIntervals(myElement, "'A' * 'B'", timerange, AFTimeSpan.Parse("1 hour")) Console.WriteLine("Calculated Values at Intervals:") For Each value In values Console.WriteLine(" '{0:0.000}' at '{1}'", value.Value, value.Timestamp) Next value ' Calculate some values with PI Points Dim piserver As PIServer = New PIServers().DefaultPIServer values = AFCalculation.CalculateAtRecordedValues(piserver, "'sinusoidu' + 'sinusoid'", timerange) Console.WriteLine("Calculated Values at Recorded Values:") For Each value In values Console.WriteLine(" '{0:0.000}' at '{1}'", value.Value, value.Timestamp) Next value ' Calculate summaries, use both attributes and pi points Dim expression As String = String.Format(CultureInfo.InvariantCulture, "'A' * 'B' + '\\{0}\sinusoid'", piserver.Name) Dim results As IDictionary(Of AFSummaryTypes, AFValues) results = AFCalculation.CalculateSummaries(myElement, expression, timerange, AFTimeSpan.Parse("1 hour"), AFSummaryTypes.All Or AFSummaryTypes.Average Or AFSummaryTypes.Maximum Or AFSummaryTypes.Minimum, AFCalculationBasis.TimeWeighted, AFSampleType.Interval, AFTimeSpan.Parse("5 minutes"), AFTimestampCalculation.Auto) Dim result As KeyValuePair(Of AFSummaryTypes, AFValues) For Each result In results Console.WriteLine("Summary Type {0} Results", result.Key) For Each value In result.Value Console.WriteLine(" '{0:0.000}' at '{1}'", value.Value, value.Timestamp) Next value Next result
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.