Added Average chat time and Average waiting time statistics

This commit is contained in:
Dmitriy Simushev 2011-11-19 14:23:04 +00:00
parent 863de0057c
commit 856123de48
7 changed files with 40 additions and 16 deletions

View File

@ -36,6 +36,7 @@ $dbtables = array(
"agentName" => "varchar(64)", "agentName" => "varchar(64)",
"agentId" => "int NOT NULL DEFAULT 0", "agentId" => "int NOT NULL DEFAULT 0",
"dtmcreated" => "datetime DEFAULT 0", "dtmcreated" => "datetime DEFAULT 0",
"dtmchatstarted" => "datetime DEFAULT 0",
"dtmmodified" => "datetime DEFAULT 0", "dtmmodified" => "datetime DEFAULT 0",
"lrevision" => "int NOT NULL DEFAULT 0", "lrevision" => "int NOT NULL DEFAULT 0",
"istate" => "int NOT NULL DEFAULT 0", "istate" => "int NOT NULL DEFAULT 0",
@ -141,7 +142,7 @@ $dbtables_indexes = array(
$memtables = array(); $memtables = array();
$dbtables_can_update = 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}chatmessage" => array("agentId"),
"${mysqlprefix}chatoperator" => array("vcavatar", "vcjabbername", "iperm", "istatus", "vcemail", "dtmrestore", "vcrestoretoken"), "${mysqlprefix}chatoperator" => array("vcavatar", "vcjabbername", "iperm", "istatus", "vcemail", "dtmrestore", "vcrestoretoken"),
"${mysqlprefix}chatban" => array(), "${mysqlprefix}chatban" => array(),

View File

@ -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); 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)) { if (in_array("${mysqlprefix}chatthread.agentTyping", $absent)) {
runsql("ALTER TABLE ${mysqlprefix}chatthread ADD agentTyping int DEFAULT 0", $link); runsql("ALTER TABLE ${mysqlprefix}chatthread ADD agentTyping int DEFAULT 0", $link);
} }

View File

