Impact 2024: The Industrial Data and AI Conference for and by Users | Nominate Speakers Now for a Ch...
The aggregates are calculated on top of the original data that was ingested from the source system to Cognite Data Fusion (CDF). As described on the documentation, CDF doesn't return aggregates or interpolations for time ranges that have no data points.For example, if the original data contains data points with a 1s granularity (every second a new data point is being measured and stored), there should be no issues to request aggregates with 10s, 1m, 10m, 1h granularities. However if the original data contains data points with a 1m granularity, asking for a granularity of 10s would still yield a new value only on a 1m granularity.If you need to get a value for each 10s, you will need to upsample your data manually by implementing some sort of interpolation.Aggregates are convenient calculations that help to deal with high amounts of data, but if you want you can also take a look at the original data that was ingested into CDF by passing null to both Aggregates and Granularity. Here’s a
So, what’s probably happening is that there’s no datapoints inside of the time window you are sending in the request for the selected time series. In these situations the AggregateDatapoints object is null (empty list of Datapoints) and the code above will fail.You can catch such a scenario by checking for null references before accessing the Select method in the LINQ query. One way to do this is to use the null-conditional operator (?.) to check if ts.AggregateDatapoints is not null before accessing its Datapoints property.Here's a minimal example on how to deal with these cases:var dps = ts.AggregateDatapoints?.Datapoints?.Select( dp => new { DateTimeOffset.FromUnixTimeMilliseconds(dp.Timestamp).DateTime, dp.Average });if (dps == null){ throw new Exception("No datapoints were available in the selected time window.");}In this example, the ?. operator checks if ts.AggregateDatapoints is not null before accessing its Datapoints property. If either ts.Aggrega
For 0.5h you should use a granularity of 30m (as granularity cannot be a rational number). You can refer to the Cognite API documentation for more information about valid options for granularity and aggregates: https://docs.cognite.com/dev/concepts/aggregation/#granularity.
Hi @samirhaj!In C#, when you create a new object using the syntax new { propertyName = propertyValue }, you are creating an anonymous type object. In the case when you omit the property name, like when using the syntax new { propertyValue }, the compiler automatically generates a property name for each property based on the name of the property value.When you call Console.WriteLine with an anonymous type object as its argument, it automatically calls the ToString() method of the object to obtain a string representation of the object, which includes the names and values of its properties.As for your desire to create a CSV with the data, it’s quite simple, here’s a minimal example on how to do it:using (var writer = new StreamWriter("output.csv")){ writer.WriteLine("DateTime,Average"); foreach (var dp in dps) writer.WriteLine($"{dp.DateTime},{dp.Average}");}In this example we are using the StreamWriter which is part of the System.IO namespace in C#. We are first writing the
In this case, declaring the client with var or CogniteSdk.Client does not make a difference. The last command Build() creates an instance of the client that you can use to fetch time series data points as with the example above.
Hi @samirhaj! To use the CDF .NET SDK you will first need to use authenticate against your Identity Provider (IdP) to acquire a valid token. If you are using an Azure Active Directory (AAD), you can use the MSAL .NET library for this purpose.Here’s a minimal C# example that reads the AAD and associated CDF variables from environment variables, initiate an interactive flow to acquire the token and uses the token to instantiate the CDF client. If you refer to the MSAL documentation, it’s straightforward to extend this example to other authentication flows.string clientId = System.Environment.GetEnvironmentVariable("CLIENT_ID");string tenantId = System.Environment.GetEnvironmentVariable("TENANT_ID");string cluster = System.Environment.GetEnvironmentVariable("CDF_CLUSTER");string project = System.Environment.GetEnvironmentVariable("CDF_PROJECT");var scopes = new List<string>{ $"https://{cluster}.cognitedata.com/.default" };var app = PublicClientApplicationBuilder .Create(clientId)
If you want to stick with using the .NET SDK you can use the MSAL .NET library to acquire a valid token. Here’s a minimal C# example that reads the AAD and associated CDF variables from environment variables, initiate an interactive flow to acquire the token and uses the token to instantiate the CDF client. If you refer to the MSAL documentation, it’s straightforward to extend this example to other authentication flows.string clientId = System.Environment.GetEnvironmentVariable("CLIENT_ID");string tenantId = System.Environment.GetEnvironmentVariable("TENANT_ID");string cluster = System.Environment.GetEnvironmentVariable("CDF_CLUSTER");string project = System.Environment.GetEnvironmentVariable("CDF_PROJECT");var scopes = new List<string>{ $"https://{cluster}.cognitedata.com/.default" };var app = PublicClientApplicationBuilder .Create(clientId) .WithAuthority(AzureCloudInstance.AzurePublic, tenantId) .WithRedirectUri("http://local host") .Build();AuthenticationResult re
Already have an account? Login
Enter your username or e-mail address. We'll send you an e-mail with instructions to reset your password.
Sorry, we're still checking this file's contents to make sure it's safe to download. Please try again in a few minutes.
Sorry, our virus scanner detected that this file isn't safe to download.