Click or drag to resize
OSIsoft, LLC

AFCalculation Class

The static class AFCalculation provides mechanisms to evaluate expressions.
Inheritance Hierarchy
SystemObject
  OSIsoft.AF.DataAFCalculation

Namespace:  OSIsoft.AF.Data
Assembly:  OSIsoft.AFSDK (in OSIsoft.AFSDK.dll) Version: 2.10.6.195
Syntax
public static class AFCalculation

The AFCalculation type exposes the following members.

Methods
  NameDescription
Public methodStatic memberCalculateAtIntervals
This method returns an AFValues collection that contains the result of evaluating the passed expression over the passed time range at a defined interval.
Public methodStatic memberCalculateAtRecordedValues
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.
Public methodStatic memberCalculateAtTimes
This method returns an AFValues collection that contains the result of evaluating the passed expression over the passed points in time.
Public methodStatic memberCalculateSummaries
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.
Public methodStatic memberConvertExpressionTarget
Convert a Performance Equation (PE) Expression from one target to another.
Public methodStatic memberConvertFilterTarget
Convert a Performance Equation Filter (PE) Expression used in a from one target to another.
Public methodStatic memberDetermineEvaluationServer
This method returns the server that the expression, with the specified target, will execute on.
Public methodStatic memberPercentTrue
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.
Top
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:

TargetExample 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

Note Notes to Callers
This method, property, or class is only available in the .NET 4 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);
    }
}
Version Information

AFSDK

Supported in: 2.10.5, 2.10, 2.9.5, 2.9, 2.8.5, 2.8, 2.7.5, 2.7, 2.6, 2.5
See Also
Enabling Operational Intelligence