Jump to content

API Call with C# in order to retrieve signals


Recommended Posts

Hi,

I've been wondering recently, how to make API calls with C# based on Seeq-server-sdk-R58 in order to retrieve signals limited by date range.

I was planning to connect to SEEQ API by access token, retrieve signals by their IDs, and limit the number of rows that could be retrieved at once. 

Has anyone accomplished something like that? I was trying but personally, I do not have much experience in c# and REST API. 

 

Thanks in advance for any advice!

Link to comment
Share on other sites

Hi Acerion12,

I am not quite sure what you mean with getting a signal limited by date range. So I created a quick-and-dirty example to get a signal by its ID and also retrieve its samples over a specific date range. The query will only return 40 samples for each call.

Seeq.Sdk.Client.ApiClient client = new Seeq.Sdk.Client.ApiClient("https://<YOUR SERVER>/api");
Seeq.Sdk.Api.AuthApi authApi = new Seeq.Sdk.Api.AuthApi(client);
authApi.Login(new Seeq.Sdk.Model.AuthInputV1 { Username = "<YOUR ACCESSKEY>", Password = "<YOUR PASSWORD FOR THE ACCESSKEY>" });

string signalId = "14E630B3-E615-4B84-9EE3-4B685D5A3938";

Seeq.Sdk.Api.SignalsApi signalsApi = new Seeq.Sdk.Api.SignalsApi(client);
Seeq.Sdk.Model.SignalOutputV1 signal = signalsApi.GetSignal(signalId);
Console.WriteLine("Signal: {0}", signal.Name); 

string start = DateTime.Now.AddDays(-3).ToUniversalTime().ToString("o");
string end = DateTime.Now.AddDays(-2).ToUniversalTime().ToString("o");
int offset = 0;
int numberOfItems = 40;
Seeq.Sdk.Model.GetSamplesOutputV1 samples;

do
{
    samples = signalsApi.GetSamples(signalId, start, end, null, null, null, null, null, offset, numberOfItems);

    foreach (Seeq.Sdk.Model.SampleOutputV1 sample in samples.Samples)
        Console.WriteLine("{0} : {1}", sample.Key, sample.Value);

    offset += numberOfItems;
    
} while (!string.IsNullOrEmpty(samples.Next));

client.Logout();

Does this answer your question?

Regards,

Thorsten

Link to comment
Share on other sites

Thanks Thorsten, it works. 

Just one more question, do you think that in order to retrieve a list of signals adding a foreach loop will be enough and optimal? (At this moment, I am going to pull out at max 30 signals once a day (1 row of data per 1 hour))

List <string> signalsID = new List<string>();
signalsID.Add("F7AC2007-4243-4B31-9E42-6EAEBCB068C1");
signalsID.Add("6D966E1D-3E8A-48CA-A84B-E665EB404EDF");
foreach (string singal  in signalsID)
{
  string signalId = singal;
  //rest of the code....
  
  do
  {
    //do
  }
}
  

 

There is still one more thing that concerns me. Providing some explanation, I am more Python enthusiast, and in that language, it would be easy to transform that kind of list into a data frame (data table). May you propose the way that I should follow to convert the output into data table in c#?

As I mentioned, I am a beginner in terms of c#.

 

Regards,

 

Edited by Acerion12
New question.
Link to comment
Share on other sites

I don't know your exact requirements, but I guess for quering hourly values for 30 signals once a day a for loop is a good start.

You can try the Microsoft.Data.Analysis Package (https://www.nuget.org/packages/Microsoft.Data.Analysis/). It contains a DataFrame class, which is similar to a Pandas DataFrame. I modified the example from above making use of the DataFrame class and filtering on rows where the value is greater than 100:

List<DateTime> keys = new List<DateTime>();
List<double> values = new List<double>();

do
{
    samples = signalsApi.GetSamples(signalId, start, end, null, null, null, null, null, offset, numberOfItems);

    foreach (Seeq.Sdk.Model.SampleOutputV1 sample in samples.Samples)
    {
        keys.Add((DateTime)sample.Key);
        values.Add((double)sample.Value);
    }
    offset += numberOfItems;

} while (!string.IsNullOrEmpty(samples.Next));

Microsoft.Data.Analysis.DataFrameColumn[] columns =
{
    new Microsoft.Data.Analysis.PrimitiveDataFrameColumn<DateTime>("Key", keys),
    new Microsoft.Data.Analysis.PrimitiveDataFrameColumn<double>("Value", values)
};

Microsoft.Data.Analysis.DataFrame df = new Microsoft.Data.Analysis.DataFrame(columns);

df = df.Filter(df["Value"].ElementwiseGreaterThan(100));

foreach (Microsoft.Data.Analysis.DataFrameRow row in df.Rows)
    Console.WriteLine("{0} : {1}", row[0], row[1]);

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...