Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 03-25-2004, 08:38 PM
MooMan65's Avatar
MooMan65 MooMan65 is offline
 
Join Date: Mar 2002
Location: New Zealand
Posts: 35
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Small Calculation Glitch

Hey everyone. I ported over the calculation that was used often in vB2 to calculate Active/NonActive members and the Activity %, and I remember having problems with it before with the percentage displaying a massive negative number after months of working properly before. I just simply removed the hack and forgot about the glitch, but now that I'm using it again I've decided to ask here on advice to how to fix it.

Basically when the member count goes above 1000 the calculation screws up:

Quote:
Total Registered Members: 1,000 (Active: -377, Inactive: 378) | Activity Rate: -37700.00 %
When before that it was working correctly.

Here is my PHP Code for the calculation of the stat:

PHP Code:
// calculate active and non active members from member stats
$snonposters=$DB_site->query_first('SELECT COUNT(*) AS users,MAX(userid) AS max FROM user WHERE posts=0');
$nonposters=$snonposters['users'];
$activemembers=$numbermembers-$nonposters;
$activityrate=sprintf("%.2f",(100*$activemembers/$numbermembers)); 
Any help would be greatly appreciated! Thanks!
Reply With Quote
  #2  
Old 03-27-2004, 04:51 AM
MooMan65's Avatar
MooMan65 MooMan65 is offline
 
Join Date: Mar 2002
Location: New Zealand
Posts: 35
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Anyone? The stat is looking very weird currently.
Reply With Quote
  #3  
Old 03-29-2004, 01:58 AM
MooMan65's Avatar
MooMan65 MooMan65 is offline
 
Join Date: Mar 2002
Location: New Zealand
Posts: 35
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Please? I'm lost here.
Reply With Quote
  #4  
Old 03-29-2004, 02:01 AM
Boofo's Avatar
Boofo Boofo is offline
 
Join Date: Mar 2002
Location: Des Moines, IA (USA)
Posts: 15,776
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Try this for the percentage:

PHP Code:
    if(activityrate 100)
    {
        
activityrate vb_number_format(($activemembers $numbermembers) * 100 1000) . '%';
    }
    else
    {
        
activityrate vb_number_format(($activemembers $numbermembers) * 1002) . '%';
    } 
Reply With Quote
  #5  
Old 03-30-2004, 07:56 AM
MooMan65's Avatar
MooMan65 MooMan65 is offline
 
Join Date: Mar 2002
Location: New Zealand
Posts: 35
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Boofo
Try this for the percentage:

PHP Code:
    if(activityrate 100)
    {
        
activityrate vb_number_format(($activemembers $numbermembers) * 100 1000) . '%';
    }
    else
    {
        
activityrate vb_number_format(($activemembers $numbermembers) * 1002) . '%';
    } 
Hmm. That gave the percentage a thousand comma (-37,700%) but didn't seem to solve anything.

The thing is I doubt the problem is in the percentage calculation. As you can see the Active Members number is screwed up, while the Inactive one isn't. Since the Active members calculation is TotalMembers - InactiveMembers it could be related to the Total Member variable.

Thing is though if I put $numbermembers ONLY it works right (displays 1000) while if I just put $nonposters it also works right (displays 378). BUT when you put them together in a calculation it treats the $numbermembers variable is only being 1. Not 1000. So 1-378 is -377 which is weird.

I've tried other random calculations and all the time it treats that variable as 1 and not 1000, but if I stick it there on it's own it displays 1000. This is just so totally random.

Anything else? Since $numbermembers is a normal variable on the forums, not one added by the hack it makes things worse... :-\
Reply With Quote
  #6  
Old 03-30-2004, 11:22 AM
Boofo's Avatar
Boofo Boofo is offline
 
Join Date: Mar 2002
Location: Des Moines, IA (USA)
Posts: 15,776
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Try doing the calculation with the following. This is what I use on my site.

HTML Code:
vb_number_format(($numbermembers / $newuserid) * 100, 2 );
Reply With Quote
  #7  
Old 04-01-2004, 03:38 AM
MooMan65's Avatar
MooMan65 MooMan65 is offline
 
Join Date: Mar 2002
Location: New Zealand
Posts: 35
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Boofo
Try doing the calculation with the following. This is what I use on my site.

HTML Code:
vb_number_format(($numbermembers / $newuserid) * 100, 2 );
Erm. That gives me a percentage of 0.09%.

PHP Code:
$activityrate=vb_number_format(($numbermembers $newuserid) * 100); 
And adjusting the variables to suit the hack ($activemembers / $numbermembers) gives me another weird number:

Quote:
Total Registered Members: 1,062 (Active: 663, Inactive: 399) | Activity Rate: 66,300.00 %
Unless you were meaning something else in that post.
Reply With Quote
  #8  
Old 04-01-2004, 04:17 AM
Boofo's Avatar
Boofo Boofo is offline
 
Join Date: Mar 2002
Location: Des Moines, IA (USA)
Posts: 15,776
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

How many members do you have? And what is the newest member's userid?

Here is the code I use in my forumhome stats hack on myy site and it works like it is supposed to:

PHP Code:
$statscache['activepercent'] = vb_number_format(($numbermembers $newuserid) * 100); 
Here are the rsults of that code:

Quote:
Total Registrations: 51, Active Registrations: (47 Members = 92.16%)
Reply With Quote
  #9  
Old 04-01-2004, 06:09 AM
MooMan65's Avatar
MooMan65 MooMan65 is offline
 
Join Date: Mar 2002
Location: New Zealand
Posts: 35
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Boofo
How many members do you have? And what is the newest member's userid?

Here is the code I use in my forumhome stats hack on myy site and it works like it is supposed to:

PHP Code:
$statscache['activepercent'] = vb_number_format(($numbermembers $newuserid) * 100); 
Here are the rsults of that code:
Currently it's at 1062 members as the problem began when the members went above 1000. That normal code I posted in my first post worked fine up until 1000 members which just strikes me as strange.

The latest UserID is 1064, which just means that we've deleted 2 members since the beginning. To 1062/1064 I'm surprised gives you the correct answer.

Our users are only active if they've posted at least once. To the first line Queries the database getting the number of users with 0 posts. The second line assigns that number to $nonposters. Third line calculates the Active members by subtracting the Non Posters from the Total Members, then finally the last line calculates the Active User Percentage by dividing the Active Users into the Total Member Count. That makes sense, and it's worked, but when it reached 1000 members it screws up. As though it overflows the variable or something. I'm not sure.

But one thing I have done that's worked is sticking in the Member count manually into the calculations. Like instead of $numbermembers I put 1062 and it works fine, but the variable doesn't.
Reply With Quote
  #10  
Old 04-01-2004, 06:20 AM
Boofo's Avatar
Boofo Boofo is offline
 
Join Date: Mar 2002
Location: Des Moines, IA (USA)
Posts: 15,776
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Try using my calculation code all by itself, without your other code above it, and tell me if it is right then.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:51 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.02389 seconds
  • Memory Usage 2,278KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_html
  • (6)bbcode_php
  • (6)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete