vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   Modification Requests/Questions (Unpaid) (https://vborg.vbsupport.ru/forumdisplay.php?f=112)
-   -   Reputation Divided by Post Count Displayed as % (https://vborg.vbsupport.ru/showthread.php?t=267801)

LuDawgs 08-01-2011 10:12 PM

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?

LuDawgs 08-02-2011 01:57 AM

A great coder took care of me. I appreciate it!

The Mailman 01-04-2013 05:14 PM

someone else want to post how this was done?

kh99 01-04-2013 09:07 PM

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.

The Mailman 01-08-2014 11:09 PM

Quote:

Originally Posted by kh99 (Post 2394780)
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%"?

kh99 01-09-2014 01:03 AM

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).

The Mailman 01-09-2014 01:32 AM

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...

kh99 01-09-2014 09:57 AM

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.
}


CAG CheechDogg 01-09-2014 11:42 AM

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 ...

The Mailman 01-09-2014 12:08 PM

Quote:

Originally Posted by kh99 (Post 2473224)
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 :confused:


All times are GMT. The time now is 03:10 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.02950 seconds
  • Memory Usage 1,737KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (5)bbcode_code_printable
  • (4)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete