UBB.Dev
Posted By: Carte Blanche [7.3] Average Daily Post count - 05/31/2008 2:06 PM
From the posts in the last 24 hours topic, here , someone asked about having an average daily post count...so I quickly whipped this up. It needs a small bit of polish to remove the decimals...but, here we go.

In /cache_builders/forum_stats.php
Find:
Code

$smarty->assign("maxonline",$maxonline);

add before:

Code

$days = 30;

$today = $html -> get_date();
$limittime = ($today - ($days * 86400));


$query = "
SELECT count(POST_ID)
FROM {$config['TABLE_PREFIX']}POSTS
WHERE POST_POSTED_TIME > $limittime
";

$sth = $dbh->do_query($query);
list($total_posts) = $dbh->fetch_array( $sth );
$avg_posts = ($total_posts / $days);

$smarty->assign("avgposts", $avg_posts);

You may set the time period to be whatever number of days you're wishing to average over. Also, if someone could give me the better division method to remove decimals, that'd be great. Anyway, on to the rest...

In /languages/english/portal_islands.php
Find:
Code

$ubbt_lang['TOP_POSTERS'] = "Top Posters";

Add after:
Code

$ubbt_lang['AVG_POSTS'] = " is the daily post average";


Or however you'd like to phrase that.

In /templates/default/island_forum_stats.tpl
Find:
Code

<b>{$posts}</b> <?php echo $ubbt_lang['POSTS'] ?>

Add after:
Code

<b>{$avgposts}</b> <?php echo $ubbt_lang['AVG_POSTS'] ?>

Hmm...I may have a quick update to this after I check out some thoughts on how best to use mod...I'm thinking maybe I should check to see if the mod is greater than 0, and if it is, then subtract the mod value from the total posts value, THEN divide it by the days so that I always end up with integer value....will post the revised code if that works.

Yes, that works, so use the code I have above for forum_stats if you want decimal values. If you don't want decimal values, and just want whole integer values....

In /cache_builders/forum_stats.php
Find:
Code

$smarty->assign("maxonline",$maxonline);

add before:

Code

$days = 30;

$today = $html -> get_date();
$limittime = ($today - ($days * 86400));


$query = "
SELECT count(POST_ID)
FROM {$config['TABLE_PREFIX']}POSTS
WHERE POST_POSTED_TIME > $limittime
";

$sth = $dbh->do_query($query);
list($total_posts) = $dbh->fetch_array( $sth );
$avg_posts_mod = ($total_posts % $days);
$total_posts = ($total_posts - $avg_posts_mod);
$avg_posts = ($total_posts / $days);

$smarty->assign("avgposts", $avg_posts);
Posted By: AllenAyres Re: [7.3] Average Daily Post count - 05/31/2008 6:35 PM
Very nice Carte Blanche - thank you for sharing thumbsup
Posted By: willing Re: [7.3] Average Daily Post count - 06/02/2008 6:09 AM
Thank you so much!

smile
© UBB.Developers