Gossamer Forum
Home : Products : Links 2.0 : Customization :

How can i take the average of the hits + votes ?

Quote Reply
How can i take the average of the hits + votes ?
hey simply what i want is to take the average of the hits and votes field together for x: if hits is 20 and + votes is 10 = (20+10)/2=15
and i want this average to be able to define as a new field so i can call it anywhere in the templates, or whatever it works out! thx for help!

Quote Reply
Re: How can i take the average of the hits + votes ? In reply to
There has been a couple of mods discussed in this forum that could probably be adapted to do what you need, I'd search the form for "average hits" and you probably run across them.

Scotty
http://trekpages.virtualave.net
Quote Reply
Re: How can i take the average of the hits + votes ? In reply to
hey scottytc, i search as told by u, but only found out how to take the daily average of hits, but not the average of hits and votes as i stated! hope elliot would help soon!

Quote Reply
Re: How can i take the average of the hits + votes ? In reply to
Elliot, plz help!

Quote Reply
Re: How can i take the average of the hits + votes ? In reply to
You do not need to create a new field for this (it also saves disk space...). Instead, it can be created dynamicly.
For example, in sub site_html_link, after:
Code:
%rec = @_;
add this:
Code:
$rec{'Average'} = int(($rec{'Hits'} + $rec{'Votes'})/2);
If you want decimal places, do a search for sprintf in the Perl/CGI forum.

Happy Coding,

--Drew
http://www.FindingHim.com
Quote Reply
Re: How can i take the average of the hits + votes ? In reply to
hey junko, thx for ur previous reply, i greatly appreciate it, another question, what if i want to multiply for example 20 to hits and votes before taking the average (('hits' * 20) + ('votes' * 20))/2
what's the correct code?
and also what if i want to average + another variable
(('hits' * 20) + ('votes' * 20) + ('undefined' * 20))/3

Quote Reply
Re: How can i take the average of the hits + votes ? In reply to
In Reply To:
what if i want to multiply for example 20 to hits and votes before taking the average (('hits' * 20) + ('votes' * 20))/2
Code:
int((20($rec{'Hits'} + $rec{'Votes'}))/2)
In Reply To:
and also what if i want to average + another variable
(('hits' * 20) + ('votes' * 20) + ('undefined' * 20))/3
Same thing...
Code:
int((20($rec{'Hits'} + $rec{'Votes'} + $rec{'Third_Value'}))/3)
It's the same thing you did in your high school Algrebra class only using Perl variables (ie. a = 20(b + c + d) / 3).

Happy Coding,

--Drew
http://www.FindingHim.com
Quote Reply
Re: How can i take the average of the hits + votes ? In reply to
thx, and also what if i want: (('hits' * 20) + ('votes' * 30) + ('undefined' * 50))/3

Quote Reply
Re: How can i take the average of the hits + votes ? In reply to
Hey I didn't say that one was already written, just that there was some that could be modified for you to use.

Scotty
http://trekpages.virtualave.net
Quote Reply
Re: How can i take the average of the hits + votes ? In reply to
hey scottytc, i appreciated ur help anyway, nice to see active helpers around this forum!

Quote Reply
Re: How can i take the average of the hits + votes ? In reply to
hey junko, can u take a sec off and reply to my last question!

Quote Reply
Re: How can i take the average of the hits + votes ? In reply to
hi junko;
hmmmm...today i managed to try what u posted in earlier msgs to find the average of the three variables, but however resulted in compilation errors!

Quote Reply
Re: How can i take the average of the hits + votes ? In reply to
i found out that problem, but howver i still want to know the equation in perl for this (('hits' * 20) + ('votes' * 30) + ('undefined' * 50))/3
plz help!