Browse Source

test rolling average'

pull/40/head
nonmakina 3 years ago
parent
commit
9137949dbf
  1. 4
      templates/themes/categories/news.html
  2. 14
      templates/themes/categories/theme.php

4
templates/themes/categories/news.html

@ -39,6 +39,7 @@
<th>{% trans "IPs last hour" %}</th>
<th>{% trans "IPs last day" %}</th>
<th>{% trans "IPs last week" %}</th>
<th>{% trans "7 day PPH moving average" %}</th>
</tr>
</thead>
<tbody>
@ -76,6 +77,9 @@
<td class="minimal">
<span>{{ boardStat.weekly_ips }}</span>
</td>
<td class="minimal">
<span>{{ boardStat.rolling_average }}</span>
</td>
</tr>
{% endfor %}
</tbody>

14
templates/themes/categories/theme.php

@ -121,6 +121,7 @@
$boardStat['hourly_ips'] = Categories::countUniqueIps($hourly, $HOUR, $_board);
$boardStat['daily_ips'] = Categories::countUniqueIps($daily, $DAY, $_board);
$boardStat['weekly_ips'] = Categories::countUniqueIps($weekly, $WEEK, $_board);
$boardStat['rolling_average'] = Categories::rollingAveragePPH($WEEK, $_board);
$pph_query = query(
sprintf("SELECT COUNT(*) AS count FROM ``posts_%s`` WHERE time > %d",
@ -155,6 +156,19 @@
return count($uniqueIps);
}
private static function rollingAveragePPH($timespan, $_board) {
$pph_query = query(
sprintf("SELECT AVG(count) as rolling FROM (
SELECT HOUR(FROM_UNIXTIME(time)) AS hour, DAYOFYEAR(FROM_UNIXTIME(time)) AS day, COUNT(*) AS count
FROM ``posts_%s``
WHERE time > %d
GROUP BY hour, day",
$_board['uri'],
time()-$timespan)
) or error(db_error());
return $pph_query->fetch()['rolling'];
}
};

Loading…
Cancel
Save