mirror of
https://github.com/Mibew/i18n.git
synced 2025-01-22 13:30:29 +03:00
Extend by operator statistics
This commit is contained in:
parent
cef80ad20b
commit
734c68a022
@ -136,7 +136,11 @@ $dbtables = array(
|
||||
"operatorid" => "int NOT NULL",
|
||||
"threads" => "int NOT NULL DEFAULT 0",
|
||||
"messages" => "int NOT NULL DEFAULT 0",
|
||||
"averagelength" => "FLOAT(10, 1) NOT NULL DEFAULT 0"
|
||||
"averagelength" => "FLOAT(10, 1) NOT NULL DEFAULT 0",
|
||||
"sentinvitations" => "int NOT NULL DEFAULT 0",
|
||||
"acceptedinvitations" => "int NOT NULL DEFAULT 0",
|
||||
"rejectedinvitations" => "int NOT NULL DEFAULT 0",
|
||||
"ignoredinvitations" => "int NOT NULL DEFAULT 0"
|
||||
),
|
||||
|
||||
"${mysqlprefix}chatrevision" => array(
|
||||
@ -242,7 +246,7 @@ $dbtables_can_update = array(
|
||||
"${mysqlprefix}chatmessage" => array("agentId"),
|
||||
"${mysqlprefix}indexedchatmessage" => array(),
|
||||
"${mysqlprefix}chatoperator" => array("vcavatar", "vcjabbername", "iperm", "istatus", "idisabled", "vcemail", "dtmrestore", "vcrestoretoken"),
|
||||
"${mysqlprefix}chatoperatorstatistics" => array(),
|
||||
"${mysqlprefix}chatoperatorstatistics" => array("sentinvitations", "acceptedinvitations", "rejectedinvitations", "ignoredinvitations"),
|
||||
"${mysqlprefix}chatban" => array(),
|
||||
"${mysqlprefix}chatgroup" => array("vcemail", "iweight", "parent", "vctitle", "vcchattitle", "vclogo", "vchosturl"),
|
||||
"${mysqlprefix}chatgroupoperator" => array(),
|
||||
|
@ -184,6 +184,22 @@ if ($act == "silentcreateall") {
|
||||
runsql("ALTER TABLE ${mysqlprefix}chatoperator ADD vcrestoretoken varchar(64)", $link);
|
||||
}
|
||||
|
||||
if (in_array("${mysqlprefix}chatoperatorstatistics.sentinvitations", $absent_columns)) {
|
||||
runsql("ALTER TABLE ${mysqlprefix}chatoperatorstatistics ADD sentinvitations int NOT NULL DEFAULT 0", $link);
|
||||
}
|
||||
|
||||
if (in_array("${mysqlprefix}chatoperatorstatistics.acceptedinvitations", $absent_columns)) {
|
||||
runsql("ALTER TABLE ${mysqlprefix}chatoperatorstatistics ADD acceptedinvitations int NOT NULL DEFAULT 0", $link);
|
||||
}
|
||||
|
||||
if (in_array("${mysqlprefix}chatoperatorstatistics.rejectedinvitations", $absent_columns)) {
|
||||
runsql("ALTER TABLE ${mysqlprefix}chatoperatorstatistics ADD rejectedinvitations int NOT NULL DEFAULT 0", $link);
|
||||
}
|
||||
|
||||
if (in_array("${mysqlprefix}chatoperatorstatistics.ignoredinvitations", $absent_columns)) {
|
||||
runsql("ALTER TABLE ${mysqlprefix}chatoperatorstatistics ADD ignoredinvitations int NOT NULL DEFAULT 0", $link);
|
||||
}
|
||||
|
||||
if (in_array("${mysqlprefix}chatresponses.vctitle", $absent_columns)) {
|
||||
runsql("ALTER TABLE ${mysqlprefix}chatresponses ADD vctitle varchar(100) NOT NULL DEFAULT '' AFTER groupid", $link);
|
||||
}
|
||||
|
@ -270,28 +270,121 @@ function calculate_operator_statistics() {
|
||||
$start = empty($result['start']) ? 0 : $result['start'];
|
||||
$today = floor(time() / (24*60*60)) * 24*60*60;
|
||||
|
||||
$statistics = array();
|
||||
|
||||
// Caclculate statistics
|
||||
$db->query(
|
||||
"INSERT INTO {chatoperatorstatistics} ( " .
|
||||
"date, operatorid, threads, messages, averagelength" .
|
||||
") SELECT (FLOOR(m.dtmcreated / (24*60*60)) * 24*60*60) AS date, " .
|
||||
"o.operatorid AS opid, " .
|
||||
// Get base operator's info
|
||||
$db_results = $db->query(
|
||||
"SELECT (FLOOR(m.dtmcreated / (24*60*60)) * 24*60*60) AS date, " .
|
||||
"m.agentId AS operator_id, " .
|
||||
"COUNT(distinct m.threadid) AS threads, " .
|
||||
"SUM(m.ikind = :kind_agent) AS msgs, " .
|
||||
"AVG(CHAR_LENGTH(m.tmessage)) AS avglen " .
|
||||
"FROM {indexedchatmessage} m, {chatoperator} o " .
|
||||
"WHERE m.agentId = o.operatorid " .
|
||||
"COUNT(m.messageid) AS messages, " .
|
||||
"AVG(CHAR_LENGTH(m.tmessage)) AS avg_msg_length " .
|
||||
// Use {indexedchatmessage} as base table because of one thread can
|
||||
// be related with more than one operator (they can change each
|
||||
// other during conversation).
|
||||
"FROM {indexedchatmessage} m, {chatthread} t " .
|
||||
"WHERE m.ikind = :kind_agent " .
|
||||
"AND m.threadid = t.threadid " .
|
||||
"AND (m.dtmcreated - :start) > 24*60*60 " .
|
||||
// Calculate statistics only for messages that older one day
|
||||
"AND (:today - m.dtmcreated) > 24*60*60 " .
|
||||
"GROUP BY date " .
|
||||
"ORDER BY date",
|
||||
// Ignore not accepted invitations
|
||||
"AND (t.invitationstate = :not_invited " .
|
||||
"OR t.invitationstate = :invitation_accepted) " .
|
||||
"GROUP BY date, operator_id",
|
||||
array(
|
||||
':kind_agent' => Thread::KIND_AGENT,
|
||||
':start' => $start,
|
||||
':today' => $today
|
||||
)
|
||||
':today' => $today,
|
||||
':not_invited' => Thread::INVITATION_NOT_INVITED,
|
||||
':invitation_accepted' => Thread::INVITATION_ACCEPTED,
|
||||
':kind_agent' => Thread::KIND_AGENT
|
||||
),
|
||||
array('return_rows' => Database::RETURN_ALL_ROWS)
|
||||
);
|
||||
|
||||
// Store retrieved data as statistics info
|
||||
foreach($db_results as $result) {
|
||||
// Cast types of some fields
|
||||
$result['avg_msg_length'] = (float)$result['avg_msg_length'];
|
||||
$result['messages'] = (int)$result['messages'];
|
||||
|
||||
$statistics[$result['date'] . '_' . $result['operator_id']] = $result;
|
||||
}
|
||||
|
||||
// Get info about invitations
|
||||
$db_results = $db->query(
|
||||
"SELECT (FLOOR(dtmcreated / (24*60*60)) * 24*60*60) AS date, " .
|
||||
"agentId as operator_id, " .
|
||||
"COUNT(threadid) AS invitation_sent, " .
|
||||
"SUM(invitationstate = :invitation_accepted) AS invitation_accepted, " .
|
||||
"SUM(invitationstate = :invitation_rejected) AS invitation_rejected, " .
|
||||
"SUM(invitationstate = :invitation_ignored) AS invitation_ignored " .
|
||||
"FROM {chatthread} " .
|
||||
"WHERE (dtmcreated - :start) > 24*60*60 " .
|
||||
// Calculate statistics only for threads that older than one day
|
||||
"AND (:today - dtmcreated) > 24*60*60 " .
|
||||
// Check if thread has related operator
|
||||
"AND agentId != 0 " .
|
||||
// Ignore not accepted invitations
|
||||
"AND (invitationstate = :invitation_accepted " .
|
||||
"OR invitationstate = :invitation_rejected " .
|
||||
"OR invitationstate = :invitation_ignored) " .
|
||||
"GROUP BY date, operator_id",
|
||||
array(
|
||||
':start' => $start,
|
||||
':today' => $today,
|
||||
':invitation_accepted' => Thread::INVITATION_ACCEPTED,
|
||||
':invitation_rejected' => Thread::INVITATION_REJECTED,
|
||||
':invitation_ignored' => Thread::INVITATION_IGNORED
|
||||
),
|
||||
array('return_rows' => Database::RETURN_ALL_ROWS)
|
||||
);
|
||||
|
||||
// Store retrieved data as statistics info
|
||||
foreach($db_results as $result) {
|
||||
$key = $result['date'] . '_' . $result['operator_id'];
|
||||
if (empty($statistics[$key])) {
|
||||
$statistics[$key] = array();
|
||||
}
|
||||
$statistics[$key] += $result;
|
||||
}
|
||||
|
||||
// Sort statistics by date before save it in the database
|
||||
ksort($statistics);
|
||||
|
||||
foreach($statistics as $row) {
|
||||
// Set default values
|
||||
$row += array(
|
||||
'threads' => 0,
|
||||
'messages' => 0,
|
||||
'avg_msg_length' => 0,
|
||||
'invitation_sent' => 0,
|
||||
'invitation_accepted' => 0,
|
||||
'invitation_rejected' => 0,
|
||||
'invitation_ignored' => 0
|
||||
);
|
||||
|
||||
// Prepare data for insert
|
||||
$insert_data = array();
|
||||
foreach($row as $field_name => $field_value) {
|
||||
$insert_data[':' . $field_name] = $field_value;
|
||||
}
|
||||
|
||||
$db->query(
|
||||
"INSERT INTO {chatoperatorstatistics} (" .
|
||||
"date, operatorid, threads, messages, averagelength, " .
|
||||
"sentinvitations, acceptedinvitations, " .
|
||||
"rejectedinvitations, ignoredinvitations " .
|
||||
") VALUES (".
|
||||
":date, :operator_id, :threads, :messages, " .
|
||||
":avg_msg_length, :invitation_sent, " .
|
||||
":invitation_accepted, :invitation_rejected, " .
|
||||
":invitation_ignored " .
|
||||
")",
|
||||
$insert_data
|
||||
);
|
||||
}
|
||||
} catch(Exception $e) {
|
||||
// Something went wrong: warn and rollback transaction.
|
||||
trigger_error(
|
||||
|
@ -462,6 +462,10 @@ report.byoperator.1=Operator
|
||||
report.byoperator.2=Chat Threads
|
||||
report.byoperator.3=Messages
|
||||
report.byoperator.4=Average message length (in chars)
|
||||
report.byoperator.5=Invitations sent
|
||||
report.byoperator.6=Invitations accepted
|
||||
report.byoperator.7=Invitations rejected
|
||||
report.byoperator.8=Invitations ignored
|
||||
report.byoperator.title=Threads by operator
|
||||
report.bypage.1=Page
|
||||
report.bypage.2=View times
|
||||
|
@ -461,6 +461,10 @@ report.byoperator.1=
|
||||
report.byoperator.2=Диалогов
|
||||
report.byoperator.3=Сообщений
|
||||
report.byoperator.4=Средняя длина сообщения (в символах)
|
||||
report.byoperator.5=Приглашений отправлено
|
||||
report.byoperator.6=Приглашений принято
|
||||
report.byoperator.7=Приглашений отклонено
|
||||
report.byoperator.8=Приглашений проигнорировано
|
||||
report.byoperator.title=Статистика по операторам
|
||||
report.bypage.1=Страница
|
||||
report.bypage.2=Просмотров
|
||||
|
@ -129,9 +129,15 @@ if ($statisticstype == 'bydate') {
|
||||
} elseif($statisticstype == 'byagent') {
|
||||
$page['reportByAgent'] = $db->query(
|
||||
"SELECT o.vclocalename AS name, " .
|
||||
"s.threads AS threads, " .
|
||||
"s.messages AS msgs, " .
|
||||
"s.averagelength AS avglen " .
|
||||
"SUM(s.threads) AS threads, " .
|
||||
"SUM(s.messages) AS msgs, " .
|
||||
"ROUND( " .
|
||||
"SUM(s.averagelength * s.messages) / SUM(s.messages), " .
|
||||
"1) AS avglen, " .
|
||||
"SUM(sentinvitations) AS sentinvitations, " .
|
||||
"SUM(acceptedinvitations) AS acceptedinvitations, " .
|
||||
"SUM(rejectedinvitations) AS rejectedinvitations, " .
|
||||
"SUM(ignoredinvitations) AS ignoredinvitations " .
|
||||
"FROM {chatoperatorstatistics} s, {chatoperator} o " .
|
||||
"WHERE s.operatorid = o.operatorid " .
|
||||
"AND s.date >= :start " .
|
||||
|
@ -164,7 +164,22 @@ require_once('inc_errors.php');
|
||||
<?php echo getlocal("report.byoperator.3") ?>
|
||||
</th><th>
|
||||
<?php echo getlocal("report.byoperator.4") ?>
|
||||
</th></tr>
|
||||
</th>
|
||||
<?php if ($page['show_invitations_info']) { ?>
|
||||
<th>
|
||||
<?php echo getlocal("report.byoperator.5") ?>
|
||||
</th>
|
||||
<th>
|
||||
<?php echo getlocal("report.byoperator.6") ?>
|
||||
</th>
|
||||
<th>
|
||||
<?php echo getlocal("report.byoperator.7") ?>
|
||||
</th>
|
||||
<th>
|
||||
<?php echo getlocal("report.byoperator.8") ?>
|
||||
</th>
|
||||
<?php } ?>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if( $page['reportByAgent'] ) { ?>
|
||||
@ -174,11 +189,17 @@ require_once('inc_errors.php');
|
||||
<td><?php echo $row['threads'] ?></td>
|
||||
<td><?php echo $row['msgs'] ?></td>
|
||||
<td><?php echo $row['avglen'] ?></td>
|
||||
<?php if ($page['show_invitations_info']) { ?>
|
||||
<td><?php echo $row['sentinvitations'] ?></td>
|
||||
<td><?php echo $row['acceptedinvitations'] ?></td>
|
||||
<td><?php echo $row['rejectedinvitations'] ?></td>
|
||||
<td><?php echo $row['ignoredinvitations'] ?></td>
|
||||
<?php } ?>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
<?php } else { ?>
|
||||
<tr>
|
||||
<td colspan="4">
|
||||
<td colspan="<?php echo($page['show_invitations_info'] ? 8 : 4); ?>">
|
||||
<?php echo getlocal("report.no_items") ?>
|
||||
</td>
|
||||
</tr>
|
||||
|
Loading…
Reference in New Issue
Block a user