Go Back   vb.org Archive > Community Discussions > Modification Requests/Questions (Unpaid)
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 08-01-2011, 11:12 PM
LuDawgs LuDawgs is offline
 
Join Date: May 2011
Posts: 89
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Reputation Divided by Post Count Displayed as %

I'm looking for someone who can help me with something. I want to be able to divide my users reputation by their post count, derive a % from it, and display it in each users postbit. I'd like to call it "Tip Ratio". This is necessary for our forum, but I can't quite figure out how to do it. Example to derive the "Tip Ratio":

Reputation: 206
Join Date: Mar 2011
Posts: 1,064
Tip Ratio: 19.4% (where 206/1064)

Anyone interested in taking this on?
Reply With Quote
  #2  
Old 08-02-2011, 02:57 AM
LuDawgs LuDawgs is offline
 
Join Date: May 2011
Posts: 89
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

A great coder took care of me. I appreciate it!
Reply With Quote
  #3  
Old 01-04-2013, 06:14 PM
The Mailman The Mailman is offline
 
Join Date: Dec 2011
Posts: 22
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

someone else want to post how this was done?
Reply With Quote
  #4  
Old 01-04-2013, 10:07 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Maybe something like this: create a plugin using hook location postbit_display_complete and code like:
Code:
if ($post['posts'] > 0)
{
    $post['tip_ratio'] = vb_number_format($post['reputation'] / $post['posts'], 1);
}
else
{
    $post['tip_ratio'] = '--'; // shouldn't ever happen, but protect against divide by 0.
}

Then use {vb:raw post.tip_ratio} in your postbit or postbit_legacy template.
Reply With Quote
Благодарность от:
CAG CheechDogg
  #5  
Old 01-09-2014, 12:09 AM
The Mailman The Mailman is offline
 
Join Date: Dec 2011
Posts: 22
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
Maybe something like this: create a plugin using hook location postbit_display_complete and code like:
Code:
if ($post['posts'] > 0)
{
    $post['tip_ratio'] = vb_number_format($post['reputation'] / $post['posts'], 1);
}
else
{
    $post['tip_ratio'] = '--'; // shouldn't ever happen, but protect against divide by 0.
}

Then use {vb:raw post.tip_ratio} in your postbit or postbit_legacy template.
thanks, but I tried it out and the # it was producing was weird

ie, a user with 109 posts and 7 rep got a "0.1"

how would i get the number to display as "6.4%"?
Reply With Quote
  #6  
Old 01-09-2014, 02:03 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yeah, that happens a lot when I post code I didn't test. I think maybe it needs a "* 100" before the comma in the vb_number_format line (sorry, I would post the code but i'm using my pad and it's too hard to enter all that).
Reply With Quote
  #7  
Old 01-09-2014, 02:32 AM
The Mailman The Mailman is offline
 
Join Date: Dec 2011
Posts: 22
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

nah, that just multiplied the weird number by 100

ie, user with 170 rep and 1,739 posts gets "17,000.0"

rep/posts should be 0.097, or if multiplied by 100 to get that % figure, 9.7%

i tried for testing purposes:
Quote:
$post['tip_ratio'] = vb_number_format($post['posts'], 1);
and the output was going to be just the post count, but instead it was however many thousands of posts, ie. a user with 2,230 posts would get "2", however, a user with less than 1000 posts would get their correct post count

Quote:
$post['tip_ratio'] = vb_number_format($post['reputation'], 1);
on the other hand would display the correct reputation # no matter what, so the issue is just calculating the correct post count variable...
Reply With Quote
  #8  
Old 01-09-2014, 10:57 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Try this:

Code:
if ($post['posts'] > 0)
{
    $post['tip_ratio'] = vb_number_format($post['reputation'] / $post['posts'] * 100, 1);
}
else
{
    $post['tip_ratio'] = '--'; // shouldn't ever happen, but protect against divide by 0.
}
Reply With Quote
  #9  
Old 01-09-2014, 12:42 PM
CAG CheechDogg's Avatar
CAG CheechDogg CAG CheechDogg is offline
 
Join Date: Feb 2012
Location: Riverside, California USA
Posts: 1,080
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

This is the code kh99 gave me to get the Tip Ratio for times thanked divided by their post count and it works perfect.

I figure you just replace post_thanks_thanked_times with reputation here right?

Hope this works, as I was getting the same type of output as you were until kh99 figured it out.

Code:
if ($post['posts'] > 0)
{
    $post['tip_ratio'] = vb_number_format($post['post_thanks_thanked_times'] / $post['posts'], 2);
}
else
{
    $post['tip_ratio'] = '--'; // shouldn't ever happen, but protect against divide by 0.
}
--------------- Added [DATE]1389276057[/DATE] at [TIME]1389276057[/TIME] ---------------

So yes, the code I posted worked for me so it should be working for you too The Mailman ...
Reply With Quote
  #10  
Old 01-09-2014, 01:08 PM
The Mailman The Mailman is offline
 
Join Date: Dec 2011
Posts: 22
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
Try this:

Code:
if ($post['posts'] > 0)
{
    $post['tip_ratio'] = vb_number_format($post['reputation'] / $post['posts'] * 100, 1);
}
else
{
    $post['tip_ratio'] = '--'; // shouldn't ever happen, but protect against divide by 0.
}
I did already. $post['posts'] is still not generating the actual post count, take a look at my above response explaining what's being output
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 02:49 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04448 seconds
  • Memory Usage 2,266KB
  • 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
  • (5)bbcode_code
  • (4)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (1)post_thanks_box_bit
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (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
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete