From 1a1edf1195490490e198fb3327ed84e0e7118cd1 Mon Sep 17 00:00:00 2001 From: demonspork Date: Thu, 18 Feb 2021 07:51:48 -0600 Subject: [PATCH] Improved Missed Call accuracy, cdr statistics, and hide duplicated CDRs from Enterprise Ring Groups Changes -------- - Improve CDR Import Logic so that missed_call column is more accurate to the "missed" status. It would previously mark unanswered outbound calls as "missed". These are their own category of call. - Don't mark the CDRs of the "legs" of an Enterprise Ring Group call as missed, only the originating_leg will be marked (one missed call per call) - We could also just "skip" importing these call legs. Simultaneous ring groups don't have these duplicated CDRs for every ringing phone. The "Skip" approach might make most of the rest of this work irrelevant. - Create `originating_leg_uuid` column in v_xml_cdr and import it into the database during CDR imports so it is available for filtering Enterprise Ring Group calls out of CDRs and reports. - Move logic that hides the agent leg of CC calls, LOSE_RACE calls, and the Enterprise Leg hiding code from xml_cdr.php into xml_cdr_inc.php into the SQL query WHERE clause so the CDR page looks more consistent. The logic is the same, but these calls are now excluded from the query result entirely instead of having to "skip" rendering them in the list on the xml_cdr.php page. - Improved CDR statistics page to use the missed_call variable instead of relying upon billsec and answer_stamp/answer_epoch. Added the same logic as the xml_cdr pages to the query so it excludes enterprise ring group call legs. - Laid the query groundwork in xml_cdr_statistics to report on Average TTA (No UI changes yet to include that statistic) Retroactive Changes --------------------- There are a few changes going back in time to bring everything in line with this better reporting accuracy: - If you want the populated the `originating_leg_uuid column` in `v_xml_cdr`, it will rely upon having the `json` column and not having deleted the data from it like I know some people do for space saving. - If you don't have the json column, you are mostly out of luck for hiding the duplicate legs of Enterprise ring group calls. It might be possible, but it isn't going to be easy. - On Newer Versions of postgres, this works: ``` UPDATE v_xml_cdr SET originating_leg_uuid = (json->'variables'->>'originating_leg_uuid')::uuid WHERE json->'variables'->>'originating_leg_uuid' IS NOT NULL; ``` - For some reason on postgres 9.4, I had to UPDATE every single record because I couldn't get it to allow the json syntax properly after the WHERE. This is fine, it doesn't change the end result it just means it has to run the UPDATE on every record, which will take a while ``` UPDATE v_xml_cdr SET originating_leg_uuid = (json->'variables'->>'originating_leg_uuid')::uuid; ``` - To remove the `missed_call = true` on all your previous outbound records so that they don't show up when you filter on missed (outbound unanswered calls can be accurately listed with TTA max 0 and direction outbound) ``` UPDATE v_xml_cdr SET missed_call = false WHERE direction = 'outbound' AND missed_call = true; ``` --- app/xml_cdr/app_config.php | 9 +++++++++ app/xml_cdr/resources/classes/xml_cdr.php | 10 +++++++--- app/xml_cdr/v_xml_cdr_import.php | 5 ++++- app/xml_cdr/xml_cdr.php | 7 ------- app/xml_cdr/xml_cdr_inc.php | 13 ++++++++++++- app/xml_cdr/xml_cdr_statistics_inc.php | 16 ++++++++++++---- 6 files changed, 44 insertions(+), 16 deletions(-) diff --git a/app/xml_cdr/app_config.php b/app/xml_cdr/app_config.php index b130e477ef..29a1acb1eb 100644 --- a/app/xml_cdr/app_config.php +++ b/app/xml_cdr/app_config.php @@ -197,6 +197,9 @@ $apps[$x]['permissions'][$y]['name'] = "xml_cdr_lose_race"; $apps[$x]['permissions'][$y]['groups'][] = "superadmin"; $y++; + $apps[$x]['permissions'][$y]['name'] = "xml_cdr_enterprise_leg"; + $apps[$x]['permissions'][$y]['groups'][] = "superadmin"; + $y++; $apps[$x]['permissions'][$y]['name'] = "xml_cdr_cc_agent_leg"; $apps[$x]['permissions'][$y]['groups'][] = "superadmin"; $y++; @@ -537,6 +540,12 @@ $apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = "char(1)"; $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "The leg of the call a or b."; $z++; + $apps[$x]['db'][$y]['fields'][$z]['name'] = "originating_leg_uuid"; + $apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = "uuid"; + $apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = "text"; + $apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = "char(36)"; + $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "Originating Leg UUID. Used to identify legs of an enterprise ring group - and exclude them "; + $z++; $apps[$x]['db'][$y]['fields'][$z]['name'] = "pdd_ms"; $apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = "numeric"; $apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = "numeric"; diff --git a/app/xml_cdr/resources/classes/xml_cdr.php b/app/xml_cdr/resources/classes/xml_cdr.php index 904f920290..20a6d6fa25 100644 --- a/app/xml_cdr/resources/classes/xml_cdr.php +++ b/app/xml_cdr/resources/classes/xml_cdr.php @@ -145,6 +145,7 @@ if (!class_exists('xml_cdr')) { $this->fields[] = "record_path"; $this->fields[] = "record_name"; $this->fields[] = "leg"; + $this->fields[] = "originating_leg_uuid"; $this->fields[] = "pdd_ms"; $this->fields[] = "rtp_audio_in_mos"; $this->fields[] = "last_app"; @@ -316,7 +317,7 @@ if (!class_exists('xml_cdr')) { //set missed calls $missed_call = 'false'; - if (strlen($xml->variables->answer_stamp) == 0) { + if (strlen($xml->variables->originating_leg_uuid) == 0 && $xml->variables->call_direction != 'outbound' && strlen($xml->variables->answer_stamp) == 0) { $missed_call = 'true'; } if ($xml->variables->missed_call == 'true') { @@ -404,6 +405,9 @@ if (!class_exists('xml_cdr')) { //store the call leg $this->array[$key]['leg'] = $leg; + //store the originating leg uuid + $this->array[$key]['originating_leg_uuid'] = urldecode($xml->variables->originating_leg_uuid); + //store post dial delay, in milliseconds $this->array[$key]['pdd_ms'] = urldecode($xml->variables->progress_mediamsec) + urldecode($xml->variables->progressmsec); @@ -430,7 +434,7 @@ if (!class_exists('xml_cdr')) { if (strlen($domain_name) == 0) { $presence_id = urldecode($xml->variables->presence_id); if (strlen($presence_id) > 0) { - $presence_array = explode($presence_id); + $presence_array = explode($presence_id, '%40'); $domain_name = $presence_array[1]; } } @@ -1210,7 +1214,7 @@ if (!class_exists('xml_cdr')) { // If the range starts with an '-' we start from the beginning // If not, we forward the file pointer // And make sure to get the end byte if spesified - if ($range0 == '-') { + if ($range == '-') { // The n-number of the last bytes is requested $c_start = $size - substr($range, 1); } diff --git a/app/xml_cdr/v_xml_cdr_import.php b/app/xml_cdr/v_xml_cdr_import.php index d8a3198aef..bfbd1026c7 100644 --- a/app/xml_cdr/v_xml_cdr_import.php +++ b/app/xml_cdr/v_xml_cdr_import.php @@ -265,6 +265,9 @@ //store the call leg $database->fields['leg'] = $leg; + + //store the originating leg + $database->fields['originating_leg_uuid'] = urldecode($xml->variables->originating_leg_uuid); //store post dial delay, in milliseconds $database->fields['pdd_ms'] = urldecode($xml->variables->progress_mediamsec) + urldecode($xml->variables->progressmsec); @@ -292,7 +295,7 @@ if (strlen($domain_name) == 0) { $presence_id = urldecode($xml->variables->presence_id); if (strlen($presence_id) > 0) { - $presence_array = explode($presence_id); + $presence_array = explode($presence_id, '%40'); $domain_name = $presence_array[1]; } } diff --git a/app/xml_cdr/xml_cdr.php b/app/xml_cdr/xml_cdr.php index 5cd4e71c94..8288e5b3d0 100644 --- a/app/xml_cdr/xml_cdr.php +++ b/app/xml_cdr/xml_cdr.php @@ -824,13 +824,6 @@ $content .= "\n"; - if (!permission_exists('xml_cdr_lose_race') && $row['hangup_cause'] == 'LOSE_RACE') { - $content = ''; - } - //show agent originated legs only to those with the permission - if (!permission_exists('xml_cdr_cc_agent_leg') && $row['cc_side'] == "agent") { - $content = ''; - } //show the leg b only to those with the permission if ($row['leg'] == 'a') { echo $content; diff --git a/app/xml_cdr/xml_cdr_inc.php b/app/xml_cdr/xml_cdr_inc.php index df1653fbb1..01b5a42f34 100644 --- a/app/xml_cdr/xml_cdr_inc.php +++ b/app/xml_cdr/xml_cdr_inc.php @@ -413,10 +413,13 @@ $sql .= "and billsec like :billsec "; $parameters['billsec'] = '%'.$billsec.'%'; } - if (strlen($hangup_cause) > 0) { + if (strlen($hangup_cause) > 0 && $hangup_cause != 'LOSE_RACE') { $sql .= "and hangup_cause like :hangup_cause "; $parameters['hangup_cause'] = '%'.$hangup_cause.'%'; } + elseif (!permission_exists('xml_cdr_lose_race')) { + $sql .= "and hangup_cause != 'LOSE_RACE' "; + } if (strlen($call_result) > 0) { switch ($call_result) { case 'answered': @@ -491,6 +494,10 @@ $sql .= "and leg = :leg "; $parameters['leg'] = $leg; } + //exclude enterprise ring group legs + if (!permission_exists('xml_cdr_enterprise_leg')) { + $sql .= "and originating_leg_uuid IS NULL "; + } if (is_numeric($tta_min)) { $sql .= "and (c.answer_epoch - c.start_epoch) >= :tta_min "; $parameters['tta_min'] = $tta_min; @@ -507,6 +514,10 @@ $sql .= "and (c.record_path is null or c.record_name is null) "; } } + //show agent originated legs only to those with the permission + if (!permission_exists('xml_cdr_cc_agent_leg')) { + $sql .= "and cc_side != 'agent' "; + } //end where if (strlen($order_by) > 0) { $sql .= order_by($order_by, $order); diff --git a/app/xml_cdr/xml_cdr_statistics_inc.php b/app/xml_cdr/xml_cdr_statistics_inc.php index 574440d413..4b1c9d9b04 100644 --- a/app/xml_cdr/xml_cdr_statistics_inc.php +++ b/app/xml_cdr/xml_cdr_statistics_inc.php @@ -153,7 +153,7 @@ $parameters['domain_uuid'] = $_SESSION['domain_uuid']; } if ($missed == true) { - $sql_where_ands[] = "billsec = '0'"; + $sql_where_ands[] = "missed_call = true "; } if (strlen($start_epoch) > 0 && strlen($stop_epoch) > 0) { $sql_where_ands[] = "start_epoch between :start_epoch and :stop_epoch"; @@ -284,6 +284,11 @@ if (!permission_exists('xml_cdr_lose_race')) { $sql_where_ands[] = "hangup_cause != 'LOSE_RACE'"; } + //Exclude enterprise ring group legs + if (!permission_exists('xml_cdr_enterprise_leg')) { + $sql_where_ands[] .= "originating_leg_uuid IS NULL"; + } + //if not admin or superadmin, only show own calls if (!permission_exists('xml_cdr_domain')) { @@ -349,7 +354,7 @@ //get the call volume between a start end end time in seconds function get_call_volume_between($start, $end, $where, $parameters) { - $sql = "select count(*) as count, sum(billsec) as seconds from v_xml_cdr "; + $sql = "select count(*) as count, sum(billsec) as seconds, sum(answer_stamp - start_stamp) as tta from v_xml_cdr "; $sql .= $where." "; $sql .= "start_epoch between :start and :end "; $parameters['start'] = $start; @@ -360,6 +365,7 @@ return array( 'volume' => $row['count'], 'seconds' => $row['seconds'], + 'tta' => $row['tta'], ); } return false; @@ -379,14 +385,13 @@ $stats[$i]['volume'] = $stat_range ? $stat_range['volume'] : 0; $stats[$i]['seconds'] = $stat_range ? $stat_range['seconds'] : 0; $stats[$i]['minutes'] = $stats[$i]['seconds'] / 60; - $stats[$i]['avg_sec'] = $stats[$i]['volume'] == 0 ? 0 : $stats[$i]['seconds'] / $stats[$i]['volume']; if ($missed) { //we select only missed calls at first place - no reasons to select it again $stats[$i]['missed'] = $stats[$i]['volume']; } else { - $where = $sql_where."billsec = '0' and "; + $where = $sql_where."missed_call = true and "; $stat_range = get_call_volume_between($stats[$i]['start_epoch'], $stats[$i]['stop_epoch'], $where, $parameters); $stats[$i]['missed'] = $stat_range ? $stat_range['volume'] : 0; } @@ -403,6 +408,9 @@ //answer / seizure ratio $stats[$i]['asr'] = $stats[$i]['volume'] == 0 ? 0 : ($success_volume / $stats[$i]['volume'] * 100); + //average time to answer + $stats[$i]['avg_tta'] = $stats[$i]['volume'] == 0 ? 0 : round($stat_range['tta'] / $success_volume); + //average length of call $stats[$i]['aloc'] = $success_volume == 0 ? 0 : $stats[$i]['minutes'] / $success_volume; }