mirror of
https://github.com/Mibew/tray.git
synced 2025-01-22 18:10:34 +03:00
Added Average chat time and Average waiting time statistics
This commit is contained in:
parent
863de0057c
commit
856123de48
@ -36,6 +36,7 @@ $dbtables = array(
|
||||
"agentName" => "varchar(64)",
|
||||
"agentId" => "int NOT NULL DEFAULT 0",
|
||||
"dtmcreated" => "datetime DEFAULT 0",
|
||||
"dtmchatstarted" => "datetime DEFAULT 0",
|
||||
"dtmmodified" => "datetime DEFAULT 0",
|
||||
"lrevision" => "int NOT NULL DEFAULT 0",
|
||||
"istate" => "int NOT NULL DEFAULT 0",
|
||||
@ -141,7 +142,7 @@ $dbtables_indexes = array(
|
||||
$memtables = array();
|
||||
|
||||
$dbtables_can_update = array(
|
||||
"${mysqlprefix}chatthread" => array("agentId", "userTyping", "agentTyping", "messageCount", "nextagent", "shownmessageid", "userid", "userAgent", "groupid"),
|
||||
"${mysqlprefix}chatthread" => array("agentId", "userTyping", "agentTyping", "messageCount", "nextagent", "shownmessageid", "userid", "userAgent", "groupid", "dtmchatstarted"),
|
||||
"${mysqlprefix}chatmessage" => array("agentId"),
|
||||
"${mysqlprefix}chatoperator" => array("vcavatar", "vcjabbername", "iperm", "istatus", "vcemail", "dtmrestore", "vcrestoretoken"),
|
||||
"${mysqlprefix}chatban" => array(),
|
||||
|
@ -87,6 +87,11 @@ if ($act == "silentcreateall") {
|
||||
runsql("update ${mysqlprefix}chatthread, ${mysqlprefix}chatoperator set agentId = operatorid where agentId = 0 AND (vclocalename = agentName OR vccommonname = agentName)", $link);
|
||||
}
|
||||
|
||||
if (in_array("${mysqlprefix}chatthread.dtmchatstarted", $absent)) {
|
||||
runsql("ALTER TABLE ${mysqlprefix}chatthread ADD dtmchatstarted datetime DEFAULT 0 AFTER dtmcreated", $link);
|
||||
runsql("update ${mysqlprefix}chatthread set dtmchatstarted = dtmcreated", $link);
|
||||
}
|
||||
|
||||
if (in_array("${mysqlprefix}chatthread.agentTyping", $absent)) {
|
||||
runsql("ALTER TABLE ${mysqlprefix}chatthread ADD agentTyping int DEFAULT 0", $link);
|
||||
}
|
||||
|
@ -565,7 +565,7 @@ function thread_by_id_($id, $link)
|
||||
{
|
||||
global $mysqlprefix;
|
||||
return select_one_row("select threadid,userName,agentName,agentId,lrevision,istate,ltoken,userTyping,agentTyping" .
|
||||
",unix_timestamp(dtmmodified) as modified, unix_timestamp(dtmcreated) as created" .
|
||||
",unix_timestamp(dtmmodified) as modified, unix_timestamp(dtmcreated) as created, unix_timestamp(dtmchatstarted) as chatstarted" .
|
||||
",remote,referer,locale,unix_timestamp(lastpinguser) as lpuser,unix_timestamp(lastpingagent) as lpagent, unix_timestamp(CURRENT_TIMESTAMP) as current,nextagent,shownmessageid,userid,userAgent,groupid" .
|
||||
" from ${mysqlprefix}chatthread where threadid = " . $id, $link);
|
||||
}
|
||||
@ -606,15 +606,18 @@ function create_thread($groupid, $username, $remoteHost, $referer, $lang, $useri
|
||||
return $newthread;
|
||||
}
|
||||
|
||||
function do_take_thread($threadid, $operatorId, $operatorName)
|
||||
function do_take_thread($threadid, $operatorId, $operatorName, $chatstart = false)
|
||||
{
|
||||
global $state_chatting;
|
||||
$link = connect();
|
||||
commit_thread($threadid,
|
||||
array("istate" => $state_chatting,
|
||||
$params = array("istate" => $state_chatting,
|
||||
"nextagent" => 0,
|
||||
"agentId" => $operatorId,
|
||||
"agentName" => "'" . db_escape_string($operatorName, $link) . "'"), $link);
|
||||
"agentName" => "'" . db_escape_string($operatorName, $link) . "'");
|
||||
if ($chatstart){
|
||||
$params['dtmchatstarted'] = "CURRENT_TIMESTAMP";
|
||||
}
|
||||
commit_thread($threadid, $params, $link);
|
||||
close_connection($link);
|
||||
}
|
||||
|
||||
@ -647,11 +650,12 @@ function take_thread($thread, $operator)
|
||||
$state = $thread['istate'];
|
||||
$threadid = $thread['threadid'];
|
||||
$message_to_post = "";
|
||||
$chatstart = $thread['chatstarted'] == 0;
|
||||
|
||||
$operatorName = ($thread['locale'] == $home_locale) ? $operator['vclocalename'] : $operator['vccommonname'];
|
||||
|
||||
if ($state == $state_queue || $state == $state_waiting || $state == $state_loading) {
|
||||
do_take_thread($threadid, $operator['operatorid'], $operatorName);
|
||||
do_take_thread($threadid, $operator['operatorid'], $operatorName, $chatstart);
|
||||
|
||||
if ($state == $state_waiting) {
|
||||
if ($operatorName != $thread['agentName']) {
|
||||
@ -664,7 +668,7 @@ function take_thread($thread, $operator)
|
||||
}
|
||||
} else if ($state == $state_chatting) {
|
||||
if ($operator['operatorid'] != $thread['agentId']) {
|
||||
do_take_thread($threadid, $operator['operatorid'], $operatorName);
|
||||
do_take_thread($threadid, $operator['operatorid'], $operatorName, $chatstart);
|
||||
$message_to_post = getstring2_("chat.status.operator.changed", array($operatorName, $thread['agentName']), $thread['locale']);
|
||||
}
|
||||
} else {
|
||||
|
@ -396,6 +396,8 @@ report.bydate.1=Date
|
||||
report.bydate.2=Chat threads
|
||||
report.bydate.3=Messages from operators
|
||||
report.bydate.4=Messages from visitors
|
||||
report.bydate.5=Average waiting time (in seconds)
|
||||
report.bydate.6=Average chat time (in seconds)
|
||||
report.bydate.title=Usage statistics for each date
|
||||
report.byoperator.1=Operator
|
||||
report.byoperator.2=Chat Threads
|
||||
|
@ -394,6 +394,8 @@ report.bydate.1=
|
||||
report.bydate.2=Диалогов
|
||||
report.bydate.3=Сообщений операторов
|
||||
report.bydate.4=Сообщений посетителей
|
||||
report.bydate.5=Среднее время ожидания (в секундах)
|
||||
report.bydate.6=Среднее время диалога (в секундах)
|
||||
report.bydate.title=Использование мессенджера по дням
|
||||
report.byoperator.1=Оператор
|
||||
report.byoperator.2=Диалогов
|
||||
|
@ -70,11 +70,13 @@ if ($start > $end) {
|
||||
|
||||
$link = connect();
|
||||
|
||||
$page['reportByDate'] = select_multi_assoc("select DATE(dtmcreated) as date, COUNT(distinct threadid) as threads, SUM(${mysqlprefix}chatmessage.ikind = $kind_agent) as agents, SUM(${mysqlprefix}chatmessage.ikind = $kind_user) as users " .
|
||||
"from ${mysqlprefix}chatmessage where unix_timestamp(dtmcreated) >= $start AND unix_timestamp(dtmcreated) < $end group by DATE(dtmcreated) order by dtmcreated desc", $link);
|
||||
$page['reportByDate'] = select_multi_assoc("select DATE(t.dtmcreated) as date, COUNT(distinct t.threadid) as threads, SUM(m.ikind = $kind_agent) as agents, SUM(m.ikind = $kind_user) as users, ROUND(AVG(unix_timestamp(t.dtmchatstarted)-unix_timestamp(t.dtmcreated)),1) as avgwaitingtime, ROUND(AVG(tmp.lastmsgtime - unix_timestamp(t.dtmchatstarted)),1) as avgchattime " .
|
||||
"from ${mysqlprefix}chatmessage m, ${mysqlprefix}chatthread t, (SELECT i.threadid, unix_timestamp(MAX(i.dtmcreated)) AS lastmsgtime FROM ${mysqlprefix}chatmessage i WHERE (ikind = $kind_user OR ikind = $kind_agent) GROUP BY i.threadid) tmp " .
|
||||
"where m.threadid = t.threadid AND tmp.threadid = t.threadid AND unix_timestamp(m.dtmcreated) >= $start AND unix_timestamp(m.dtmcreated) < $end group by DATE(m.dtmcreated) order by m.dtmcreated desc", $link);
|
||||
|
||||
$page['reportByDateTotal'] = select_one_row("select COUNT(distinct threadid) as threads, SUM(${mysqlprefix}chatmessage.ikind = $kind_agent) as agents, SUM(${mysqlprefix}chatmessage.ikind = $kind_user) as users " .
|
||||
"from ${mysqlprefix}chatmessage where unix_timestamp(dtmcreated) >= $start AND unix_timestamp(dtmcreated) < $end", $link);
|
||||
$page['reportByDateTotal'] = select_one_row("select DATE(t.dtmcreated) as date, COUNT(distinct t.threadid) as threads, SUM(m.ikind = $kind_agent) as agents, SUM(m.ikind = $kind_user) as users, ROUND(AVG(unix_timestamp(t.dtmchatstarted)-unix_timestamp(t.dtmcreated)),1) as avgwaitingtime, ROUND(AVG(tmp.lastmsgtime - unix_timestamp(t.dtmchatstarted)),1) as avgchattime " .
|
||||
"from ${mysqlprefix}chatmessage m, ${mysqlprefix}chatthread t, (SELECT i.threadid, unix_timestamp(MAX(i.dtmcreated)) AS lastmsgtime FROM ${mysqlprefix}chatmessage i WHERE (ikind = $kind_user OR ikind = $kind_agent) GROUP BY i.threadid) tmp " .
|
||||
"where m.threadid = t.threadid AND tmp.threadid = t.threadid AND unix_timestamp(m.dtmcreated) >= $start AND unix_timestamp(m.dtmcreated) < $end", $link);
|
||||
|
||||
$page['reportByAgent'] = select_multi_assoc("select vclocalename as name, COUNT(distinct threadid) as threads, SUM(ikind = $kind_agent) as msgs, AVG(CHAR_LENGTH(tmessage)) as avglen " .
|
||||
"from ${mysqlprefix}chatmessage, ${mysqlprefix}chatoperator " .
|
||||
|
@ -82,6 +82,10 @@ require_once('inc_errors.php');
|
||||
<?php echo getlocal("report.bydate.3") ?>
|
||||
</th><th>
|
||||
<?php echo getlocal("report.bydate.4") ?>
|
||||
</th><th>
|
||||
<?php echo getlocal("report.bydate.5") ?>
|
||||
</th><th>
|
||||
<?php echo getlocal("report.bydate.6") ?>
|
||||
</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@ -92,6 +96,8 @@ require_once('inc_errors.php');
|
||||
<td><?php echo $row['threads'] ?></td>
|
||||
<td><?php echo $row['agents'] ?></td>
|
||||
<td><?php echo $row['users'] ?></td>
|
||||
<td><?php echo $row['avgwaitingtime'] ?></td>
|
||||
<td><?php echo $row['avgchattime'] ?></td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
<tr>
|
||||
@ -99,10 +105,12 @@ require_once('inc_errors.php');
|
||||
<td><?php echo $page['reportByDateTotal']['threads'] ?></td>
|
||||
<td><?php echo $page['reportByDateTotal']['agents'] ?></td>
|
||||
<td><?php echo $page['reportByDateTotal']['users'] ?></td>
|
||||
<td><?php echo $page['reportByDateTotal']['avgwaitingtime'] ?></td>
|
||||
<td><?php echo $page['reportByDateTotal']['avgchattime'] ?></td>
|
||||
</tr>
|
||||
<?php } else { ?>
|
||||
<tr>
|
||||
<td colspan="4">
|
||||
<td colspan="6">
|
||||
<?php echo getlocal("report.no_items") ?>
|
||||
</td>
|
||||
</tr>
|
||||
|
Loading…
Reference in New Issue
Block a user