begining code optimization, ajax-reload of lh-list and localtx, speeding up refresh - no reload of whole page, only reload of subtables

This commit is contained in:
dg9vh 2016-10-07 19:24:26 +00:00
parent ce314843e9
commit bef71b246a
9 changed files with 205 additions and 52 deletions

37
ajax.php Normal file
View file

@ -0,0 +1,37 @@
<?php
session_start();
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
include "config/config.php";
include "include/tools.php";
include "include/functions.php";
$mmdvmconfigs = getMMDVMConfig();
$logLinesMMDVM = getMMDVMLog();
$reverseLogLinesMMDVM = $logLinesMMDVM;
array_multisort($reverseLogLinesMMDVM,SORT_DESC);
//$lastHeard = $_SESSION['lastHeard'];
if ($_GET['section'] == "lastHeard") {
$lastHeard = getLastHeard($reverseLogLinesMMDVM, FALSE);
echo '{"data": '.json_encode($lastHeard)."}";
}
if ($_GET['section'] == "localTx") {
$localTXList = getHeardList($reverseLogLinesMMDVM, FALSE);
$lastHeard = Array();
for ($i = 0; $i < count($localTXList); $i++) {
$listElem = $localTXList[$i];
if ($listElem[6] == "RF" && ($listElem[1]=="D-Star" || startsWith($listElem[1], "DMR") || $listElem[1]=="YSF" || $listElem[1]=="P25")) {
$listElem[3] = getName($listElem[2]);
if (constant("SHOWQRZ") && $listElem[2] !== "??????????" && !is_numeric($listElem[2])) {
$listElem[2] = "<a target=\"_new\" href=\"https://qrz.com/db/$listElem[2]\">".str_replace("0","&Oslash;",$listElem[2])."</a>";
} else {
$listElem[2] = "<a target=\"_new\" href=\"http://dmr.darc.de/dmr-userreg.php?usrid=$listElem[2]\">".$listElem[2]."</a>";
}
array_push($lastHeard, $listElem);
}
}
echo '{"data": '.json_encode($lastHeard)."}";
}
?>

View file

