简体   繁体   中英

How to avoid doing sum on repeating values in an interval

I'm currently running into an issue I hope you can help me with. I need to roll-up data to a daily format being produced every 15mins. Here's the code I am using first:

 SELECT TOP 1000 agi.date_time as [Date], AGI.AGENT_URN as AgentID, asgi.skillgroup_urn as SkillID, count(distinct(asgi.skillgroup_urn)) as [# of skills], sum(asgi.CALLS_HANDLED) as [Calls Handled In], sum(agi.LOGGED_ON_TIME)/count(DISTINCT(asgi.SKILLGROUP_URN)) as [Logged On Time (Per Agent)], sum(agi.NOT_READY_TIME)/count(DISTINCT(asgi.SKILLGROUP_URN)) as [Not Ready Time (Per Agent)], sum(agi.AVAIL_TIME)/count(DISTINCT(asgi.SKILLGROUP_URN)) as [Available Time (Per Agent)] FROM AGENT_INTERVAL AGI LEFT OUTER JOIN AGENT_SKILLGROUP_INTERVAL ASGI ON AGI.AGENT_URN = ASGI.AGENT_URN AND AGI.DATE_TIME = ASGI.DATE_TIME WHERE 1=1 AND AGI.DATE_TIME between '2018-07-26 16:15:00 ' and '2018-07-26 16:45:59' GROUP BY AGI.DATE_TIME, AGI.AGENT_URN, asgi.skillgroup_urn ORDER BY 2 

Here's the result:

Interval data

As you can see, the Logged On Time, Not Ready Time and Available Time per agent values are getting repeated since this is tied to the AgentID. This view is not telling the truth. Agent was logged for 900secs in the 17:45 interval and again 900 secs for the 18:00 interval. If I were to sum this now, it would give me a result of 9,000 secs which is incorrect for Logged On Time. Not Ready Time and Available Time are also incorrect.

If I remove SkillID from the select statement, my values reflect correctly

Without skills being represented

This time, I am getting 900 secs for 17:45 and 900 as well for 18:00 which is correct.

Where I'm having issues is rolling this back up to an entire day.

 SELECT TOP 1000 cast(agi.date_time as date) as [Date], AGI.AGENT_URN as AgentID, asgi.skillgroup_urn as SkillID, count(distinct(asgi.skillgroup_urn)) as [# of skills], sum(asgi.CALLS_HANDLED) as [Calls Handled In], sum(agi.LOGGED_ON_TIME)/count(DISTINCT(asgi.SKILLGROUP_URN)) as [Logged On Time (Per Agent)], sum(agi.NOT_READY_TIME)/count(DISTINCT(asgi.SKILLGROUP_URN)) as [Not Ready Time (Per Agent)], sum(agi.AVAIL_TIME)/count(DISTINCT(asgi.SKILLGROUP_URN)) as [Available Time (Per Agent)] FROM AGENT_INTERVAL AGI LEFT OUTER JOIN AGENT_SKILLGROUP_INTERVAL ASGI ON AGI.AGENT_URN = ASGI.AGENT_URN AND AGI.DATE_TIME = ASGI.DATE_TIME WHERE 1=1 AND AGI.DATE_TIME between '2018-07-26 16:15:00 ' and '2018-07-26 16:45:59' GROUP BY cast(AGI.DATE_TIME as date), AGI.AGENT_URN, ORDER BY 2 

Data rolled up to the day

Now my logged on time is 1500 secs which is 300secs less than reality.

How can I fix this so that when I roll-up data to the day,I get the accurate logged on time, not ready time and available time in my report?

Thanks for your help!

Daily view per skill

For 1 call agent you can divide agent state into: available, on-call, after-call-work (work-not-ready), aux (avaya guys like many different aux codes for different break types), offline, other.

You don't really need to process offline, but you have to distinct and process other time properly. You can consult Avaya Call Management System (Avaya CMS) guides for proper description, but in short it's time when agent is working for other skill or processes direct calls - either on call or after-call work. So, only 1 skill can have call time or ACW time at one moment, and these two have priority over available and other.

If you want to process multiple call(chat) handling system, you are in trouble - this way you will deal with intersecting calls all the time. Still you can divide time by intervals with call/ACW time priority over available and aux time.

Essentially available and aux time should be in synch for all skills, but if not, then use your judgement - per-skill reports are easier here than per-agent.

For mentioned Avaya CMS there is 15-minutes summarization, that - I believe - is done outside of DB, then interval data is stored in runtime tables, and in the end of the day interval data is summarized into daily data. Similarly weekly and monthly data is processed.

I'd suggest you to read CMS documentation - it has defined database structure that works for decades, so they mostly catched all nuances.

As a side note, in "my own" call center operator console, there was a definite table for operator states history with start-stop times and one definitive state for this interval. So summarization was a bit easier than combining different intersecting records.

Found the solution to my problem by modifying my code in the following fashion.

select 
AGI.*
,ROW_NUMBER() OVER (PARTITION BY DATE_TIME,AGENT_URN ORDER BY DATE_TIME) AS SEQNUM 
from AGENT_SKILLGROUP_INTERVAL AGI

)

SELECT 

CAST(AI.DATE_TIME AS DATE) [Date]
,SUM(AI.CALLS_HANDLED) AS [Calls Handled In]
,SUM(AI.HANDLED_CALLS_TALK_TIME)/nullif(sum(AI.calls_handled),0) as [Avg. Talk Time In]
,SUM(AI.INCOMING_CALLS_ON_HOLD_TIME)/nullif(sum(AI.calls_handled),0) as [Avg. Hold Time In]
,SUM(AI.HANDLED_CALLS_TIME-(AI.HANDLED_CALLS_TALK_TIME + AI.INCOMING_CALLS_ON_HOLD_TIME))/nullif(sum(AI.calls_handled),0) as [Avg. Wrap Time In]
,SUM(AI.[HANDLED_CALLS_TIME])/nullif(sum(AI.calls_handled),0) as [Avg. Handle Time In]
,SUM(CASE WHEN SEQNUM = 1 THEN AI.LOGGED_ON_TIME END) AS [Logged On Time (Per Agent)]
,SUM(ai.HANDLED_CALLS_TALK_TIME) as [Talk Time In]
,SUM(ai.HANDLED_CALLS_TALK_TIME + ai.INCOMING_CALLS_ON_HOLD_TIME) as [Phone Time In]
,SUM(ai.[INCOMING_CALLS_ON_HOLD_TIME]) as [Hold Time In]
,SUM(ai.HANDLED_CALLS_TIME-(ai.HANDLED_CALLS_TALK_TIME + ai.INCOMING_CALLS_ON_HOLD_TIME) ) AS [Wrap Time In]
,SUM(CASE WHEN SEQNUM = 1 THEN AI.NOT_READY_TIME END) as [Not Ready Time (Per Agent)]
,SUM(CASE WHEN SEQNUM = 1 THEN AI.AVAIL_TIME END) as [Available Time (Per Agent)]

FROM Agent_Interval AI


group by 
CAST(AI.DATE_TIME AS DATE)

By giving a rank to each interval, I can now accurately report on my logged_on_time, avail_time and not_ready_time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM