# Application Design Question

**URL:** <https://www.ruby-forum.com/t/application-design-question/60688>\
**Category:** Rails\
**Created:** [January 10, 2006, 4:48am UTC](https://www.ruby-forum.com/t/application-design-question/60688 "2006-01-10T04:48:30Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![bplummer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/6de8d8/32.png) [@bplummer](https://www.ruby-forum.com/u/bplummer)\
**Post date:** [January 10, 2006, 4:48am UTC](https://www.ruby-forum.com/t/application-design-question/60688/1 "2006-01-10T04:48:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bplummer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/6de8d8/32.png) [@bplummer](https://www.ruby-forum.com/u/bplummer)\
**Post date:** [January 10, 2006, 6:21am UTC](https://www.ruby-forum.com/t/application-design-question/60688/2 "2006-01-10T06:21:57Z")

</div>

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

- Universal Troubleshooting Process courseware
- Troubleshooting Techniques of the Successful Technologist
- Rapid Learning: Secret Weapon of the Successful Technologist  
Webmaster
- [Troubleshooters.Com](http://Troubleshooters.Com)
- [http://www.troubleshooters.com](http://www.troubleshooters.com)

---

<div class="post-metadata">

**Author:** ![bplummer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/6de8d8/32.png) [@bplummer](https://www.ruby-forum.com/u/bplummer)\
**Post date:** [January 10, 2006, 6:34am UTC](https://www.ruby-forum.com/t/application-design-question/60688/3 "2006-01-10T06:34:08Z")

</div>

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:

> > 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](http://www.troubleshooters.com)
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

- Bill

---

<div class="post-metadata">

**Author:** ![bplummer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/6de8d8/32.png) [@bplummer](https://www.ruby-forum.com/u/bplummer)\
**Post date:** [January 10, 2006, 7:17am UTC](https://www.ruby-forum.com/t/application-design-question/60688/4 "2006-01-10T07:17:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bplummer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/6de8d8/32.png) [@bplummer](https://www.ruby-forum.com/u/bplummer)\
**Post date:** [January 10, 2006, 6:37am UTC](https://www.ruby-forum.com/t/application-design-question/60688/5 "2006-01-10T06:37:20Z")

</div>

Bill P. wrote:

> the easiest but if I change the scoring recalculating the scores is a  
> bit troublesome.
> 
> 1. 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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
University of Chicago - NSIT Web Services  
AIM: farmerje  
Jabber: removed\_email\_address@domain.invalid  
Phone: (773)363-1058

---

<div class="post-metadata">

**Author:** ![bplummer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/6de8d8/32.png) [@bplummer](https://www.ruby-forum.com/u/bplummer)\
**Post date:** [January 10, 2006, 1:55pm UTC](https://www.ruby-forum.com/t/application-design-question/60688/6 "2006-01-10T13:55:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![bplummer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/6de8d8/32.png) [@bplummer](https://www.ruby-forum.com/u/bplummer)\
**Post date:** [January 10, 2006, 3:39pm UTC](https://www.ruby-forum.com/t/application-design-question/60688/7 "2006-01-10T15:39:30Z")

</div>

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

> > > 1. Calculate when the fish is entered into the system. This seems  
> > > select multiplier\*length as score from entries order by score  
> > > removed\_email\_address@domain.invalid  
> > > [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)
> 
> - Bill
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–  
Steve L.  
Author:

- Universal Troubleshooting Process courseware
- Troubleshooting Techniques of the Successful Technologist
- Rapid Learning: Secret Weapon of the Successful Technologist  
Webmaster
- [Troubleshooters.Com](http://Troubleshooters.Com)
- [http://www.troubleshooters.com](http://www.troubleshooters.com)

(Legal Disclaimer) Follow these suggestions at your own risk.

---

<div class="post-metadata">

**Author:** ![bplummer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/6de8d8/32.png) [@bplummer](https://www.ruby-forum.com/u/bplummer)\
**Post date:** [January 10, 2006, 7:38am UTC](https://www.ruby-forum.com/t/application-design-question/60688/8 "2006-01-10T07:38:18Z")

</div>

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 P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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](http://www.troubleshooters.com)
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–

- Nic
