Verified Commit 474dfb27 authored by Camil Staps's avatar Camil Staps 🚀

Max/avg nr of unique visitors p/d added to longterm stats (#62)

parent 7d807c09
<?php
require_once('./conf.php');
$sqlavg =
$sqlavgreq =
"SELECT AVG(`number`) as avgn FROM
(SELECT COUNT(*) as number
FROM `log`
......@@ -9,7 +9,7 @@ $sqlavg =
`responsecode` <> " . E_DOSPROTECT . " AND
`date` BETWEEN timestamp('$startTime') AND timestamp('$endTime')
GROUP BY DATE(`date`)) counts";
$sqlmax =
$sqlmaxreq =
"SELECT number as maxn, thedate as maxd FROM
(SELECT DATE(`date`) as thedate, COUNT(*) as number
FROM `log`
......@@ -19,27 +19,60 @@ $sqlmax =
GROUP BY DATE(`date`)
ORDER BY number DESC, thedate DESC
LIMIT 1) counts";
$sqlavgvis =
"SELECT AVG(number) as avgn FROM
(SELECT DATE(`date`) as thedate, COUNT(DISTINCT ip, useragent_id) as number
FROM `log`
WHERE
`responsecode` <> " . E_DOSPROTECT . " AND
`date` BETWEEN timestamp('$startTime') AND timestamp('$endTime')
GROUP BY DATE(`date`)) counts;";
$sqlmaxvis =
"SELECT number as maxn, thedate as maxd FROM
(SELECT DATE(`date`) as thedate, COUNT(DISTINCT ip, useragent_id) as number
FROM `log`
WHERE
`responsecode` <> " . E_DOSPROTECT . " AND
`date` BETWEEN timestamp('$startTime') AND timestamp('$endTime')
GROUP BY DATE(`date`)
ORDER BY number DESC, thedate DESC
LIMIT 1) counts;";
$stmt = $db->stmt_init();
if (!$stmt->prepare($sqlavgreq))
var_dump($stmt->error);
$stmt->execute();
$stmt->bind_result($avgr);
$stmt->fetch();
$stmt->close();
$stmt = $db->stmt_init();
if (!$stmt->prepare($sqlmaxreq))
var_dump($stmt->error);
$stmt->execute();
$stmt->bind_result($maxrn, $maxrd);
$stmt->fetch();
$stmt->close();
$stmt = $db->stmt_init();
if (!$stmt->prepare($sqlavg))
if (!$stmt->prepare($sqlavgvis))
var_dump($stmt->error);
$stmt->execute();
$stmt->bind_result($avgn);
$stmt->bind_result($avgv);
$stmt->fetch();
$stmt->close();
$stmt = $db->stmt_init();
if (!$stmt->prepare($sqlmax))
if (!$stmt->prepare($sqlmaxvis))
var_dump($stmt->error);
$stmt->execute();
$stmt->bind_result($maxn, $maxd);
$stmt->bind_result($maxvn, $maxvd);
$stmt->fetch();
$stmt->close();
$results =
[ 'avgn' => $avgn
, 'maxn' => $maxn
, 'maxd' => $maxd
[ 'requests' => ['avgn' => $avgr, 'maxn' => $maxrn, 'maxd' => $maxrd]
, 'visitors' => ['avgn' => $avgv, 'maxn' => $maxvn, 'maxd' => $maxvd]
];
header('Content-Type: text/javascript');
......
......@@ -73,6 +73,14 @@
.chart-container .charts .chart.active {
display: block;
}
#extremes table {
margin: 3em auto 0;
}
#extremes td, #extremes th {
padding-right: 1em;
}
</style>
</head>
<body>
......@@ -88,8 +96,23 @@
<div class="charts">
<div class="chart active" id="by-hour"></div>
<div class="chart" id="extremes">
<p>Maximum number of requests: <span id="maxn"></span> on <span id="maxd"></span>.</p>
<p>Average number of requests per day (on days with requests): <span id="avgn"></span>.
<table>
<tr>
<td></td>
<th>Requests</th>
<th>Visitors</th>
</tr>
<tr>
<th>Max</th>
<td><strong id="req-maxn"></strong>, on <span id="req-maxd"></span></td>
<td><strong id="vis-maxn"></strong>, on <span id="vis-maxd"></span></td>
</tr>
<tr>
<th>Avg</th>
<td id="req-avgn"></td>
<td id="vis-avgn"></td>
</tr>
</table>
</div>
<div class="chart" id="oss"></div>
<div class="chart" id="types"></div>
......@@ -102,9 +125,12 @@
if (typeof query == 'undefined')
query = '?callback=?';
$.getJSON('ajax/extremes.php' + query, function(data) {
$('#extremes #maxn').text(data['maxn']);
$('#extremes #maxd').text(data['maxd']);
$('#extremes #avgn').text(data['avgn']);
$('#extremes #req-maxn').text(data.requests.maxn);
$('#extremes #req-maxd').text(data.requests.maxd);
$('#extremes #req-avgn').text(data.requests.avgn);
$('#extremes #vis-maxn').text(data.visitors.maxn);
$('#extremes #vis-maxd').text(data.visitors.maxd);
$('#extremes #vis-avgn').text(data.visitors.avgn);
});
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment