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
On Monday 09 January 2006 10:46 pm, Bill Pennington wrote:> 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.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
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:> On Monday 09 January 2006 10:46 pm, Bill Pennington wrote: >> 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. > > 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 > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >- Bill
Bill Pennington wrote:> 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. > > TIAYou 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
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:> Bill Pennington wrote: >> 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 > > 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 > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >- Bill
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:> 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: > > > On Monday 09 January 2006 10:46 pm, Bill Pennington wrote: > >> 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. > > > > 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 > > _______________________________________________ > > Rails mailing list > > 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 >-- - Nic
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 1/10/06, Nic Werner <nicwerner@gmail.com> wrote:> > 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: > > 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: > > > > > On Monday 09 January 2006 10:46 pm, Bill Pennington wrote: > > >> 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. > > > > > > 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 > > > _______________________________________________ > > > Rails mailing list > > > 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 > > > > > -- > - Nic > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060110/76c0b31d/attachment.html
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> > On Jan 9, 2006, at 9:34 PM, Jesse Farmer wrote: > > Bill Pennington wrote: > >> 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 > > > > 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 > > _______________________________________________ > > Rails mailing list > > 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.