forked from leftypol/leftypol
Adds more IP counters
This commit is contained in:
parent
e9d03ef243
commit
735a9a6249
2 changed files with 42 additions and 15 deletions
|
@ -36,7 +36,9 @@
|
||||||
<tr>
|
<tr>
|
||||||
<th>{% trans "Board" %}</th>
|
<th>{% trans "Board" %}</th>
|
||||||
<th>{% trans "PPH" %}</th>
|
<th>{% trans "PPH" %}</th>
|
||||||
<th>{% trans "Recent IPs" %}</th>
|
<th>{% trans "IPs last hour" %}</th>
|
||||||
|
<th>{% trans "IPs last 24 hours (lynxchan-style)" %}</th>
|
||||||
|
<th>{% trans "IPs last 72 hours (8ch-style)" %}</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
@ -50,6 +52,12 @@
|
||||||
<td class="minimal">
|
<td class="minimal">
|
||||||
<span>{{ stats.recent_ips }}</span>
|
<span>{{ stats.recent_ips }}</span>
|
||||||
</td>
|
</td>
|
||||||
|
<td class="minimal">
|
||||||
|
<span>{{ stats.daily_ips }}</span>
|
||||||
|
</td>
|
||||||
|
<td class="minimal">
|
||||||
|
<span>{{ stats.tridaily_ips }}</span>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% for boardStat in stats.boards %}
|
{% for boardStat in stats.boards %}
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -62,6 +70,12 @@
|
||||||
<td class="minimal">
|
<td class="minimal">
|
||||||
<span>{{ boardStat.recent_ips }}</span>
|
<span>{{ boardStat.recent_ips }}</span>
|
||||||
</td>
|
</td>
|
||||||
|
<td class="minimal">
|
||||||
|
<span>{{ board.daily_ips }}</span>
|
||||||
|
</td>
|
||||||
|
<td class="minimal">
|
||||||
|
<span>{{ board.tridaily_ips }}</span>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
|
@ -100,8 +100,14 @@
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$HOUR = 3600;
|
||||||
|
$DAY = $HOUR * 24;
|
||||||
|
$TRIDAY = $DAY * 3;
|
||||||
|
|
||||||
$stats = [];
|
$stats = [];
|
||||||
$unique = [];
|
$unique = [];
|
||||||
|
$daily = [];
|
||||||
|
$tridaily = [];
|
||||||
|
|
||||||
foreach (array_merge(... $config['boards']) as $uri) {
|
foreach (array_merge(... $config['boards']) as $uri) {
|
||||||
$_board = getBoardInfo($uri);
|
$_board = getBoardInfo($uri);
|
||||||
|
@ -112,6 +118,10 @@
|
||||||
|
|
||||||
$boardStat['title'] = $_board['title'];
|
$boardStat['title'] = $_board['title'];
|
||||||
|
|
||||||
|
$boardStat['hourly_ips'] = Categories::countUniqueIps($unique, $HOUR, $_board);
|
||||||
|
$boardStat['daily_ips'] = Categories::countUniqueIps($unique, $DAY, $_board);
|
||||||
|
$boardStat['tridaily_ips'] = Categories::countUniqueIps($unique, $TRIDAY, $_board);
|
||||||
|
|
||||||
$pph_query = query(
|
$pph_query = query(
|
||||||
sprintf("SELECT COUNT(*) AS count FROM ``posts_%s`` WHERE time > %d",
|
sprintf("SELECT COUNT(*) AS count FROM ``posts_%s`` WHERE time > %d",
|
||||||
$_board['uri'],
|
$_board['uri'],
|
||||||
|
@ -120,28 +130,31 @@
|
||||||
|
|
||||||
$boardStat['pph'] = $pph_query->fetch()['count'];
|
$boardStat['pph'] = $pph_query->fetch()['count'];
|
||||||
|
|
||||||
$unique_query = query(
|
|
||||||
sprintf("SELECT DISTINCT ip FROM ``posts_%s`` WHERE time > %d",
|
|
||||||
$_board['uri'],
|
|
||||||
time()-3600)
|
|
||||||
) or error(db_error());
|
|
||||||
|
|
||||||
$unique_ips = $unique_query->fetchAll();
|
|
||||||
$boardStat['recent_ips'] = count($unique_ips);
|
|
||||||
|
|
||||||
foreach ($unique_ips as $_k => $row) {
|
|
||||||
$unique[$row['ip']] = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
$stats['boards'][] = $boardStat;
|
$stats['boards'][] = $boardStat;
|
||||||
}
|
}
|
||||||
|
|
||||||
$stats['recent_ips'] = count($unique);
|
$stats['hourly_ips'] = count($unique);
|
||||||
|
$stats['daily_ips'] = count($unique);
|
||||||
|
$stats['tridaily_ips'] = count($unique);
|
||||||
$stats['pph'] = array_sum(array_column($stats['boards'], 'pph'));
|
$stats['pph'] = array_sum(array_column($stats['boards'], 'pph'));
|
||||||
|
|
||||||
return $stats;
|
return $stats;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static function countUniqueIps($markAsCounted, $timespan, $_board) {
|
||||||
|
$unique_query = query(
|
||||||
|
sprintf("SELECT DISTINCT ip FROM ``posts_%s`` WHERE time > %d",
|
||||||
|
$_board['uri'],
|
||||||
|
time()-$timespan)
|
||||||
|
) or error(db_error());
|
||||||
|
$uniqueIps = $unique_query->fetchAll();
|
||||||
|
foreach ($unique_ips as $_k => $row) {
|
||||||
|
$markAsCounted[$row['ip']] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return count($unique_ips);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue