mirror of
https://github.com/ACSPRI/queXS
synced 2024-04-02 12:12:16 +00:00
Merged from McMasterReports branch
This commit is contained in:
@@ -51,7 +51,7 @@ function get_CPH_by_shift($qid,$sid)
|
||||
{
|
||||
global $db;
|
||||
|
||||
$sql = "SELECT o.firstName,o.operator_id,c.completions,ca.time, c.completions/ca.time as CPH
|
||||
$sql = "SELECT o.firstName,o.operator_id,c.completions,SEC_TO_TIME(ca.time) as time, c.completions/(ca.time / 3600) as CPH
|
||||
FROM operator as o
|
||||
JOIN ( SELECT count(*) as completions,a.operator_id
|
||||
FROM `call` as a, `case` as b, `shift` as s
|
||||
@@ -62,7 +62,7 @@ function get_CPH_by_shift($qid,$sid)
|
||||
AND s.`start` <= a.`start`
|
||||
AND s.`end` >= a.`start`
|
||||
GROUP BY a.operator_id) as c on (c.operator_id = o.operator_id)
|
||||
JOIN ( SELECT SUM( TIMESTAMPDIFF(SECOND , a.start, IFNULL(a.end,CONVERT_TZ(NOW(),'System','UTC')))) /3600 as time, a.operator_id
|
||||
JOIN ( SELECT SUM( TIMESTAMPDIFF(SECOND , a.start, IFNULL(a.end,CONVERT_TZ(NOW(),'System','UTC')))) as time, a.operator_id
|
||||
FROM `call_attempt` as a, `case` as b, `shift` as s
|
||||
WHERE a.case_id = b.case_id
|
||||
AND b.questionnaire_id = '$qid'
|
||||
@@ -85,7 +85,7 @@ function get_CPH_by_questionnaire($qid)
|
||||
{
|
||||
global $db;
|
||||
|
||||
$sql = "SELECT o.firstName,o.operator_id,c.completions,ca.time, c.completions/ca.time as CPH
|
||||
$sql = "SELECT o.firstName,o.operator_id,c.completions,SEC_TO_TIME(ca.time) as time, c.completions/(ca.time / 3600) as CPH
|
||||
FROM operator as o
|
||||
JOIN ( SELECT count(*) as completions,a.operator_id
|
||||
FROM `call` as a, `case` as b
|
||||
@@ -93,13 +93,216 @@ function get_CPH_by_questionnaire($qid)
|
||||
AND a.case_id = b.case_id
|
||||
AND b.questionnaire_id = '$qid'
|
||||
GROUP BY a.operator_id) as c on (c.operator_id = o.operator_id)
|
||||
JOIN ( SELECT SUM( TIMESTAMPDIFF(SECOND , a.start, IFNULL(a.end,CONVERT_TZ(NOW(),'System','UTC')))) /3600 as time, a.operator_id
|
||||
JOIN ( SELECT SUM( TIMESTAMPDIFF(SECOND , a.start, IFNULL(a.end,CONVERT_TZ(NOW(),'System','UTC')))) as time, a.operator_id
|
||||
FROM `call_attempt` as a, `case` as b
|
||||
WHERE a.case_id = b.case_id
|
||||
AND b.questionnaire_id = '$qid'
|
||||
GROUP BY operator_id) as ca on (ca.operator_id = o.operator_id)
|
||||
ORDER BY cph DESC";
|
||||
|
||||
|
||||
return $db->GetAll($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get stats by interviewer by questionnaire by shift
|
||||
*
|
||||
* @param int $questionnaire_id The questionnaire
|
||||
* @param int $shift_id The shift id
|
||||
* @return arrayh An array containing operator_id,firstName,CPH,effectiveness,
|
||||
*/
|
||||
function get_stats_by_shift($questionnaire_id,$shift_id)
|
||||
{
|
||||
global $db;
|
||||
|
||||
$sql = "SELECT o.operator_id, o.firstName, (calltime.totaltime / callattempttime.totaltime) AS effectiveness, c.completions,SEC_TO_TIME(callattempttime.totaltime) as time, c.completions/(callattempttime.totaltime / 3600) as CPH, SEC_TO_TIME(calltime.totaltime) as callt, SEC_TO_TIME(callattempttime.totaltime) as callatemptt, calls.calls as totalcalls, calls.calls/(callattempttime.totaltime / 3600) as CALLSPH, calltime.totaltime as calltotaltime, callattempttime.totaltime as callattempttotaltime
|
||||
|
||||
FROM operator AS o
|
||||
JOIN (
|
||||
SELECT SUM( TIMESTAMPDIFF(
|
||||
SECOND , c.start, IFNULL( c.end, CONVERT_TZ( NOW( ) , 'System', 'UTC' ) ) ) ) AS totaltime, operator_id
|
||||
FROM `call` AS c, `case` as b, `shift` as s
|
||||
WHERE c.case_id = b.case_id
|
||||
AND b.questionnaire_id = '$questionnaire_id'
|
||||
AND s.shift_id = '$shift_id'
|
||||
AND s.`start` <= c.`start`
|
||||
AND s.`end` >= c.`start`
|
||||
GROUP BY operator_id
|
||||
) AS calltime ON ( calltime.operator_id = o.operator_id )
|
||||
JOIN (
|
||||
SELECT SUM( TIMESTAMPDIFF(
|
||||
SECOND , c.start, IFNULL( c.end, CONVERT_TZ( NOW( ) , 'System', 'UTC' ) ) ) ) AS totaltime, operator_id
|
||||
FROM `call_attempt` AS c, `case` as b, `shift` as s
|
||||
WHERE c.case_id = b.case_id
|
||||
AND s.shift_id = '$shift_id'
|
||||
AND s.`start` <= c.`start`
|
||||
AND s.`end` >= c.`start`
|
||||
AND b.questionnaire_id = '$questionnaire_id'
|
||||
GROUP BY operator_id
|
||||
) AS callattempttime ON ( callattempttime.operator_id = o.operator_id )
|
||||
JOIN ( SELECT count(*) as completions,a.operator_id
|
||||
FROM `call` as a, `case` as b, `shift` as s
|
||||
WHERE a.outcome_id = '10'
|
||||
AND s.shift_id = '$shift_id'
|
||||
AND s.`start` <= a.`start`
|
||||
AND s.`end` >= a.`start`
|
||||
AND a.case_id = b.case_id
|
||||
AND b.questionnaire_id = '$questionnaire_id'
|
||||
GROUP BY a.operator_id) as c on (c.operator_id = o.operator_id)
|
||||
JOIN ( SELECT count(*) as calls,a.operator_id
|
||||
FROM `call` as a, `case` as b, `shift` as s
|
||||
WHERE a.case_id = b.case_id
|
||||
AND s.shift_id = '$shift_id'
|
||||
AND s.`start` <= a.`start`
|
||||
AND s.`end` >= a.`start`
|
||||
AND b.questionnaire_id = '$questionnaire_id'
|
||||
GROUP BY a.operator_id) as calls on (calls.operator_id = o.operator_id)
|
||||
ORDER BY effectiveness DESC";
|
||||
|
||||
return $db->GetAll($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert seconds to time in HH:MM:SS
|
||||
*
|
||||
* @param int Seconds
|
||||
* @return string Time in format HH:MM:SS
|
||||
*/
|
||||
function sec_to_time($seconds)
|
||||
{
|
||||
|
||||
if($seconds >= 3600){
|
||||
$h = floor($seconds/3600);
|
||||
$seconds = ($seconds%3600);
|
||||
}
|
||||
if($seconds >= 60){
|
||||
$m = floor($seconds/60);
|
||||
$seconds = ($seconds%60);
|
||||
}
|
||||
$s = floor($seconds);
|
||||
|
||||
return sprintf("%02d:%02d:%02d", $h, $m, $s);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Given the stats, add a total line
|
||||
*
|
||||
* @param array The result set from the database
|
||||
* @return array The result set plus a total row
|
||||
*/
|
||||
function get_stats_total($rs)
|
||||
{
|
||||
$completions = 0;
|
||||
$calls = 0;
|
||||
$totaltime = 0;
|
||||
$calltime = 0;
|
||||
|
||||
foreach($rs as $r)
|
||||
{
|
||||
$completions += $r['completions'];
|
||||
$calls += $r['totalcalls'];
|
||||
$totaltime += $r['callattempttotaltime'];
|
||||
$calltime += $r['calltotaltime'];
|
||||
}
|
||||
|
||||
if ($totaltime == 0)
|
||||
{
|
||||
$effectiveness = 0;
|
||||
$cph = 0;
|
||||
$callsph = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
$effectiveness = round($calltime / $totaltime,4);
|
||||
$cph = round($completions/($totaltime/3600),4);
|
||||
$callsph = round($calls/($totaltime/3600),4);
|
||||
}
|
||||
|
||||
$rs[] = array("effectiveness" => $effectiveness, "completions" => $completions,"time" => sec_to_time($totaltime),"totalcalls" => $calls,"callt" => sec_to_time($calltime),"CPH" => $cph,"CALLSPH" => $callsph);
|
||||
|
||||
return $rs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get stats by interviewer
|
||||
*
|
||||
* @return arrayh An array containing operator_id,firstName,CPH,effectiveness,
|
||||
*/
|
||||
function get_stats()
|
||||
{
|
||||
global $db;
|
||||
|
||||
$sql = "SELECT o.operator_id, o.firstName, (calltime.totaltime / callattempttime.totaltime) AS effectiveness, c.completions,SEC_TO_TIME(callattempttime.totaltime) as time, c.completions/(callattempttime.totaltime / 3600) as CPH, SEC_TO_TIME(calltime.totaltime) as callt, SEC_TO_TIME(callattempttime.totaltime) as callatemptt, calls.calls as totalcalls, calls.calls/(callattempttime.totaltime / 3600) as CALLSPH, calltime.totaltime as calltotaltime, callattempttime.totaltime as callattempttotaltime
|
||||
FROM operator AS o
|
||||
JOIN (
|
||||
SELECT SUM( TIMESTAMPDIFF(
|
||||
SECOND , c.start, IFNULL( c.end, CONVERT_TZ( NOW( ) , 'System', 'UTC' ) ) ) ) AS totaltime, operator_id
|
||||
FROM `call` AS c
|
||||
GROUP BY operator_id
|
||||
) AS calltime ON ( calltime.operator_id = o.operator_id )
|
||||
JOIN (
|
||||
SELECT SUM( TIMESTAMPDIFF(
|
||||
SECOND , c.start, IFNULL( c.end, CONVERT_TZ( NOW( ) , 'System', 'UTC' ) ) ) ) AS totaltime, operator_id
|
||||
FROM `call_attempt` AS c, `case` as b
|
||||
GROUP BY operator_id
|
||||
) AS callattempttime ON ( callattempttime.operator_id = o.operator_id )
|
||||
JOIN ( SELECT count(*) as completions,a.operator_id
|
||||
FROM `call` as a
|
||||
WHERE a.outcome_id = '10'
|
||||
GROUP BY a.operator_id) as c on (c.operator_id = o.operator_id)
|
||||
JOIN ( SELECT count(*) as calls,a.operator_id
|
||||
FROM `call` as a
|
||||
GROUP BY a.operator_id) as calls on (calls.operator_id = o.operator_id)
|
||||
ORDER BY effectiveness DESC";
|
||||
|
||||
return $db->GetAll($sql);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get stats by interviewer by questionnaire
|
||||
*
|
||||
* @param int $questionnaire_id The questionnaire
|
||||
* @return arrayh An array containing operator_id,firstName,CPH,effectiveness,
|
||||
*/
|
||||
function get_stats_by_questionnaire($questionnaire_id)
|
||||
{
|
||||
global $db;
|
||||
|
||||
$sql = "SELECT o.operator_id, o.firstName, (calltime.totaltime / callattempttime.totaltime) AS effectiveness, c.completions,SEC_TO_TIME(callattempttime.totaltime) as time, c.completions/(callattempttime.totaltime / 3600) as CPH, SEC_TO_TIME(calltime.totaltime) as callt, SEC_TO_TIME(callattempttime.totaltime) as callatemptt, calls.calls as totalcalls, calls.calls/(callattempttime.totaltime / 3600) as CALLSPH, calltime.totaltime as calltotaltime, callattempttime.totaltime as callattempttotaltime
|
||||
|
||||
FROM operator AS o
|
||||
JOIN (
|
||||
SELECT SUM( TIMESTAMPDIFF(
|
||||
SECOND , c.start, IFNULL( c.end, CONVERT_TZ( NOW( ) , 'System', 'UTC' ) ) ) ) AS totaltime, operator_id
|
||||
FROM `call` AS c, `case` as b
|
||||
WHERE c.case_id = b.case_id
|
||||
AND b.questionnaire_id = '$questionnaire_id'
|
||||
GROUP BY operator_id
|
||||
) AS calltime ON ( calltime.operator_id = o.operator_id )
|
||||
JOIN (
|
||||
SELECT SUM( TIMESTAMPDIFF(
|
||||
SECOND , c.start, IFNULL( c.end, CONVERT_TZ( NOW( ) , 'System', 'UTC' ) ) ) ) AS totaltime, operator_id
|
||||
FROM `call_attempt` AS c, `case` as b
|
||||
WHERE c.case_id = b.case_id
|
||||
AND b.questionnaire_id = '$questionnaire_id'
|
||||
GROUP BY operator_id
|
||||
) AS callattempttime ON ( callattempttime.operator_id = o.operator_id )
|
||||
JOIN ( SELECT count(*) as completions,a.operator_id
|
||||
FROM `call` as a, `case` as b
|
||||
WHERE a.outcome_id = '10'
|
||||
AND a.case_id = b.case_id
|
||||
AND b.questionnaire_id = '$questionnaire_id'
|
||||
GROUP BY a.operator_id) as c on (c.operator_id = o.operator_id)
|
||||
JOIN ( SELECT count(*) as calls,a.operator_id
|
||||
FROM `call` as a, `case` as b
|
||||
WHERE a.case_id = b.case_id
|
||||
AND b.questionnaire_id = '$questionnaire_id'
|
||||
GROUP BY a.operator_id) as calls on (calls.operator_id = o.operator_id)
|
||||
ORDER BY effectiveness DESC";
|
||||
|
||||
return $db->GetAll($sql);
|
||||
}
|
||||
|
||||
@@ -113,13 +316,13 @@ function get_CPH()
|
||||
{
|
||||
global $db;
|
||||
|
||||
$sql = "SELECT o.firstName,o.operator_id,c.completions,ca.time, c.completions/ca.time as CPH
|
||||
$sql = "SELECT o.firstName,o.operator_id,c.completions,SEC_TO_TIME(ca.time) as time, c.completions/(ca.time / 3600) as CPH
|
||||
FROM operator as o
|
||||
JOIN ( SELECT count(*) as completions,operator_id
|
||||
FROM `call`
|
||||
WHERE outcome_id = '10'
|
||||
GROUP BY operator_id) as c on (c.operator_id = o.operator_id)
|
||||
JOIN ( SELECT SUM( TIMESTAMPDIFF(SECOND , start, IFNULL(end,CONVERT_TZ(NOW(),'System','UTC')))) /3600 as time, operator_id
|
||||
JOIN ( SELECT SUM( TIMESTAMPDIFF(SECOND , start, IFNULL(end,CONVERT_TZ(NOW(),'System','UTC')))) as time, operator_id
|
||||
FROM `call_attempt`
|
||||
GROUP BY operator_id) as ca on (ca.operator_id = o.operator_id)
|
||||
ORDER BY cph DESC";
|
||||
|
||||
Reference in New Issue
Block a user