I am designing an application to run a fishing tournament I am
hosting. Each fish entered will be given a point total based on the
length of the fish and the species of fish. Each species has a point
multiplier. For Example Trout have a multiplier of 10 so a 20 inch
Trout would have a score of 200.
My conundrum is in where and when do I calculate the points. The
options I have come up with so far:
-
Calculate when the fish is entered into the system. This seems
like the easiest but if I change the scoring recalculating the scores
is a bit troublesome.
-
Calculate when displayed. Seems rather intensive CPU wise and
makes doing “Top 10” list rather troublesome.
I am leaning towards option 1 but I wanted to ping the community to
see if anyone has any brilliant ideas.
TIA
On Monday 09 January 2006 10:46 pm, Bill P. wrote:
like the easiest but if I change the scoring recalculating the scores
is a bit troublesome.
- Calculate when displayed. Seems rather intensive CPU wise and
makes doing “Top 10” list rather troublesome.
I am leaning towards option 1 but I wanted to ping the community to
see if anyone has any brilliant ideas.
I vote for #2 for the exact reason you stated as a disadvantage of #1.
Also,
#2 better complys with DRY, because you don’t have that extra column
hanging
around.
That being said, if there are thousands of fish, and the web page is
being hit
alot, I vote for #1 for speed considerations (which is the rationale for
most
DRY violations). You could always make a procedure to update the point
field
based on the latest equation, and run it at midnight
SteveT
Steve L.
Author:
Thanks Steve, for my “Top Ten” problem aka creating a sorted list
would you suggest I do that in SQL space? I also need to do a leader
board where each users points are totaled then the users are sorted.
I am leaning towards #1 since I hopefully won’t be changing the
points system and if I do a one time update should be fine.
Thanks!
On Jan 9, 2006, at 9:22 PM, Steve L. wrote:
- Calculate when the fish is entered into the system. This seems
#1. Also,
based on the latest equation, and run it at midnight
Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails
Thanks Jesse that works great but doesn’t feel very DRY but I am
probably just clueless about how to make it DRY
On Jan 9, 2006, at 9:34 PM, Jesse F. wrote:
scores is a bit troublesome.
to get a “Top 10” list.
Bill P. wrote:
the easiest but if I change the scoring recalculating the scores is a
bit troublesome.
- Calculate when displayed. Seems rather intensive CPU wise and makes
doing “Top 10” list rather troublesome.
I am leaning towards option 1 but I wanted to ping the community to see
if anyone has any brilliant ideas.
TIA
You don’t need to do either. For example, your SQL query could look
like
select multiplier*length as score from entries order by score desc
limit 10
to get a “Top 10” list.
Jesse F. [email protected]
University of Chicago - NSIT Web Services
AIM: farmerje
Jabber: [email protected]
Phone: (773)363-1058
I’d do option 2.
If in the future you are running a new tournament with new rules, then
it’s
easy to pull up the “classic” fish of yesteryear and calculate what
their
scores would be easily…so something of the lines of pulling up Jebb’s
winners 10 years running would be a snap.
I’d also do this in SQL space. I’d likely have a table or something
VERY
handy in my Ruby script to hold my score multipliers for each fish (I’d
very
much likely have this in a table of fishes or something more
normalized).
I’d cache my results.
I’d have a beer and gloat.
Hope this helps in the decision process.
On Tuesday 10 January 2006 01:16 am, Bill P. wrote:
Thanks Jesse that works great but doesn’t feel very DRY but I am
probably just clueless about how to make it DRY
Hi Bill,
I think Jesse’s solution is as DRY as it gets. He’s calculating on the
fly, so
he’s not storing an extra column. I hadn’t read your post carefully, so
I
wasn’t aware that you’re only displaying 10 rows. I can’t imagine the 10
rows
would slow a web browser.
Jesse has a great solution. He’s shifting the calculation from your
controller
to the DBMS itself. I’d imagine the DBMS is optimized to do that.
I don’t know if there’s a Railsish way to do Jesse’s solution, but you
can
always use the find_by_sql method.
SteveT
- Calculate when the fish is entered into the system. This seems
select multiplier*length as score from entries order by score
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails
Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails
–
Steve L.
Author:
(Legal Disclaimer) Follow these suggestions at your own risk.
I vote for #2, but honestly, whether you do it in SQL or generate it
from Rails, is it really going to be that bad? We’re talking
multiplication of a few small numbers, not rotating 3D objects in
real-time.
Bill, you’re going to get a lot better at this as you go, and later on
you’ll have the framework and knowledge to test it yourself. I know
you want to do the right thing initially, but part of this is
experimentation
On 1/9/06, Bill P. [email protected] wrote:
- Calculate when the fish is entered into the system. This seems
#1. Also,
based on the latest equation, and run it at midnight
Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails
–