1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-11-30 18:24:29 +01:00

(Hopefully) fixed last hour counts.

Also added extensive comments and adjusted logical branches.

Signed-off-by: 8n-tech <8n-tech@users.noreply.github.com>
This commit is contained in:
8n-tech 2015-04-21 12:00:29 +10:00
parent 97ae37651f
commit 5ea7541817
2 changed files with 29 additions and 5 deletions

View File

@ -181,7 +181,7 @@ foreach ($response['boards'] as $boardUri => &$board) {
} }
$board['pph_average'] = round( $boardActivity['average'][ $boardUri ], $precision ); $board['pph_average'] = round( $boardActivity['average'][ $boardUri ], $precision );
$board['pph'] = round( $boardActivity['average'][ $boardUri ], 0 ); $board['pph'] = (int) $boardActivity['last'][ $boardUri ];
$board['ppd'] = round( $boardActivity['today'][ $boardUri ], $precision ); $board['ppd'] = round( $boardActivity['today'][ $boardUri ], $precision );
unset( $precision ); unset( $precision );

View File

@ -894,35 +894,59 @@ function fetchBoardActivity( array $uris = array(), $forTime = false, $detailed
// Format the results. // Format the results.
foreach ($bsResult as $bsRow) { foreach ($bsResult as $bsRow) {
if ($bsRow['stat_hour'] == $forHour) {
$boardActivity['last'][$bsRow['stat_uri']] = $bsRow['post_count'];
}
// Do we need to define the arrays for this URI? // Do we need to define the arrays for this URI?
if (!isset($boardActivity['active'][$bsRow['stat_uri']])) { if (!isset($boardActivity['active'][$bsRow['stat_uri']])) {
// We are operating under the assumption that no arrays exist.
// Because of that, we are flat defining their values.
// Set the last hour count to 0 in case this isn't the row from this hour.
$boardActivity['last'][$bsRow['stat_uri']] = 0;
// If this post was made in the last 24 hours, define 'today' with it.
if ($bsRow['stat_hour'] <= $forHour && $bsRow['stat_hour'] >= $yesterHour) { if ($bsRow['stat_hour'] <= $forHour && $bsRow['stat_hour'] >= $yesterHour) {
$boardActivity['today'][$bsRow['stat_uri']] = $bsRow['post_count']; $boardActivity['today'][$bsRow['stat_uri']] = $bsRow['post_count'];
// If this post was made the last hour, redefine 'last' with it.
if ($bsRow['stat_hour'] == $forHour) {
$boardActivity['last'][$bsRow['stat_uri']] = $bsRow['post_count'];
}
} }
else { else {
// First record was not made today, define as zero.
$boardActivity['today'][$bsRow['stat_uri']] = 0; $boardActivity['today'][$bsRow['stat_uri']] = 0;
} }
// Set the active posters as the unserialized array.
$boardActivity['active'][$bsRow['stat_uri']] = unserialize( $bsRow['author_ip_array'] ); $boardActivity['active'][$bsRow['stat_uri']] = unserialize( $bsRow['author_ip_array'] );
// Start the average PPH off at the current post count.
$boardActivity['average'][$bsRow['stat_uri']] = $bsRow['post_count']; $boardActivity['average'][$bsRow['stat_uri']] = $bsRow['post_count'];
} }
else { else {
// These arrays ARE defined so we ARE going to assume they exist and compound their values.
// If this row came from today, add its post count to 'today'.
if ($bsRow['stat_hour'] <= $forHour && $bsRow['stat_hour'] >= $yesterHour) { if ($bsRow['stat_hour'] <= $forHour && $bsRow['stat_hour'] >= $yesterHour) {
$boardActivity['today'][$bsRow['stat_uri']] += $bsRow['post_count']; $boardActivity['today'][$bsRow['stat_uri']] += $bsRow['post_count'];
// If this post came from this hour, set it to the post count.
// This is an explicit set because we should never get two rows from the same hour.
if ($bsRow['stat_hour'] == $forHour) {
$boardActivity['last'][$bsRow['stat_uri']] = $bsRow['post_count'];
}
} }
// Merge our active poster arrays. Unique counting is done below.
$boardActivity['active'][$bsRow['stat_uri']] = array_merge( $boardActivity['active'][$bsRow['stat_uri']], unserialize( $bsRow['author_ip_array'] ) ); $boardActivity['active'][$bsRow['stat_uri']] = array_merge( $boardActivity['active'][$bsRow['stat_uri']], unserialize( $bsRow['author_ip_array'] ) );
// Add our post count to the average. Averaging is done below.
$boardActivity['average'][$bsRow['stat_uri']] += $bsRow['post_count']; $boardActivity['average'][$bsRow['stat_uri']] += $bsRow['post_count'];
} }
} }
// Count the unique posters for each board.
foreach ($boardActivity['active'] as &$activity) { foreach ($boardActivity['active'] as &$activity) {
$activity = count( array_unique( $activity ) ); $activity = count( array_unique( $activity ) );
} }
// Average the number of posts made for each board.
foreach ($boardActivity['average'] as &$activity) { foreach ($boardActivity['average'] as &$activity) {
$activity /= 72; $activity /= 72;
} }