Accessing metrics when using Analytics query & .NET SDK

Hi,

This I'm quite sure is a stupid question but I'm struggling to work with the metrics that return from an analytics query. In this case I'm performing a Queue Observation query. I can get the results out and loop through each of them but I'm not entirely sure how I should access each one individually.

For example I want to add a custom label and display them in a WPF app. How can I access the data - like, assign "Oonqueueueusers" to a specific variable (or display in a text box)?

This is the query I have so far and it works (in as much as it returns me the data) but I'm at a loss on how to access it to better present it. In this example I'm just writing it to the console, and I get output like:

oInteracting: 1
oWaiting: 0
oMemberUsers: 17
oOnQueueUsers: 1

But I'd like to be able to have these values in individual text boxes, or in a data grid.

var analyticsApi = new AnalyticsApi();
            var body = new QueueObservationQuery();
            var filter = new QueueObservationQueryFilter();

        List<QueueObservationQueryPredicate> predicates = new List<QueueObservationQueryPredicate>();   
        QueueObservationQueryPredicate predicateQueue = new QueueObservationQueryPredicate();
        predicateQueue.Type = QueueObservationQueryPredicate.TypeEnum.Dimension;
        predicateQueue.Dimension = QueueObservationQueryPredicate.DimensionEnum.Queueid;
        predicateQueue._Operator = QueueObservationQueryPredicate.OperatorEnum.Matches;
        predicateQueue.Value = queueId;
        predicates.Add(predicateQueue);

        QueueObservationQueryPredicate predicateMedia = new QueueObservationQueryPredicate();
        predicateMedia.Type = QueueObservationQueryPredicate.TypeEnum.Dimension;
        predicateMedia.Dimension = QueueObservationQueryPredicate.DimensionEnum.Mediatype;
        predicateMedia._Operator = QueueObservationQueryPredicate.OperatorEnum.Matches;
        predicateMedia.Value = "voice";
        predicates.Add(predicateMedia);

        List <QueueObservationQuery.MetricsEnum> metrics = new List<QueueObservationQuery.MetricsEnum>();
        metrics.Add(QueueObservationQuery.MetricsEnum.Oonqueueusers);
        metrics.Add(QueueObservationQuery.MetricsEnum.Ooffqueueusers);
        metrics.Add(QueueObservationQuery.MetricsEnum.Owaiting);
        metrics.Add(QueueObservationQuery.MetricsEnum.Ointeracting);
        metrics.Add(QueueObservationQuery.MetricsEnum.Omemberusers);

        filter.Predicates = predicates;
        filter.Type = QueueObservationQueryFilter.TypeEnum.And;
        body.Filter = filter;
        body.Metrics = metrics;
        
        try
        {
            // Query for queue observations
            QueueObservationQueryResponse result = analyticsApi.PostAnalyticsQueuesObservationsQuery(body);
            foreach (var dataresult in result.Results)
            {
                foreach (var metric in dataresult.Data)
                {
                    Console.WriteLine($"{metric.Metric}: {metric.Stats.Count}");
                }
            }
        }
        catch (Exception error)
        {
            Console.WriteLine("Exception when calling AnalyticsApi.PostAnalyticsQueuesObservationsQuery: " + error.Message);
        }

This is a bit rough draft, but your question is pretty broad;

Create a class that inherits from DialogWindow, add a constructor to your custom class that takes a QueueObservationQueryResponse, run your query, create your instance of the new dialog passing the data to it, call ShowModal() and setup your display either directly in the XAML or do any transformation in the constructor then display it in the XAML.

Oh, yikes, that was a bit more complicated than I had hoped / expected.

I will dig into that and see how far I get...

Thank you for the direction.

Edit: I'm actually not sure I entirely understand your answer. I already have the WPF Window etc constructed, so, I guess the question is - how do I do this part: "do any transformation in the constructor then display it in the XAML". E.g. I have the query response containing the data I need - one part of that data is the metric oInteracting. I can access this by looping through every bit of data in the result but how can I specifically retrieve this one part?

You're dancing around an area that can fill libraries, unfortunately.

Once you can visualize what you want your end output to look like, work back from there to design a class that best expresses it, then work from there to design whatever level of looping you need to populate that class so that you can display it.

Transformation tends to be intense, messy, and personal, so it's hard to walk someone through it without a lot of specifics.

What the APIs produce is rarely what we need, so we often have to dig through the results to reconstruct them in a way that suits our intended purpose. I tend to flatten a lot of the data to get elements on a common level for example. In your case I may create a class that has elements from both dataresult and metric in one place, then during my loop through those elements I am building a list of those new classes, populating their values, and then passing that final flattened list to it's consumer.

If i were doing it to a WPF form like you were I'd bind a DataGrid to that list, and set the bindings for each column as appropriate, and probably create a DataTable instead of a List to make it easier on me.

1 Like

I'll echo this sentiment. The Platform API's objects typically reflect the structure of the data as it exists within Genesys Cloud, which is normalized for storage and retrieval. The Platform API strives to be unopinionated about how clients will consume the data and therefore delivers it in its raw form with the expectation that client applications will transform it in whatever way is best for their needs for streamlined consumption in their context.

Oh, I see - so I am expected to loop through it and convert it into whatever "framework" I need?

I had assumed that would be inefficient but your explanation (and Tim's) makes sense. I feel a little better about the bits I'm doing then.

Thank you.

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.