@ -277,7 +277,8 @@ function getHeardList($logLines, $onlyLast) {
// Callsign or ID should be less than 11 chars long, otherwise it could be errorneous
if ( strlen($callsign) < 11 ) {
array_push($heardList, array($timestamp, $mode, $callsign, $id, $target, $source, $duration, $loss, $ber));
$name = "";//getName($callsign);
array_push($heardList, array($timestamp, $mode, $callsign, $name, $id, $target, $source, $duration, $loss, $ber));
$duration = "";
$loss ="";
$ber = "";
@ -297,8 +298,17 @@ function getLastHeard($logLines, $onlyLast) {
$counter = 0;
foreach ($heardList as $listElem) {
if ( ($listElem[1] == "D-Star") || ($listElem[1] == "YSF") || ($listElem[1] == "P25") || (startsWith($listElem[1], "DMR")) ) {
if(!(array_search($listElem[2]."#".$listElem[1].$listElem[3], $heardCalls) > -1)) {
array_push($heardCalls, $listElem[2]."#".$listElem[1].$listElem[3]);
if(!(array_search($listElem[2]."#".$listElem[1].$listElem[4], $heardCalls) > -1)) {
array_push($heardCalls, $listElem[2]."#".$listElem[1].$listElem[4]);
$listElem[3] = getName($listElem[2]);
if (constant("SHOWQRZ") && $listElem[2] !== "??????????" && !is_numeric($listElem[2])) {
$listElem[2] = "<a target=\"_new\" href=\"https://qrz.com/db/$listElem[2]\">".str_replace("0","&Oslash;",$listElem[2])."</a>";
} else {
$listElem[2] = "<a target=\"_new\" href=\"http://dmr.darc.de/dmr-userreg.php?usrid=$listElem[2]\">".$listElem[2]."</a>";
}
array_push($lastHeard, $listElem);
$counter++;
}

View file

@ -2,14 +2,14 @@
//Some basic inits
$mmdvmconfigs = getMMDVMConfig();
$logLinesMMDVM = getMMDVMLog();
$_SESSION['logLinesMMDVM'] = $logLinesMMDVM;
$reverseLogLinesMMDVM = $logLinesMMDVM;
array_multisort($reverseLogLinesMMDVM,SORT_DESC);
$_SESSION['reverseLogLinesMMDVM'] = $reverseLogLinesMMDVM;
$lastHeard = getLastHeard($reverseLogLinesMMDVM, FALSE);
$_SESSION['lastHeard'] = $lastHeard;
if (defined("ENABLEYSFGATEWAY")) {
$YSFGatewayconfigs = getYSFGatewayConfig();
$logLinesYSFGateway = getYSFGatewayLog();
$reverseLogLinesYSFGateway = $logLinesYSFGateway;
array_multisort($reverseLogLinesYSFGateway,SORT_DESC);
$activeYSFReflectors = getActiveYSFReflectors($reverseLogLinesYSFGateway);
$activeYSFReflectors = getActiveYSFReflectors();
}
?>

33
include/lh_ajax.php Normal file
View file

@ -0,0 +1,33 @@
<?php
$totalLH = count($lastHeard);
?>
<div class="panel panel-default">
<!-- Standard-Panel-Inhalt -->
<div class="panel-heading">Last Heard List of today's <?php echo $totalLH; ?> callsigns.</div>
<!-- Tabelle -->
<div class="table-responsive">
<table id="lastHeard" class="table table-condensed table-striped table-hover">
<thead>
<tr>
<th>Time (UTC)</th>
<th>Mode</th>
<th>Callsign</th>
<?php
if (defined("ENABLEXTDLOOKUP")) {
?>
<th>Name</th>
<?php
}
?>
<th>DSTAR-ID</th>
<th>Target</th>
<th>Source</th>
<th>Dur (s)</th>
<th>Loss</th>
<th>BER</th>
</tr>
</thead>
</table>
</div>
</div>

View file

@ -1,6 +1,6 @@
<?php
$localTXList = getHeardList($reverseLogLinesMMDVM, FALSE);
//array_multisort($localTXList,SORT_DESC);
?>
@ -34,7 +34,7 @@ $localTXList = getHeardList($reverseLogLinesMMDVM, FALSE);
<?php
for ($i = 0; $i < count($localTXList); $i++) {
$listElem = $localTXList[$i];
if ($listElem[5] == "RF" && ($listElem[1]=="D-Star" || startsWith($listElem[1], "DMR") || $listElem[1]=="YSF" || $listElem[1]=="P25")) {
if ($listElem[6] == "RF" && ($listElem[1]=="D-Star" || startsWith($listElem[1], "DMR") || $listElem[1]=="YSF" || $listElem[1]=="P25")) {
echo"<tr>";
echo"<td nowrap>$listElem[0]</td>";
echo"<td nowrap>$listElem[1]</td>";
@ -44,23 +44,23 @@ for ($i = 0; $i < count($localTXList); $i++) {
echo"<td nowrap><a target=\"_new\" href=\"http://dmr.darc.de/dmr-userreg.php?usrid=$listElem[2]\">".$listElem[2]."</td>";
}
if (defined("ENABLEXTDLOOKUP")) {
echo "<td class=\"nowrap\">".getName($listElem[2])."</td>";
echo "<td class=\"nowrap\">$listElem[3]</td>";
}
echo"<td nowrap>$listElem[3]</td>";
echo"<td nowrap>$listElem[4]</td>";
echo"<td nowrap>$listElem[5]</td>";
echo"<td nowrap>$listElem[6]</td>";
if ($listElem[6] == null) {
echo'<td nowrap>in TX</td><td></td><td></td>';
} else if ($listElem[6] == "SMS") {
} else if ($listElem[7] == "SMS") {
echo'<td nowrap>sending or receiving SMS</td><td></td><td></td>';
} else {
echo"<td nowrap>$listElem[6]</td>";
echo"<td nowrap>$listElem[7]</td>";
echo"<td nowrap>$listElem[8]</td>";
echo"<td nowrap>$listElem[9]</td>";
}
echo"</tr>\n";
}
}
}
?>
</tbody>

33
include/localtx_ajax.php Normal file
View file

@ -0,0 +1,33 @@
<?php
$totalLH = count($lastHeard);
?>
<div class="panel panel-default">
<!-- Standard-Panel-Inhalt -->
<div class="panel-heading">Today's local transmissions</div>
<!-- Tabelle -->
<div class="table-responsive">
<table id="localTx" class="table table-condensed table-striped table-hover">
<thead>
<tr>
<th>Time (UTC)</th>
<th>Mode</th>
<th>Callsign</th>
<?php
if (defined("ENABLEXTDLOOKUP")) {
?>
<th>Name</th>
<?php
}
?>
<th>DSTAR-ID</th>
<th>Target</th>
<th>Source</th>
<th>Dur (s)</th>
<th>Loss</th>
<th>BER</th>
</tr>
</thead>
</table>
</div>
</div>

View file

@ -1,4 +1,5 @@
<?php
session_start();
$time = microtime();
$time = explode(' ', $time);
$time = $time[1] + $time[0];
@ -17,13 +18,6 @@ include "version.php";
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=0.6,maximum-scale=1, user-scalable=yes">
<?php
if (!isset($_GET['stoprefresh'])) {
?>
<meta http-equiv="refresh" content="<?php echo REFRESHAFTER?>">
<?php
}
?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.3/jquery.min.js"></script>
<!-- Das neueste kompilierte und minimierte CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/latest/css/bootstrap.min.css">
@ -74,8 +68,8 @@ include "include/sysinfo.php";
include "include/disk.php";
include "include/repeaterinfo.php";
include "include/modes.php";
include "include/lh.php";
include "include/localtx.php";
include "include/lh_ajax.php";
include "include/localtx_ajax.php";
if (defined("ENABLEYSFGATEWAY")) {
include "include/ysfgatewayinfo.php";
}
@ -105,11 +99,51 @@ if (!isset($_GET['stoprefresh'])) {
$(document).ready(function(){
var lastHeardT = $('#lastHeard').dataTable( {
"aaSorting": [[0,'desc']]
"aaSorting": [[0,'desc']],
"ajax": '<?php
$protocol = "http";
if ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || $_SERVER['SERVER_PORT'] == 443)
$protocol = "https";
echo $protocol."://";
$base_dir = __DIR__; // Absolute path to your installation, ex: /var/www/mywebsite
$doc_root = preg_replace("!${_SERVER['SCRIPT_NAME']}$!", '', $_SERVER['SCRIPT_FILENAME']); # ex: /var/www
echo $_SERVER['HTTP_HOST'].preg_replace("!^${doc_root}!", '', $base_dir) ?>/ajax.php?section=lastHeard',
"deferRender": true
} );
<?php
if (!isset($_GET['stoprefresh'])) {
?>
setInterval( function () {
lastHeardT.api().ajax.reload( );
}, <?php echo REFRESHAFTER * 1000 ?> );
<?php
}
?>
var localTxT = $('#localTx').dataTable( {
"aaSorting": [[0,'desc']]
"aaSorting": [[0,'desc']],
"ajax": '<?php
$protocol = "http";
if ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || $_SERVER['SERVER_PORT'] == 443)
$protocol = "https";
echo $protocol."://";
$base_dir = __DIR__; // Absolute path to your installation, ex: /var/www/mywebsite
$doc_root = preg_replace("!${_SERVER['SCRIPT_NAME']}$!", '', $_SERVER['SCRIPT_FILENAME']); # ex: /var/www
echo $_SERVER['HTTP_HOST'].preg_replace("!^${doc_root}!", '', $base_dir) ?>/ajax.php?section=localTx',
"deferRender": true
} );
<?php
if (!isset($_GET['stoprefresh'])) {
?>
setInterval( function () {
localTxT.api().ajax.reload( );
}, <?php echo REFRESHAFTER * 1000 ?> );
<?php
}
?>
var ysfGatewaysT = $('#ysfGateways').dataTable( {
"aaSorting": [[0,'asc']]
} );

View file

@ -1,4 +1,5 @@
<?php
session_start();
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
include "config/config.php";
@ -9,9 +10,13 @@ $logLinesMMDVM = getShortMMDVMLog();
$reverseLogLinesMMDVM = $logLinesMMDVM;
array_multisort($reverseLogLinesMMDVM,SORT_DESC);
$lastHeard = getLastHeard($reverseLogLinesMMDVM, True);
$oldLastHeard = $_SESSION['lastHeard'];
echo"<!--";
var_dump($lastHeard);
echo"-->";
foreach ($lastHeard as $listElem) {
echo "<tr>";
if ($listElem[6] == null) {
if ($listElem[7] == null) {
echo"<td nowrap>$listElem[0]</td>";
echo"<td nowrap>$listElem[1]</td>";
if (constant("SHOWQRZ") && $listElem[2] !== "??????????" && !is_numeric($listElem[2])) {
@ -20,14 +25,15 @@ foreach ($lastHeard as $listElem) {
echo"<td nowrap><a target=\"_new\" href=\"http://dmr.darc.de/dmr-userreg.php?usrid=$listElem[2]\">".$listElem[2]."</td>";
}
if (defined("ENABLEXTDLOOKUP")) {
echo "<td nowrap>".getName($listElem[2])."</td>";
//echo "<td nowrap>".getName($listElem[2])."</td>";
echo "<td nowrap>$listElem[3]</td>";
}
echo"<td nowrap>$listElem[3]</td>";
echo"<td nowrap>$listElem[4]</td>";
echo"<td nowrap>$listElem[5]</td>";
if ($listElem[5] == "RF"){
echo "<td nowrap><span class=\"label label-success\">RF</span></td>";
}else{
echo"<td nowrap>$listElem[5]</td>";
echo"<td nowrap>$listElem[6]</td>";
}
$UTC = new DateTimeZone("UTC");
$d1 = new DateTime($listElem[0], $UTC);

View file

@ -1,3 +1,3 @@
<?php
define("VERSION", "20161001-2");
define("VERSION", "20161007-1");
?>