[ASTPPCOM-455] Dashboard call count and pie chart Created: 11/Jul/18 Updated: 27/Oct/19 Resolved: 18/Oct/18 |
|
| Status: | Done |
| Project: | ASTPP Community |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | New Feature | ||
| Reporter: | fozzygo4 | Assignee: | Samir Doshi |
| Resolution: | Done | Votes: | 0 |
| Labels: | bug_confirmed | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
Hello, I have picked up, what I think is an issue in 3.6 on the dashboard where the call count (Answered, failed) etc is counting the provider calls as well as customers / resellers. This gives an inaccurate count of calls and in a way it is a duplication. The provider and customers / reseller count should be separated. I have modified the code in /astpp/application/modules/dashboard/model/dashboard_model.php to exclude provider calls on the call count. See code below: function get_call_statistics($table, $parent_id, $start_date = '', $end_date = '', $group_flag = true) { $this->db->select ( "count(uniqueid) as sum, count(CASE WHEN billseconds > 0 THEN 1 END) as answered, MAX(billseconds) AS mcd, SUM(billseconds) AS duration, count(CASE WHEN disposition NOT IN ('NORMAL_CLEARING','SUCCESS','NORMAL_CLEARING [16]') THEN 1 END) as failed, SUM(CASE WHEN calltype !='free' THEN billseconds ELSE 0 END) as billable, sum(debit-cost) as profit, sum(debit) as debit, sum(cost) as cost, SUM(CASE WHEN billseconds > 0 THEN 1 ELSE 0 END) as completed, DAY(callstart) as day", false ); $this->db->where ( 'callstart >=', $start_date . " 00:00:00" ); $this->db->where ( 'callstart <=', $end_date . " 23:59:59" ); $this->db->where ( 'reseller_id', $parent_id ); if ($table == cdrs) $this->db->where ( 'type !=', "3" ); if ($group_flag) $this->db->group_by ( "DAY(callstart)" ); $result = $this->db->get ( $table ); return $result; } I have added the following to exclude providers: if ($table == cdrs) $this->db->where ( 'type !=', "3" ); For the pie chart I add the same in the where clause but not sure how to use it in the parameters. I add AND type != '3' after the $where parameter in the SELECT query.
function get_customer_maximum_callminutes($start_date, $end_date) {
$start_date = $start_date . " 00:00:00";
$end_date = $end_date . " 23:59:59";
$accountinfo = $this->session->userdata ( 'accountinfo' );
$parent_id = ($accountinfo ['type'] == 1) ? $accountinfo ['id'] : 0;
if ($this->session->userdata ( 'userlevel_logintype' ) != 0 && $this->session->userdata ( 'userlevel_logintype' ) != 3) {
$where = "reseller_id ='$parent_id'";
} else {
$where = "accountid ='$parent_id'";
}
$where = $where . " AND callstart >= '" . $start_date . "' AND callstart <= '" . $end_date . "'";
$select_query = "(SELECT sum( billseconds ) AS billseconds,accountid FROM (cdrs) WHERE $where AND type != '3' group by accountid order$
union
(SELECT sum( billseconds ) AS billseconds,accountid FROM (reseller_cdrs) WHERE $where
group by accountid order by sum(billseconds) desc limit 10 ) ORDER BY billseconds DESC LIMIT 10 ";
return $this->db->query ( $select_query );
}
function get_customer_maximum_callcount($start_date, $end_date) {
$start_date = $start_date . " 00:00:00";
$end_date = $end_date . " 23:59:59";
$accountinfo = $this->session->userdata ( 'accountinfo' );
$parent_id = ($accountinfo ['type'] == 1) ? $accountinfo ['id'] : 0;
if ($this->session->userdata ( 'userlevel_logintype' ) != 0 && $this->session->userdata ( 'userlevel_logintype' ) != 3) {
$where = "reseller_id ='$parent_id'";
} else {
$where = "accountid ='$parent_id'";
}
$where = $where . " AND callstart >= '" . $start_date . "' AND callstart <= '" . $end_date . "'";
$select_query = "(SELECT count(uniqueid) as call_count, `accountid` FROM (`cdrs`) WHERE $where AND type != '3' GROUP BY `accountid` OR$
UNION
(SELECT count(uniqueid) as call_count,accountid FROM (reseller_cdrs) WHERE $where GROUP BY `accountid` ORDER BY `call_count` desc LIMIT 10)
ORDER BY call_count desc limit 10";
return $this->db->query ( $select_query );
|
| Comments |
| Comment by Samir Doshi [ 12/Jul/18 ] |
|
Hi @FozzyGo4 That's not correct. You will get type = 3 in cdrs table when any provider has tried to make calls or send you calls. Basically whoever making calls (Leg A), we capture that account type and insert into cdrs table as we consider they are the originator of the If you will put type != 3 then it will start skipping of your interconnect provider cdrs as well DID cdrs, and that will make report inappropriate. |
| Comment by fozzygo4 [ 12/Jul/18 ] |
|
We are both half right. In the CDR table there are double entries for an inbound call. The same call with the same date time stamp has two records of type = 3. One is a DID and the other is a Local with disposition of STANDARD. The dashboard currently counts 2 count(uniqueid) as sum calls but it is actually only 1 call. The query needs to only count the DID record I feel but correct me please if I'm wrong. |
| Comment by Samir Doshi [ 16/Jul/18 ] |
|
For DID calls, yes we are doing two entries of CDRs. The reason for not merging both CDRs in dashboard is, both call records are associated with a different account and both records have billable seconds (However for providers you have the option to make chargeable to make it free using INB_FREE) and their charges. If we will apply unique constraint while showing in dashboard, then it will start showing incorrect counts as it may possible someone has charged provider based on allocated tariff plan and it will be skipped. |
| Comment by fozzygo4 [ 16/Jul/18 ] |
|
Im not saying "do not capture two records". Im saying the call count is duplicated and is incorrect. Let me try and explain. Regardless of how many records are in the CDR and if the call is free or charged for, it is still 1 call for 60 seconds. The dashboard graph and pie graph is currently counting records so it will see 1st CDR with Provider ID (STANDARD) and 2nd CDR with Customer ID (DID) as 2 calls and the minute count is now 120 seconds (2 minutes). This means all inbound calls are counted twice and the dashboard is not accurate. It should only count 1 of these CDR records on the dashboard. |
| Comment by Samir Doshi [ 19/Jul/18 ] |
|
I agree with your point. Dashboard logic requires a change to display 1 We will work out on that. [image: Mailtrack] Best RegardsSamir Doshi Disclaimer: On Tue, Jul 17, 2018 at 12:46 AM, Stephen Forster <notifications@github.com> > Im not saying "do not capture two records". Im saying the call count is |
| Comment by Samir Doshi [ 24/Jul/18 ] |
|
Hi @FozzyGo4 We changed code to make dashboard graph working. Here is the code, function get_call_statistics($table, $parent_id, $start_date = '', $end_date = '', $group_flag = true) { $this->db->select ( "count(DISTINCT substr(uniqueid,1,36)) as sum, count(CASE WHEN (billseconds > 0 and substr(uniqueid,37,3)!='DID') THEN 1 END) as answered, MAX(billseconds) AS mcd, SUM(CASE WHEN (billseconds > 0 and substr(uniqueid,37,3)!='DID') THEN 1 END) AS duration, count(CASE WHEN (disposition NOT IN ('NORMAL_CLEARING','SUCCESS','NORMAL_CLEARING [16]') and substr(uniqueid,37,3)!='DID') THEN 1 END) as failed, SUM(CASE WHEN (calltype !='free' and substr(uniqueid,37,3)!='DID') THEN billseconds ELSE 0 END) as billable, sum(debit-cost) as profit, sum(debit) as debit, sum(cost) as cost, SUM(CASE WHEN (billseconds > 0 and substr(uniqueid,37,3)!='DID') THEN 1 ELSE 0 END) as completed, DAY(callstart) as day", false ); $this->db->where ( 'callstart >=', $start_date . " 00:00:00" ); $this->db->where ( 'callstart <=', $end_date . " 23:59:59" ); $this->db->where ( 'reseller_id', $parent_id ); if ($group_flag) $this->db->group_by ( "DAY(callstart)" ); $result = $this->db->get ( $table ); return $result; } Please replace this code in dashboard_model.php and check. If this works well then we will workout on other related reports. |
| Comment by fozzygo4 [ 24/Jul/18 ] |
|
I see, so you are excluding all calls with disposition of "DID" so the query is counting the actual calls. Good idea. I will make the changes and check from my side and give feedback. |
| Comment by Samir Doshi [ 25/Jul/18 ] |
|
Alright. Waiting for your feedback [image: Mailtrack] Best RegardsSamir Doshi Disclaimer: On Tue, Jul 24, 2018 at 11:49 AM, Stephen Forster <notifications@github.com> > I see, so you are excluding all calls with disposition of "DID" so the |
| Comment by Samir Doshi [ 08/Sep/18 ] |
|
Hi @FozzyGo4 Did you check? |
| Comment by fozzygo4 [ 08/Sep/18 ] |
|
Hi, yes sorry I did check and it works as expected thank you. Sent from my iPhone On 08 Sep 2018, at 9:31 AM, Samir Doshi <notifications@github.com<notifications@github.com Hi @FozzyGo4<https://github.com/FozzyGo4> Did you check? - |
| Comment by Samir Doshi [ 08/Sep/18 ] |
|
Alright. Thanks for the update. On Sat, Sep 8, 2018, 1:52 PM Stephen Forster <notifications@github.com> > Hi, yes sorry I did check and it works as expected thank you. |
| Comment by fozzygo4 [ 13/Oct/18 ] |
|
Hi Samir, Further to the fixes with the pie charts, I have optimised the speed of the query to MySQL by using temporary tables in the PHP code. I noticed that the query was putting a lot of stress on the MySQL DB. This is mostly because of MySQL and "order by descending" having to work with millions of records. By using a query to get only the records required into a temporary table and then running the charts query on the temp data, the query is much faster and less stress on the recourses of the server. Shall I contribute the code here? |
| Comment by Samir Doshi [ 16/Oct/18 ] |
|
Yes please. On Sun, Oct 14, 2018, 12:45 AM Stephen Forster <notifications@github.com> > Hi Samir, |
| Comment by fozzygo4 [ 18/Oct/18 ] |
|
Herewith the modified code. Top 10 customer minutes function
function get_customer_maximum_callminutes($start_date, $end_date) {
$start_date = $start_date . " 00:00:00";
$end_date = $end_date . " 23:59:59";
$accountinfo = $this->session->userdata ( 'accountinfo' );
$parent_id = ($accountinfo ['type'] == 1) ? $accountinfo ['id'] : 0;
if ($this->session->userdata ( 'userlevel_logintype' ) != 0 && $this->session->userdata ( 'userlevel_logintype' ) != 3) {
$where = "reseller_id ='$parent_id'";
} else {
$where = "accountid ='$parent_id'";
}
$where = $where . " AND callstart >= '" . $start_date . "' AND callstart <= '" . $end_date . "'";
$billingsectemp_query = "CREATE TEMPORARY TABLE IF NOT EXISTS totalbillingsec AS (SELECT billseconds,accountid FROM (cdrs) WHERE $where and type != '3')
UNION
(SELECT billseconds,accountid FROM (cdrs) WHERE $where and type = '3' AND disposition = 'DID')
UNION
(SELECT billseconds,accountid FROM (reseller_cdrs) WHERE $where ) ";
$select_query = "SELECT sum( billseconds ) as billseconds, accountid from totalbillingsec group by accountid order by billseconds DESC LIMIT 10";
$this->db->query ( $billingsectemp_query );
return $this->db->query ( $select_query );
}
Top 10 customer call count function
function get_customer_maximum_callcount($start_date, $end_date) {
$start_date = $start_date . " 00:00:00";
$end_date = $end_date . " 23:59:59";
$accountinfo = $this->session->userdata ( 'accountinfo' );
$parent_id = ($accountinfo ['type'] == 1) ? $accountinfo ['id'] : 0;
if ($this->session->userdata ( 'userlevel_logintype' ) != 0 && $this->session->userdata ( 'userlevel_logintype' ) != 3) {
$where = "reseller_id ='$parent_id'";
} else {
$where = "accountid ='$parent_id'";
}
$where = $where . " AND callstart >= '" . $start_date . "' AND callstart <= '" . $end_date . "'";
$callcounttemp_query = "CREATE TEMPORARY TABLE IF NOT EXISTS totalcalls AS (SELECT uniqueid,accountid FROM cdrs WHERE $where)
UNION
(SELECT uniqueid, accountid FROM reseller_cdrs WHERE $where) ";
$select_query = "SELECT count(DISTINCT substr(uniqueid,1,36)) as call_count, accountid FROM totalcalls GROUP BY accountid ORDER BY call_count desc LIMIT 10";
$this->db->query ( $callcounttemp_query );
return $this->db->query ( $select_query );
}
The changes are to first get the data based on where clause into a temporary table and then run the order by, group by and and calculations on the temporary data. Shaves of many seconds and resources on my system. Im sure you could probably optimise this even further and perhaps use the same principle on other modules like reports. Regards |