Forum: Ruby on Rails Application Design Question

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C204883ecbdf04c9a5bc9b024f5ed575?d=identicon&s=25 Bill Pennington (Guest)
on 2006-01-10 04:48
(Received via mailing list)
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:

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

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


- Bill
C9af522fc39d5de90f21119543c2b9ab?d=identicon&s=25 Steve Litt (Guest)
on 2006-01-10 06:21
(Received via mailing list)
On Monday 09 January 2006 10:46 pm, Bill Pennington wrote:
> like the easiest but if I change the scoring recalculating the scores
> is a bit troublesome.
>
> 2. 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 Litt
Author:
   * Universal Troubleshooting Process courseware
   * Troubleshooting Techniques of the Successful Technologist
   * Rapid Learning: Secret Weapon of the Successful Technologist
Webmaster
   * Troubleshooters.Com
   * http://www.troubleshooters.com
C204883ecbdf04c9a5bc9b024f5ed575?d=identicon&s=25 Bill Pennington (Guest)
on 2006-01-10 06:34
(Received via mailing list)
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 Litt wrote:

>> 1. Calculate when the fish is entered into the system. This seems
> #1. Also,
> based on the latest equation, and run it at midnight :-)
>    * http://www.troubleshooters.com
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>



- Bill
F7a2f59c93fae91cb2c9a44060b34a13?d=identicon&s=25 Jesse Farmer (vann)
on 2006-01-10 06:37
(Received via mailing list)
Bill Pennington wrote:
> the easiest but if I change the scoring recalculating the scores  is a
> bit troublesome.
>
> 2. 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 Farmer <farmerje@uchicago.edu>
University of Chicago - NSIT Web Services
AIM:    farmerje
Jabber: farmerje@im.uchicago.edu
Phone:  (773)363-1058
C204883ecbdf04c9a5bc9b024f5ed575?d=identicon&s=25 Bill Pennington (Guest)
on 2006-01-10 07:17
(Received via mailing list)
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 Farmer wrote:

>> scores  is a bit troublesome.
> to get a "Top 10" list.
>
- Bill
B0e227ae419295321ca2aff4c27ad99d?d=identicon&s=25 Nic Werner (Guest)
on 2006-01-10 07:38
(Received via mailing list)
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

- Nic


On 1/9/06, Bill Pennington <bill@norcalkayakanglers.com> wrote:
>
> >> 1. Calculate when the fish is entered into the system. This seems
> > #1. Also,
> > based on the latest equation, and run it at midnight :-)
> >    * http://www.troubleshooters.com
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>


--
- Nic
4d202d20a766a00eab9ab42825eba9ba?d=identicon&s=25 Joe Manfoo (joemanfoo)
on 2006-01-10 13:55
(Received via mailing list)
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.
C9af522fc39d5de90f21119543c2b9ab?d=identicon&s=25 Steve Litt (Guest)
on 2006-01-10 15:39
(Received via mailing list)
On Tuesday 10 January 2006 01:16 am, Bill Pennington 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


> >> 1. Calculate when the fish is entered into the system. This seems
> >   select multiplier*length as score from entries order by score
> > Rails@lists.rubyonrails.org
> > http://lists.rubyonrails.org/mailman/listinfo/rails
>
> - Bill
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails

--
Steve Litt
Author:
   * Universal Troubleshooting Process courseware
   * Troubleshooting Techniques of the Successful Technologist
   * Rapid Learning: Secret Weapon of the Successful Technologist
Webmaster
   * Troubleshooters.Com
   * http://www.troubleshooters.com

(Legal Disclaimer) Follow these suggestions at your own risk.
This topic is locked and can not be replied to.