Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AF SDK Reference

AFAnalysis.GetCounts(T) Method (AFDatabase)

  • Last UpdatedNov 18, 2025
  • 4 minute read
AFAnalysis.GetCounts(T) Method (AFDatabase)
Get the number of analyses for each filter.

Namespace:  OSIsoft.AF.Analysis
Assembly:  OSIsoft.AFSDK (in OSIsoft.AFSDK.dll) Version: 3.1.1.1182

Syntax

public static IList<KeyValuePair<T, int>> GetCounts<T>(
	AFDatabase database
)
where T : AFObject
Public Shared Function GetCounts(Of T As AFObject) ( 
	database As AFDatabase
) As IList(Of KeyValuePair(Of T, Integer))

Dim database As AFDatabase
Dim returnValue As IList(Of KeyValuePair(Of T, Integer))

returnValue = AFAnalysis.GetCounts(database)
public:
generic<typename T>
where T : AFObject
static IList<KeyValuePair<T, int>>^ GetCounts(
	AFDatabase^ database
)
static member GetCounts : 
        database : AFDatabase -> IList<KeyValuePair<'T, int>>  when 'T : AFObject

Parameters

database
Type: OSIsoft.AFAFDatabase
The database to search for analysis counts by filter.

Type Parameters

T
The type of objects used to filter analyses. The following types are supported: AFAnalysisTemplate, AFCategory.

Return Value

Type: IListKeyValuePairT, Int32
Returns a list of KeyValuePairTKey, TValue items where the key is the filter object of the analyses and the value is the number of analyses associated to the filter object. The key will be for the analyses that do not have the filter object.

Remarks

This method will make one call to the server to get the number of analyses associated with each filter object. For a filter type of AFAnalysisTemplate, this method will return the number of analyses created from each analysis template. For a filter type of AFCategory, this method will return the number of analyses for each analysis category.

Examples

// This example demonstrates how to call the GetCounts method to return
// the number of analyses based upon different filters.

// Get the Database
PISystems myPISystems = new PISystems();
PISystem myPISystem = myPISystems.DefaultPISystem;
AFDatabase myDB = myPISystem.Databases.DefaultDatabase;

// Create some filter objects
AFCategory myCategory1 = myDB.AnalysisCategories.Add("MyCategory#1");
AFCategory myCategory2 = myDB.AnalysisCategories.Add("MyCategory#2");
AFAnalysisTemplate myTemplate = myDB.AnalysisTemplates.Add("MyTemplate#1");
myTemplate.Categories.Add(myCategory1);

// Create some Analyses
AFAnalysis myAnalysis0 = new AFAnalysis(myDB, "MyAnalysis#0");
myAnalysis0.Description = "This is the analysis with no categories or template";
myAnalysis0.SetStatus(AFStatus.Enabled);
AFAnalysis myAnalysis1 = new AFAnalysis(myDB, "MyAnalysis#1", myTemplate);
myAnalysis1.Description = "This is the first analysis example";
myAnalysis1.Categories.Add(myCategory2);
myAnalysis1.SetStatus(AFStatus.Enabled);
AFAnalysis myAnalysis2 = new AFAnalysis(myDB, "MyAnalysis#2");
myAnalysis2.Description = "This is the second analysis example";
myAnalysis2.Categories.Add(myCategory2);
myAnalysis2.SetStatus(AFStatus.NotReady);
myDB.CheckIn();

// Get analysis counts by Status and display results
IList<KeyValuePair<AFStatus, int>> statusCounts = AFAnalysis.GetCounts(myDB);
foreach (var item in statusCounts)
{
    Console.WriteLine("{0} = {1}", item.Key, item.Value);
}

// Get analysis counts by Category and display results
IList<KeyValuePair<AFCategory, int>> catCounts = AFAnalysis.GetCounts<AFCategory>(myDB);
foreach (var item in catCounts)
{
    Console.WriteLine("{0} = {1}", item.Key, item.Value);
}

// Get analysis counts by Template and display results
IList<KeyValuePair<AFAnalysisTemplate, int>> tmplCounts = AFAnalysis.GetCounts<AFAnalysisTemplate>(myDB);
foreach (var item in tmplCounts)
{
    Console.WriteLine("{0} = {1}", item.Key, item.Value);
}
' This example demonstrates how to call the GetCounts method to return
' the number of analyses based upon different filters.

' Get the Database
Dim myPISystems As New PISystems()
Dim myPISystem As PISystem = myPISystems.DefaultPISystem
Dim myDB As AFDatabase = myPISystem.Databases.DefaultDatabase

' Create some filter objects
Dim myCategory1 As AFCategory = myDB.AnalysisCategories.Add("MyCategory#1")
Dim myCategory2 As AFCategory = myDB.AnalysisCategories.Add("MyCategory#2")
Dim myTemplate As AFAnalysisTemplate = myDB.AnalysisTemplates.Add("MyTemplate#1")
myTemplate.Categories.Add(myCategory1)

' Create some Analyses
Dim myAnalysis0 As New AFAnalysis(myDB, "MyAnalysis#0")
myAnalysis0.Description = "This is the analysis with no categories or template"
myAnalysis0.SetStatus(AFStatus.Enabled)
Dim myAnalysis1 As New AFAnalysis(myDB, "MyAnalysis#1", myTemplate)
myAnalysis1.Description = "This is the first analysis example"
myAnalysis1.Categories.Add(myCategory2)
myAnalysis1.SetStatus(AFStatus.Enabled)
Dim myAnalysis2 As New AFAnalysis(myDB, "MyAnalysis#2")
myAnalysis2.Description = "This is the second analysis example"
myAnalysis2.Categories.Add(myCategory2)
myAnalysis2.SetStatus(AFStatus.NotReady)
myDB.CheckIn()

' Get analysis counts by Status and display results
Dim statusCounts As IList(Of KeyValuePair(Of AFStatus, Integer)) = AFAnalysis.GetCounts(myDB)
For Each item As KeyValuePair(Of AFStatus, Integer) In statusCounts
    Console.WriteLine("{0} = {1}", item.Key, item.Value)
Next

' Get analysis counts by Category and display results
Dim catCounts As IList(Of KeyValuePair(Of AFCategory, Integer)) = AFAnalysis.GetCounts(Of AFCategory)(myDB)
For Each item As KeyValuePair(Of AFCategory, Integer) In catCounts
    Console.WriteLine("{0} = {1}", item.Key, item.Value)
Next

' Get analysis counts by Template and display results
Dim tmplCounts As IList(Of KeyValuePair(Of AFAnalysisTemplate, Integer)) = AFAnalysis.GetCounts(Of AFAnalysisTemplate)(myDB)
For Each item As KeyValuePair(Of AFAnalysisTemplate, Integer) In tmplCounts
    Console.WriteLine("{0} = {1}", item.Key, item.Value)
Next

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.

Version Information

AFSDK

Supported in: 3.1.1, 3.1.0, 3.0.2, 3.0.1, 3.0.0, 2.10.11, 2.10.5, 2.10.0, 2.10, 2.9.5, 2.9, 2.8.5, 2.8, 2.7.5, 2.7

See Also

In This Topic
Related Links
TitleResults for “How to create a CRG?”Also Available in