From 9137949dbfcc2859346b414b22cc77150c002045 Mon Sep 17 00:00:00 2001 From: nonmakina Date: Sun, 21 Feb 2021 19:32:11 -0600 Subject: [PATCH] test rolling average' --- templates/themes/categories/news.html | 4 ++++ templates/themes/categories/theme.php | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/templates/themes/categories/news.html b/templates/themes/categories/news.html index 4aadc633..1f0fe933 100644 --- a/templates/themes/categories/news.html +++ b/templates/themes/categories/news.html @@ -39,6 +39,7 @@ {% trans "IPs last hour" %} {% trans "IPs last day" %} {% trans "IPs last week" %} + {% trans "7 day PPH moving average" %} @@ -76,6 +77,9 @@ {{ boardStat.weekly_ips }} + + {{ boardStat.rolling_average }} + {% endfor %} diff --git a/templates/themes/categories/theme.php b/templates/themes/categories/theme.php index 65c1c721..0b94840b 100644 --- a/templates/themes/categories/theme.php +++ b/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']; + } };