@ -565,7 +565,7 @@ function thread_by_id_($id, $link)
{ {
global $mysqlprefix; global $mysqlprefix;
return select_one_row("select threadid,userName,agentName,agentId,lrevision,istate,ltoken,userTyping,agentTyping" . 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" . ",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); " from ${mysqlprefix}chatthread where threadid = " . $id, $link);
} }
@ -606,15 +606,18 @@ function create_thread($groupid, $username, $remoteHost, $referer, $lang, $useri
return $newthread; return $newthread;
} }
function do_take_thread($threadid, $operatorId, $operatorName) function do_take_thread($threadid, $operatorId, $operatorName, $chatstart = false)
{ {
global $state_chatting; global $state_chatting;
$link = connect(); $link = connect();
commit_thread($threadid, $params = array("istate" => $state_chatting,
array("istate" => $state_chatting, "nextagent" => 0,
"nextagent" => 0, "agentId" => $operatorId,
"agentId" => $operatorId, "agentName" => "'" . db_escape_string($operatorName, $link) . "'");
"agentName" => "'" . db_escape_string($operatorName, $link) . "'"), $link); if ($chatstart){
$params['dtmchatstarted'] = "CURRENT_TIMESTAMP";
}
commit_thread($threadid, $params, $link);
close_connection($link); close_connection($link);
} }
@ -647,11 +650,12 @@ function take_thread($thread, $operator)
$state = $thread['istate']; $state = $thread['istate'];
$threadid = $thread['threadid']; $threadid = $thread['threadid'];
$message_to_post = ""; $message_to_post = "";
$chatstart = $thread['chatstarted'] == 0;
$operatorName = ($thread['locale'] == $home_locale) ? $operator['vclocalename'] : $operator['vccommonname']; $operatorName = ($thread['locale'] == $home_locale) ? $operator['vclocalename'] : $operator['vccommonname'];
if ($state == $state_queue || $state == $state_waiting || $state == $state_loading) { 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 ($state == $state_waiting) {
if ($operatorName != $thread['agentName']) { if ($operatorName != $thread['agentName']) {
@ -664,7 +668,7 @@ function take_thread($thread, $operator)
} }
} else if ($state == $state_chatting) { } else if ($state == $state_chatting) {
if ($operator['operatorid'] != $thread['agentId']) { 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']); $message_to_post = getstring2_("chat.status.operator.changed", array($operatorName, $thread['agentName']), $thread['locale']);
} }
} else { } else {

View File

@ -396,6 +396,8 @@ report.bydate.1=Date
report.bydate.2=Chat threads report.bydate.2=Chat threads
report.bydate.3=Messages from operators report.bydate.3=Messages from operators
report.bydate.4=Messages from visitors 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.bydate.title=Usage statistics for each date
report.byoperator.1=Operator report.byoperator.1=Operator
report.byoperator.2=Chat Threads report.byoperator.2=Chat Threads

View File

@ -394,6 +394,8 @@ report.bydate.1=
report.bydate.2=Диалогов report.bydate.2=Диалогов
report.bydate.3=Сообщений операторов report.bydate.3=Сообщений операторов
report.bydate.4=Сообщений посетителей report.bydate.4=Сообщений посетителей
report.bydate.5=Среднее время ожидания (в секундах)
report.bydate.6=Среднее время диалога (в секундах)
report.bydate.title=Использование мессенджера по дням report.bydate.title=Использование мессенджера по дням
report.byoperator.1=Оператор report.byoperator.1=Оператор
report.byoperator.2=Диалогов report.byoperator.2=Диалогов

View File

@ -70,11 +70,13 @@ if ($start > $end) {
$link = connect(); $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 " . $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 where unix_timestamp(dtmcreated) >= $start AND unix_timestamp(dtmcreated) < $end group by DATE(dtmcreated) order by dtmcreated desc", $link); "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 " . $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 where unix_timestamp(dtmcreated) >= $start AND unix_timestamp(dtmcreated) < $end", $link); "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 " . $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 " . "from ${mysqlprefix}chatmessage, ${mysqlprefix}chatoperator " .

View File

@ -82,6 +82,10 @@ require_once('inc_errors.php');
<?php echo getlocal("report.bydate.3") ?> <?php echo getlocal("report.bydate.3") ?>
</th><th> </th><th>
<?php echo getlocal("report.bydate.4") ?> <?php echo getlocal("report.bydate.4") ?>
</th><th>
<?php echo getlocal("report.bydate.5") ?>
</th><th>
<?php echo getlocal("report.bydate.6") ?>
</th></tr> </th></tr>
</thead> </thead>
<tbody> <tbody>
@ -92,6 +96,8 @@ require_once('inc_errors.php');
<td><?php echo $row['threads'] ?></td> <td><?php echo $row['threads'] ?></td>
<td><?php echo $row['agents'] ?></td> <td><?php echo $row['agents'] ?></td>
<td><?php echo $row['users'] ?></td> <td><?php echo $row['users'] ?></td>
<td><?php echo $row['avgwaitingtime'] ?></td>
<td><?php echo $row['avgchattime'] ?></td>
</tr> </tr>
<?php } ?> <?php } ?>
<tr> <tr>
@ -99,10 +105,12 @@ require_once('inc_errors.php');
<td><?php echo $page['reportByDateTotal']['threads'] ?></td> <td><?php echo $page['reportByDateTotal']['threads'] ?></td>
<td><?php echo $page['reportByDateTotal']['agents'] ?></td> <td><?php echo $page['reportByDateTotal']['agents'] ?></td>
<td><?php echo $page['reportByDateTotal']['users'] ?></td> <td><?php echo $page['reportByDateTotal']['users'] ?></td>
<td><?php echo $page['reportByDateTotal']['avgwaitingtime'] ?></td>
<td><?php echo $page['reportByDateTotal']['avgchattime'] ?></td>
</tr> </tr>
<?php } else { ?> <?php } else { ?>
<tr> <tr>
<td colspan="4"> <td colspan="6">
<?php echo getlocal("report.no_items") ?> <?php echo getlocal("report.no_items") ?>
</td> </td>
</tr> </tr>