Genesys CTI User Forum > Genesys-related Development
Cannot get count of agents on breaks using statserver CurrNumberNotReadyStatuses
merve.ugursac:
Hello everyone,
What I want to do is, when a call is waiting on a virtual queue, I need the count of agents on breaks of that particular queue. > Break : 3, LunchBreak :4
I have definitions on statServerReporting filters, for all notready statues such as below.
AUX_RC_1 : PairExist("Lunch Break",Lunch Break")
AUX_RC_2 : PairExist("Meeting",Meeting")
AUX_RC_3 : PairExist("Break",Break") etc.
I have this piece of code on statServerProtocol.Received event, for every virtual queue on the system.
The problem is I can not get the count on the row "int count = Convert.ToInt32(@event.StringValue);",, it is always empty .
Can anyone lead me on what I do wrong?
breakNames : string array (AUX_RC_1, AUX_RC_2, AUX_RC_3 )
[quote]
var requestOpenStatistic = RequestOpenStatistic.Create();
requestOpenStatistic.StatisticObject = StatisticObject.Create();
requestOpenStatistic.StatisticObject.ObjectType = StatisticObjectType.GroupAgents;
requestOpenStatistic.StatisticObject.TenantName = "Environment";
requestOpenStatistic.StatisticObject.TenantPassword = "";
requestOpenStatistic.StatisticMetric = StatisticMetric.Create();
requestOpenStatistic.StatisticMetric.StatisticType = "CurrNumberNotReadyStatuses";
requestOpenStatistic.Notification = Notification.Create();
requestOpenStatistic.Notification.Mode = NotificationMode.Immediate;
for (int i = 0; i < breakNames?.Length; i++)
{
string breakName = breakNames[i].TrimStart().TrimEnd();
requestOpenStatistic.ReferenceId = queueStatisticId++;
requestOpenStatistic.StatisticObject.ObjectId = agentGroupName ; //"Corporate" agent.agentGroup
requestOpenStatistic.StatisticMetric.Filter = breakName; // NotReadyStatus : Mola, Egitim, Yemek Molası vb.
var response = StatProtocol.Request(requestOpenStatistic);
if (response == null || response.Id != EventStatisticOpened.MessageId)
{
// response.Id : 1 > EventError
// response.Id : 2 > EventInfo
// response.Id : 22 > EventStatisticOpened
CustomLogger.Instance().Error(methodName, new Exception($" - StatServer bağlantı hatası - RequestOpenStatistic failed. - StatProtocol.State : {StatProtocol.State} - response.Id : {response.Id} - agentGroupName :{agentGroupName} - breakName : {breakName} - Message : {response.Name} - ProtocolDescription : {response.ProtocolDescription}"));
}
else
{
var @event = response as EventStatisticOpened;
int count = Convert.ToInt32(@event.StringValue);
CustomLogger.Instance().Info($" - OnWaitingCallsEventInfo - {methodName} - stat sorgu sonucu -> @event.StringValue: {@event.StringValue}- @event.ReferenceId : {@event.ReferenceId}");
CustomLogger.Instance().Info($" - OnWaitingCallsEventInfo - {methodName} - agentGroupName : {agentGroupName}- breakName : {breakName}, count : {count}");
if (count > 0)
{
result.Add(new AgentBreakModel
{
Count = count,
Status = breakName, // breakName "AUX_RC_3" (AUX_RC_3 => Break )
StatusDescription = "" // "Break"
});
CustomLogger.Instance().Info($" - OnWaitingCallsEventInfo - {methodName} - AgentBreakModel eklendi : agentGroupName : {agentGroupName} - breakName : {breakName} - count : {count} ");
}
}
}
[/quote]
hsujdik:
Probably because you are casting response as EventStatisticOpened. The class that has the actual value is EventInfo, and you have to match it against the REQ_ID (ReferenceId of the RequestOpenStat/Ex that you are holding in your variable queueStatisticId) to know about which Statistic it refers to
merve.ugursac:
Hey, I am grateful for your response. Thank you. But it is EventStatisticOpened. (I tried EventInfo too neveretheless).
Here are the logs. My agent is on "Break" break type which maps to AUX_RC_3, I was expecting to see "1" (@event.StringValue: 1 ) as count but it is "" ( @event.StringValue: )
AUX_RC_3 : PairExist("Break","Break")
2022-04-02 12:44:16,605: [ INFO] -----> EventStatisticOpened geldi
2022-04-02 12:44:16,605: [ INFO] - OnWaitingCallsEventInfo - GetAgentCountPerBreak() - stat sorgu sonucu -> @event.StringValue: - @event.ReferenceId : 2
2022-04-02 12:44:16,605: [ INFO] - OnWaitingCallsEventInfo - GetAgentCountPerBreak() - agentGroupName : TestCampaign- breakName : AUX_RC_3, count : 0
2022-04-02 12:44:16,605: [ INFO] - OnWaitingCallsEventInfo - GetAgentCountPerBreak() - AgentBreakModel eklendi : agentGroupName : TestCampaign - breakName : AUX_RC_3 - count : 0
hsujdik:
Hi,
I have put together a small example code for you to use as a reference:
[code]
using Genesyslab.Platform.Commons.Protocols;
using Genesyslab.Platform.Reporting.Protocols;
using Genesyslab.Platform.Reporting.Protocols.StatServer;
using Genesyslab.Platform.Reporting.Protocols.StatServer.Events;
using Genesyslab.Platform.Reporting.Protocols.StatServer.Requests;
using System;
using System.Collections.Generic;
namespace StatServerReasonCode
{
class Program
{
static Dictionary<int, Tuple<string, string>> referenceIds = new Dictionary<int, Tuple<string, string>>();
static void Main(string[] args)
{
string statServerHost = "10.131.3.101";
int statServerPort = 7000;
StatServerProtocol exampleProtocol = new StatServerProtocol(new Endpoint(statServerHost, statServerPort));
// Specifies a method to handle non-request related messages
exampleProtocol.Received += statServer_StatReceived;
exampleProtocol.Open();
// All your Groups that you want to monitor
HashSet<string> agentGroups = new HashSet<string>
{
"Group1",
"Group2",
"Group3",
"Group4"
};
// All filters that you want to apply to your Statistic Type in separate statistics
HashSet<string> filters = new HashSet<string>
{
"AUX_RC_1",
"AUX_RC_2",
"AUX_RC_3"
};
foreach (string groupName in agentGroups)
{
foreach (string filter in filters)
{
// This is used to get which object/filter when the EventInfo is received.
// Will later be added to the static dictionary referenceIds to be retreived later on the
// Message handler "statServer_StatReceived" method
Tuple<string, string> agentGroupAndFilter = new Tuple<string, string>(groupName, filter);
StatisticObject statObject = StatisticObject.Create();
statObject.ObjectType = StatisticObjectType.GroupAgents;
statObject.TenantName = "Environment";
statObject.ObjectId = agentGroupAndFilter.Item1;
StatisticMetric statMetric = StatisticMetric.Create();
statMetric.StatisticType = "CurrNumberNotReadyStatuses";
statMetric.Filter = agentGroupAndFilter.Item2;
Notification statNotification = Notification.Create();
statNotification.Mode = NotificationMode.Immediate;
statNotification.Insensitivity = 1;
RequestOpenStatistic requestOpenStatistic = RequestOpenStatistic.Create();
requestOpenStatistic.StatisticObject = statObject;
requestOpenStatistic.StatisticMetric = statMetric;
requestOpenStatistic.Notification = statNotification;
IMessage response = exampleProtocol.Request(requestOpenStatistic);
referenceIds.Add(requestOpenStatistic.ReferenceId, agentGroupAndFilter);
switch(response.Name)
{
case "EventStatisticOpened":
Console.WriteLine($"Registered statistic for object {groupName} and filter {filter}");
break;
case "EventError":
Console.WriteLine($"Error opening statistic for object {groupName} and filter {filter}");
break;
}
}
}
}
private static void statServer_StatReceived(object sender, EventArgs e)
{
IMessage message = ((MessageEventArgs)e).Message;
// Discard messages that are not of type "EventInfo" (message that contains statistic values)
if (!message.Name.Equals("EventInfo", StringComparison.InvariantCultureIgnoreCase)) return;
EventInfo eventInfo = (EventInfo)message;
// Discard messages that are not about a statistic that we are waiting for the data
if (!referenceIds.ContainsKey(eventInfo.ReferenceId)) return;
// Get the group/filter combination based on the ReferenceId of the received message
Tuple<string, string> agentGroupAndFilter = referenceIds[eventInfo.ReferenceId];
string groupName = agentGroupAndFilter.Item1;
string filter = agentGroupAndFilter.Item2;
Console.WriteLine($"Received current value of group {groupName}, filter {filter}: {eventInfo.IntValue}");
}
}
}
[/code]
Regards,
HDS
merve.ugursac:
Hi,
I appreciate the effort you've put in to help me! Thank you very much! I can get the count now on a sample project that represents mine.
The problem now is, I need the count in an immediate call since on protocol received I read the call count waiting on each virtual queue. Inside this function I need an immediate request-response of this agent-break counts. That was why I had tried to read the response immediately afterwards. I have adjusted my code to read both queries on statProtocol.received but the response of the agentcount is not available when I need that since its not immediate this way.
Do you think there is a way to accomplish this?
For the following :
907 is my virtual queue and result : 1 because I am on the line and the agent of this queue is on break (AUX_RC_3 which will be queried with a referanceId of 10002), so I need the count of agents who are under this virtQueue.
2022-04-04 10:26:56,579: [ INFO] OnWaitingCallsEventInfo()- result : 1 referanceId : 907
2022-04-04 10:26:56,579: [ INFO] OnWaitingCallsEventInfo()- referanceId (queue.DbId) : 907 için result : 1, queue.QueueName :VQ_TestCampaign, queue.QueueMaxAgent :0.
2022-04-04 10:26:56,583: [ INFO] GetCampaingNameFromVirtualQueueId() - QueueId : 907 , VQ_TestCampaign - virtualQueue.Switch.Name : SIPSwitch_DR , AgentGroupName Found : TestCampaign
2022-04-04 10:26:56,886: [ INFO] - OnWaitingCallsEventInfo - Agents on break : [] [b] I needed the count here [/b]
2022-04-04 10:26:56,886: [ INFO] - OnWaitingCallsEventInfo - -- ResultValues , IsCallFirstCall false , FirstCallTime: 4.04.2022 10:26:56
2022-04-04 10:26:56,886: [ INFO] OnWaitingCallsEventInfo()- result : 0 referanceId : 10000 [b] --> AUX_RC_1[/b]
2022-04-04 10:26:56,886: [ INFO] OnWaitingCallsEventInfo()- result : 0 referanceId : 10001 [b]--> AUX_RC_2[/b]
2022-04-04 10:26:56,886: [ INFO] OnWaitingCallsEventInfo()- result : 1 referanceId : 10002 [b] --> AUX_RC_3 --> but I got it here[/b]
2022-04-04 10:26:56,889: [ INFO] OnWaitingCallsEventInfo()- result : 0 referanceId : 10003 [b]--> AUX_RC_4[/b]
Long story short, I need the reponse here :
[code]
switch (response.Name)
{
case "EventStatisticOpened":
Console.WriteLine($"{methodName} - Registered statistic for object {agentGroupName} and filter {agentGroupAndFilter}"); [b]--> here [/b]
break;
case "EventError":
Console.WriteLine($"{methodName} - Error opening statistic for object {agentGroupName} and filter {agentGroupAndFilter}");
break;
default:
Console.WriteLine($"{methodName} - response.Name : {agentGroupName} and filter {agentGroupAndFilter}");
break;
}
[/code]
Navigation
[0] Message Index
[#] Next page
Go to full version