I am trying to get concurrent calls from my CDR for asterisk reporting via MySQL Query. I have seen other suggestions and they included JOINs and ONs and some other calls that I didnt fully understand what they were doing so I couldnt adjust for my application.
I have multiple departments with their own set of DIDs which I need individual reports for. My current script is wrong as it grabs the number of calls that occurred while a call was in progress meaning that if a call was connected from 1pm to 2pm, it will count all the subsequent calls that occurred between 1pm and 2pm which is not what I want. I want the number of concurrent calls not how many calls occurred.
My Dataset
calldate | callsource | calldestination | duration | callended
--------------------| ------------| ----------------| -------- | ---------
2016-12-01 15:45:00 | 12121111111 | 12031234567 | 120 | 2016-12-01 15:47:00
--------------------| ------------| ----------------| -------- | ---------
2016-12-01 15:45:10 | 12122332223 | 12121111111 | 15 | 2016-12-01 15:45:25
--------------------| ------------| ----------------| -------- | ---------
2016-12-01 15:45:12 | 12121111111 | 12033254678 | 15 | 2016-12-01 15:45:27
--------------------| ------------| ----------------| -------- | ---------
2016-12-01 15:45:20 | 12123333333 | 12031223244 | 50 | 2016-12-01 15:47:10
--------------------| ------------| ----------------| -------- | ---------
2016-12-01 15:45:26 | 12121111111 | 12031231222 | 10 | 2016-12-01 15:45:33
--------------------|-------------|-----------------|----------|----------
2016-12-01 15:45:27 | 12120433322 | 12031456544 | 10 | 2016-12-01 15:45:37
I want to find out the billing department's max concurrent calls:
Billing Department's DIDs:
1212111111
1212333333
So the above would output:
Max Concurrent Calls: 3
I am trying to do this with MySQL and PHP so the formatting and all is irrelevant on the web page side. I just need to get the 3 out of the MySQL query.
My current attempt would return 5 since they all occurred within the first calls start and end time.
The only way I see doing this currently is to loop through every line with an inner loop of every line seeing if it occurred during the outer loop and incrementing max concurrent if surpassed.
Thoughts?
Thanks,
--E