Get trends - Metasys - LIT-12013522 - Software Application - Basic Services client library for .NET (and COM) - Metasys API - 4.2

Metasys REST Client for .NET and COM Developer Guide

Brand
Metasys
Product name
Basic Services client library for .NET (and COM)
Metasys API
Document type
API Reference Guide
Document number
LIT-12013522
Version
4.2
Revision date
2021-04-07
Language
English

To get all available samples using a specific time filter, use the GetSamples method. The library delivers a PagedResult that contains a list of Sample. The GetSamples method accepts the GUID of the object, the attribute ID, and a TimeFilter object to filter the response.

Table 1. Get trend samples .NET signature
Library method name GetSamples
Description To get available trends samples
Method signature PagedResult<Sample> GetSamples(Guid objectId, int attributeId, TimeFilter filter);
Method input parameters
  • objectId: GUID of the object the method targets and retrieves the trend samples.
  • attributeId: numeric identifier of the attribute configured for the trend.
  • filter: filter object that specifies the start time and the end time the method uses to filter the target samples.
Return value A PagedResult of Sample.
The following .NET C# code is an example of a successful get trends response:
Guid trendedObjectId = client.GetObjectIdentifier("Win2016-VM2:vNAE2343701/Field Bus MSTP1.VAV-08.ZN-T");
// Get attributes where trend extension is configured
List<Attribute> trendedAttributes = client.Trends.GetTrendedAttributes(trendedObjectId);
int attributeId = trendedAttributes[0].Id;
TimeFilter timeFilter = new TimeFilter
  {
    StartTime = new DateTime(2020, 5, 12),
    EndTime = new DateTime(2020, 5, 13)
  };
PagedResult<Sample> samplesPager = client.Trends.GetSamples(trendedObjectId, attributeId, timeFilter);              
// Prints the number of records fetched and paging information
Console.WriteLine("Total:" + samplesPager.Total);
Console.WriteLine("Current page:" + samplesPager.CurrentPage);
Console.WriteLine("Page size:" + samplesPager.PageSize);
Console.WriteLine("Pages:" + samplesPager.PageCount);
/*                       
Total:145
Current page:1
Page size:100
Pages:2
*/
Sample firstSample = samplesPager.Items.FirstOrDefault();
Console.WriteLine(firstSample);
/*                       
  {
    "Value": 82.0,
    "Unit": "deg F",
    "Timestamp": "2020-05-12T05:00:00Z",
    "IsReliable": true
  }
*/