Helpful Information
 
 
Category: vBulletin.org Forum
[SMALL RELEASE] Average Posts / Day

i am sorry if this was released before i thought maybe some non-php programmers might need it :)

#####open member.php

##find:
$userinfo=$DB_site->query_first("SELECT username,joindate,lastpost,usertitle,email,showemail,invisible,homepage,icq,aim, yahoo,biography,posts FROM user WHERE userid=$userid");

##add below:
$postinfo=$DB_site->query_first("select count(postid) as total_posts, sum(LENGTH(pagetext)) as total_chars from post where userid='$userid'");

$user_join_timestamp = date("U",$userinfo[joindate]);
$system_timestamp = date("U");
$ts_difference = round(($system_timestamp - $user_join_timestamp ) / 86400);
$average_posts = round($userinfo[posts] / $ts_difference ,2);
$average_chars_per_post = round($postinfo[total_chars] / $postinfo[total_posts]);

####open your getinfo template

##find:
$totalposts

##add next to it:
(An average of $average_posts posts per day with an averge of average_chars_per_post per post)


[EDIT]:
with this code it will also show average count of letters / post!!!!!

Looks pretty cool.

You said the code is crappy though...will it cause any unnecessary load time due to bad queries?

Is it optimized?

nono, no extra queries it just uses the variables it gets from the usual UserInfo queries anyway.
all it is, is some calculating, and it's optimized to my best knowledge :)

and i said it's crappy because it's really simple ;)

just updated the code above to one more feature ;)

fix
An average of $average_posts posts per day with an average of $average_chars_per_post per post

I'm also getting an error on line
$average_posts = round($userinfo[posts] / $duh,2);

Wrong parameter count for round()

ver. 1.1.3


And here's my formatting (no reason, just posting :))

total posts<br>
Average of $average_posts posts per day<br>
Average of $average_chars_per_post characters per post

Where do you get $duh?

woops i am sorry i had two different formats of the code, and i rewrote it with nicer variable names and forgot to change that one

now it should work ;)

Still getting an error for
$average_posts = round($userinfo[posts] / $ts_difference ,2);

Warning: Wrong parameter count for round() in member.php3 on line 623

BlackJack i guess you're using php3 right ? unfortunately php3 doesnt support the precision in the round command
just replace the line with
$average_posts = round($userinfo[posts] / $ts_difference);
then, delete the ",2"

That did it. Thanks.

Another thing :) I get an error at the top of a page if the person hasn't made posts, and an instance with 1 post,

Warning: Division by zero in /www/thzclan/forums/member.php3 on line 624

0 posts - http://www.thzclan.com/forums/member.php3?action=getinfo&userid=41

and heres one with 1 post - http://www.thzclan.com/forums/member.php3?action=getinfo&userid=44

Not everybody with 1 post has the error.

I can live with this, but if there is a fix I'd apprieciate it, thanks.

PHP3

yEAh A FIX IS NEEDed please finish your hack:)
thanks

Just check before if the posts are less then 2, then the values are "N/A', else the values are what they are :P

That's how i've done it

Ummmm
I'm not sure what you mean, please explain...:p
thanks

Just use something like

$userjointimestamp=date("U",$userinfo[joindate]);
$systemtimestamp=date("U");
$tsdifference=round(($systemtimestamp-$userjointimestamp)/86400);
$tsdifference=$tsdifference+1;
if ($userinfo[posts]>=2) {
$averageposts=round($userinfo[posts]/$tsdifference,2);
$averagecharsperpost=round($postinfo[totalchars]/$postinfo[totalposts]);
} else {
$averageposts="NVT";
$averagecharsperpost="NVT";
}


The only way when you NOW can get an division by zero error, is when the user's posts are deleted, but his postnumber isn't, so it still reads like 22 posts even if he hasn't got any..

But otherwise, it works fine.. for me though :)

How would you do this for vBB2. Can somebody make it or remodel it quickly. It would be really useful.


Thx

Originally posted by mrlister
How would you do this for vBB2. Can somebody make it or remodel it quickly. It would be really useful.


Thx

it is already in vb2. Click on user profile and have a look.

oh ok. thx it's just that in the member.php thing it said something about mail so i got confused










privacy (GDPR)